Skip to content

Commit

Permalink
Add cache config options for trie db and snapshot (ava-labs#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbuchwald authored Oct 20, 2022
1 parent 73bb000 commit d3b10d2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
17 changes: 3 additions & 14 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,6 @@ func New(
if chainDb == nil {
return nil, errors.New("chainDb cannot be nil")
}
if !config.Pruning && config.TrieDirtyCache > 0 {
// If snapshots are enabled, allocate 2/5 of the TrieDirtyCache memory cap to the snapshot cache
if config.SnapshotCache > 0 {
config.TrieCleanCache += config.TrieDirtyCache * 3 / 5
config.SnapshotCache += config.TrieDirtyCache * 2 / 5
} else {
// If snapshots are disabled, the TrieDirtyCache will be written through to the clean cache
// so move the cache allocation from the dirty cache to the clean cache
config.TrieCleanCache += config.TrieDirtyCache
config.TrieDirtyCache = 0
}
}

// round TrieCleanCache and SnapshotCache up to nearest 64MB, since fastcache will mmap
// memory in 64MBs chunks.
Expand All @@ -145,8 +133,9 @@ func New(

log.Info(
"Allocated trie memory caches",
"clean", common.StorageSize(config.TrieCleanCache)*1024*1024,
"dirty", common.StorageSize(config.TrieDirtyCache)*1024*1024,
"trie clean", common.StorageSize(config.TrieCleanCache)*1024*1024,
"trie dirty", common.StorageSize(config.TrieDirtyCache)*1024*1024,
"snapshot clean", common.StorageSize(config.SnapshotCache)*1024*1024,
)

chainConfig, genesisErr := core.SetupGenesisBlock(chainDb, config.Genesis, lastAcceptedHash)
Expand Down
4 changes: 2 additions & 2 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func NewDefaultConfig() Config {
LightPeers: 100,
UltraLightFraction: 75,
DatabaseCache: 512,
TrieCleanCache: 256,
TrieCleanCache: 512,
TrieDirtyCache: 256,
TrieDirtyCommitTarget: 20,
SnapshotCache: 128,
SnapshotCache: 256,
Miner: miner.Config{},
TxPool: core.DefaultTxPoolConfig,
RPCGasCap: 25000000,
Expand Down
14 changes: 14 additions & 0 deletions plugin/evm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const (
defaultAcceptorQueueLimit = 64 // Provides 2 minutes of buffer (2s block target) for a commit delay
defaultPruningEnabled = true
defaultCommitInterval = 4096
defaultTrieCleanCache = 512
defaultTrieDirtyCache = 256
defaultTrieDirtyCommitTarget = 20
defaultSnapshotCache = 256
defaultSyncableCommitInterval = defaultCommitInterval * 4
defaultSnapshotAsync = true
defaultRpcGasCap = 50_000_000 // Default to 50M Gas Limit
Expand Down Expand Up @@ -85,6 +89,12 @@ type Config struct {
RPCGasCap uint64 `json:"rpc-gas-cap"`
RPCTxFeeCap float64 `json:"rpc-tx-fee-cap"`

// Cache settings
TrieCleanCache int `json:"trie-clean-cache"` // Size of the trie clean cache (MB)
TrieDirtyCache int `json:"trie-dirty-cache"` // Size of the trie dirty cache (MB)
TrieDirtyCommitTarget int `json:"trie-dirty-commit-target"` // Memory limit to target in the dirty cache before performing a commit (MB)
SnapshotCache int `json:"snapshot-cache"` // Size of the snapshot disk layer clean cache (MB)

// Eth Settings
Preimages bool `json:"preimages-enabled"`
SnapshotAsync bool `json:"snapshot-async"`
Expand Down Expand Up @@ -170,6 +180,10 @@ func (c *Config) SetDefaults() {
c.ContinuousProfilerFrequency.Duration = defaultContinuousProfilerFrequency
c.ContinuousProfilerMaxFiles = defaultContinuousProfilerMaxFiles
c.Pruning = defaultPruningEnabled
c.TrieCleanCache = defaultTrieCleanCache
c.TrieDirtyCache = defaultTrieDirtyCache
c.TrieDirtyCommitTarget = defaultTrieDirtyCommitTarget
c.SnapshotCache = defaultSnapshotCache
c.AcceptorQueueLimit = defaultAcceptorQueueLimit
c.CommitInterval = defaultCommitInterval
c.SnapshotAsync = defaultSnapshotAsync
Expand Down
4 changes: 4 additions & 0 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ func (vm *VM) Initialize(
vm.ethConfig.AllowUnprotectedTxs = vm.config.AllowUnprotectedTxs
vm.ethConfig.Preimages = vm.config.Preimages
vm.ethConfig.Pruning = vm.config.Pruning
vm.ethConfig.TrieCleanCache = vm.config.TrieCleanCache
vm.ethConfig.TrieDirtyCache = vm.config.TrieDirtyCache
vm.ethConfig.TrieDirtyCommitTarget = vm.config.TrieDirtyCommitTarget
vm.ethConfig.SnapshotCache = vm.config.SnapshotCache
vm.ethConfig.AcceptorQueueLimit = vm.config.AcceptorQueueLimit
vm.ethConfig.PopulateMissingTries = vm.config.PopulateMissingTries
vm.ethConfig.PopulateMissingTriesParallelism = vm.config.PopulateMissingTriesParallelism
Expand Down

0 comments on commit d3b10d2

Please sign in to comment.