Skip to content

Commit

Permalink
update config names and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Brindrajsinh-Chauhan committed May 6, 2024
1 parent f69c24a commit 7db6543
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 53 deletions.
34 changes: 17 additions & 17 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,22 @@ type CacheConfig struct {
SnapshotLimit int // Memory allowance (MB) to use for caching snapshot entries in memory
Preimages bool // Whether to store preimage of trie key to the disk

AllowForceUpdate bool // Enable to force snapshots based on commit counts
SnapRootCommitThreshold int // Number of commits to force a root snapshot
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
AllowForceUpdate bool // Enable to force snapshots based on commit counts
CommitThreshold int // Number of commits to force a root snapshot
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
}

// defaultCacheConfig are the default caching values if none are specified by the
// user (also used during testing).
var defaultCacheConfig = &CacheConfig{
TrieCleanLimit: 256,
TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute,
SnapshotLimit: 256,
SnapshotWait: true,
AllowForceUpdate: false,
SnapRootCommitThreshold: 100,
TrieCleanLimit: 256,
TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute,
SnapshotLimit: 256,
SnapshotWait: true,
AllowForceUpdate: false,
CommitThreshold: 128,
}

// BlockChain represents the canonical chain given a database with a genesis
Expand Down Expand Up @@ -401,12 +401,12 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
recover = true
}
snapconfig := snapshot.Config{
CacheSize: bc.cacheConfig.SnapshotLimit,
Recovery: recover,
NoBuild: bc.cacheConfig.SnapshotNoBuild,
AsyncBuild: !bc.cacheConfig.SnapshotWait,
AllowForceUpdate: bc.cacheConfig.AllowForceUpdate,
SnapRootCommitThreshold: bc.cacheConfig.SnapRootCommitThreshold,
CacheSize: bc.cacheConfig.SnapshotLimit,
Recovery: recover,
NoBuild: bc.cacheConfig.SnapshotNoBuild,
AsyncBuild: !bc.cacheConfig.SnapshotWait,
AllowForceUpdate: bc.cacheConfig.AllowForceUpdate,
CommitThreshold: bc.cacheConfig.CommitThreshold,
}
bc.snaps, _ = snapshot.New(snapconfig, bc.db, bc.triedb, head.Root)
}
Expand Down
2 changes: 1 addition & 1 deletion core/state/snapshot/difflayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var (
bloomStorageHasherOffset = 0

// Count for number of commits before fore disk root update
defaultSnapRootCommitThreshold = 100
defaultCommitThreshold = 128
)

