From b071097d5f9303e79178ad5b93c8f92681ed063c Mon Sep 17 00:00:00 2001 From: Chris Li <271678682li@gmail.com> Date: Mon, 22 Jul 2024 16:17:15 +0800 Subject: [PATCH] Revert "core: avoid to cache block before wroten into db (#2566)" This reverts commit 863fdea026818c976d8bba2a35c2e1ca7f4323da. --- core/blockchain.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index a91b149179..cf55904e68 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -657,6 +657,13 @@ func (bc *BlockChain) cacheDiffLayer(diffLayer *types.DiffLayer, diffLayerCh cha } } +func (bc *BlockChain) cacheBlock(hash common.Hash, block *types.Block) { + bc.blockCache.Add(hash, block) + if bc.chainConfig.IsCancun(block.Number(), block.Time()) { + bc.sidecarsCache.Add(hash, block.Sidecars()) + } +} + // empty returns an indicator whether the blockchain is empty. // Note, it's a special case that we connect a non-empty ancient // database with an empty node, so that we can plugin the ancient @@ -2279,6 +2286,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) vtime := time.Since(vstart) proctime := time.Since(start) // processing + validation + bc.cacheBlock(block.Hash(), block) + // Update the metrics touched during block processing and validation accountReadTimer.Update(statedb.AccountReads) // Account reads are complete(in processing) storageReadTimer.Update(statedb.StorageReads) // Storage reads are complete(in processing)