Skip to content

Commit

Permalink
Uses oldest block in triegc instead of current head of the chain in F…
Browse files Browse the repository at this point in the history
…lushTrieDB
  • Loading branch information
diegoximenes committed Jan 23, 2025
1 parent 300664a commit b39f1fa
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions core/blockchain_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,29 @@ func (bc *BlockChain) FlushTrieDB(advanceBlockChainMutex *sync.Mutex, capLimit c
advanceBlockChainMutex.Lock()
defer advanceBlockChainMutex.Unlock()

err := bc.triedb.Commit(bc.CurrentBlock().Root, true)
if err != nil {
return err
if !bc.triegc.Empty() {
_, triegcBlockNumber := bc.triegc.Peek()
blockNumber := uint64(-triegcBlockNumber)

header := bc.GetHeaderByNumber(blockNumber)
if header == nil {
log.Warn("Reorg in progress, trie commit postponed")
} else {
err := bc.triedb.Commit(header.Root, true)
if err != nil {
return err
}

bc.gcproc = 0
bc.lastWrite = blockNumber
}
}

err = bc.triedb.Cap(capLimit)
err := bc.triedb.Cap(capLimit)
if err != nil {
return err
}

bc.gcproc = 0
bc.lastWrite = bc.CurrentBlock().Number.Uint64()

return nil
}

Expand Down

0 comments on commit b39f1fa

Please sign in to comment.