Skip to content

Commit

Permalink
eth/api_backend: check nil finalized block in HeaderByNumber (#359)
Browse files Browse the repository at this point in the history
This commit adds nil check for finalized block before getting the header in
HeaderByNumber.
  • Loading branch information
minh-bq authored Oct 2, 2023
1 parent 7a0fdd4 commit b968f44
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb
return b.eth.blockchain.CurrentBlock().Header(), nil
}
if number == rpc.FinalizedBlockNumber {
return b.eth.blockchain.FinalizedBlock().Header(), nil
finalizedBlock := b.eth.blockchain.FinalizedBlock()
if finalizedBlock != nil {
return finalizedBlock.Header(), nil
} else {
return nil, errors.New("header not found")
}
}

return b.eth.blockchain.GetHeaderByNumber(uint64(number)), nil
Expand Down

0 comments on commit b968f44

Please sign in to comment.