diff --git a/core/blockchain.go b/core/blockchain.go index 9e7affa910..ba54f023de 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1393,7 +1393,7 @@ func (bc *BlockChain) Stop() { if !bc.cacheConfig.TrieDirtyDisabled { triedb := bc.triedb var once sync.Once - for _, offset := range []uint64{0, 1, TriesInMemory - 1} { + for _, offset := range []uint64{0, 1, bc.TriesInMemory() - 1} { if number := bc.CurrentBlock().Number.Uint64(); number > offset { recent := bc.GetBlockByNumber(number - offset) log.Info("Writing cached state to disk", "block", recent.Number(), "hash", recent.Hash(), "root", recent.Root()) @@ -1801,6 +1801,12 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. if err := blockBatch.Write(); err != nil { log.Crit("Failed to write block into disk", "err", err) } + bc.hc.tdCache.Add(block.Hash(), externTd) + bc.blockCache.Add(block.Hash(), block) + bc.receiptsCache.Add(block.Hash(), receipts) + if bc.chainConfig.IsCancun(block.Number(), block.Time()) { + bc.sidecarsCache.Add(block.Hash(), block.Sidecars()) + } wg.Done() }() @@ -1825,7 +1831,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. // Flush limits are not considered for the first TriesInMemory blocks. current := block.NumberU64() - if current <= TriesInMemory { + if current <= bc.TriesInMemory() { return nil } // If we exceeded our memory allowance, flush matured singleton nodes to disk diff --git a/miner/bid_simulator.go b/miner/bid_simulator.go index 0dca51d20e..c28d357063 100644 --- a/miner/bid_simulator.go +++ b/miner/bid_simulator.go @@ -409,7 +409,7 @@ func (b *bidSimulator) clearLoop() { } delete(b.bestBid, parentHash) for k, v := range b.bestBid { - if v.bid.BlockNumber <= blockNumber-core.TriesInMemory { + if v.bid.BlockNumber <= blockNumber-b.chain.TriesInMemory() { v.env.discard() delete(b.bestBid, k) } @@ -418,7 +418,7 @@ func (b *bidSimulator) clearLoop() { b.simBidMu.Lock() for k, v := range b.simulatingBid { - if v.bid.BlockNumber <= blockNumber-core.TriesInMemory { + if v.bid.BlockNumber <= blockNumber-b.chain.TriesInMemory() { v.env.discard() delete(b.simulatingBid, k) }