Skip to content

Commit

Permalink
triedb/pathdb: enlarge maxDiffLayers and TrieInMemory to 512
Browse files Browse the repository at this point in the history
  • Loading branch information
CaraWang committed Sep 19, 2024
1 parent 9e46b4d commit f4dc8c5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const (
maxBadBlockLimit = 16
maxFutureBlocks = 256
maxTimeFutureBlocks = 30
TriesInMemory = 128
TriesInMemory = 512
maxBeyondBlocks = 2048
prefetchTxNumber = 100

Expand Down Expand Up @@ -209,7 +209,7 @@ var defaultCacheConfig = &CacheConfig{
TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute,
SnapshotLimit: 256,
TriesInMemory: 128,
TriesInMemory: 512,
SnapshotWait: true,
StateScheme: rawdb.HashScheme,
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (
forkSeed1 = 2
forkSeed2 = 3

TestTriesInMemory = 128
TestTriesInMemory = 512
)

// newCanonical creates a chain database, and injects a deterministic canonical
Expand Down Expand Up @@ -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}) })

Expand Down Expand Up @@ -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)
})
Expand All @@ -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})
})

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion triedb/pathdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion triedb/pathdb/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit f4dc8c5

Please sign in to comment.