From 05bf7097741526ebee04f626ed6f556dce389b94 Mon Sep 17 00:00:00 2001 From: barryz Date: Wed, 4 Aug 2021 19:08:26 +0800 Subject: [PATCH 1/2] fix: TriesInmemory specified but not work --- cmd/utils/flags.go | 6 ++++++ core/blockchain.go | 3 +++ 2 files changed, 9 insertions(+) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 8197b8ceab..b4d93fc1f1 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1598,6 +1598,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) { cfg.TrieDirtyCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100 } + if ctx.GlobalIsSet(TriesInMemoryFlag.Name) { + cfg.TriesInMemory = ctx.GlobalUint64(TriesInMemoryFlag.Name) + } if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheSnapshotFlag.Name) { cfg.SnapshotCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheSnapshotFlag.Name) / 100 } @@ -1924,6 +1927,9 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) { cache.TrieDirtyLimit = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100 } + if ctx.GlobalIsSet(TriesInMemoryFlag.Name) { + cache.TriesInMemory = ctx.GlobalUint64(TriesInMemoryFlag.Name) + } vmcfg := vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)} // TODO(rjl493456442) disable snapshot generation/wiping if the chain is read only. diff --git a/core/blockchain.go b/core/blockchain.go index 3cc44fc4e5..adbafe38ee 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -217,6 +217,9 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par if cacheConfig == nil { cacheConfig = defaultCacheConfig } + if cacheConfig.TriesInMemory != 128 { + log.Warn("TriesInMemory isn't the default value(128) and may cause system instability", "triesInMemory", cacheConfig.TriesInMemory) + } bodyCache, _ := lru.New(bodyCacheLimit) bodyRLPCache, _ := lru.New(bodyCacheLimit) receiptsCache, _ := lru.New(receiptsCacheLimit) From 3eba529e8d61e9f28619e939148bbe8424fd00cb Mon Sep 17 00:00:00 2001 From: barryz Date: Mon, 9 Aug 2021 09:58:28 +0800 Subject: [PATCH 2/2] change warning log when TriesInMemory isn't default --- core/blockchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/blockchain.go b/core/blockchain.go index adbafe38ee..7a1bd5088b 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -218,7 +218,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par cacheConfig = defaultCacheConfig } if cacheConfig.TriesInMemory != 128 { - log.Warn("TriesInMemory isn't the default value(128) and may cause system instability", "triesInMemory", cacheConfig.TriesInMemory) + log.Warn("TriesInMemory isn't the default value(128), you need specify exact same TriesInMemory when prune data", "triesInMemory", cacheConfig.TriesInMemory) } bodyCache, _ := lru.New(bodyCacheLimit) bodyRLPCache, _ := lru.New(bodyCacheLimit)