Skip to content

Commit

Permalink
eth/state, les/state: properly init statedb accesslist when tracing, f…
Browse files Browse the repository at this point in the history
…ixes #22475
  • Loading branch information
holiman committed Mar 11, 2021
1 parent be87f76 commit bd6f954
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions eth/state_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func (eth *Ethereum) stateAtTransaction(block *types.Block, txIndex int, reexec
msg, _ := tx.AsMessage(signer)
txContext := core.NewEVMTxContext(msg)
context := core.NewEVMBlockContext(block.Header(), eth.blockchain, nil)
statedb.Prepare(tx.Hash(), block.Hash(), idx)
if idx == txIndex {
return msg, context, statedb, release, nil
}
Expand Down
9 changes: 8 additions & 1 deletion eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config
// Trace all the transactions contained within
for i, tx := range task.block.Transactions() {
msg, _ := tx.AsMessage(signer)
task.statedb.Prepare(tx.Hash(), task.block.Hash(), i)
res, err := api.traceTx(ctx, msg, blockCtx, task.statedb, config)
if err != nil {
task.results[i] = &txTraceResult{Error: err.Error()}
Expand Down Expand Up @@ -478,13 +479,15 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
threads = len(txs)
}
blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
blockHash := block.Hash()
for th := 0; th < threads; th++ {
pend.Add(1)
go func() {
defer pend.Done()
// Fetch and execute the next transaction trace tasks
for task := range jobs {
msg, _ := txs[task.index].AsMessage(signer)
task.statedb.Prepare(txs[task.index].Hash(), blockHash, task.index)
res, err := api.traceTx(ctx, msg, blockCtx, task.statedb, config)
if err != nil {
results[task.index] = &txTraceResult{Error: err.Error()}
Expand All @@ -503,7 +506,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
// Generate the next state snapshot fast without tracing
msg, _ := tx.AsMessage(signer)
txContext := core.NewEVMTxContext(msg)

statedb.Prepare(tx.Hash(), block.Hash(), i)
vmenv := vm.NewEVM(blockCtx, txContext, statedb, api.backend.ChainConfig(), vm.Config{})
if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil {
failed = err
Expand Down Expand Up @@ -713,6 +716,10 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.CallArgs, blockNrOrHa
// Execute the trace
msg := args.ToMessage(api.backend.RPCGasCap())
vmctx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
// We call Prepare here with dummy values -- since we're doing a call and not
// actually executing a tx, not much else to do. The Prepare call initializes
// a new AccessList.
statedb.Prepare(common.Hash{}, common.Hash{}, 0)
return api.traceTx(ctx, msg, vmctx, statedb, config)
}

Expand Down
1 change: 1 addition & 0 deletions les/state_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (leth *LightEthereum) stateAtTransaction(ctx context.Context, block *types.
msg, _ := tx.AsMessage(signer)
txContext := core.NewEVMTxContext(msg)
context := core.NewEVMBlockContext(block.Header(), leth.blockchain, nil)
statedb.Prepare(tx.Hash(), block.Hash(), idx)
if idx == txIndex {
return msg, context, statedb, func() {}, nil
}
Expand Down

0 comments on commit bd6f954

Please sign in to comment.