From f4dc8c58f22fa16507dba1f9a6e8c2cae2112f99 Mon Sep 17 00:00:00 2001 From: Cara Wang Date: Thu, 5 Sep 2024 21:19:16 +0800 Subject: [PATCH] triedb/pathdb: enlarge maxDiffLayers and TrieInMemory to 512 --- core/blockchain.go | 6 +++--- core/blockchain_diff_test.go | 2 +- core/blockchain_test.go | 22 +++++++++++----------- triedb/pathdb/database.go | 2 +- triedb/pathdb/database_test.go | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index da5c93c5c0..1cfb5b361a 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -118,7 +118,7 @@ const ( maxBadBlockLimit = 16 maxFutureBlocks = 256 maxTimeFutureBlocks = 30 - TriesInMemory = 128 + TriesInMemory = 512 maxBeyondBlocks = 2048 prefetchTxNumber = 100 @@ -209,7 +209,7 @@ var defaultCacheConfig = &CacheConfig{ TrieDirtyLimit: 256, TrieTimeLimit: 5 * time.Minute, SnapshotLimit: 256, - TriesInMemory: 128, + TriesInMemory: 512, SnapshotWait: true, StateScheme: rawdb.HashScheme, } @@ -334,7 +334,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis if cacheConfig == nil { cacheConfig = defaultCacheConfig } - if cacheConfig.StateScheme == rawdb.HashScheme && cacheConfig.TriesInMemory != 128 { + if cacheConfig.StateScheme == rawdb.HashScheme && cacheConfig.TriesInMemory != TriesInMemory { log.Warn("TriesInMemory isn't the default value (128), you need specify the same TriesInMemory when pruning data", "triesInMemory", cacheConfig.TriesInMemory, "scheme", cacheConfig.StateScheme) } diff --git a/core/blockchain_diff_test.go b/core/blockchain_diff_test.go index 8ec14bce43..7b5291afbc 100644 --- a/core/blockchain_diff_test.go +++ b/core/blockchain_diff_test.go @@ -230,7 +230,7 @@ func (b *testBackend) close() { func (b *testBackend) Chain() *BlockChain { return b.chain } func TestFreezeDiffLayer(t *testing.T) { - blockNum := 1024 + blockNum := 2048 fullBackend := newTestBackend(blockNum, true) defer fullBackend.close() for len(fullBackend.chain.diffQueueBuffer) > 0 { diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 3917117b91..6e77a9fcfa 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -54,7 +54,7 @@ var ( forkSeed1 = 2 forkSeed2 = 3 - TestTriesInMemory = 128 + TestTriesInMemory = 512 ) // newCanonical creates a chain database, and injects a deterministic canonical @@ -1952,7 +1952,7 @@ func testLargeReorgTrieGC(t *testing.T, scheme string) { Config: params.TestChainConfig, BaseFee: big.NewInt(params.InitialBaseFee), } - genDb, shared, _ := GenerateChainWithGenesis(genesis, engine, 64, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) }) + genDb, shared, _ := GenerateChainWithGenesis(genesis, engine, 200, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) }) original, _ := GenerateChain(genesis.Config, shared[len(shared)-1], engine, genDb, 2*TriesInMemory, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{2}) }) competitor, _ := GenerateChain(genesis.Config, shared[len(shared)-1], engine, genDb, 2*TriesInMemory+1, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{3}) }) @@ -2161,7 +2161,7 @@ func testLowDiffLongChain(t *testing.T, scheme string) { } // We must use a pretty long chain to ensure that the fork doesn't overtake us // until after at least 128 blocks post tip - genDb, blocks, _ := GenerateChainWithGenesis(genesis, engine, 6*TriesInMemory, func(i int, b *BlockGen) { + genDb, blocks, _ := GenerateChainWithGenesis(genesis, engine, TriesInMemory, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) b.OffsetTime(-9) }) @@ -2181,7 +2181,7 @@ func testLowDiffLongChain(t *testing.T, scheme string) { } // Generate fork chain, starting from an early block parent := blocks[10] - fork, _ := GenerateChain(genesis.Config, parent, engine, genDb, 8*TriesInMemory, func(i int, b *BlockGen) { + fork, _ := GenerateChain(genesis.Config, parent, engine, genDb, 2*TriesInMemory, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{2}) }) @@ -2225,7 +2225,7 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon gspec = &Genesis{ Config: &chainConfig, - Alloc: types.GenesisAlloc{addr: {Balance: big.NewInt(math.MaxInt64)}}, + Alloc: types.GenesisAlloc{addr: {Balance: new(big.Int).Mul(big.NewInt(5), big.NewInt(math.MaxInt64))}}, BaseFee: big.NewInt(params.InitialBaseFee), } signer = types.LatestSigner(gspec.Config) @@ -2327,9 +2327,9 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon // [ Cn, Cn+1, Cc, Sn+3 ... Sm] // ^ ^ ^ pruned func TestPrunedImportSide(t *testing.T) { - //glogger := log.NewGlogHandler(log.StreamHandler(os.Stdout, log.TerminalFormat(false))) - //glogger.Verbosity(3) - //log.Root().SetHandler(log.Handler(glogger)) + // glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false)) + // glogger.Verbosity(3) + // log.SetDefault(log.NewLogger(glogger)) testSideImport(t, 3, 3, -1) testSideImport(t, 3, -3, -1) testSideImport(t, 10, 0, -1) @@ -2338,9 +2338,9 @@ func TestPrunedImportSide(t *testing.T) { } func TestPrunedImportSideWithMerging(t *testing.T) { - //glogger := log.NewGlogHandler(log.StreamHandler(os.Stdout, log.TerminalFormat(false))) - //glogger.Verbosity(3) - //log.Root().SetHandler(log.Handler(glogger)) + // glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false)) + // glogger.Verbosity(3) + // log.SetDefault(log.NewLogger(glogger)) testSideImport(t, 3, 3, 0) testSideImport(t, 3, -3, 0) testSideImport(t, 10, 0, 0) diff --git a/triedb/pathdb/database.go b/triedb/pathdb/database.go index f60677fc93..efc15d7667 100644 --- a/triedb/pathdb/database.go +++ b/triedb/pathdb/database.go @@ -38,7 +38,7 @@ import ( const ( // maxDiffLayers is the maximum diff layers allowed in the layer tree. - maxDiffLayers = 128 + maxDiffLayers = 512 // defaultCleanSize is the default memory allowance of clean cache. defaultCleanSize = 16 * 1024 * 1024 diff --git a/triedb/pathdb/database_test.go b/triedb/pathdb/database_test.go index 368f1e5a8f..a758e855be 100644 --- a/triedb/pathdb/database_test.go +++ b/triedb/pathdb/database_test.go @@ -113,7 +113,7 @@ func newTester(t *testing.T, historyLimit uint64) *tester { snapStorages: make(map[common.Hash]map[common.Hash]map[common.Hash][]byte), } ) - for i := 0; i < 2*128; i++ { + for i := 0; i < 2*maxDiffLayers; i++ { var parent = types.EmptyRootHash if len(obj.roots) != 0 { parent = obj.roots[len(obj.roots)-1]