From b1113aa07ee554575be9276b862fd786d1db52be Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi <1591639+s1na@users.noreply.github.com> Date: Tue, 25 Apr 2023 15:15:43 +0200 Subject: [PATCH] eth: fix crash on querying finalized block (#27162) eth: fix crash on querying nil finalized block --- eth/api_backend.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eth/api_backend.go b/eth/api_backend.go index ac160b073..0e4521173 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -134,6 +134,9 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe return nil, errors.New("'finalized' tag not supported on pre-merge network") } header := b.eth.blockchain.CurrentFinalBlock() + if header == nil { + return nil, errors.New("finalized block not found") + } return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil } if number == rpc.SafeBlockNumber { @@ -141,6 +144,9 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe return nil, errors.New("'safe' tag not supported on pre-merge network") } header := b.eth.blockchain.CurrentSafeBlock() + if header == nil { + return nil, errors.New("safe block not found") + } return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil } return b.eth.blockchain.GetBlockByNumber(uint64(number)), nil