mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
tidy up after merging v1.11.4
This commit is contained in:
parent
ba8aaf38b9
commit
830ef885c3
4 changed files with 28 additions and 91 deletions
|
|
@ -195,7 +195,11 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
|
|||
return receipt, nil
|
||||
}
|
||||
|
||||
func ApplyTransactionForPreExec(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, msg types.Message, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) {
|
||||
func ApplyTransactionForPreExec(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) {
|
||||
msg, err := TransactionToMessage(tx, types.MakeSigner(config, header.Number), header.BaseFee)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
blockContext := NewEVMBlockContext(header, bc, author)
|
||||
blockContext.BaseFee = big.NewInt(0)
|
||||
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg)
|
||||
|
|
|
|||
|
|
@ -28,65 +28,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
|
||||
<<<<<<< HEAD
|
||||
var emptyCodeHash = crypto.Keccak256Hash(nil)
|
||||
|
||||
// StateTransition represents a state transition.
|
||||
//
|
||||
// == The State Transitioning Model
|
||||
//
|
||||
// A state transition is a change made when a transaction is applied to the current world
|
||||
// state. The state transitioning model does all the necessary work to work out a valid new
|
||||
// state root.
|
||||
//
|
||||
// 1. Nonce handling
|
||||
// 2. Pre pay gas
|
||||
// 3. Create a new state object if the recipient is nil
|
||||
// 4. Value transfer
|
||||
//
|
||||
// == If contract creation ==
|
||||
//
|
||||
// 4a. Attempt to run transaction data
|
||||
// 4b. If valid, use result as code for the new state object
|
||||
//
|
||||
// == end ==
|
||||
//
|
||||
// 5. Run Script section
|
||||
// 6. Derive new state root
|
||||
type StateTransition struct {
|
||||
gp *GasPool
|
||||
msg Message
|
||||
gas uint64
|
||||
gasPrice *big.Int
|
||||
gasFeeCap *big.Int
|
||||
gasTipCap *big.Int
|
||||
initialGas uint64
|
||||
value *big.Int
|
||||
data []byte
|
||||
state vm.StateDB
|
||||
evm *vm.EVM
|
||||
}
|
||||
|
||||
// Message represents a message sent to a contract.
|
||||
type Message interface {
|
||||
From() common.Address
|
||||
To() *common.Address
|
||||
|
||||
GasPrice() *big.Int
|
||||
GasFeeCap() *big.Int
|
||||
GasTipCap() *big.Int
|
||||
Gas() uint64
|
||||
Value() *big.Int
|
||||
|
||||
Nonce() uint64
|
||||
IsFake() bool
|
||||
IsPre() bool
|
||||
Data() []byte
|
||||
AccessList() types.AccessList
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> v1.11.4
|
||||
// ExecutionResult includes all output after executing given evm
|
||||
// message no matter the execution itself is successful or not.
|
||||
type ExecutionResult struct {
|
||||
|
|
@ -199,6 +140,9 @@ type Message struct {
|
|||
// account nonce in state. It also disables checking that the sender is an EOA.
|
||||
// This field will be set to true for operations like RPC eth_call.
|
||||
SkipAccountChecks bool
|
||||
|
||||
// Pre Exec
|
||||
IsPre bool
|
||||
}
|
||||
|
||||
// TransactionToMessage converts a transaction into a Message.
|
||||
|
|
@ -331,18 +275,18 @@ func (st *StateTransition) preCheck() error {
|
|||
|
||||
// pre exec tx not check sender
|
||||
// pre exec for gnosis safe address
|
||||
if !st.msg.IsPre() {
|
||||
// Make sure the sender is an EOA
|
||||
codeHash := st.state.GetCodeHash(msg.From)
|
||||
if codeHash != (common.Hash{}) && codeHash != types.EmptyCodeHash {
|
||||
return fmt.Errorf("%w: address %v, codehash: %s", ErrSenderNoEOA,
|
||||
msg.From.Hex(), codeHash)
|
||||
}
|
||||
if !st.msg.IsPre {
|
||||
// Make sure the sender is an EOA
|
||||
codeHash := st.state.GetCodeHash(msg.From)
|
||||
if codeHash != (common.Hash{}) && codeHash != types.EmptyCodeHash {
|
||||
return fmt.Errorf("%w: address %v, codehash: %s", ErrSenderNoEOA,
|
||||
msg.From.Hex(), codeHash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure that transaction gasFeeCap is greater than the baseFee (post london)
|
||||
if st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) && !st.msg.IsPre() {
|
||||
if st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) && !st.msg.IsPre {
|
||||
// Skip the checks if gas fields are zero and baseFee was explicitly disabled (eth_call)
|
||||
if !st.evm.Config.NoBaseFee || msg.GasFeeCap.BitLen() > 0 || msg.GasTipCap.BitLen() > 0 {
|
||||
if l := msg.GasFeeCap.BitLen(); l > 256 {
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ type PreExecTx struct {
|
|||
type preData struct {
|
||||
block *types.Block
|
||||
tx *types.Transaction
|
||||
msg types.Message
|
||||
msg *core.Message
|
||||
stateDb *state.StateDB
|
||||
header *types.Header
|
||||
}
|
||||
|
|
@ -69,8 +69,7 @@ func NewPreExecAPI(e *Ethereum) *PreExecAPI {
|
|||
return &PreExecAPI{e: e}
|
||||
}
|
||||
|
||||
func (api *PreExecAPI) getBlockAndMsg(origin *PreExecTx, number *big.Int) (*types.Block, types.Message) {
|
||||
fromAddr := common.HexToAddress(origin.From)
|
||||
func (api *PreExecAPI) getBlockAndMsg(origin *PreExecTx, header *types.Header) (*types.Block, *core.Message) {
|
||||
toAddr := common.HexToAddress(origin.To)
|
||||
|
||||
tx := types.NewTx(&types.LegacyTx{
|
||||
|
|
@ -82,23 +81,13 @@ func (api *PreExecAPI) getBlockAndMsg(origin *PreExecTx, number *big.Int) (*type
|
|||
Data: hexutil.MustDecode(origin.Data),
|
||||
})
|
||||
|
||||
number.Add(number, big.NewInt(1))
|
||||
number := big.NewInt(header.Number.Int64() + 1)
|
||||
block := types.NewBlock(
|
||||
&types.Header{Number: number},
|
||||
[]*types.Transaction{tx}, nil, nil, newHash())
|
||||
|
||||
msg := types.NewMessage(
|
||||
fromAddr,
|
||||
&toAddr,
|
||||
hexutil.MustDecodeUint64(origin.Nonce),
|
||||
hexutil.MustDecodeBig(origin.Value),
|
||||
hexutil.MustDecodeUint64(origin.Gas),
|
||||
hexutil.MustDecodeBig(origin.GasPrice),
|
||||
tx.GasFeeCap(),
|
||||
tx.GasTipCap(),
|
||||
hexutil.MustDecode(origin.Data),
|
||||
nil, false, true,
|
||||
)
|
||||
msg, _ := core.TransactionToMessage(tx, types.MakeSigner(api.e.APIBackend.ChainConfig(), header.Number), header.BaseFee)
|
||||
msg.IsPre = true
|
||||
return block, msg
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +107,7 @@ func (api *PreExecAPI) prepareData(ctx context.Context, origin *PreExecTx) (*pre
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
d.block, d.msg = api.getBlockAndMsg(origin, latestNumber)
|
||||
d.block, d.msg = api.getBlockAndMsg(origin, d.header)
|
||||
d.tx = d.block.Transactions()[0]
|
||||
return &d, nil
|
||||
}
|
||||
|
|
@ -136,7 +125,7 @@ func (api *PreExecAPI) GetLogs(ctx context.Context, origin *PreExecTx) (*types.R
|
|||
|
||||
d.stateDb.SetTxContext(d.tx.Hash(), 0)
|
||||
receipt, err := core.ApplyTransactionForPreExec(
|
||||
bc.Config(), bc, nil, gp, d.stateDb, d.header, d.tx, d.msg, &gas, *bc.GetVMConfig())
|
||||
bc.Config(), bc, nil, gp, d.stateDb, d.header, d.tx, &gas, *bc.GetVMConfig())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -167,9 +156,9 @@ func (api *PreExecAPI) TraceTransaction(ctx context.Context, origin *PreExecTx)
|
|||
// Call Prepare to clear out the statedb access list
|
||||
d.stateDb.SetTxContext(d.tx.Hash(), 0)
|
||||
|
||||
tracer.SetMessage(d.block.Number(), d.block.Hash(), d.tx.Hash(), uint(txIndex), d.msg.From(), d.msg.To(), *d.msg.Value())
|
||||
tracer.SetMessage(d.block.Number(), d.block.Hash(), d.tx.Hash(), uint(txIndex), d.msg.From, d.msg.To, *d.msg.Value)
|
||||
|
||||
_, err = core.ApplyMessage(vmenv, d.msg, new(core.GasPool).AddGas(d.msg.Gas()))
|
||||
_, err = core.ApplyMessage(vmenv, d.msg, new(core.GasPool).AddGas(d.msg.GasLimit))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("tracing failed: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,8 +142,8 @@ func ethCallCacheKey(b Backend, blockHash common.Hash, to *common.Address, input
|
|||
return sb.String()
|
||||
}
|
||||
|
||||
func handleNative(ctx context.Context, state *state.StateDB, msg types.Message) ([]byte, int, error) {
|
||||
data := msg.Data()
|
||||
func handleNative(ctx context.Context, state *state.StateDB, msg *core.Message) ([]byte, int, error) {
|
||||
data := msg.Data
|
||||
method, err := erc20ABI.MethodById(data)
|
||||
if err != nil {
|
||||
return nil, errNativeMethodNotFound, err
|
||||
|
|
@ -227,7 +227,7 @@ func doOneCall(ctx context.Context, b Backend, state *state.StateDB, header *typ
|
|||
}
|
||||
|
||||
// skip EVM if requests for native token
|
||||
if strings.ToLower(msg.To().Hex()) == nativeAddr {
|
||||
if strings.ToLower(msg.To.Hex()) == nativeAddr {
|
||||
res, code, err := handleNative(ctx, state, msg)
|
||||
if err != nil {
|
||||
result.Code = code
|
||||
|
|
|
|||
Loading…
Reference in a new issue