@@ -45,6 +45,7 @@ import (
45
45
"github.com/ethereum/go-ethereum/ethdb"
46
46
"github.com/ethereum/go-ethereum/params"
47
47
"github.com/ethereum/go-ethereum/trie"
48
+ "github.com/ethereum/go-ethereum/triedb/pathdb"
48
49
"github.com/holiman/uint256"
49
50
)
50
51
54
55
forkSeed1 = 2
55
56
forkSeed2 = 3
56
57
57
- TestTriesInMemory = 128
58
+ TestTriesInMemory = 128
59
+ TestMaxDiffLayers = pathdb .MaxDiffLayers
60
+ TestAdditionalLayers = 128
58
61
)
59
62
60
63
// newCanonical creates a chain database, and injects a deterministic canonical
@@ -1953,8 +1956,8 @@ func testLargeReorgTrieGC(t *testing.T, scheme string) {
1953
1956
BaseFee : big .NewInt (params .InitialBaseFee ),
1954
1957
}
1955
1958
genDb , shared , _ := GenerateChainWithGenesis (genesis , engine , 64 , func (i int , b * BlockGen ) { b .SetCoinbase (common.Address {1 }) })
1956
- original , _ := GenerateChain (genesis .Config , shared [len (shared )- 1 ], engine , genDb , 2 * TriesInMemory , func (i int , b * BlockGen ) { b .SetCoinbase (common.Address {2 }) })
1957
- competitor , _ := GenerateChain (genesis .Config , shared [len (shared )- 1 ], engine , genDb , 2 * TriesInMemory + 1 , func (i int , b * BlockGen ) { b .SetCoinbase (common.Address {3 }) })
1959
+ original , _ := GenerateChain (genesis .Config , shared [len (shared )- 1 ], engine , genDb , TestMaxDiffLayers + TestAdditionalLayers , func (i int , b * BlockGen ) { b .SetCoinbase (common.Address {2 }) })
1960
+ competitor , _ := GenerateChain (genesis .Config , shared [len (shared )- 1 ], engine , genDb , TestMaxDiffLayers + TestAdditionalLayers + 1 , func (i int , b * BlockGen ) { b .SetCoinbase (common.Address {3 }) })
1958
1961
1959
1962
// Import the shared chain and the original canonical one
1960
1963
db , _ := rawdb .NewDatabaseWithFreezer (rawdb .NewMemoryDatabase (), t .TempDir (), "" , false , false , false , false , false )
@@ -1991,11 +1994,11 @@ func testLargeReorgTrieGC(t *testing.T, scheme string) {
1991
1994
if _ , err := chain .InsertChain (competitor [len (competitor )- 2 :]); err != nil {
1992
1995
t .Fatalf ("failed to finalize competitor chain: %v" , err )
1993
1996
}
1994
- // In path-based trie database implementation, it will keep 128 diff + 1 disk
1995
- // layers, totally 129 latest states available. In hash-based it's 128.
1997
+ // In path-based trie database implementation, it will keep maxDiffLayers diff + 1 disk
1998
+ // layers, totally maxDiffLayers+1 latest states available. In hash-based it's 128.
1996
1999
states := TestTriesInMemory
1997
2000
if scheme == rawdb .PathScheme {
1998
- states = states + 1
2001
+ states = TestMaxDiffLayers + 1
1999
2002
}
2000
2003
for i , block := range competitor [:len (competitor )- states ] {
2001
2004
if chain .HasState (block .Root ()) {
@@ -2936,7 +2939,7 @@ func testSideImportPrunedBlocks(t *testing.T, scheme string) {
2936
2939
BaseFee : big .NewInt (params .InitialBaseFee ),
2937
2940
}
2938
2941
// Generate and import the canonical chain
2939
- _ , blocks , _ := GenerateChainWithGenesis (genesis , engine , 2 * TriesInMemory , nil )
2942
+ _ , blocks , _ := GenerateChainWithGenesis (genesis , engine , TestMaxDiffLayers + TestAdditionalLayers , nil )
2940
2943
2941
2944
chain , err := NewBlockChain (rawdb .NewMemoryDatabase (), DefaultCacheConfigWithScheme (scheme ), genesis , nil , engine , vm.Config {}, nil , nil )
2942
2945
if err != nil {
@@ -2947,11 +2950,11 @@ func testSideImportPrunedBlocks(t *testing.T, scheme string) {
2947
2950
if n , err := chain .InsertChain (blocks ); err != nil {
2948
2951
t .Fatalf ("block %d: failed to insert into chain: %v" , n , err )
2949
2952
}
2950
- // In path-based trie database implementation, it will keep 128 diff + 1 disk
2951
- // layers, totally 129 latest states available. In hash-based it's 128.
2953
+ // In path-based trie database implementation, it will keep maxDiffLayers diff + 1 disk
2954
+ // layers, totally maxDiffLayers+1 latest states available. In hash-based it's 128.
2952
2955
states := TestTriesInMemory
2953
2956
if scheme == rawdb .PathScheme {
2954
- states = TestTriesInMemory + 1
2957
+ states = TestMaxDiffLayers + 1
2955
2958
}
2956
2959
lastPrunedIndex := len (blocks ) - states - 1
2957
2960
lastPrunedBlock := blocks [lastPrunedIndex ]
0 commit comments