Skip to content

Commit

Permalink
core: get header from block cache (ethereum#23299)
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na authored and Martin committed Aug 28, 2021
1 parent 1415923 commit 4518808
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/blockchain.go
Expand Up @@ -2417,12 +2417,22 @@ func (bc *BlockChain) GetTdByHash(hash common.Hash) *big.Int {
// GetHeader retrieves a block header from the database by hash and number,
// caching it if found.
func (bc *BlockChain) GetHeader(hash common.Hash, number uint64) *types.Header {
// Blockchain might have cached the whole block, only if not go to headerchain
if block, ok := bc.blockCache.Get(hash); ok {
return block.(*types.Block).Header()
}

return bc.hc.GetHeader(hash, number)
}

// GetHeaderByHash retrieves a block header from the database by hash, caching it if
// found.
func (bc *BlockChain) GetHeaderByHash(hash common.Hash) *types.Header {
// Blockchain might have cached the whole block, only if not go to headerchain
if block, ok := bc.blockCache.Get(hash); ok {
return block.(*types.Block).Header()
}

return bc.hc.GetHeaderByHash(hash)
}

Expand Down

0 comments on commit 4518808

Please sign in to comment.