Skip to content

Commit

Permalink
core, light: handle the nil return value of GetBlockNumber, fix Xin…
Browse files Browse the repository at this point in the history
  • Loading branch information
JukLee0ira committed Jan 23, 2025
1 parent bc2f68d commit 1972914
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion light/lightchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 1972914

Please sign in to comment.