diff --git a/core/bench_test.go b/core/bench_test.go index 6e64f558ff..2830022662 100644 --- a/core/bench_test.go +++ b/core/bench_test.go @@ -324,9 +324,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) { genesis := &Genesis{Config: params.AllEthashProtocolChanges} makeChainForBench(db, genesis, full, count) db.Close() - options := *defaultConfig - options.ArchiveMode = true - + options := DefaultConfig().WithArchive(true) b.ReportAllocs() b.ResetTimer() @@ -337,7 +335,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) { } db = rawdb.NewDatabase(pdb) - chain, err := NewBlockChain(db, genesis, ethash.NewFaker(), &options) + chain, err := NewBlockChain(db, genesis, ethash.NewFaker(), options) if err != nil { b.Fatalf("error creating chain: %v", err) } diff --git a/core/block_validator_test.go b/core/block_validator_test.go index 8df0aa4afb..fcc99effd0 100644 --- a/core/block_validator_test.go +++ b/core/block_validator_test.go @@ -49,7 +49,7 @@ func testHeaderVerification(t *testing.T, scheme string) { headers[i] = block.Header() } // Run the header checker for blocks one-by-one, checking for both valid and invalid nonces - options := DefaultBlockChainConfig(scheme) + options := DefaultConfig().WithStateScheme(scheme) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), options) defer chain.Stop() if err != nil { diff --git a/core/blockchain.go b/core/blockchain.go index 0de1d57a7a..386cc52057 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -212,23 +212,30 @@ func (o *BlockChainConfig) triedbConfig(isVerkle bool) *triedb.Config { return config } -// defaultConfig are the default blockchain options if none are specified by the -// user (also used during testing). -var defaultConfig = &BlockChainConfig{ - TrieCleanLimit: 256, - TrieDirtyLimit: 256, - TrieTimeLimit: 5 * time.Minute, - StateScheme: rawdb.HashScheme, - SnapshotLimit: 256, - SnapshotWait: true, - ChainHistoryMode: history.KeepAll, +// DefaultConfig returns the default config. +// Note the returned object is safe to modify! +func DefaultConfig() *BlockChainConfig { + return &BlockChainConfig{ + TrieCleanLimit: 256, + TrieDirtyLimit: 256, + TrieTimeLimit: 5 * time.Minute, + StateScheme: rawdb.HashScheme, + SnapshotLimit: 256, + SnapshotWait: true, + ChainHistoryMode: history.KeepAll, + } } -// DefaultBlockChainConfig returns the default config with a provided state scheme. -func DefaultBlockChainConfig(scheme string) *BlockChainConfig { - config := *defaultConfig - config.StateScheme = scheme - return &config +// WithArchive enabled/disables archive mode on the config. +func (cfg BlockChainConfig) WithArchive(on bool) *BlockChainConfig { + cfg.ArchiveMode = on + return &cfg +} + +// WithStateScheme sets the state storage scheme on the config. +func (cfg BlockChainConfig) WithStateScheme(scheme string) *BlockChainConfig { + cfg.StateScheme = scheme + return &cfg } // txLookup is wrapper over transaction lookup along with the corresponding @@ -312,7 +319,7 @@ type BlockChain struct { // and Processor. func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine, cfg *BlockChainConfig) (*BlockChain, error) { if cfg == nil { - cfg = DefaultBlockChainConfig(rawdb.HashScheme) + cfg = DefaultConfig() } // Open trie database with provided config diff --git a/core/blockchain_repair_test.go b/core/blockchain_repair_test.go index 0c243612fb..ca8a740a98 100644 --- a/core/blockchain_repair_test.go +++ b/core/blockchain_repair_test.go @@ -1931,7 +1931,7 @@ func testIssue23496(t *testing.T, scheme string) { BaseFee: big.NewInt(params.InitialBaseFee), } engine = ethash.NewFullFaker() - options = DefaultBlockChainConfig(scheme) + options = DefaultConfig().WithStateScheme(scheme) ) chain, err := NewBlockChain(db, gspec, engine, options) if err != nil { @@ -1985,7 +1985,7 @@ func testIssue23496(t *testing.T, scheme string) { } defer db.Close() - chain, err = NewBlockChain(db, gspec, engine, DefaultBlockChainConfig(scheme)) + chain, err = NewBlockChain(db, gspec, engine, DefaultConfig().WithStateScheme(scheme)) if err != nil { t.Fatalf("Failed to recreate chain: %v", err) } diff --git a/core/blockchain_snapshot_test.go b/core/blockchain_snapshot_test.go index f5bc28e9ae..44ad8dedec 100644 --- a/core/blockchain_snapshot_test.go +++ b/core/blockchain_snapshot_test.go @@ -81,7 +81,7 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo } engine = ethash.NewFullFaker() ) - chain, err := NewBlockChain(db, gspec, engine, DefaultBlockChainConfig(basic.scheme)) + chain, err := NewBlockChain(db, gspec, engine, DefaultConfig().WithStateScheme(basic.scheme)) if err != nil { t.Fatalf("Failed to create chain: %v", err) } @@ -232,7 +232,7 @@ func (snaptest *snapshotTest) test(t *testing.T) { // Restart the chain normally chain.Stop() - newchain, err := NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, DefaultBlockChainConfig(snaptest.scheme)) + newchain, err := NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, DefaultConfig().WithStateScheme(snaptest.scheme)) if err != nil { t.Fatalf("Failed to recreate chain: %v", err) } @@ -274,13 +274,13 @@ func (snaptest *crashSnapshotTest) test(t *testing.T) { // the crash, we do restart twice here: one after the crash and one // after the normal stop. It's used to ensure the broken snapshot // can be detected all the time. - newchain, err := NewBlockChain(newdb, snaptest.gspec, snaptest.engine, DefaultBlockChainConfig(snaptest.scheme)) + newchain, err := NewBlockChain(newdb, snaptest.gspec, snaptest.engine, DefaultConfig().WithStateScheme(snaptest.scheme)) if err != nil { t.Fatalf("Failed to recreate chain: %v", err) } newchain.Stop() - newchain, err = NewBlockChain(newdb, snaptest.gspec, snaptest.engine, DefaultBlockChainConfig(snaptest.scheme)) + newchain, err = NewBlockChain(newdb, snaptest.gspec, snaptest.engine, DefaultConfig().WithStateScheme(snaptest.scheme)) if err != nil { t.Fatalf("Failed to recreate chain: %v", err) } @@ -325,7 +325,7 @@ func (snaptest *gappedSnapshotTest) test(t *testing.T) { newchain.Stop() // Restart the chain with enabling the snapshot - options = DefaultBlockChainConfig(snaptest.scheme) + options = DefaultConfig().WithStateScheme(snaptest.scheme) newchain, err = NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, options) if err != nil { t.Fatalf("Failed to recreate chain: %v", err) @@ -354,7 +354,7 @@ func (snaptest *setHeadSnapshotTest) test(t *testing.T) { chain.SetHead(snaptest.setHead) chain.Stop() - newchain, err := NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, DefaultBlockChainConfig(snaptest.scheme)) + newchain, err := NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, DefaultConfig().WithStateScheme(snaptest.scheme)) if err != nil { t.Fatalf("Failed to recreate chain: %v", err) } @@ -416,7 +416,7 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) { tmp.triedb.Close() tmp.stopWithoutSaving() - newchain, err = NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, DefaultBlockChainConfig(snaptest.scheme)) + newchain, err = NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, DefaultConfig().WithStateScheme(snaptest.scheme)) if err != nil { t.Fatalf("Failed to recreate chain: %v", err) } diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 4182b8f938..c2e0c0ee1b 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -66,7 +66,7 @@ func newCanonical(engine consensus.Engine, n int, full bool, scheme string) (eth } ) // Initialize a fresh chain with only a genesis block - options := DefaultBlockChainConfig(scheme) + options := DefaultConfig().WithStateScheme(scheme) blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, options) // Create and inject the requested chain @@ -724,7 +724,7 @@ func testFastVsFullChains(t *testing.T, scheme string) { }) // Import the chain as an archive node for the comparison baseline archiveDb := rawdb.NewMemoryDatabase() - archive, _ := NewBlockChain(archiveDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + archive, _ := NewBlockChain(archiveDb, gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) defer archive.Stop() if n, err := archive.InsertChain(blocks); err != nil { @@ -732,7 +732,7 @@ func testFastVsFullChains(t *testing.T, scheme string) { } // Fast import the chain as a non-archive node to test fastDb := rawdb.NewMemoryDatabase() - fast, _ := NewBlockChain(fastDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + fast, _ := NewBlockChain(fastDb, gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) defer fast.Stop() if n, err := fast.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), 0); err != nil { @@ -745,7 +745,7 @@ func testFastVsFullChains(t *testing.T, scheme string) { } defer ancientDb.Close() - ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) defer ancient.Stop() if n, err := ancient.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), uint64(len(blocks)/2)); err != nil { @@ -852,11 +852,8 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) { archiveDb := makeDb() defer archiveDb.Close() - options := *defaultConfig - options.ArchiveMode = true - options.StateScheme = scheme - - archive, _ := NewBlockChain(archiveDb, gspec, ethash.NewFaker(), &options) + options := DefaultConfig().WithArchive(true).WithStateScheme(scheme) + archive, _ := NewBlockChain(archiveDb, gspec, ethash.NewFaker(), options) if n, err := archive.InsertChain(blocks); err != nil { t.Fatalf("failed to process block %d: %v", n, err) } @@ -869,7 +866,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) { // Import the chain as a non-archive node and ensure all pointers are updated fastDb := makeDb() defer fastDb.Close() - fast, _ := NewBlockChain(fastDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + fast, _ := NewBlockChain(fastDb, gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) defer fast.Stop() if n, err := fast.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), 0); err != nil { @@ -882,7 +879,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) { // Import the chain as a ancient-first node and ensure all pointers are updated ancientDb := makeDb() defer ancientDb.Close() - ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) defer ancient.Stop() if n, err := ancient.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), uint64(3*len(blocks)/4)); err != nil { @@ -903,7 +900,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) { for i, block := range blocks { headers[i] = block.Header() } - light, _ := NewBlockChain(lightDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + light, _ := NewBlockChain(lightDb, gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) if n, err := light.InsertHeaderChain(headers); err != nil { t.Fatalf("failed to insert header %d: %v", n, err) } @@ -976,7 +973,7 @@ func testChainTxReorgs(t *testing.T, scheme string) { }) // Import the chain. This runs all block validation rules. db := rawdb.NewMemoryDatabase() - blockchain, _ := NewBlockChain(db, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + blockchain, _ := NewBlockChain(db, gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) if i, err := blockchain.InsertChain(chain); err != nil { t.Fatalf("failed to insert original chain[%d]: %v", i, err) } @@ -1050,7 +1047,7 @@ func testLogReorgs(t *testing.T, scheme string) { signer = types.LatestSigner(gspec.Config) ) - blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) defer blockchain.Stop() rmLogsCh := make(chan RemovedLogsEvent) @@ -1106,7 +1103,7 @@ func testLogRebirth(t *testing.T, scheme string) { gspec = &Genesis{Config: params.TestChainConfig, Alloc: types.GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}} signer = types.LatestSigner(gspec.Config) engine = ethash.NewFaker() - blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, DefaultBlockChainConfig(scheme)) + blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, DefaultConfig().WithStateScheme(scheme)) ) defer blockchain.Stop() @@ -1187,7 +1184,7 @@ func testSideLogRebirth(t *testing.T, scheme string) { addr1 = crypto.PubkeyToAddress(key1.PublicKey) gspec = &Genesis{Config: params.TestChainConfig, Alloc: types.GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}} signer = types.LatestSigner(gspec.Config) - blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) ) defer blockchain.Stop() @@ -1386,7 +1383,7 @@ func testEIP155Transition(t *testing.T, scheme string) { } }) - blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) defer blockchain.Stop() if _, err := blockchain.InsertChain(blocks); err != nil { @@ -1479,7 +1476,7 @@ func testEIP161AccountRemoval(t *testing.T, scheme string) { block.AddTx(tx) }) // account must exist pre eip 161 - blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) defer blockchain.Stop() if _, err := blockchain.InsertChain(types.Blocks{blocks[0]}); err != nil { @@ -1537,7 +1534,7 @@ func testBlockchainHeaderchainReorgConsistency(t *testing.T, scheme string) { } // Import the canonical and fork chain side by side, verifying the current block // and current header consistency - chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, DefaultBlockChainConfig(scheme)) + chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, DefaultConfig().WithStateScheme(scheme)) if err != nil { t.Fatalf("failed to create tester chain: %v", err) } @@ -1627,7 +1624,7 @@ func testLargeReorgTrieGC(t *testing.T, scheme string) { db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) defer db.Close() - chain, err := NewBlockChain(db, genesis, engine, DefaultBlockChainConfig(scheme)) + chain, err := NewBlockChain(db, genesis, engine, DefaultConfig().WithStateScheme(scheme)) if err != nil { t.Fatalf("failed to create tester chain: %v", err) } @@ -1695,7 +1692,7 @@ func testBlockchainRecovery(t *testing.T, scheme string) { t.Fatalf("failed to create temp freezer db: %v", err) } defer ancientDb.Close() - ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) if n, err := ancient.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), uint64(3*len(blocks)/4)); err != nil { t.Fatalf("failed to insert receipt %d: %v", n, err) @@ -1708,7 +1705,7 @@ func testBlockchainRecovery(t *testing.T, scheme string) { rawdb.WriteHeadFastBlockHash(ancientDb, midBlock.Hash()) // Reopen broken blockchain again - ancient, _ = NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme)) + ancient, _ = NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(scheme)) defer ancient.Stop() if num := ancient.CurrentBlock().Number.Uint64(); num != 0 { t.Errorf("head block mismatch: have #%v, want #%v", num, 0) @@ -1751,7 +1748,7 @@ func testLowDiffLongChain(t *testing.T, scheme string) { diskdb, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) defer diskdb.Close() - chain, err := NewBlockChain(diskdb, genesis, engine, DefaultBlockChainConfig(scheme)) + chain, err := NewBlockChain(diskdb, genesis, engine, DefaultConfig().WithStateScheme(scheme)) if err != nil { t.Fatalf("failed to create tester chain: %v", err) } @@ -1966,7 +1963,7 @@ func testInsertKnownChainData(t *testing.T, typ string, scheme string) { } defer chaindb.Close() - chain, err := NewBlockChain(chaindb, genesis, engine, DefaultBlockChainConfig(scheme)) + chain, err := NewBlockChain(chaindb, genesis, engine, DefaultConfig().WithStateScheme(scheme)) if err != nil { t.Fatalf("failed to create tester chain: %v", err) } @@ -2235,7 +2232,7 @@ func getLongAndShortChains(scheme string) (*BlockChain, []*types.Block, []*types genDb, longChain, _ := GenerateChainWithGenesis(genesis, engine, 80, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) }) - chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, DefaultBlockChainConfig(scheme)) + chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, DefaultConfig().WithStateScheme(scheme)) if err != nil { return nil, nil, nil, nil, fmt.Errorf("failed to create tester chain: %v", err) } @@ -2503,7 +2500,7 @@ func testSideImportPrunedBlocks(t *testing.T, scheme string) { } defer db.Close() - chain, err := NewBlockChain(db, genesis, engine, DefaultBlockChainConfig(scheme)) + chain, err := NewBlockChain(db, genesis, engine, DefaultConfig().WithStateScheme(scheme)) if err != nil { t.Fatalf("failed to create tester chain: %v", err) } @@ -2602,7 +2599,7 @@ func testDeleteCreateRevert(t *testing.T, scheme string) { b.AddTx(tx) }) // Import the canonical chain - options := DefaultBlockChainConfig(scheme) + options := DefaultConfig().WithStateScheme(scheme) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options) if err != nil { t.Fatalf("failed to create tester chain: %v", err) @@ -2716,7 +2713,7 @@ func testDeleteRecreateSlots(t *testing.T, scheme string) { b.AddTx(tx) }) // Import the canonical chain - options := DefaultBlockChainConfig(scheme) + options := DefaultConfig().WithStateScheme(scheme) options.VmConfig = vm.Config{ Tracer: logger.NewJSONLogger(nil, os.Stdout), } @@ -2800,7 +2797,7 @@ func testDeleteRecreateAccount(t *testing.T, scheme string) { b.AddTx(tx) }) // Import the canonical chain - options := DefaultBlockChainConfig(scheme) + options := DefaultConfig().WithStateScheme(scheme) options.VmConfig = vm.Config{ Tracer: logger.NewJSONLogger(nil, os.Stdout), } @@ -2977,7 +2974,7 @@ func testDeleteRecreateSlotsAcrossManyBlocks(t *testing.T, scheme string) { current = exp }) // Import the canonical chain - options := DefaultBlockChainConfig(scheme) + options := DefaultConfig().WithStateScheme(scheme) options.VmConfig = vm.Config{ //Debug: true, //Tracer: vm.NewJSONLogger(nil, os.Stdout), @@ -3117,7 +3114,7 @@ func testInitThenFailCreateContract(t *testing.T, scheme string) { }) // Import the canonical chain - options := DefaultBlockChainConfig(scheme) + options := DefaultConfig().WithStateScheme(scheme) options.VmConfig = vm.Config{ //Debug: true, //Tracer: vm.NewJSONLogger(nil, os.Stdout), @@ -3209,7 +3206,7 @@ func testEIP2718Transition(t *testing.T, scheme string) { }) // Import the canonical chain - options := DefaultBlockChainConfig(scheme) + options := DefaultConfig().WithStateScheme(scheme) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options) if err != nil { t.Fatalf("failed to create tester chain: %v", err) @@ -3304,7 +3301,7 @@ func testEIP1559Transition(t *testing.T, scheme string) { b.AddTx(tx) }) - options := DefaultBlockChainConfig(scheme) + options := DefaultConfig().WithStateScheme(scheme) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options) if err != nil { t.Fatalf("failed to create tester chain: %v", err) @@ -3418,7 +3415,7 @@ func testSetCanonical(t *testing.T, scheme string) { diskdb, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) defer diskdb.Close() - options := DefaultBlockChainConfig(scheme) + options := DefaultConfig().WithStateScheme(scheme) chain, err := NewBlockChain(diskdb, gspec, engine, options) if err != nil { t.Fatalf("failed to create tester chain: %v", err) @@ -3528,7 +3525,7 @@ func testCanonicalHashMarker(t *testing.T, scheme string) { _, forkB, _ := GenerateChainWithGenesis(gspec, engine, c.forkB, func(i int, gen *BlockGen) {}) // Initialize test chain - options := DefaultBlockChainConfig(scheme) + options := DefaultConfig().WithStateScheme(scheme) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options) if err != nil { t.Fatalf("failed to create tester chain: %v", err) @@ -3860,9 +3857,9 @@ func TestTransientStorageReset(t *testing.T) { }) // Initialize the blockchain with 1153 enabled. - options := *defaultConfig + options := DefaultConfig() options.VmConfig = vmConfig - chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, &options) + chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options) if err != nil { t.Fatalf("failed to create tester chain: %v", err) } @@ -3956,11 +3953,11 @@ func TestEIP3651(t *testing.T) { b.AddTx(tx) }) - options := *defaultConfig + options := DefaultConfig() options.VmConfig = vm.Config{ Tracer: logger.NewMarkdownLogger(&logger.Config{}, os.Stderr).Hooks(), } - chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, &options) + chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options) if err != nil { t.Fatalf("failed to create tester chain: %v", err) } @@ -4219,7 +4216,7 @@ func testChainReorgSnapSync(t *testing.T, ancientLimit uint64) { db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) defer db.Close() - options := DefaultBlockChainConfig(rawdb.PathScheme) + options := DefaultConfig().WithStateScheme(rawdb.PathScheme) chain, _ := NewBlockChain(db, gspec, beacon.New(ethash.NewFaker()), options) defer chain.Stop() @@ -4330,13 +4327,13 @@ func testInsertChainWithCutoff(t *testing.T, cutoff uint64, ancientLimit uint64, }() // Enable pruning in cache config. - config := DefaultBlockChainConfig(rawdb.PathScheme) + config := DefaultConfig().WithStateScheme(rawdb.PathScheme) config.ChainHistoryMode = history.KeepPostMerge db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) defer db.Close() - options := DefaultBlockChainConfig(rawdb.PathScheme) + options := DefaultConfig().WithStateScheme(rawdb.PathScheme) chain, _ := NewBlockChain(db, genesis, beacon.New(ethash.NewFaker()), options) defer chain.Stop() diff --git a/core/chain_makers.go b/core/chain_makers.go index 8e432aa78a..fe2e25d2d7 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -579,7 +579,7 @@ func GenerateVerkleChain(config *params.ChainConfig, parent *types.Block, engine func GenerateVerkleChainWithGenesis(genesis *Genesis, engine consensus.Engine, n int, gen func(int, *BlockGen)) (common.Hash, ethdb.Database, []*types.Block, []types.Receipts, []*verkle.VerkleProof, []verkle.StateDiff) { db := rawdb.NewMemoryDatabase() - cacheConfig := DefaultBlockChainConfig(rawdb.PathScheme) + cacheConfig := DefaultConfig().WithStateScheme(rawdb.PathScheme) cacheConfig.SnapshotLimit = 0 triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true)) defer triedb.Close() diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index f18b2df010..cc9672199e 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -233,7 +233,7 @@ func ExampleGenerateChain() { }) // Import the chain. This runs all block validation rules. - blockchain, _ := NewBlockChain(db, gspec, ethash.NewFaker(), DefaultBlockChainConfig(rawdb.HashScheme)) + blockchain, _ := NewBlockChain(db, gspec, ethash.NewFaker(), DefaultConfig().WithStateScheme(rawdb.HashScheme)) defer blockchain.Stop() if i, err := blockchain.InsertChain(chain); err != nil { diff --git a/core/genesis_test.go b/core/genesis_test.go index 99e4962e63..9dc4bfb3df 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -130,7 +130,7 @@ func testSetupGenesis(t *testing.T, scheme string) { tdb := triedb.NewDatabase(db, newDbConfig(scheme)) oldcustomg.Commit(db, tdb) - bc, _ := NewBlockChain(db, &oldcustomg, ethash.NewFullFaker(), DefaultBlockChainConfig(scheme)) + bc, _ := NewBlockChain(db, &oldcustomg, ethash.NewFullFaker(), DefaultConfig().WithStateScheme(scheme)) defer bc.Stop() _, blocks, _ := GenerateChainWithGenesis(&oldcustomg, ethash.NewFaker(), 4, nil) diff --git a/core/verkle_witness_test.go b/core/verkle_witness_test.go index ce9cd1c285..a89672e6e5 100644 --- a/core/verkle_witness_test.go +++ b/core/verkle_witness_test.go @@ -119,7 +119,7 @@ func TestProcessVerkle(t *testing.T) { // Verkle trees use the snapshot, which must be enabled before the // data is saved into the tree+database. // genesis := gspec.MustCommit(bcdb, triedb) - options := DefaultBlockChainConfig(rawdb.PathScheme) + options := DefaultConfig().WithStateScheme(rawdb.PathScheme) options.SnapshotLimit = 0 blockchain, _ := NewBlockChain(bcdb, gspec, beacon.New(ethash.NewFaker()), options) defer blockchain.Stop() @@ -255,7 +255,7 @@ func TestProcessParentBlockHash(t *testing.T) { }) t.Run("Verkle", func(t *testing.T) { db := rawdb.NewMemoryDatabase() - cacheConfig := DefaultBlockChainConfig(rawdb.PathScheme) + cacheConfig := DefaultConfig().WithStateScheme(rawdb.PathScheme) cacheConfig.SnapshotLimit = 0 triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true)) statedb, _ := state.New(types.EmptyVerkleHash, state.NewDatabase(triedb, nil)) diff --git a/eth/filters/filter_test.go b/eth/filters/filter_test.go index 307a85a287..a80cd4260f 100644 --- a/eth/filters/filter_test.go +++ b/eth/filters/filter_test.go @@ -277,7 +277,7 @@ func testFilters(t *testing.T, history uint64, noHistory bool) { } }) var l uint64 - options := core.DefaultBlockChainConfig(rawdb.HashScheme) + options := core.DefaultConfig().WithStateScheme(rawdb.HashScheme) options.TxLookupLimit = &l bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options) if err != nil { @@ -437,7 +437,7 @@ func TestRangeLogs(t *testing.T) { chain, _ := core.GenerateChain(gspec.Config, gspec.ToBlock(), ethash.NewFaker(), db, 1000, func(i int, gen *core.BlockGen) {}) var l uint64 - options := core.DefaultBlockChainConfig(rawdb.HashScheme) + options := core.DefaultConfig().WithStateScheme(rawdb.HashScheme) options.TxLookupLimit = &l bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options) if err != nil { diff --git a/eth/tracers/internal/tracetest/supply_test.go b/eth/tracers/internal/tracetest/supply_test.go index a06e123f01..8aedc9d564 100644 --- a/eth/tracers/internal/tracetest/supply_test.go +++ b/eth/tracers/internal/tracetest/supply_test.go @@ -554,7 +554,7 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG return nil, nil, fmt.Errorf("failed to create call tracer: %v", err) } - options := core.DefaultBlockChainConfig(rawdb.PathScheme) + options := core.DefaultConfig().WithStateScheme(rawdb.PathScheme) options.VmConfig = vm.Config{Tracer: tracer} chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, options) if err != nil {