Skip to content

Commit

Permalink
Fix panic on getting safe block
Browse files Browse the repository at this point in the history
Since bor doesn't have "safe" block, the api should always return null when requested safe block.
  • Loading branch information
cffls committed Oct 8, 2024
1 parent 7e3018a commit c94dd19
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
if number == rpc.SafeBlockNumber {
header := b.eth.blockchain.CurrentSafeBlock()

return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
if header == nil {
return nil, errors.New("safe block not found")
} else {
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
}
}

return b.eth.blockchain.GetBlockByNumber(uint64(number)), nil
Expand Down
5 changes: 5 additions & 0 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,11 @@ func TestRPCGetBlockOrHeader(t *testing.T) {
fullTx: true,
file: "hash-pending-fullTx",
},
// 26. safe block
{
blockNumber: rpc.SafeBlockNumber,
file: "tag-safe",
},
}

for i, tt := range testSuite {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null

0 comments on commit c94dd19

Please sign in to comment.