@@ -197,6 +197,7 @@ func (c *CacheConfig) triedbConfig(isVerkle bool) *triedb.Config {
197197 StateHistory : c .StateHistory ,
198198 CleanCacheSize : c .TrieCleanLimit * 1024 * 1024 ,
199199 WriteBufferSize : c .TrieDirtyLimit * 1024 * 1024 ,
200+ MaxDiffLayers : c .TriesInMemory ,
200201 }
201202 }
202203 return config
@@ -577,7 +578,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
577578// NewParallelBlockChain , similar to NewBlockChain, creates a new blockchain object, but with a parallel state processor
578579func NewParallelBlockChain (db ethdb.Database , cacheConfig * CacheConfig , genesis * Genesis , overrides * ChainOverrides , engine consensus.Engine , vmConfig vm.Config , shouldPreserve func (header * types.Header ) bool , txLookupLimit * uint64 , checker ethereum.ChainValidator , numprocs int , enforce bool ) (* BlockChain , error ) {
579580 bc , err := NewBlockChain (db , cacheConfig , genesis , overrides , engine , vmConfig , shouldPreserve , txLookupLimit , checker )
580-
581581 if err != nil {
582582 return nil , err
583583 }
@@ -1475,7 +1475,7 @@ func (bc *BlockChain) Stop() {
14751475 if ! bc .cacheConfig .TrieDirtyDisabled {
14761476 triedb := bc .triedb
14771477
1478- for _ , offset := range []uint64 {0 , 1 , state .TriesInMemory - 1 } {
1478+ for _ , offset := range []uint64 {0 , 1 , bc . cacheConfig .TriesInMemory - 1 } {
14791479 if number := bc .CurrentBlock ().Number .Uint64 (); number > offset {
14801480 recent := bc .GetBlockByNumber (number - offset )
14811481
@@ -1710,9 +1710,10 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
17101710 }
17111711
17121712 // Delete block data from the main database.
1713- var (
1714- canonHashes = make (map [common.Hash ]struct {}, len (blockChain ))
1715- )
1713+ var (
1714+ canonHashes = make (map [common.Hash ]struct {}, len (blockChain ))
1715+ )
1716+
17161717 batch = bc .db .NewBatch ()
17171718 for _ , block := range blockChain {
17181719 canonHashes [block .Hash ()] = struct {}{}
@@ -1954,7 +1955,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
19541955
19551956 // Flush limits are not considered for the first TriesInMemory blocks.
19561957 current := block .NumberU64 ()
1957- if current <= state .TriesInMemory {
1958+ if current <= bc . cacheConfig .TriesInMemory {
19581959 return []* types.Log {}, nil
19591960 }
19601961 // If we exceeded our memory allowance, flush matured singleton nodes to disk
@@ -1967,7 +1968,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
19671968 _ = bc .triedb .Cap (limit - ethdb .IdealBatchSize )
19681969 }
19691970 // Find the next state trie we need to commit
1970- chosen := current - state .TriesInMemory
1971+ chosen := current - bc . cacheConfig .TriesInMemory
19711972 flushInterval := time .Duration (bc .flushInterval .Load ())
19721973 // If we exceeded time allowance, flush an entire trie to disk
19731974 if bc .gcproc > flushInterval {
@@ -1979,8 +1980,8 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
19791980 } else {
19801981 // If we're exceeding limits but haven't reached a large enough memory gap,
19811982 // warn the user that the system is becoming unstable.
1982- if chosen < bc .lastWrite + state .TriesInMemory && bc .gcproc >= 2 * flushInterval {
1983- log .Info ("State in memory for too long, committing" , "time" , bc .gcproc , "allowance" , flushInterval , "optimum" , float64 (chosen - bc .lastWrite )/ state . TriesInMemory )
1983+ if chosen < bc .lastWrite + bc . cacheConfig .TriesInMemory && bc .gcproc >= 2 * flushInterval {
1984+ log .Info ("State in memory for too long, committing" , "time" , bc .gcproc , "allowance" , flushInterval , "optimum" , float64 (chosen - bc .lastWrite )/ float64 ( bc . cacheConfig . TriesInMemory ) )
19841985 }
19851986 // Flush an entire trie and restart the counters
19861987 _ = bc .triedb .Commit (header .Root , true )
0 commit comments