Skip to content

Commit 494b0a5

Browse files
committed
commit oldest in-memory trie on shutdown
1 parent 6e88a28 commit 494b0a5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

core/blockchain.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"io"
24+
"math"
2425
"math/big"
2526
"sort"
2627
"sync"
@@ -883,9 +884,15 @@ func (bc *BlockChain) Stop() {
883884
if !bc.cacheConfig.TrieDirtyDisabled {
884885
triedb := bc.stateCache.TrieDB()
885886

886-
for _, offset := range []uint64{0, 1, bc.cacheConfig.TriesInMemory - 1} {
887+
for _, offset := range []uint64{0, 1, math.MaxUint64} {
887888
if number := bc.CurrentBlock().NumberU64(); number > offset {
888-
recent := bc.GetBlockByNumber(number - offset)
889+
var recent *types.Block
890+
if offset == math.MaxUint {
891+
_, latest := bc.triegc.Peek()
892+
recent = bc.GetBlockByNumber(uint64(-latest))
893+
} else {
894+
recent = bc.GetBlockByNumber(number - offset)
895+
}
889896
if recent.Root() == (common.Hash{}) {
890897
continue
891898
}

0 commit comments

Comments
 (0)