Skip to content

Commit

Permalink
Merge branch 'develop' into BEP-341-produce-consecutive-blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBSC committed Jul 23, 2024
2 parents 11488c3 + 6260a26 commit d696b30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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()
}()

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions miner/bid_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit d696b30

Please sign in to comment.