core: rename to BlockChainConfig

This commit is contained in:
Felix Lange 2025-06-18 16:08:13 +02:00
parent 5f69d45200
commit 233e56eff3
23 changed files with 109 additions and 109 deletions

View file

@ -2164,7 +2164,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
if err != nil { if err != nil {
Fatalf("%v", err) Fatalf("%v", err)
} }
options := &core.BlockChainOptions{ options := &core.BlockChainConfig{
TrieCleanLimit: ethconfig.Defaults.TrieCleanCache, TrieCleanLimit: ethconfig.Defaults.TrieCleanCache,
NoPrefetch: ctx.Bool(CacheNoPrefetchFlag.Name), NoPrefetch: ctx.Bool(CacheNoPrefetchFlag.Name),
TrieDirtyLimit: ethconfig.Defaults.TrieDirtyCache, TrieDirtyLimit: ethconfig.Defaults.TrieDirtyCache,

View file

@ -324,7 +324,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
genesis := &Genesis{Config: params.AllEthashProtocolChanges} genesis := &Genesis{Config: params.AllEthashProtocolChanges}
makeChainForBench(db, genesis, full, count) makeChainForBench(db, genesis, full, count)
db.Close() db.Close()
options := *defaultOptions options := *defaultConfig
options.ArchiveMode = true options.ArchiveMode = true
b.ReportAllocs() b.ReportAllocs()

View file

@ -49,7 +49,7 @@ func testHeaderVerification(t *testing.T, scheme string) {
headers[i] = block.Header() headers[i] = block.Header()
} }
// Run the header checker for blocks one-by-one, checking for both valid and invalid nonces // Run the header checker for blocks one-by-one, checking for both valid and invalid nonces
options := BlockchainOptionsWithScheme(scheme) options := DefaultBlockChainConfig(scheme)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), options) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), options)
defer chain.Stop() defer chain.Stop()
if err != nil { if err != nil {

View file

@ -149,8 +149,8 @@ const (
BlockChainVersion uint64 = 9 BlockChainVersion uint64 = 9
) )
// BlockChainOptions contains the configuration fields for setting up blockchain. // BlockChainConfig contains the configuration of the BlockChain object.
type BlockChainOptions struct { type BlockChainConfig struct {
// Trie database related options // Trie database related options
TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory
TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk
@ -187,7 +187,7 @@ type BlockChainOptions struct {
} }
// triedbConfig derives the configures for trie database. // triedbConfig derives the configures for trie database.
func (o *BlockChainOptions) triedbConfig(isVerkle bool) *triedb.Config { func (o *BlockChainConfig) triedbConfig(isVerkle bool) *triedb.Config {
config := &triedb.Config{ config := &triedb.Config{
Preimages: o.Preimages, Preimages: o.Preimages,
IsVerkle: isVerkle, IsVerkle: isVerkle,
@ -212,9 +212,9 @@ func (o *BlockChainOptions) triedbConfig(isVerkle bool) *triedb.Config {
return config return config
} }
// defaultOptions are the default blockchain options if none are specified by the // defaultConfig are the default blockchain options if none are specified by the
// user (also used during testing). // user (also used during testing).
var defaultOptions = &BlockChainOptions{ var defaultConfig = &BlockChainConfig{
TrieCleanLimit: 256, TrieCleanLimit: 256,
TrieDirtyLimit: 256, TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute, TrieTimeLimit: 5 * time.Minute,
@ -224,10 +224,9 @@ var defaultOptions = &BlockChainOptions{
ChainHistoryMode: history.KeepAll, ChainHistoryMode: history.KeepAll,
} }
// BlockchainOptionsWithScheme returns a deep copied default chain config with // DefaultBlockChainConfig returns the default config with a provided state scheme.
// a provided state scheme. func DefaultBlockChainConfig(scheme string) *BlockChainConfig {
func BlockchainOptionsWithScheme(scheme string) *BlockChainOptions { config := *defaultConfig
config := *defaultOptions
config.StateScheme = scheme config.StateScheme = scheme
return &config return &config
} }
@ -255,7 +254,7 @@ type txLookup struct {
// canonical chain. // canonical chain.
type BlockChain struct { type BlockChain struct {
chainConfig *params.ChainConfig // Chain & network configuration chainConfig *params.ChainConfig // Chain & network configuration
options *BlockChainOptions // Blockchain configuration cfg *BlockChainConfig // Blockchain configuration
db ethdb.Database // Low level persistent database to store final content in db ethdb.Database // Low level persistent database to store final content in
snaps *snapshot.Tree // Snapshot tree for fast trie leaf access snaps *snapshot.Tree // Snapshot tree for fast trie leaf access
@ -311,22 +310,23 @@ type BlockChain struct {
// NewBlockChain returns a fully initialised block chain using information // NewBlockChain returns a fully initialised block chain using information
// available in the database. It initialises the default Ethereum Validator // available in the database. It initialises the default Ethereum Validator
// and Processor. // and Processor.
func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine, options *BlockChainOptions) (*BlockChain, error) { func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine, cfg *BlockChainConfig) (*BlockChain, error) {
if options == nil { if cfg == nil {
options = defaultOptions cfg = DefaultBlockChainConfig(rawdb.HashScheme)
} }
// Open trie database with provided config // Open trie database with provided config
enableVerkle, err := EnableVerkleAtGenesis(db, genesis) enableVerkle, err := EnableVerkleAtGenesis(db, genesis)
if err != nil { if err != nil {
return nil, err return nil, err
} }
triedb := triedb.NewDatabase(db, options.triedbConfig(enableVerkle)) triedb := triedb.NewDatabase(db, cfg.triedbConfig(enableVerkle))
// Write the supplied genesis to the database if it has not been initialized // Write the supplied genesis to the database if it has not been initialized
// yet. The corresponding chain config will be returned, either from the // yet. The corresponding chain config will be returned, either from the
// provided genesis or from the locally stored configuration if the genesis // provided genesis or from the locally stored configuration if the genesis
// has already been initialized. // has already been initialized.
chainConfig, genesisHash, compatErr, err := SetupGenesisBlockWithOverride(db, triedb, genesis, options.Overrides) chainConfig, genesisHash, compatErr, err := SetupGenesisBlockWithOverride(db, triedb, genesis, cfg.Overrides)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -340,7 +340,7 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
bc := &BlockChain{ bc := &BlockChain{
chainConfig: chainConfig, chainConfig: chainConfig,
options: options, cfg: cfg,
db: db, db: db,
triedb: triedb, triedb: triedb,
triegc: prque.New[int64, common.Hash](nil), triegc: prque.New[int64, common.Hash](nil),
@ -352,13 +352,13 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
blockCache: lru.NewCache[common.Hash, *types.Block](blockCacheLimit), blockCache: lru.NewCache[common.Hash, *types.Block](blockCacheLimit),
txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit), txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit),
engine: engine, engine: engine,
logger: options.VmConfig.Tracer, logger: cfg.VmConfig.Tracer,
} }
bc.hc, err = NewHeaderChain(db, chainConfig, engine, bc.insertStopped) bc.hc, err = NewHeaderChain(db, chainConfig, engine, bc.insertStopped)
if err != nil { if err != nil {
return nil, err return nil, err
} }
bc.flushInterval.Store(int64(options.TrieTimeLimit)) bc.flushInterval.Store(int64(cfg.TrieTimeLimit))
bc.statedb = state.NewDatabase(bc.triedb, nil) bc.statedb = state.NewDatabase(bc.triedb, nil)
bc.validator = NewBlockValidator(chainConfig, bc) bc.validator = NewBlockValidator(chainConfig, bc)
bc.prefetcher = newStatePrefetcher(chainConfig, bc.hc) bc.prefetcher = newStatePrefetcher(chainConfig, bc.hc)
@ -407,7 +407,7 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
// Note it's unnecessary in path mode which always keep trie data and // Note it's unnecessary in path mode which always keep trie data and
// state data consistent. // state data consistent.
var diskRoot common.Hash var diskRoot common.Hash
if bc.options.SnapshotLimit > 0 && bc.options.StateScheme == rawdb.HashScheme { if bc.cfg.SnapshotLimit > 0 && bc.cfg.StateScheme == rawdb.HashScheme {
diskRoot = rawdb.ReadSnapshotRoot(bc.db) diskRoot = rawdb.ReadSnapshotRoot(bc.db)
} }
if diskRoot != (common.Hash{}) { if diskRoot != (common.Hash{}) {
@ -494,8 +494,8 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
} }
// Start tx indexer if it's enabled. // Start tx indexer if it's enabled.
if bc.options.TxLookupLimit != nil { if bc.cfg.TxLookupLimit != nil {
bc.txIndexer = newTxIndexer(*bc.options.TxLookupLimit, bc) bc.txIndexer = newTxIndexer(*bc.cfg.TxLookupLimit, bc)
} }
return bc, nil return bc, nil
} }
@ -503,11 +503,11 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
func (bc *BlockChain) setupSnapshot() { func (bc *BlockChain) setupSnapshot() {
// Short circuit if the chain is established with path scheme, as the // Short circuit if the chain is established with path scheme, as the
// state snapshot has been integrated into path database natively. // state snapshot has been integrated into path database natively.
if bc.options.StateScheme == rawdb.PathScheme { if bc.cfg.StateScheme == rawdb.PathScheme {
return return
} }
// Load any existing snapshot, regenerating it if loading failed // Load any existing snapshot, regenerating it if loading failed
if bc.options.SnapshotLimit > 0 { if bc.cfg.SnapshotLimit > 0 {
// If the chain was rewound past the snapshot persistent layer (causing // If the chain was rewound past the snapshot persistent layer (causing
// a recovery block number to be persisted to disk), check if we're still // a recovery block number to be persisted to disk), check if we're still
// in recovery mode and in that case, don't invalidate the snapshot on a // in recovery mode and in that case, don't invalidate the snapshot on a
@ -519,10 +519,10 @@ func (bc *BlockChain) setupSnapshot() {
recover = true recover = true
} }
snapconfig := snapshot.Config{ snapconfig := snapshot.Config{
CacheSize: bc.options.SnapshotLimit, CacheSize: bc.cfg.SnapshotLimit,
Recovery: recover, Recovery: recover,
NoBuild: bc.options.SnapshotNoBuild, NoBuild: bc.cfg.SnapshotNoBuild,
AsyncBuild: !bc.options.SnapshotWait, AsyncBuild: !bc.cfg.SnapshotWait,
} }
bc.snaps, _ = snapshot.New(snapconfig, bc.db, bc.triedb, head.Root) bc.snaps, _ = snapshot.New(snapconfig, bc.db, bc.triedb, head.Root)
@ -646,7 +646,7 @@ func (bc *BlockChain) loadLastState() error {
func (bc *BlockChain) initializeHistoryPruning(latest uint64) error { func (bc *BlockChain) initializeHistoryPruning(latest uint64) error {
freezerTail, _ := bc.db.Tail() freezerTail, _ := bc.db.Tail()
switch bc.options.ChainHistoryMode { switch bc.cfg.ChainHistoryMode {
case history.KeepAll: case history.KeepAll:
if freezerTail == 0 { if freezerTail == 0 {
return nil return nil
@ -667,7 +667,7 @@ func (bc *BlockChain) initializeHistoryPruning(latest uint64) error {
// postmerge directly on an existing DB. We could just trigger the pruning // postmerge directly on an existing DB. We could just trigger the pruning
// here, but it'd be a bit dangerous since they may not have intended this // here, but it'd be a bit dangerous since they may not have intended this
// action to happen. So just tell them how to do it. // action to happen. So just tell them how to do it.
log.Error(fmt.Sprintf("Chain history mode is configured as %q, but database is not pruned.", bc.options.ChainHistoryMode.String())) log.Error(fmt.Sprintf("Chain history mode is configured as %q, but database is not pruned.", bc.cfg.ChainHistoryMode.String()))
log.Error(fmt.Sprintf("Run 'geth prune-history' to prune pre-merge history.")) log.Error(fmt.Sprintf("Run 'geth prune-history' to prune pre-merge history."))
return fmt.Errorf("history pruning requested via configuration") return fmt.Errorf("history pruning requested via configuration")
} }
@ -683,7 +683,7 @@ func (bc *BlockChain) initializeHistoryPruning(latest uint64) error {
return nil return nil
default: default:
return fmt.Errorf("invalid history mode: %d", bc.options.ChainHistoryMode) return fmt.Errorf("invalid history mode: %d", bc.cfg.ChainHistoryMode)
} }
} }
@ -1258,7 +1258,7 @@ func (bc *BlockChain) Stop() {
// - HEAD: So we don't need to reprocess any blocks in the general case // - HEAD: So we don't need to reprocess any blocks in the general case
// - HEAD-1: So we don't do large reorgs if our HEAD becomes an uncle // - HEAD-1: So we don't do large reorgs if our HEAD becomes an uncle
// - HEAD-127: So we have a hard limit on the number of blocks reexecuted // - HEAD-127: So we have a hard limit on the number of blocks reexecuted
if !bc.options.ArchiveMode { if !bc.cfg.ArchiveMode {
triedb := bc.triedb triedb := bc.triedb
for _, offset := range []uint64{0, 1, state.TriesInMemory - 1} { for _, offset := range []uint64{0, 1, state.TriesInMemory - 1} {
@ -1564,7 +1564,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
return nil return nil
} }
// If we're running an archive node, always flush // If we're running an archive node, always flush
if bc.options.ArchiveMode { if bc.cfg.ArchiveMode {
return bc.triedb.Commit(root, false) return bc.triedb.Commit(root, false)
} }
// Full but not archive node, do proper garbage collection // Full but not archive node, do proper garbage collection
@ -1579,7 +1579,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
// If we exceeded our memory allowance, flush matured singleton nodes to disk // If we exceeded our memory allowance, flush matured singleton nodes to disk
var ( var (
_, nodes, imgs = bc.triedb.Size() // all memory is contained within the nodes return for hashdb _, nodes, imgs = bc.triedb.Size() // all memory is contained within the nodes return for hashdb
limit = common.StorageSize(bc.options.TrieDirtyLimit) * 1024 * 1024 limit = common.StorageSize(bc.cfg.TrieDirtyLimit) * 1024 * 1024
) )
if nodes > limit || imgs > 4*1024*1024 { if nodes > limit || imgs > 4*1024*1024 {
bc.triedb.Cap(limit - ethdb.IdealBatchSize) bc.triedb.Cap(limit - ethdb.IdealBatchSize)
@ -1929,7 +1929,7 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
) )
defer interrupt.Store(true) // terminate the prefetch at the end defer interrupt.Store(true) // terminate the prefetch at the end
if bc.options.NoPrefetch { if bc.cfg.NoPrefetch {
statedb, err = state.New(parentRoot, bc.statedb) statedb, err = state.New(parentRoot, bc.statedb)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1954,7 +1954,7 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
} }
go func(start time.Time, throwaway *state.StateDB, block *types.Block) { go func(start time.Time, throwaway *state.StateDB, block *types.Block) {
// Disable tracing for prefetcher executions. // Disable tracing for prefetcher executions.
vmCfg := bc.options.VmConfig vmCfg := bc.cfg.VmConfig
vmCfg.Tracer = nil vmCfg.Tracer = nil
bc.prefetcher.Prefetch(block, throwaway, vmCfg, &interrupt) bc.prefetcher.Prefetch(block, throwaway, vmCfg, &interrupt)
@ -1973,7 +1973,7 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
// Generate witnesses either if we're self-testing, or if it's the // Generate witnesses either if we're self-testing, or if it's the
// only block being inserted. A bit crude, but witnesses are huge, // only block being inserted. A bit crude, but witnesses are huge,
// so we refuse to make an entire chain of them. // so we refuse to make an entire chain of them.
if bc.options.VmConfig.StatelessSelfValidation || makeWitness { if bc.cfg.VmConfig.StatelessSelfValidation || makeWitness {
witness, err = stateless.NewWitness(block.Header(), bc) witness, err = stateless.NewWitness(block.Header(), bc)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1998,7 +1998,7 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
// Process block using the parent state as reference point // Process block using the parent state as reference point
pstart := time.Now() pstart := time.Now()
res, err := bc.processor.Process(block, statedb, bc.options.VmConfig) res, err := bc.processor.Process(block, statedb, bc.cfg.VmConfig)
if err != nil { if err != nil {
bc.reportBlock(block, res, err) bc.reportBlock(block, res, err)
return nil, err return nil, err
@ -2018,7 +2018,7 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
// witness builder/runner, which would otherwise be impossible due to the // witness builder/runner, which would otherwise be impossible due to the
// various invalid chain states/behaviors being contained in those tests. // various invalid chain states/behaviors being contained in those tests.
xvstart := time.Now() xvstart := time.Now()
if witness := statedb.Witness(); witness != nil && bc.options.VmConfig.StatelessSelfValidation { if witness := statedb.Witness(); witness != nil && bc.cfg.VmConfig.StatelessSelfValidation {
log.Warn("Running stateless self-validation", "block", block.Number(), "hash", block.Hash()) log.Warn("Running stateless self-validation", "block", block.Number(), "hash", block.Hash())
// Remove critical computed fields from the block to force true recalculation // Remove critical computed fields from the block to force true recalculation
@ -2029,7 +2029,7 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
task := types.NewBlockWithHeader(context).WithBody(*block.Body()) task := types.NewBlockWithHeader(context).WithBody(*block.Body())
// Run the stateless self-cross-validation // Run the stateless self-cross-validation
crossStateRoot, crossReceiptRoot, err := ExecuteStateless(bc.chainConfig, bc.options.VmConfig, task, witness) crossStateRoot, crossReceiptRoot, err := ExecuteStateless(bc.chainConfig, bc.cfg.VmConfig, task, witness)
if err != nil { if err != nil {
return nil, fmt.Errorf("stateless self-validation failed: %v", err) return nil, fmt.Errorf("stateless self-validation failed: %v", err)
} }

View file

@ -408,7 +408,7 @@ func (bc *BlockChain) Genesis() *types.Block {
// GetVMConfig returns the block chain VM config. // GetVMConfig returns the block chain VM config.
func (bc *BlockChain) GetVMConfig() *vm.Config { func (bc *BlockChain) GetVMConfig() *vm.Config {
return &bc.options.VmConfig return &bc.cfg.VmConfig
} }
// TxIndexProgress returns the transaction indexing progress. // TxIndexProgress returns the transaction indexing progress.

View file

@ -1781,7 +1781,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s
Config: params.AllEthashProtocolChanges, Config: params.AllEthashProtocolChanges,
} }
engine = ethash.NewFullFaker() engine = ethash.NewFullFaker()
option = &BlockChainOptions{ option = &BlockChainConfig{
TrieCleanLimit: 256, TrieCleanLimit: 256,
TrieDirtyLimit: 256, TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute, TrieTimeLimit: 5 * time.Minute,
@ -1931,7 +1931,7 @@ func testIssue23496(t *testing.T, scheme string) {
BaseFee: big.NewInt(params.InitialBaseFee), BaseFee: big.NewInt(params.InitialBaseFee),
} }
engine = ethash.NewFullFaker() engine = ethash.NewFullFaker()
options = BlockchainOptionsWithScheme(scheme) options = DefaultBlockChainConfig(scheme)
) )
chain, err := NewBlockChain(db, gspec, engine, options) chain, err := NewBlockChain(db, gspec, engine, options)
if err != nil { if err != nil {
@ -1985,7 +1985,7 @@ func testIssue23496(t *testing.T, scheme string) {
} }
defer db.Close() defer db.Close()
chain, err = NewBlockChain(db, gspec, engine, BlockchainOptionsWithScheme(scheme)) chain, err = NewBlockChain(db, gspec, engine, DefaultBlockChainConfig(scheme))
if err != nil { if err != nil {
t.Fatalf("Failed to recreate chain: %v", err) t.Fatalf("Failed to recreate chain: %v", err)
} }

View file

@ -1985,7 +1985,7 @@ func testSetHeadWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme
Config: params.AllEthashProtocolChanges, Config: params.AllEthashProtocolChanges,
} }
engine = ethash.NewFullFaker() engine = ethash.NewFullFaker()
options = &BlockChainOptions{ options = &BlockChainConfig{
TrieCleanLimit: 256, TrieCleanLimit: 256,
TrieDirtyLimit: 256, TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute, TrieTimeLimit: 5 * time.Minute,

View file

@ -81,7 +81,7 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo
} }
engine = ethash.NewFullFaker() engine = ethash.NewFullFaker()
) )
chain, err := NewBlockChain(db, gspec, engine, BlockchainOptionsWithScheme(basic.scheme)) chain, err := NewBlockChain(db, gspec, engine, DefaultBlockChainConfig(basic.scheme))
if err != nil { if err != nil {
t.Fatalf("Failed to create chain: %v", err) t.Fatalf("Failed to create chain: %v", err)
} }
@ -232,7 +232,7 @@ func (snaptest *snapshotTest) test(t *testing.T) {
// Restart the chain normally // Restart the chain normally
chain.Stop() chain.Stop()
newchain, err := NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, BlockchainOptionsWithScheme(snaptest.scheme)) newchain, err := NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, DefaultBlockChainConfig(snaptest.scheme))
if err != nil { if err != nil {
t.Fatalf("Failed to recreate chain: %v", err) 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 // 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 // after the normal stop. It's used to ensure the broken snapshot
// can be detected all the time. // can be detected all the time.
newchain, err := NewBlockChain(newdb, snaptest.gspec, snaptest.engine, BlockchainOptionsWithScheme(snaptest.scheme)) newchain, err := NewBlockChain(newdb, snaptest.gspec, snaptest.engine, DefaultBlockChainConfig(snaptest.scheme))
if err != nil { if err != nil {
t.Fatalf("Failed to recreate chain: %v", err) t.Fatalf("Failed to recreate chain: %v", err)
} }
newchain.Stop() newchain.Stop()
newchain, err = NewBlockChain(newdb, snaptest.gspec, snaptest.engine, BlockchainOptionsWithScheme(snaptest.scheme)) newchain, err = NewBlockChain(newdb, snaptest.gspec, snaptest.engine, DefaultBlockChainConfig(snaptest.scheme))
if err != nil { if err != nil {
t.Fatalf("Failed to recreate chain: %v", err) t.Fatalf("Failed to recreate chain: %v", err)
} }
@ -310,7 +310,7 @@ func (snaptest *gappedSnapshotTest) test(t *testing.T) {
gappedBlocks, _ := GenerateChain(snaptest.gspec.Config, blocks[len(blocks)-1], snaptest.engine, snaptest.genDb, snaptest.gapped, func(i int, b *BlockGen) {}) gappedBlocks, _ := GenerateChain(snaptest.gspec.Config, blocks[len(blocks)-1], snaptest.engine, snaptest.genDb, snaptest.gapped, func(i int, b *BlockGen) {})
// Insert a few more blocks without enabling snapshot // Insert a few more blocks without enabling snapshot
var options = &BlockChainOptions{ var options = &BlockChainConfig{
TrieCleanLimit: 256, TrieCleanLimit: 256,
TrieDirtyLimit: 256, TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute, TrieTimeLimit: 5 * time.Minute,
@ -325,7 +325,7 @@ func (snaptest *gappedSnapshotTest) test(t *testing.T) {
newchain.Stop() newchain.Stop()
// Restart the chain with enabling the snapshot // Restart the chain with enabling the snapshot
options = BlockchainOptionsWithScheme(snaptest.scheme) options = DefaultBlockChainConfig(snaptest.scheme)
newchain, err = NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, options) newchain, err = NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, options)
if err != nil { if err != nil {
t.Fatalf("Failed to recreate chain: %v", err) t.Fatalf("Failed to recreate chain: %v", err)
@ -354,7 +354,7 @@ func (snaptest *setHeadSnapshotTest) test(t *testing.T) {
chain.SetHead(snaptest.setHead) chain.SetHead(snaptest.setHead)
chain.Stop() chain.Stop()
newchain, err := NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, BlockchainOptionsWithScheme(snaptest.scheme)) newchain, err := NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, DefaultBlockChainConfig(snaptest.scheme))
if err != nil { if err != nil {
t.Fatalf("Failed to recreate chain: %v", err) t.Fatalf("Failed to recreate chain: %v", err)
} }
@ -383,7 +383,7 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
// and state committed. // and state committed.
chain.Stop() chain.Stop()
config := &BlockChainOptions{ config := &BlockChainConfig{
TrieCleanLimit: 256, TrieCleanLimit: 256,
TrieDirtyLimit: 256, TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute, TrieTimeLimit: 5 * time.Minute,
@ -399,7 +399,7 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
newchain.Stop() newchain.Stop()
// Restart the chain, the wiper should start working // Restart the chain, the wiper should start working
config = &BlockChainOptions{ config = &BlockChainConfig{
TrieCleanLimit: 256, TrieCleanLimit: 256,
TrieDirtyLimit: 256, TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute, TrieTimeLimit: 5 * time.Minute,
@ -416,7 +416,7 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
tmp.triedb.Close() tmp.triedb.Close()
tmp.stopWithoutSaving() tmp.stopWithoutSaving()
newchain, err = NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, BlockchainOptionsWithScheme(snaptest.scheme)) newchain, err = NewBlockChain(snaptest.db, snaptest.gspec, snaptest.engine, DefaultBlockChainConfig(snaptest.scheme))
if err != nil { if err != nil {
t.Fatalf("Failed to recreate chain: %v", err) t.Fatalf("Failed to recreate chain: %v", err)
} }

View file

@ -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 // Initialize a fresh chain with only a genesis block
options := BlockchainOptionsWithScheme(scheme) options := DefaultBlockChainConfig(scheme)
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, options) blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, options)
// Create and inject the requested chain // 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 // Import the chain as an archive node for the comparison baseline
archiveDb := rawdb.NewMemoryDatabase() archiveDb := rawdb.NewMemoryDatabase()
archive, _ := NewBlockChain(archiveDb, gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) archive, _ := NewBlockChain(archiveDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
defer archive.Stop() defer archive.Stop()
if n, err := archive.InsertChain(blocks); err != nil { 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 // Fast import the chain as a non-archive node to test
fastDb := rawdb.NewMemoryDatabase() fastDb := rawdb.NewMemoryDatabase()
fast, _ := NewBlockChain(fastDb, gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) fast, _ := NewBlockChain(fastDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
defer fast.Stop() defer fast.Stop()
if n, err := fast.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), 0); err != nil { 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() defer ancientDb.Close()
ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
defer ancient.Stop() defer ancient.Stop()
if n, err := ancient.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), uint64(len(blocks)/2)); err != nil { if n, err := ancient.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), uint64(len(blocks)/2)); err != nil {
@ -852,7 +852,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) {
archiveDb := makeDb() archiveDb := makeDb()
defer archiveDb.Close() defer archiveDb.Close()
options := *defaultOptions options := *defaultConfig
options.ArchiveMode = true options.ArchiveMode = true
options.StateScheme = scheme options.StateScheme = scheme
@ -869,7 +869,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) {
// Import the chain as a non-archive node and ensure all pointers are updated // Import the chain as a non-archive node and ensure all pointers are updated
fastDb := makeDb() fastDb := makeDb()
defer fastDb.Close() defer fastDb.Close()
fast, _ := NewBlockChain(fastDb, gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) fast, _ := NewBlockChain(fastDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
defer fast.Stop() defer fast.Stop()
if n, err := fast.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), 0); err != nil { if n, err := fast.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), 0); err != nil {
@ -882,7 +882,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) {
// Import the chain as a ancient-first node and ensure all pointers are updated // Import the chain as a ancient-first node and ensure all pointers are updated
ancientDb := makeDb() ancientDb := makeDb()
defer ancientDb.Close() defer ancientDb.Close()
ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
defer ancient.Stop() defer ancient.Stop()
if n, err := ancient.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), uint64(3*len(blocks)/4)); err != nil { if n, err := ancient.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), uint64(3*len(blocks)/4)); err != nil {
@ -903,7 +903,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) {
for i, block := range blocks { for i, block := range blocks {
headers[i] = block.Header() headers[i] = block.Header()
} }
light, _ := NewBlockChain(lightDb, gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) light, _ := NewBlockChain(lightDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
if n, err := light.InsertHeaderChain(headers); err != nil { if n, err := light.InsertHeaderChain(headers); err != nil {
t.Fatalf("failed to insert header %d: %v", n, err) t.Fatalf("failed to insert header %d: %v", n, err)
} }
@ -976,7 +976,7 @@ func testChainTxReorgs(t *testing.T, scheme string) {
}) })
// Import the chain. This runs all block validation rules. // Import the chain. This runs all block validation rules.
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
blockchain, _ := NewBlockChain(db, gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) blockchain, _ := NewBlockChain(db, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
if i, err := blockchain.InsertChain(chain); err != nil { if i, err := blockchain.InsertChain(chain); err != nil {
t.Fatalf("failed to insert original chain[%d]: %v", i, err) t.Fatalf("failed to insert original chain[%d]: %v", i, err)
} }
@ -1050,7 +1050,7 @@ func testLogReorgs(t *testing.T, scheme string) {
signer = types.LatestSigner(gspec.Config) signer = types.LatestSigner(gspec.Config)
) )
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
defer blockchain.Stop() defer blockchain.Stop()
rmLogsCh := make(chan RemovedLogsEvent) rmLogsCh := make(chan RemovedLogsEvent)
@ -1106,7 +1106,7 @@ func testLogRebirth(t *testing.T, scheme string) {
gspec = &Genesis{Config: params.TestChainConfig, Alloc: types.GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}} gspec = &Genesis{Config: params.TestChainConfig, Alloc: types.GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}}
signer = types.LatestSigner(gspec.Config) signer = types.LatestSigner(gspec.Config)
engine = ethash.NewFaker() engine = ethash.NewFaker()
blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, BlockchainOptionsWithScheme(scheme)) blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, DefaultBlockChainConfig(scheme))
) )
defer blockchain.Stop() defer blockchain.Stop()
@ -1187,7 +1187,7 @@ func testSideLogRebirth(t *testing.T, scheme string) {
addr1 = crypto.PubkeyToAddress(key1.PublicKey) addr1 = crypto.PubkeyToAddress(key1.PublicKey)
gspec = &Genesis{Config: params.TestChainConfig, Alloc: types.GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}} gspec = &Genesis{Config: params.TestChainConfig, Alloc: types.GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}}
signer = types.LatestSigner(gspec.Config) signer = types.LatestSigner(gspec.Config)
blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
) )
defer blockchain.Stop() defer blockchain.Stop()
@ -1386,7 +1386,7 @@ func testEIP155Transition(t *testing.T, scheme string) {
} }
}) })
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
defer blockchain.Stop() defer blockchain.Stop()
if _, err := blockchain.InsertChain(blocks); err != nil { if _, err := blockchain.InsertChain(blocks); err != nil {
@ -1479,7 +1479,7 @@ func testEIP161AccountRemoval(t *testing.T, scheme string) {
block.AddTx(tx) block.AddTx(tx)
}) })
// account must exist pre eip 161 // account must exist pre eip 161
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
defer blockchain.Stop() defer blockchain.Stop()
if _, err := blockchain.InsertChain(types.Blocks{blocks[0]}); err != nil { if _, err := blockchain.InsertChain(types.Blocks{blocks[0]}); err != nil {
@ -1537,7 +1537,7 @@ func testBlockchainHeaderchainReorgConsistency(t *testing.T, scheme string) {
} }
// Import the canonical and fork chain side by side, verifying the current block // Import the canonical and fork chain side by side, verifying the current block
// and current header consistency // and current header consistency
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, BlockchainOptionsWithScheme(scheme)) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, DefaultBlockChainConfig(scheme))
if err != nil { if err != nil {
t.Fatalf("failed to create tester chain: %v", err) t.Fatalf("failed to create tester chain: %v", err)
} }
@ -1627,7 +1627,7 @@ func testLargeReorgTrieGC(t *testing.T, scheme string) {
db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false)
defer db.Close() defer db.Close()
chain, err := NewBlockChain(db, genesis, engine, BlockchainOptionsWithScheme(scheme)) chain, err := NewBlockChain(db, genesis, engine, DefaultBlockChainConfig(scheme))
if err != nil { if err != nil {
t.Fatalf("failed to create tester chain: %v", err) t.Fatalf("failed to create tester chain: %v", err)
} }
@ -1695,7 +1695,7 @@ func testBlockchainRecovery(t *testing.T, scheme string) {
t.Fatalf("failed to create temp freezer db: %v", err) t.Fatalf("failed to create temp freezer db: %v", err)
} }
defer ancientDb.Close() defer ancientDb.Close()
ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) ancient, _ := NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
if n, err := ancient.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), uint64(3*len(blocks)/4)); err != nil { 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) t.Fatalf("failed to insert receipt %d: %v", n, err)
@ -1708,7 +1708,7 @@ func testBlockchainRecovery(t *testing.T, scheme string) {
rawdb.WriteHeadFastBlockHash(ancientDb, midBlock.Hash()) rawdb.WriteHeadFastBlockHash(ancientDb, midBlock.Hash())
// Reopen broken blockchain again // Reopen broken blockchain again
ancient, _ = NewBlockChain(ancientDb, gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(scheme)) ancient, _ = NewBlockChain(ancientDb, gspec, ethash.NewFaker(), DefaultBlockChainConfig(scheme))
defer ancient.Stop() defer ancient.Stop()
if num := ancient.CurrentBlock().Number.Uint64(); num != 0 { if num := ancient.CurrentBlock().Number.Uint64(); num != 0 {
t.Errorf("head block mismatch: have #%v, want #%v", num, 0) t.Errorf("head block mismatch: have #%v, want #%v", num, 0)
@ -1751,7 +1751,7 @@ func testLowDiffLongChain(t *testing.T, scheme string) {
diskdb, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) diskdb, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false)
defer diskdb.Close() defer diskdb.Close()
chain, err := NewBlockChain(diskdb, genesis, engine, BlockchainOptionsWithScheme(scheme)) chain, err := NewBlockChain(diskdb, genesis, engine, DefaultBlockChainConfig(scheme))
if err != nil { if err != nil {
t.Fatalf("failed to create tester chain: %v", err) t.Fatalf("failed to create tester chain: %v", err)
} }
@ -1966,7 +1966,7 @@ func testInsertKnownChainData(t *testing.T, typ string, scheme string) {
} }
defer chaindb.Close() defer chaindb.Close()
chain, err := NewBlockChain(chaindb, genesis, engine, BlockchainOptionsWithScheme(scheme)) chain, err := NewBlockChain(chaindb, genesis, engine, DefaultBlockChainConfig(scheme))
if err != nil { if err != nil {
t.Fatalf("failed to create tester chain: %v", err) t.Fatalf("failed to create tester chain: %v", err)
} }
@ -2235,7 +2235,7 @@ func getLongAndShortChains(scheme string) (*BlockChain, []*types.Block, []*types
genDb, longChain, _ := GenerateChainWithGenesis(genesis, engine, 80, func(i int, b *BlockGen) { genDb, longChain, _ := GenerateChainWithGenesis(genesis, engine, 80, func(i int, b *BlockGen) {
b.SetCoinbase(common.Address{1}) b.SetCoinbase(common.Address{1})
}) })
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, BlockchainOptionsWithScheme(scheme)) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, DefaultBlockChainConfig(scheme))
if err != nil { if err != nil {
return nil, nil, nil, nil, fmt.Errorf("failed to create tester chain: %v", err) return nil, nil, nil, nil, fmt.Errorf("failed to create tester chain: %v", err)
} }
@ -2503,7 +2503,7 @@ func testSideImportPrunedBlocks(t *testing.T, scheme string) {
} }
defer db.Close() defer db.Close()
chain, err := NewBlockChain(db, genesis, engine, BlockchainOptionsWithScheme(scheme)) chain, err := NewBlockChain(db, genesis, engine, DefaultBlockChainConfig(scheme))
if err != nil { if err != nil {
t.Fatalf("failed to create tester chain: %v", err) t.Fatalf("failed to create tester chain: %v", err)
} }
@ -2602,7 +2602,7 @@ func testDeleteCreateRevert(t *testing.T, scheme string) {
b.AddTx(tx) b.AddTx(tx)
}) })
// Import the canonical chain // Import the canonical chain
options := BlockchainOptionsWithScheme(scheme) options := DefaultBlockChainConfig(scheme)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options)
if err != nil { if err != nil {
t.Fatalf("failed to create tester chain: %v", err) t.Fatalf("failed to create tester chain: %v", err)
@ -2716,7 +2716,7 @@ func testDeleteRecreateSlots(t *testing.T, scheme string) {
b.AddTx(tx) b.AddTx(tx)
}) })
// Import the canonical chain // Import the canonical chain
options := BlockchainOptionsWithScheme(scheme) options := DefaultBlockChainConfig(scheme)
options.VmConfig = vm.Config{ options.VmConfig = vm.Config{
Tracer: logger.NewJSONLogger(nil, os.Stdout), Tracer: logger.NewJSONLogger(nil, os.Stdout),
} }
@ -2800,7 +2800,7 @@ func testDeleteRecreateAccount(t *testing.T, scheme string) {
b.AddTx(tx) b.AddTx(tx)
}) })
// Import the canonical chain // Import the canonical chain
options := BlockchainOptionsWithScheme(scheme) options := DefaultBlockChainConfig(scheme)
options.VmConfig = vm.Config{ options.VmConfig = vm.Config{
Tracer: logger.NewJSONLogger(nil, os.Stdout), Tracer: logger.NewJSONLogger(nil, os.Stdout),
} }
@ -2977,7 +2977,7 @@ func testDeleteRecreateSlotsAcrossManyBlocks(t *testing.T, scheme string) {
current = exp current = exp
}) })
// Import the canonical chain // Import the canonical chain
options := BlockchainOptionsWithScheme(scheme) options := DefaultBlockChainConfig(scheme)
options.VmConfig = vm.Config{ options.VmConfig = vm.Config{
//Debug: true, //Debug: true,
//Tracer: vm.NewJSONLogger(nil, os.Stdout), //Tracer: vm.NewJSONLogger(nil, os.Stdout),
@ -3117,7 +3117,7 @@ func testInitThenFailCreateContract(t *testing.T, scheme string) {
}) })
// Import the canonical chain // Import the canonical chain
options := BlockchainOptionsWithScheme(scheme) options := DefaultBlockChainConfig(scheme)
options.VmConfig = vm.Config{ options.VmConfig = vm.Config{
//Debug: true, //Debug: true,
//Tracer: vm.NewJSONLogger(nil, os.Stdout), //Tracer: vm.NewJSONLogger(nil, os.Stdout),
@ -3209,7 +3209,7 @@ func testEIP2718Transition(t *testing.T, scheme string) {
}) })
// Import the canonical chain // Import the canonical chain
options := BlockchainOptionsWithScheme(scheme) options := DefaultBlockChainConfig(scheme)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options)
if err != nil { if err != nil {
t.Fatalf("failed to create tester chain: %v", err) t.Fatalf("failed to create tester chain: %v", err)
@ -3304,7 +3304,7 @@ func testEIP1559Transition(t *testing.T, scheme string) {
b.AddTx(tx) b.AddTx(tx)
}) })
options := BlockchainOptionsWithScheme(scheme) options := DefaultBlockChainConfig(scheme)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options)
if err != nil { if err != nil {
t.Fatalf("failed to create tester chain: %v", err) t.Fatalf("failed to create tester chain: %v", err)
@ -3418,7 +3418,7 @@ func testSetCanonical(t *testing.T, scheme string) {
diskdb, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) diskdb, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false)
defer diskdb.Close() defer diskdb.Close()
options := BlockchainOptionsWithScheme(scheme) options := DefaultBlockChainConfig(scheme)
chain, err := NewBlockChain(diskdb, gspec, engine, options) chain, err := NewBlockChain(diskdb, gspec, engine, options)
if err != nil { if err != nil {
t.Fatalf("failed to create tester chain: %v", err) t.Fatalf("failed to create tester chain: %v", err)
@ -3528,7 +3528,7 @@ func testCanonicalHashMarker(t *testing.T, scheme string) {
_, forkB, _ := GenerateChainWithGenesis(gspec, engine, c.forkB, func(i int, gen *BlockGen) {}) _, forkB, _ := GenerateChainWithGenesis(gspec, engine, c.forkB, func(i int, gen *BlockGen) {})
// Initialize test chain // Initialize test chain
options := BlockchainOptionsWithScheme(scheme) options := DefaultBlockChainConfig(scheme)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, options)
if err != nil { if err != nil {
t.Fatalf("failed to create tester chain: %v", err) t.Fatalf("failed to create tester chain: %v", err)
@ -3860,7 +3860,7 @@ func TestTransientStorageReset(t *testing.T) {
}) })
// Initialize the blockchain with 1153 enabled. // Initialize the blockchain with 1153 enabled.
options := *defaultOptions options := *defaultConfig
options.VmConfig = vmConfig options.VmConfig = vmConfig
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, &options) chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), gspec, engine, &options)
if err != nil { if err != nil {
@ -3956,7 +3956,7 @@ func TestEIP3651(t *testing.T) {
b.AddTx(tx) b.AddTx(tx)
}) })
options := *defaultOptions options := *defaultConfig
options.VmConfig = vm.Config{ options.VmConfig = vm.Config{
Tracer: logger.NewMarkdownLogger(&logger.Config{}, os.Stderr).Hooks(), Tracer: logger.NewMarkdownLogger(&logger.Config{}, os.Stderr).Hooks(),
} }
@ -4219,7 +4219,7 @@ func testChainReorgSnapSync(t *testing.T, ancientLimit uint64) {
db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false)
defer db.Close() defer db.Close()
options := BlockchainOptionsWithScheme(rawdb.PathScheme) options := DefaultBlockChainConfig(rawdb.PathScheme)
chain, _ := NewBlockChain(db, gspec, beacon.New(ethash.NewFaker()), options) chain, _ := NewBlockChain(db, gspec, beacon.New(ethash.NewFaker()), options)
defer chain.Stop() defer chain.Stop()
@ -4330,13 +4330,13 @@ func testInsertChainWithCutoff(t *testing.T, cutoff uint64, ancientLimit uint64,
}() }()
// Enable pruning in cache config. // Enable pruning in cache config.
config := BlockchainOptionsWithScheme(rawdb.PathScheme) config := DefaultBlockChainConfig(rawdb.PathScheme)
config.ChainHistoryMode = history.KeepPostMerge config.ChainHistoryMode = history.KeepPostMerge
db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false)
defer db.Close() defer db.Close()
options := BlockchainOptionsWithScheme(rawdb.PathScheme) options := DefaultBlockChainConfig(rawdb.PathScheme)
chain, _ := NewBlockChain(db, genesis, beacon.New(ethash.NewFaker()), options) chain, _ := NewBlockChain(db, genesis, beacon.New(ethash.NewFaker()), options)
defer chain.Stop() defer chain.Stop()

