mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
Fix panic on getting safe block
Since bor doesn't have "safe" block, the api should always return null when requested safe block.
This commit is contained in:
parent
2a7c58a616
commit
a7578a3cea
3 changed files with 11 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
1
internal/ethapi/testdata/eth_getBlockByNumber-tag-safe.json
vendored
Normal file
1
internal/ethapi/testdata/eth_getBlockByNumber-tag-safe.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
null
|
||||
Loading…
Reference in a new issue