Skip to content

Commit

Permalink
internal/ethapi: fix simulation + new logging schema
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Oct 11, 2024
1 parent bfb09e7 commit cae550b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions core/state/statedb_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,8 @@ func (s *stateDBLogger) GetTrie() Trie {
func (s *stateDBLogger) AccessEvents() *AccessEvents {
return s.inner.AccessEvents()
}

// Error returns any memorized database failure occurred previously.
func (s *stateDBLogger) Error() error {
return s.inner.Error()
}
3 changes: 3 additions & 0 deletions core/vm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ type StateDB interface {
GetTrie() state.Trie
// AccessEvents returns the access-events collected for verkle-witness processing.
AccessEvents() *state.AccessEvents

// Error returns any memorized database failure occurred previously.
Error() error
}

// CallContext provides a basic interface for the EVM calling conventions. The EVM
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ func applyMessage(ctx context.Context, b Backend, args TransactionArgs, state *s
return applyMessageWithEVM(ctx, evm, msg, state, timeout, gp)
}

func applyMessageWithEVM(ctx context.Context, evm *vm.EVM, msg *core.Message, state *state.StateDB, timeout time.Duration, gp *core.GasPool) (*core.ExecutionResult, error) {
func applyMessageWithEVM(ctx context.Context, evm *vm.EVM, msg *core.Message, state vm.StateDB, timeout time.Duration, gp *core.GasPool) (*core.ExecutionResult, error) {
// Wait for the context to be done and cancel the evm. Even if the
// EVM has finished, cancelling may be done (repeatedly)
go func() {
Expand Down
1 change: 1 addition & 0 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,7 @@ func TestSimulateV1(t *testing.T) {
t.Fatalf("failed to unmarshal result: %v", err)
}
if !reflect.DeepEqual(have, tc.want) {
t.Log(string(resBytes))
t.Errorf("test %s, result mismatch, have\n%v\n, want\n%v\n", tc.name, have, tc.want)
}
})
Expand Down
8 changes: 6 additions & 2 deletions internal/ethapi/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
evm = vm.NewEVM(blockContext, vm.TxContext{GasPrice: new(big.Int)}, sim.state, sim.chainConfig, *vmConfig)
)
sim.state.SetLogger(tracer.Hooks())
logState := vm.StateDB(sim.state.Wrapped())
if logState == nil {
logState = vm.StateDB(sim.state)
}
// It is possible to override precompiles with EVM bytecode, or
// move them to another address.
if precompiles != nil {
Expand All @@ -205,8 +209,8 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
tracer.reset(tx.Hash(), uint(i))
// EoA check is always skipped, even in validation mode.
msg := call.ToMessage(header.BaseFee, !sim.validate, true)
evm.Reset(core.NewEVMTxContext(msg), sim.state)
result, err := applyMessageWithEVM(ctx, evm, msg, sim.state, timeout, sim.gp)
evm.Reset(core.NewEVMTxContext(msg), logState)
result, err := applyMessageWithEVM(ctx, evm, msg, logState, timeout, sim.gp)
if err != nil {
txErr := txValidationError(err)
return nil, nil, txErr
Expand Down

0 comments on commit cae550b

Please sign in to comment.