func init() {
Expand Down
41 changes: 25 additions & 16 deletions core/state/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,24 @@ type snapshot interface {

// Config includes the configurations for snapshots.
type Config struct {
CacheSize int // Megabytes permitted to use for read caches
Recovery bool // Indicator that the snapshots is in the recovery mode
NoBuild bool // Indicator that the snapshots generation is disallowed
AsyncBuild bool // The snapshot generation is allowed to be constructed asynchronously
AllowForceUpdate bool // Enable forcing snap root generation on a commit count
SnapRootCommitThreshold int // Number of commit after which to attempt snap root update
CacheSize int // Megabytes permitted to use for read caches
Recovery bool // Indicator that the snapshots is in the recovery mode
NoBuild bool // Indicator that the snapshots generation is disallowed
AsyncBuild bool // The snapshot generation is allowed to be constructed asynchronously
AllowForceUpdate bool // Enable forcing snap root generation on a commit count
CommitThreshold int // Number of commit after which to attempt snap root update
}

// sanitize checks the provided user configurations and changes anything that's
// unreasonable or unworkable.
func (c *Config) sanitize() Config {
conf := *c

if conf.CommitThreshold == 0 {
log.Warn("Sanitizing invalid commit threshold to default", "defaultThreshold", defaultCommitThreshold)
conf.CommitThreshold = defaultCommitThreshold
}
return conf
}

// Tree is an Ethereum state snapshot tree. It consists of one persistent base
Expand Down Expand Up @@ -194,20 +206,17 @@ type Tree struct {
// - otherwise, the entire snapshot is considered invalid and will be recreated on
// a background thread.
func New(config Config, diskdb ethdb.KeyValueStore, triedb *trie.Database, root common.Hash) (*Tree, error) {
// apply default to config and fix invalid values
conf := config.sanitize()

// Create a new, empty snapshot tree
snap := &Tree{
config: config,
config: conf,
diskdb: diskdb,
triedb: triedb,
layers: make(map[common.Hash]snapshot),
}

// Setting the default interval value if it is enabled and not set
// Important to set it to at least default value if enabled to avoid update snap root very aggressively
if config.AllowForceUpdate && (config.SnapRootCommitThreshold == 0) {
snap.config.SnapRootCommitThreshold = defaultSnapRootCommitThreshold
}

// Attempt to load a previously persisted snapshot and rebuild one if failed
head, disabled, err := loadSnapshot(diskdb, triedb, root, config.CacheSize, config.Recovery, config.NoBuild)
if disabled {
Expand Down Expand Up @@ -501,7 +510,7 @@ func (t *Tree) cap(diff *diffLayer, layers int, force bool) *diskLayer {
t.onFlatten()
}
diff.parent = flattened
log.Debug("Validating snapRoot update", "limit", aggregatorMemoryLimit, "currentMemory", flattened.memory, "commitThreshold", t.config.SnapRootCommitThreshold, "forceSnapshot", force)
log.Debug("Validating snapRoot update", "limit", aggregatorMemoryLimit, "currentMemory", flattened.memory, "commitThreshold", t.config.CommitThreshold, "forceSnapshot", force)
if (flattened.memory < aggregatorMemoryLimit) && !force {
// Accumulator layer is smaller than the limit, so we can abort, unless
// there's a snapshot being generated currently. In that case, the trie
Expand Down Expand Up @@ -867,8 +876,8 @@ func (t *Tree) CompareThreshold() bool {
if !t.config.AllowForceUpdate {
return false
}
log.Debug("Commit counters", "counter", t.commitCounter, "threshold", t.config.SnapRootCommitThreshold)
if t.commitCounter > t.config.SnapRootCommitThreshold {
log.Debug("Snapshot Commit counters", "counter", t.commitCounter, "threshold", t.config.CommitThreshold)
if t.commitCounter > t.config.CommitThreshold {
t.commitCounter = 0
return true
}
Expand Down
4 changes: 2 additions & 2 deletions core/state/snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ func TestForceSnapRootCaps(t *testing.T) {
base.root: base,
},
config: Config{
AllowForceUpdate: true,
SnapRootCommitThreshold: 10,
AllowForceUpdate: true,
CommitThreshold: 10,
},
}

Expand Down
22 changes: 11 additions & 11 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,17 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
EnablePreimageRecording: config.EnablePreimageRecording,
}
cacheConfig = &core.CacheConfig{
TrieCleanLimit: config.TrieCleanCache,
TrieCleanJournal: stack.ResolvePath(config.TrieCleanCacheJournal),
TrieCleanRejournal: config.TrieCleanCacheRejournal,
TrieCleanNoPrefetch: config.NoPrefetch,
TrieDirtyLimit: config.TrieDirtyCache,
TrieDirtyDisabled: config.NoPruning,
TrieTimeLimit: config.TrieTimeout,
SnapshotLimit: config.SnapshotCache,
Preimages: config.Preimages,
AllowForceUpdate: config.AllowForceUpdate,
SnapRootCommitThreshold: config.SnapRootCommitThreshold,
TrieCleanLimit: config.TrieCleanCache,
TrieCleanJournal: stack.ResolvePath(config.TrieCleanCacheJournal),
TrieCleanRejournal: config.TrieCleanCacheRejournal,
TrieCleanNoPrefetch: config.NoPrefetch,
TrieDirtyLimit: config.TrieDirtyCache,
TrieDirtyDisabled: config.NoPruning,
TrieTimeLimit: config.TrieTimeout,
SnapshotLimit: config.SnapshotCache,
Preimages: config.Preimages,
AllowForceUpdate: config.AllowForceUpdate,
CommitThreshold: config.CommitThreshold,
}
)
// Override the chain config with provided settings.
Expand Down
2 changes: 1 addition & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ type Config struct {
SnapshotCache int
Preimages bool
AllowForceUpdate bool
SnapRootCommitThreshold int
CommitThreshold int

// This is the number of blocks for which logs will be cached in the filter system.
FilterLogCacheSize int
Expand Down
10 changes: 5 additions & 5 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 7db6543

Please sign in to comment.