Skip to content

Commit

Permalink
Fix panics in debug_TraceTransaction (bnb-chain#27)
Browse files Browse the repository at this point in the history
* Make sure L1CostFunc is set on returned context

* Fix panic if HistoricalRPCService is not set

* Can we just return nil?

* Simplify
  • Loading branch information
mdehoog authored and protolambda committed Feb 22, 2023
1 parent c48b8aa commit 28c13bd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion eth/state_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ func (eth *Ethereum) stateAtTransaction(ctx context.Context, block *types.Block,
msg, _ := tx.AsMessage(signer, block.BaseFee())
txContext := core.NewEVMTxContext(msg)
context := core.NewEVMBlockContext(block.Header(), eth.blockchain, nil)
context.L1CostFunc = types.NewL1CostFunc(eth.blockchain.Config(), statedb)
if idx == txIndex {
return msg, context, statedb, release, nil
}
context.L1CostFunc = types.NewL1CostFunc(eth.blockchain.Config(), statedb)
// Not yet the searched for transaction, execute on top of the current state
vmenv := vm.NewEVM(context, txContext, statedb, eth.blockchain.Config(), vm.Config{})
statedb.SetTxContext(tx.Hash(), idx)
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *
if err != nil {
return nil, err
}
if tx == nil {
if tx == nil && api.backend.HistoricalRPCService() != nil {
var histResult []*txTraceResult
err = api.backend.HistoricalRPCService().CallContext(ctx, &histResult, "debug_traceTransaction", hash, config)
if err != nil && err.Error() == "not found" {
Expand Down

0 comments on commit 28c13bd

Please sign in to comment.