View file

@ -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) { 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() db := rawdb.NewMemoryDatabase()
cacheConfig := BlockchainOptionsWithScheme(rawdb.PathScheme) cacheConfig := DefaultBlockChainConfig(rawdb.PathScheme)
cacheConfig.SnapshotLimit = 0 cacheConfig.SnapshotLimit = 0
triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true)) triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true))
defer triedb.Close() defer triedb.Close()

View file

@ -233,7 +233,7 @@ func ExampleGenerateChain() {
}) })
// Import the chain. This runs all block validation rules. // Import the chain. This runs all block validation rules.
blockchain, _ := NewBlockChain(db, gspec, ethash.NewFaker(), BlockchainOptionsWithScheme(rawdb.HashScheme)) blockchain, _ := NewBlockChain(db, gspec, ethash.NewFaker(), DefaultBlockChainConfig(rawdb.HashScheme))
defer blockchain.Stop() defer blockchain.Stop()
if i, err := blockchain.InsertChain(chain); err != nil { if i, err := blockchain.InsertChain(chain); err != nil {

View file

@ -130,7 +130,7 @@ func testSetupGenesis(t *testing.T, scheme string) {
tdb := triedb.NewDatabase(db, newDbConfig(scheme)) tdb := triedb.NewDatabase(db, newDbConfig(scheme))
oldcustomg.Commit(db, tdb) oldcustomg.Commit(db, tdb)
bc, _ := NewBlockChain(db, &oldcustomg, ethash.NewFullFaker(), BlockchainOptionsWithScheme(scheme)) bc, _ := NewBlockChain(db, &oldcustomg, ethash.NewFullFaker(), DefaultBlockChainConfig(scheme))
defer bc.Stop() defer bc.Stop()
_, blocks, _ := GenerateChainWithGenesis(&oldcustomg, ethash.NewFaker(), 4, nil) _, blocks, _ := GenerateChainWithGenesis(&oldcustomg, ethash.NewFaker(), 4, nil)

View file

@ -119,7 +119,7 @@ func TestProcessVerkle(t *testing.T) {
// Verkle trees use the snapshot, which must be enabled before the // Verkle trees use the snapshot, which must be enabled before the
// data is saved into the tree+database. // data is saved into the tree+database.
// genesis := gspec.MustCommit(bcdb, triedb) // genesis := gspec.MustCommit(bcdb, triedb)
options := BlockchainOptionsWithScheme(rawdb.PathScheme) options := DefaultBlockChainConfig(rawdb.PathScheme)
options.SnapshotLimit = 0 options.SnapshotLimit = 0
blockchain, _ := NewBlockChain(bcdb, gspec, beacon.New(ethash.NewFaker()), options) blockchain, _ := NewBlockChain(bcdb, gspec, beacon.New(ethash.NewFaker()), options)
defer blockchain.Stop() defer blockchain.Stop()
@ -255,7 +255,7 @@ func TestProcessParentBlockHash(t *testing.T) {
}) })
t.Run("Verkle", func(t *testing.T) { t.Run("Verkle", func(t *testing.T) {
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
cacheConfig := BlockchainOptionsWithScheme(rawdb.PathScheme) cacheConfig := DefaultBlockChainConfig(rawdb.PathScheme)
cacheConfig.SnapshotLimit = 0 cacheConfig.SnapshotLimit = 0
triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true)) triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true))
statedb, _ := state.New(types.EmptyVerkleHash, state.NewDatabase(triedb, nil)) statedb, _ := state.New(types.EmptyVerkleHash, state.NewDatabase(triedb, nil))

View file

@ -67,7 +67,7 @@ func newTestBlockChain(t *testing.T, n int, gspec *core.Genesis, generator func(
_, blocks, _ := core.GenerateChainWithGenesis(gspec, engine, n, generator) _, blocks, _ := core.GenerateChainWithGenesis(gspec, engine, n, generator)
// Import the canonical chain // Import the canonical chain
options := &core.BlockChainOptions{ options := &core.BlockChainConfig{
TrieCleanLimit: 256, TrieCleanLimit: 256,
TrieDirtyLimit: 256, TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute, TrieTimeLimit: 5 * time.Minute,

View file

@ -194,7 +194,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
vmConfig = vm.Config{ vmConfig = vm.Config{
EnablePreimageRecording: config.EnablePreimageRecording, EnablePreimageRecording: config.EnablePreimageRecording,
} }
options = &core.BlockChainOptions{ options = &core.BlockChainConfig{
TrieCleanLimit: config.TrieCleanCache, TrieCleanLimit: config.TrieCleanCache,
NoPrefetch: config.NoPrefetch, NoPrefetch: config.NoPrefetch,
TrieDirtyLimit: config.TrieDirtyCache, TrieDirtyLimit: config.TrieDirtyCache,

View file

@ -277,7 +277,7 @@ func testFilters(t *testing.T, history uint64, noHistory bool) {
} }
}) })
var l uint64 var l uint64
options := core.BlockchainOptionsWithScheme(rawdb.HashScheme) options := core.DefaultBlockChainConfig(rawdb.HashScheme)
options.TxLookupLimit = &l options.TxLookupLimit = &l
bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options) bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options)
if err != nil { 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) {}) chain, _ := core.GenerateChain(gspec.Config, gspec.ToBlock(), ethash.NewFaker(), db, 1000, func(i int, gen *core.BlockGen) {})
var l uint64 var l uint64
options := core.BlockchainOptionsWithScheme(rawdb.HashScheme) options := core.DefaultBlockChainConfig(rawdb.HashScheme)
options.TxLookupLimit = &l options.TxLookupLimit = &l
bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options) bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options)
if err != nil { if err != nil {

View file

@ -211,7 +211,7 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, cancunBlock *big.Int, pe
}) })
// Construct testing chain // Construct testing chain
chain, err := core.NewBlockChain(db, gspec, engine, &core.BlockChainOptions{NoPrefetch: true}) chain, err := core.NewBlockChain(db, gspec, engine, &core.BlockChainConfig{NoPrefetch: true})
if err != nil { if err != nil {
t.Fatalf("Failed to create local chain, %v", err) t.Fatalf("Failed to create local chain, %v", err)
} }

