Skip to content

Commit

Permalink
feat: add TrieCommitInterval configuration, commit trie every TrieCom…
Browse files Browse the repository at this point in the history
…mitInterval blocks. (#45)

* try

* add TrieCommitInterval into ethconfig

---------

Co-authored-by: Welkin <[email protected]>
  • Loading branch information
welkin22 and Welkin authored Jan 5, 2024
1 parent 95d5458 commit 99f8289
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 89 deletions.
4 changes: 3 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ type CacheConfig struct {

SnapshotNoBuild bool // Whether the background generation is allowed
SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it

TrieCommitInterval uint64 // Define a block height interval, commit trie every TrieCommitInterval block height.
}

// defaultCacheConfig are the default caching values if none are specified by the
Expand Down Expand Up @@ -1424,7 +1426,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
chosen := current - bc.cacheConfig.TriesInMemory
flushInterval := time.Duration(atomic.LoadInt64(&bc.flushInterval))
// If we exceeded time allowance, flush an entire trie to disk
if bc.gcproc > flushInterval {
if bc.gcproc > flushInterval || (bc.cacheConfig.TrieCommitInterval != 0 && chosen%bc.cacheConfig.TrieCommitInterval == 0) {
// If the header is missing (canonical chain behind), we're reorging a low
// diff sidechain. Suspend committing until this operation is completed.
header := bc.GetHeaderByNumber(chosen)
Expand Down
1 change: 1 addition & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
TriesInMemory: config.TriesInMemory,
SnapshotLimit: config.SnapshotCache,
Preimages: config.Preimages,
TrieCommitInterval: config.TrieCommitInterval,
}
)
// Override the chain config with provided settings.
Expand Down
2 changes: 2 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var Defaults = Config{
TrieDirtyCache: 256,
TrieTimeout: 60 * time.Minute,
TriesInMemory: 128,
TrieCommitInterval: 0,
SnapshotCache: 102,
FilterLogCacheSize: 32,
Miner: miner.DefaultConfig,
Expand Down Expand Up @@ -168,6 +169,7 @@ type Config struct {
TrieDirtyCache int
TrieTimeout time.Duration
TriesInMemory uint64 // How many tries keeps in memory
TrieCommitInterval uint64 // Define a block height interval, commit trie every TrieCommitInterval block height.
SnapshotCache int
Preimages bool

Expand Down
225 changes: 137 additions & 88 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 99f8289

Please sign in to comment.