Merge pull request #818 from JukLee0ira/fix-rawdb

core, light: handle the nil return value of `GetBlockNumber`
This commit is contained in:
Daniel Liu 2025-01-23 13:57:56 +08:00 committed by GitHub
commit c3badb4298
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -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

View file

@ -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
}