View file

@ -116,7 +116,7 @@ func getChain() *core.BlockChain {
Alloc: ga, Alloc: ga,
} }
_, blocks, _ := core.GenerateChainWithGenesis(gspec, ethash.NewFaker(), 2, func(i int, gen *core.BlockGen) {}) _, blocks, _ := core.GenerateChainWithGenesis(gspec, ethash.NewFaker(), 2, func(i int, gen *core.BlockGen) {})
options := &core.BlockChainOptions{ options := &core.BlockChainConfig{
TrieCleanLimit: 0, TrieCleanLimit: 0,
TrieDirtyLimit: 0, TrieDirtyLimit: 0,
TrieTimeLimit: 5 * time.Minute, TrieTimeLimit: 5 * time.Minute,

View file

@ -77,7 +77,7 @@ func newTestBackend(t *testing.T, n int, gspec *core.Genesis, generator func(i i
_, blocks, _ := core.GenerateChainWithGenesis(gspec, backend.engine, n, generator) _, blocks, _ := core.GenerateChainWithGenesis(gspec, backend.engine, n, generator)
// Import the canonical chain // Import the canonical chain
options := &core.BlockChainOptions{ options := &core.BlockChainConfig{
TrieCleanLimit: 256, TrieCleanLimit: 256,
TrieDirtyLimit: 256, TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute, TrieTimeLimit: 5 * time.Minute,
@ -1144,7 +1144,7 @@ func newTestMergedBackend(t *testing.T, n int, gspec *core.Genesis, generator fu
_, blocks, _ := core.GenerateChainWithGenesis(gspec, backend.engine, n, generator) _, blocks, _ := core.GenerateChainWithGenesis(gspec, backend.engine, n, generator)
// Import the canonical chain // Import the canonical chain
options := &core.BlockChainOptions{ options := &core.BlockChainConfig{
TrieCleanLimit: 256, TrieCleanLimit: 256,
TrieDirtyLimit: 256, TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute, TrieTimeLimit: 5 * time.Minute,

View file

@ -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) return nil, nil, fmt.Errorf("failed to create call tracer: %v", err)
} }
options := core.BlockchainOptionsWithScheme(rawdb.PathScheme) options := core.DefaultBlockChainConfig(rawdb.PathScheme)
options.VmConfig = vm.Config{Tracer: tracer} options.VmConfig = vm.Config{Tracer: tracer}
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, options) chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), genesis, engine, options)
if err != nil { if err != nil {

View file

@ -444,7 +444,7 @@ type testBackend struct {
func newTestBackend(t *testing.T, n int, gspec *core.Genesis, engine consensus.Engine, generator func(i int, b *core.BlockGen)) *testBackend { func newTestBackend(t *testing.T, n int, gspec *core.Genesis, engine consensus.Engine, generator func(i int, b *core.BlockGen)) *testBackend {
var ( var (
txLookupLimit = uint64(0) txLookupLimit = uint64(0)
options = &core.BlockChainOptions{ options = &core.BlockChainConfig{
TrieCleanLimit: 256, TrieCleanLimit: 256,
TrieDirtyLimit: 256, TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute, TrieTimeLimit: 5 * time.Minute,

View file

@ -117,7 +117,7 @@ func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine
default: default:
t.Fatalf("unexpected consensus engine type: %T", engine) t.Fatalf("unexpected consensus engine type: %T", engine)
} }
chain, err := core.NewBlockChain(db, gspec, engine, &core.BlockChainOptions{ArchiveMode: true}) chain, err := core.NewBlockChain(db, gspec, engine, &core.BlockChainConfig{ArchiveMode: true})
if err != nil { if err != nil {
t.Fatalf("core.NewBlockChain failed: %v", err) t.Fatalf("core.NewBlockChain failed: %v", err)
} }

View file

@ -151,7 +151,7 @@ func (t *BlockTest) Run(snapshotter bool, scheme string, witness bool, tracer *t
// Wrap the original engine within the beacon-engine // Wrap the original engine within the beacon-engine
engine := beacon.New(ethash.NewFaker()) engine := beacon.New(ethash.NewFaker())
options := &core.BlockChainOptions{ options := &core.BlockChainConfig{
TrieCleanLimit: 0, TrieCleanLimit: 0,
StateScheme: scheme, StateScheme: scheme,
Preimages: true, Preimages: true,