@@ -33,6 +33,7 @@ import (
3333 "github.com/ethereum/go-ethereum/consensus"
3434 "github.com/ethereum/go-ethereum/consensus/beacon"
3535 "github.com/ethereum/go-ethereum/consensus/ethash"
36+ "github.com/ethereum/go-ethereum/core/history"
3637 "github.com/ethereum/go-ethereum/core/rawdb"
3738 "github.com/ethereum/go-ethereum/core/state"
3839 "github.com/ethereum/go-ethereum/core/types"
@@ -4312,13 +4313,7 @@ func testChainReorgSnapSync(t *testing.T, ancientLimit uint64) {
43124313// be persisted without the receipts and bodies; chain after should be persisted
43134314// normally.
43144315func TestInsertChainWithCutoff (t * testing.T ) {
4315- testInsertChainWithCutoff (t , 32 , 32 ) // cutoff = 32, ancientLimit = 32
4316- testInsertChainWithCutoff (t , 32 , 64 ) // cutoff = 32, ancientLimit = 64 (entire chain in ancient)
4317- testInsertChainWithCutoff (t , 32 , 65 ) // cutoff = 32, ancientLimit = 65 (64 blocks in ancient, 1 block in live)
4318- }
4319-
4320- func testInsertChainWithCutoff (t * testing.T , cutoff uint64 , ancientLimit uint64 ) {
4321- // log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelDebug, true)))
4316+ const chainLength = 64
43224317
43234318 // Configure and generate a sample block chain
43244319 var (
@@ -4333,24 +4328,51 @@ func testInsertChainWithCutoff(t *testing.T, cutoff uint64, ancientLimit uint64)
43334328 signer = types .LatestSigner (gspec .Config )
43344329 engine = beacon .New (ethash .NewFaker ())
43354330 )
4336- _ , blocks , receipts := GenerateChainWithGenesis (gspec , engine , int ( 2 * cutoff ) , func (i int , block * BlockGen ) {
4331+ _ , blocks , receipts := GenerateChainWithGenesis (gspec , engine , chainLength , func (i int , block * BlockGen ) {
43374332 block .SetCoinbase (common.Address {0x00 })
4338-
43394333 tx , err := types .SignTx (types .NewTransaction (block .TxNonce (address ), common.Address {0x00 }, big .NewInt (1000 ), params .TxGas , block .header .BaseFee , nil ), signer , key )
43404334 if err != nil {
43414335 panic (err )
43424336 }
43434337 block .AddTx (tx )
43444338 })
4345- db , _ := rawdb .NewDatabaseWithFreezer (rawdb .NewMemoryDatabase (), "" , "" , false )
4346- defer db .Close ()
43474339
4340+ // Run the actual tests.
4341+ t .Run ("cutoff-32/ancientLimit-32" , func (t * testing.T ) {
4342+ // cutoff = 32, ancientLimit = 32
4343+ testInsertChainWithCutoff (t , 32 , 32 , gspec , blocks , receipts )
4344+ })
4345+ t .Run ("cutoff-32/ancientLimit-64" , func (t * testing.T ) {
4346+ // cutoff = 32, ancientLimit = 64 (entire chain in ancient)
4347+ testInsertChainWithCutoff (t , 32 , 64 , gspec , blocks , receipts )
4348+ })
4349+ t .Run ("cutoff-32/ancientLimit-64" , func (t * testing.T ) {
4350+ // cutoff = 32, ancientLimit = 65 (64 blocks in ancient, 1 block in live)
4351+ testInsertChainWithCutoff (t , 32 , 65 , gspec , blocks , receipts )
4352+ })
4353+ }
4354+
4355+ func testInsertChainWithCutoff (t * testing.T , cutoff uint64 , ancientLimit uint64 , genesis * Genesis , blocks []* types.Block , receipts []types.Receipts ) {
4356+ // log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelDebug, true)))
4357+
4358+ // Add a known pruning point for the duration of the test.
4359+ ghash := genesis .ToBlock ().Hash ()
43484360 cutoffBlock := blocks [cutoff - 1 ]
4361+ history .PrunePoints [ghash ] = & history.PrunePoint {
4362+ BlockNumber : cutoffBlock .NumberU64 (),
4363+ BlockHash : cutoffBlock .Hash (),
4364+ }
4365+ defer func () {
4366+ delete (history .PrunePoints , ghash )
4367+ }()
4368+
4369+ // Enable pruning in cache config.
43494370 config := DefaultCacheConfigWithScheme (rawdb .PathScheme )
4350- config .HistoryPruningCutoffNumber = cutoffBlock .NumberU64 ()
4351- config .HistoryPruningCutoffHash = cutoffBlock .Hash ()
4371+ config .ChainHistoryMode = history .KeepPostMerge
43524372
4353- chain , _ := NewBlockChain (db , DefaultCacheConfigWithScheme (rawdb .PathScheme ), gspec , nil , beacon .New (ethash .NewFaker ()), vm.Config {}, nil , nil )
4373+ db , _ := rawdb .NewDatabaseWithFreezer (rawdb .NewMemoryDatabase (), "" , "" , false )
4374+ defer db .Close ()
4375+ chain , _ := NewBlockChain (db , DefaultCacheConfigWithScheme (rawdb .PathScheme ), genesis , nil , beacon .New (ethash .NewFaker ()), vm.Config {}, nil , nil )
43544376 defer chain .Stop ()
43554377
43564378 var (
@@ -4381,8 +4403,8 @@ func testInsertChainWithCutoff(t *testing.T, cutoff uint64, ancientLimit uint64)
43814403 t .Errorf ("head header #%d: header mismatch: want: %v, got: %v" , headHeader .Number , blocks [len (blocks )- 1 ].Hash (), headHeader .Hash ())
43824404 }
43834405 headBlock := chain .CurrentBlock ()
4384- if headBlock .Hash () != gspec . ToBlock (). Hash () {
4385- t .Errorf ("head block #%d: header mismatch: want: %v, got: %v" , headBlock .Number , gspec . ToBlock (). Hash () , headBlock .Hash ())
4406+ if headBlock .Hash () != ghash {
4407+ t .Errorf ("head block #%d: header mismatch: want: %v, got: %v" , headBlock .Number , ghash , headBlock .Hash ())
43864408 }
43874409
43884410 // Iterate over all chain data components, and cross reference
0 commit comments