Skip to content

Commit

Permalink
fix: the TrieCommitInterval not taking effect on restart (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
welkin22 authored May 7, 2024
1 parent 7acbb10 commit d109de1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,15 @@ func (bc *BlockChain) Stop() {
if !bc.cacheConfig.TrieDirtyDisabled {
triedb := bc.triedb

for _, offset := range []uint64{0, 1, TriesInMemory - 1} {
blockOffsets := []uint64{0, 1, TriesInMemory - 1}
if bc.cacheConfig.TrieCommitInterval != 0 {
current := bc.CurrentBlock().Number.Uint64()
blockShouldCommitOffset := current - current/bc.cacheConfig.TrieCommitInterval*bc.cacheConfig.TrieCommitInterval
if blockShouldCommitOffset > 1 && blockShouldCommitOffset < TriesInMemory-1 {
blockOffsets = append(blockOffsets, blockShouldCommitOffset)
}
}
for _, offset := range blockOffsets {
if number := bc.CurrentBlock().Number.Uint64(); number > offset {
recent := bc.GetBlockByNumber(number - offset)

Expand Down

0 comments on commit d109de1

Please sign in to comment.