Skip to content

Commit eef1d24

Browse files
committed
add gcproc initial value randomization
1 parent 084f638 commit eef1d24

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

core/blockchain.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"io"
2424
"math"
2525
"math/big"
26+
"math/rand/v2"
2627
"runtime"
2728
"slices"
2829
"strings"
@@ -160,8 +161,9 @@ type CacheConfig struct {
160161
SnapshotRestoreMaxGas uint64 // Rollback up to this much gas to restore snapshot (otherwise snapshot recalculated from nothing)
161162

162163
// Arbitrum: configure GC window
163-
TriesInMemory uint64 // Height difference before which a trie may not be garbage-collected
164-
TrieRetention time.Duration // Time limit before which a trie may not be garbage-collected
164+
TriesInMemory uint64 // Height difference before which a trie may not be garbage-collected
165+
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)
165167

166168
MaxNumberOfBlocksToSkipStateSaving uint32
167169
MaxAmountOfGasToSkipStateSaving uint64
@@ -203,6 +205,7 @@ var defaultCacheConfig = &CacheConfig{
203205
// Arbitrum Config Options
204206
TriesInMemory: state.DefaultTriesInMemory,
205207
TrieRetention: 30 * time.Minute,
208+
TrieTimeLimitRandomOffset: 0,
206209
MaxNumberOfBlocksToSkipStateSaving: 0,
207210
MaxAmountOfGasToSkipStateSaving: 0,
208211

@@ -376,6 +379,10 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
376379
bc.prefetcher = newStatePrefetcher(chainConfig, bc.hc)
377380
bc.processor = NewStateProcessor(chainConfig, bc.hc)
378381

382+
if cacheConfig.TrieTimeLimitRandomOffset > 0 {
383+
bc.gcproc = time.Duration(rand.Int64N(int64(cacheConfig.TrieTimeLimitRandomOffset)))
384+
}
385+
379386
bc.genesisBlock = bc.GetBlockByNumber(0)
380387
if bc.genesisBlock == nil {
381388
return nil, ErrNoGenesis

0 commit comments

Comments
 (0)