Add Backend interface function PrepareTx

This commit is contained in:
Tony Chen 2025-04-22 23:00:24 +08:00
parent efb469c635
commit 83bf13b0b7
3 changed files with 12 additions and 0 deletions

View file

@ -418,3 +418,7 @@ func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Blo
func (b *EthAPIBackend) GetCustomPrecompiles(int64) map[common.Address]vm.PrecompiledContract {
return nil
}
func (b *EthAPIBackend) PrepareTx(statedb vm.StateDB, tx *types.Transaction) error {
return nil
}

View file

@ -90,6 +90,7 @@ type Backend interface {
StateAtBlock(ctx context.Context, block *types.Block, reexec uint64, base vm.StateDB, readOnly bool, preferDisk bool) (vm.StateDB, StateReleaseFunc, error)
StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (*types.Transaction, vm.BlockContext, vm.StateDB, StateReleaseFunc, error)
GetCustomPrecompiles(int64) map[common.Address]vm.PrecompiledContract
PrepareTx(statedb vm.StateDB, tx *types.Transaction) error
}
// API is the collection of tracing APIs exposed over the private debugging endpoint.
@ -1010,6 +1011,9 @@ func (api *API) traceTx(ctx context.Context, tx *types.Transaction, message *cor
// Call Prepare to clear out the statedb access list
statedb.SetTxContext(txctx.TxHash, txctx.TxIndex)
if err := api.backend.PrepareTx(statedb, tx); err != nil {
return nil, err
}
_, err = core.ApplyTransactionWithEVM(message, api.backend.ChainConfig(), new(core.GasPool).AddGas(message.GasLimit), statedb, vmctx.BlockNumber, txctx.BlockHash, tx, &usedGas, vmenv)
if err != nil {
// Due to how our mempool works, a transaction with insufficient funds can be included in a block. For tracing purposes, we should ignore this.

View file

@ -188,6 +188,10 @@ func (b *testBackend) GetCustomPrecompiles(int64) map[common.Address]vm.Precompi
return nil
}
func (b *testBackend) PrepareTx(statedb vm.StateDB, tx *types.Transaction) error {
return nil
}
func TestTraceCall(t *testing.T) {
t.Parallel()