Commit 20df7459 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

l2geth: docall protect nil block (#736)

* l2geth: protect nil in eth_call

* chore: add changeset
parent d32d9155
---
'@eth-optimism/l2geth': patch
---
Protect a possible `nil` reference in `eth_call` when the blockchain is empty
......@@ -937,14 +937,16 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
if err != nil {
return nil, 0, false, err
}
txs := block.Transactions()
if header.Number.Uint64() != 0 {
if len(txs) != 1 {
return nil, 0, false, fmt.Errorf("block %d has more than 1 transaction", header.Number.Uint64())
if block != nil {
txs := block.Transactions()
if header.Number.Uint64() != 0 {
if len(txs) != 1 {
return nil, 0, false, fmt.Errorf("block %d has more than 1 transaction", header.Number.Uint64())
}
tx := txs[0]
blockNumber = tx.L1BlockNumber()
timestamp = new(big.Int).SetUint64(tx.L1Timestamp())
}
tx := txs[0]
blockNumber = tx.L1BlockNumber()
timestamp = new(big.Int).SetUint64(tx.L1Timestamp())
}
msg, err = core.EncodeSimulatedMessage(msg, timestamp, blockNumber, executionManager, stateManager)
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment