diff --git a/core/blockchain.go b/core/blockchain.go index 1631b338c8..358cdcd30f 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -891,7 +891,11 @@ func (bc *BlockChain) GetBlock(hash common.Hash, number uint64) *types.Block { // GetBlockByHash retrieves a block from the database by hash, caching it if found. func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block { - return bc.GetBlock(hash, *bc.hc.GetBlockNumber(hash)) + number := bc.hc.GetBlockNumber(hash) + if number == nil { + return nil + } + return bc.GetBlock(hash, *number) } // GetBlockByNumber retrieves a block from the database by number, caching it diff --git a/light/lightchain.go b/light/lightchain.go index 6a78c6ebb4..02f3210d02 100644 --- a/light/lightchain.go +++ b/light/lightchain.go @@ -218,7 +218,11 @@ func (lc *LightChain) GetBody(ctx context.Context, hash common.Hash) (*types.Bod if cached, ok := lc.bodyCache.Get(hash); ok && cached != nil { return cached, nil } - body, err := GetBody(ctx, lc.odr, hash, *lc.hc.GetBlockNumber(hash)) + number := lc.hc.GetBlockNumber(hash) + if number == nil { + return nil, errors.New("unknown block") + } + body, err := GetBody(ctx, lc.odr, hash, *number) if err != nil { return nil, err }