Skip to content

Commit

Permalink
l2geth: docall protect nil block (#736)
Browse files Browse the repository at this point in the history
* l2geth: protect nil in eth_call

* chore: add changeset
  • Loading branch information
tynes authored May 3, 2021
1 parent d32d915 commit 20df745
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-hotels-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/l2geth': patch
---

Protect a possible `nil` reference in `eth_call` when the blockchain is empty
16 changes: 9 additions & 7 deletions l2geth/internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 20df745

Please sign in to comment.