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 ...@@ -937,14 +937,16 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
if err != nil { if err != nil {
return nil, 0, false, err return nil, 0, false, err
} }
txs := block.Transactions() if block != nil {
if header.Number.Uint64() != 0 { txs := block.Transactions()
if len(txs) != 1 { if header.Number.Uint64() != 0 {
return nil, 0, false, fmt.Errorf("block %d has more than 1 transaction", header.Number.Uint64()) 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) msg, err = core.EncodeSimulatedMessage(msg, timestamp, blockNumber, executionManager, stateManager)
if err != nil { 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