From a0ae9f85e524609a1fe4172cb4536fc314702e7b Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi <1591639+s1na@users.noreply.github.com> Date: Tue, 3 Aug 2021 17:29:47 +0200 Subject: [PATCH] core: get header from block cache (#23299) --- core/blockchain.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index 48a23da79bd8..e14291aa54c3 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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) }