Skip to content

Commit cae550b

Browse files
committed
internal/ethapi: fix simulation + new logging schema
1 parent bfb09e7 commit cae550b

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

core/state/statedb_logger.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,8 @@ func (s *stateDBLogger) GetTrie() Trie {
251251
func (s *stateDBLogger) AccessEvents() *AccessEvents {
252252
return s.inner.AccessEvents()
253253
}
254+
255+
// Error returns any memorized database failure occurred previously.
256+
func (s *stateDBLogger) Error() error {
257+
return s.inner.Error()
258+
}

core/vm/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ type StateDB interface {
114114
GetTrie() state.Trie
115115
// AccessEvents returns the access-events collected for verkle-witness processing.
116116
AccessEvents() *state.AccessEvents
117+
118+
// Error returns any memorized database failure occurred previously.
119+
Error() error
117120
}
118121

119122
// CallContext provides a basic interface for the EVM calling conventions. The EVM

internal/ethapi/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ func applyMessage(ctx context.Context, b Backend, args TransactionArgs, state *s
12121212
return applyMessageWithEVM(ctx, evm, msg, state, timeout, gp)
12131213
}
12141214

1215-
func applyMessageWithEVM(ctx context.Context, evm *vm.EVM, msg *core.Message, state *state.StateDB, timeout time.Duration, gp *core.GasPool) (*core.ExecutionResult, error) {
1215+
func applyMessageWithEVM(ctx context.Context, evm *vm.EVM, msg *core.Message, state vm.StateDB, timeout time.Duration, gp *core.GasPool) (*core.ExecutionResult, error) {
12161216
// Wait for the context to be done and cancel the evm. Even if the
12171217
// EVM has finished, cancelling may be done (repeatedly)
12181218
go func() {

internal/ethapi/api_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,7 @@ func TestSimulateV1(t *testing.T) {
21952195
t.Fatalf("failed to unmarshal result: %v", err)
21962196
}
21972197
if !reflect.DeepEqual(have, tc.want) {
2198+
t.Log(string(resBytes))
21982199
t.Errorf("test %s, result mismatch, have\n%v\n, want\n%v\n", tc.name, have, tc.want)
21992200
}
22002201
})

internal/ethapi/simulate.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
188188
evm = vm.NewEVM(blockContext, vm.TxContext{GasPrice: new(big.Int)}, sim.state, sim.chainConfig, *vmConfig)
189189
)
190190
sim.state.SetLogger(tracer.Hooks())
191+
logState := vm.StateDB(sim.state.Wrapped())
192+
if logState == nil {
193+
logState = vm.StateDB(sim.state)
194+
}
191195
// It is possible to override precompiles with EVM bytecode, or
192196
// move them to another address.
193197
if precompiles != nil {
@@ -205,8 +209,8 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
205209
tracer.reset(tx.Hash(), uint(i))
206210
// EoA check is always skipped, even in validation mode.
207211
msg := call.ToMessage(header.BaseFee, !sim.validate, true)
208-
evm.Reset(core.NewEVMTxContext(msg), sim.state)
209-
result, err := applyMessageWithEVM(ctx, evm, msg, sim.state, timeout, sim.gp)
212+
evm.Reset(core.NewEVMTxContext(msg), logState)
213+
result, err := applyMessageWithEVM(ctx, evm, msg, logState, timeout, sim.gp)
210214
if err != nil {
211215
txErr := txValidationError(err)
212216
return nil, nil, txErr

0 commit comments

Comments
 (0)