@@ -23,7 +23,6 @@ import (
23
23
"io"
24
24
"math"
25
25
"math/big"
26
- "math/rand/v2"
27
26
"runtime"
28
27
"slices"
29
28
"strings"
@@ -163,7 +162,7 @@ type CacheConfig struct {
163
162
// Arbitrum: configure GC window
164
163
TriesInMemory uint64 // Height difference before which a trie may not be garbage-collected
165
164
TrieRetention time.Duration // Time limit before which a trie may not be garbage-collected
166
- TrieTimeLimitRandomOffset time.Duration // Range of random offset of the commit due to TrieTimeLimit period (randomizes initial gcproc value)
165
+ TrieTimeLimitRandomOffset time.Duration // Range of random offset of each commit due to TrieTimeLimit period
167
166
168
167
MaxNumberOfBlocksToSkipStateSaving uint32
169
168
MaxAmountOfGasToSkipStateSaving uint64
@@ -298,8 +297,10 @@ type BlockChain struct {
298
297
vmConfig vm.Config
299
298
logger * tracing.Hooks
300
299
300
+ // Arbitrum:
301
301
numberOfBlocksToSkipStateSaving uint32
302
302
amountOfGasInBlocksToSkipStateSaving uint64
303
+ gcprocRandOffset time.Duration // random offset for gcproc time
303
304
}
304
305
305
306
type trieGcEntry struct {
@@ -379,9 +380,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
379
380
bc .prefetcher = newStatePrefetcher (chainConfig , bc .hc )
380
381
bc .processor = NewStateProcessor (chainConfig , bc .hc )
381
382
382
- if cacheConfig .TrieTimeLimitRandomOffset > 0 {
383
- bc .gcproc = time .Duration (rand .Int64N (int64 (cacheConfig .TrieTimeLimitRandomOffset )))
384
- }
383
+ bc .gcprocRandOffset = bc .generateGcprocRandOffset ()
385
384
386
385
bc .genesisBlock = bc .GetBlockByNumber (0 )
387
386
if bc .genesisBlock == nil {
@@ -1634,8 +1633,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
1634
1633
}
1635
1634
flushInterval := time .Duration (bc .flushInterval .Load ())
1636
1635
// If we exceeded out time allowance, flush an entire trie to disk
1636
+ // The time threshold can be offset by gcprocRandOffset if TrieTimeLimitRandomOffset > 0; the offset is re-generated after each full trie flush
1637
1637
// In case of archive node that skips some trie commits we don't flush tries here
1638
- if bc .gcproc > flushInterval && prevEntry != nil && ! archiveNode {
1638
+ if bc .gcproc + bc . gcprocRandOffset > flushInterval && prevEntry != nil && ! archiveNode {
1639
1639
// If the header is missing (canonical chain behind), we're reorging a low
1640
1640
// diff sidechain. Suspend committing until this operation is completed.
1641
1641
header := bc .GetHeaderByNumber (prevNum )
@@ -1651,6 +1651,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
1651
1651
bc .triedb .Commit (header .Root , true )
1652
1652
bc .lastWrite = prevNum
1653
1653
bc .gcproc = 0
1654
+ bc .gcprocRandOffset = bc .generateGcprocRandOffset ()
1654
1655
}
1655
1656
}
1656
1657
if prevEntry != nil {
0 commit comments