From 2f7cb0455e1789850ec4c14d152340436b04d5e2 Mon Sep 17 00:00:00 2001 From: Welkin Date: Mon, 16 Oct 2023 13:47:39 +0800 Subject: [PATCH] fix: cache data after successful writing --- core/blockchain.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 2b51883f81..ae83427e10 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1868,14 +1868,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool) vtime := time.Since(vstart) proctime := time.Since(start) // processing + validation - // pre-cache the block and receipts, so that it can be retrieved quickly by rcp - bc.CacheBlock(block.Hash(), block) - err = types.Receipts(receipts).DeriveFields(bc.chainConfig, block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), block.Transactions()) - if err != nil { - log.Warn("Failed to derive receipt fields", "block", block.Hash(), "err", err) - } - bc.CacheReceipts(block.Hash(), receipts) - // 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) @@ -1907,6 +1899,15 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool) if err != nil { return it.index, err } + + // pre-cache the block and receipts, so that it can be retrieved quickly by rcp + bc.CacheBlock(block.Hash(), block) + err = types.Receipts(receipts).DeriveFields(bc.chainConfig, block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), block.Transactions()) + if err != nil { + log.Warn("Failed to derive receipt fields", "block", block.Hash(), "err", err) + } + bc.CacheReceipts(block.Hash(), receipts) + // Update the metrics touched during block commit accountCommitTimer.Update(statedb.AccountCommits) // Account commits are complete, we can mark them storageCommitTimer.Update(statedb.StorageCommits) // Storage commits are complete, we can mark them