core: refactor NewBlockchain. Add blockChainConfig.

This commit is contained in:
makinje 2024-01-07 19:20:06 -05:00
parent 0b471c312a
commit 3bdb06450d
29 changed files with 688 additions and 141 deletions

View file

@ -84,7 +84,12 @@ func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.Genesis
GasLimit: gasLimit,
Alloc: alloc,
}
blockchain, _ := core.NewBlockChain(database, nil, &genesis, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config := core.NewBlockChainConfig(
core.WithGenesis(&genesis),
core.WithVmConfig(&vm.Config{}),
)
blockchain, _ := core.NewBlockChain(database, ethash.NewFaker(), config)
backend := &SimulatedBackend{
database: database,

View file

@ -2121,8 +2121,14 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
}
vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)}
bcConfig := core.NewBlockChainConfig(
core.WithCacheConfig(cache),
core.WithGenesis(gspec),
core.WithVmConfig(&vmcfg),
)
// Disable transaction indexing/unindexing by default.
chain, err := core.NewBlockChain(chainDb, cache, gspec, nil, engine, vmcfg, nil, nil)
chain, err := core.NewBlockChain(chainDb, engine, bcConfig)
if err != nil {
Fatalf("Can't create BlockChain: %v", err)
}

View file

@ -54,8 +54,13 @@ func TestReimportMirroredState(t *testing.T) {
}
copy(genspec.ExtraData[extraVanity:], addr[:])
config := core.NewBlockChainConfig(
core.WithGenesis(genspec),
core.WithVmConfig(&vm.Config{}),
)
// Generate a batch of blocks, each properly signed
chain, _ := core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, genspec, nil, engine, vm.Config{}, nil, nil)
chain, _ := core.NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
defer chain.Stop()
_, blocks, _ := core.GenerateChainWithGenesis(genspec, engine, 3, func(i int, block *core.BlockGen) {
@ -87,7 +92,7 @@ func TestReimportMirroredState(t *testing.T) {
}
// Insert the first two blocks and make sure the chain is valid
db = rawdb.NewMemoryDatabase()
chain, _ = core.NewBlockChain(db, nil, genspec, nil, engine, vm.Config{}, nil, nil)
chain, _ = core.NewBlockChain(db, engine, config)
defer chain.Stop()
if _, err := chain.InsertChain(blocks[:2]); err != nil {
@ -100,7 +105,7 @@ func TestReimportMirroredState(t *testing.T) {
// Simulate a crash by creating a new chain on top of the database, without
// flushing the dirty states out. Insert the last block, triggering a sidechain
// reimport.
chain, _ = core.NewBlockChain(db, nil, genspec, nil, engine, vm.Config{}, nil, nil)
chain, _ = core.NewBlockChain(db, engine, config)
defer chain.Stop()
if _, err := chain.InsertChain(blocks[2:]); err != nil {

View file

@ -457,8 +457,14 @@ func (tt *cliqueTest) run(t *testing.T) {
}
batches[len(batches)-1] = append(batches[len(batches)-1], block)
}
bcConfig := core.NewBlockChainConfig(
core.WithGenesis(genesis),
core.WithVmConfig(&vm.Config{}),
)
// Pass all the headers through clique and ensure tallying succeeds
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, genesis, nil, engine, vm.Config{}, nil, nil)
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), engine, bcConfig)
if err != nil {
t.Fatalf("failed to create test chain: %v", err)
}

View file

@ -195,7 +195,9 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
// Time the insertion of the new chain.
// State and blocks are stored in the same DB.
chainman, _ := NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config := NewBlockChainConfig(WithGenesis(gspec), WithVmConfig(&vm.Config{}))
chainman, _ := NewBlockChain(db, ethash.NewFaker(), config)
defer chainman.Stop()
b.ReportAllocs()
b.ResetTimer()
@ -298,6 +300,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
db.Close()
cacheConfig := *defaultCacheConfig
cacheConfig.TrieDirtyDisabled = true
config := NewBlockChainConfig(WithCacheConfig(&cacheConfig), WithVmConfig(&vm.Config{}))
b.ReportAllocs()
b.ResetTimer()
@ -307,7 +310,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
if err != nil {
b.Fatalf("error opening database at %v: %v", dir, err)
}
chain, err := NewBlockChain(db, &cacheConfig, nil, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
chain, err := NewBlockChain(db, ethash.NewFaker(), config)
if err != nil {
b.Fatalf("error creating chain: %v", err)
}

View file

@ -50,7 +50,14 @@ 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
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
)
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), config)
defer chain.Stop()
for i := 0; i < len(blocks); i++ {
@ -163,7 +170,8 @@ func testHeaderVerificationForMerging(t *testing.T, isClique bool) {
t.Logf("Post-merge header: %d", block.NumberU64())
}
// Run the header checker for blocks one-by-one, checking for both valid and invalid nonces
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{}, nil, nil)
config := NewBlockChainConfig(WithGenesis(gspec), WithVmConfig(&vm.Config{}))
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
defer chain.Stop()
// Verify the blocks before the merging

View file

@ -260,20 +260,98 @@ type BlockChain struct {
vmConfig vm.Config
}
// blockChainConfig stores configuration options for the BlockChain.
type blockChainConfig struct {
cacheConfig *CacheConfig
genesis *Genesis
overrides *ChainOverrides
shouldPreserve func(header *types.Header) bool
txLookupLimit *uint64
vmConfig *vm.Config
}
// A BlockChainOption is a function that takes in and modifies a *blockChainConfig
type BlockChainOption func(config *blockChainConfig)
// NewBlockChainConfig creates a new blockChainConfig with optional configurations.
func NewBlockChainConfig(options ...BlockChainOption) *blockChainConfig {
var config blockChainConfig
for _, f := range options {
f(&config)
}
return &config
}
// WithCacheConfig returns a BlockChainOption that sets the CacheConfig.
func WithCacheConfig(cacheConfig *CacheConfig) BlockChainOption {
changeConfig := func(bcConfig *blockChainConfig) {
bcConfig.cacheConfig = cacheConfig
}
return changeConfig
}
// WithGenesis returns a BlockChainOption that sets the genesis block.
func WithGenesis(genesis *Genesis) BlockChainOption {
changeGenesis := func(bcConfig *blockChainConfig) {
bcConfig.genesis = genesis
}
return changeGenesis
}
// WithOverrides returns a BlockChainOption that sets the overrides for the BlockChain.
func WithOverrides(overrides *ChainOverrides) BlockChainOption {
changeOverrides := func(config *blockChainConfig) {
config.overrides = overrides
}
return changeOverrides
}
// WithShouldPreserve returns a BlockChainOption that sets the shouldPreserve function.
func WithShouldPreserve(shouldPreserve func(header *types.Header) bool) BlockChainOption {
changeShouldPreserve := func(config *blockChainConfig) {
config.shouldPreserve = shouldPreserve
}
return changeShouldPreserve
}
// WithTxLookupLimit returns a BlockChainOption that sets the transaction lookup limit.
func WithTxLookupLimit(limit *uint64) BlockChainOption {
changeTxLookupLimit := func(config *blockChainConfig) {
config.txLookupLimit = limit
}
return changeTxLookupLimit
}
// WithVmConfig returns a BlockChainOption that sets the vm.Config.
func WithVmConfig(vmConfig *vm.Config) BlockChainOption {
changeVmConfig := func(config *blockChainConfig) {
config.vmConfig = vmConfig
}
return changeVmConfig
}
// NewBlockChain returns a fully initialised block chain using information
// available in the database. It initialises the default Ethereum Validator
// and Processor.
func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64) (*BlockChain, error) {
if cacheConfig == nil {
cacheConfig = defaultCacheConfig
func NewBlockChain(db ethdb.Database, engine consensus.Engine, bcConfig *blockChainConfig) (*BlockChain, error) {
if bcConfig.cacheConfig == nil {
bcConfig.cacheConfig = defaultCacheConfig
}
// Open trie database with provided config
triedb := trie.NewDatabase(db, cacheConfig.triedbConfig())
triedb := trie.NewDatabase(db, bcConfig.cacheConfig.triedbConfig())
// Setup the genesis block, commit the provided genesis specification
// to database if the genesis block is not present yet, or load the
// stored one from database.
chainConfig, genesisHash, genesisErr := SetupGenesisBlockWithOverride(db, triedb, genesis, overrides)
chainConfig, genesisHash, genesisErr := SetupGenesisBlockWithOverride(db, triedb, bcConfig.genesis, bcConfig.overrides)
if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok {
return nil, genesisErr
}
@ -287,7 +365,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
bc := &BlockChain{
chainConfig: chainConfig,
cacheConfig: cacheConfig,
cacheConfig: bcConfig.cacheConfig,
db: db,
triedb: triedb,
triegc: prque.New[int64, common.Hash](nil),
@ -300,10 +378,10 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
txLookupCache: lru.NewCache[common.Hash, *rawdb.LegacyTxLookupEntry](txLookupCacheLimit),
futureBlocks: lru.NewCache[common.Hash, *types.Block](maxFutureBlocks),
engine: engine,
vmConfig: vmConfig,
vmConfig: *bcConfig.vmConfig,
}
bc.flushInterval.Store(int64(cacheConfig.TrieTimeLimit))
bc.forker = NewForkChoice(bc, shouldPreserve)
bc.flushInterval.Store(int64(bcConfig.cacheConfig.TrieTimeLimit))
bc.forker = NewForkChoice(bc, bcConfig.shouldPreserve)
bc.stateCache = state.NewDatabaseWithNodeDB(bc.db, bc.triedb)
bc.validator = NewBlockValidator(chainConfig, bc, engine)
bc.prefetcher = newStatePrefetcher(chainConfig, bc, engine)
@ -464,8 +542,8 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
rawdb.WriteChainConfig(db, genesisHash, chainConfig)
}
// Start tx indexer/unindexer if required.
if txLookupLimit != nil {
bc.txLookupLimit = *txLookupLimit
if bcConfig.txLookupLimit != nil {
bc.txLookupLimit = *bcConfig.txLookupLimit
bc.wg.Add(1)
go bc.maintainTxIndex()

View file

@ -1794,7 +1794,10 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s
config.SnapshotLimit = 256
config.SnapshotWait = true
}
chain, err := NewBlockChain(db, config, gspec, nil, engine, vm.Config{}, nil, nil)
baseConfig := NewBlockChainConfig(WithCacheConfig(config), WithGenesis(gspec), WithVmConfig(&vm.Config{}))
chain, err := NewBlockChain(db, engine, baseConfig)
if err != nil {
t.Fatalf("Failed to create chain: %v", err)
}
@ -1855,7 +1858,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s
}
defer db.Close()
newChain, err := NewBlockChain(db, config, gspec, nil, engine, vm.Config{}, nil, nil)
newChain, err := NewBlockChain(db, engine, baseConfig)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}
@ -1927,7 +1930,14 @@ func testIssue23496(t *testing.T, scheme string) {
}
engine = ethash.NewFullFaker()
)
chain, err := NewBlockChain(db, DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil, nil)
baseConfig := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(db, engine, baseConfig)
if err != nil {
t.Fatalf("Failed to create chain: %v", err)
}
@ -1977,7 +1987,7 @@ func testIssue23496(t *testing.T, scheme string) {
}
defer db.Close()
chain, err = NewBlockChain(db, DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil, nil)
chain, err = NewBlockChain(db, engine, baseConfig)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}

View file

@ -1997,7 +1997,14 @@ func testSetHeadWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme
config.SnapshotLimit = 256
config.SnapshotWait = true
}
chain, err := NewBlockChain(db, config, gspec, nil, engine, vm.Config{}, nil, nil)
bcConfig := NewBlockChainConfig(
WithGenesis(gspec),
WithCacheConfig(config),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(db, engine, bcConfig)
if err != nil {
t.Fatalf("Failed to create chain: %v", err)
}

View file

@ -80,8 +80,13 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo
Config: params.AllEthashProtocolChanges,
}
engine = ethash.NewFullFaker()
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(basic.scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(db, DefaultCacheConfigWithScheme(basic.scheme), gspec, nil, engine, vm.Config{}, nil, nil)
)
chain, err := NewBlockChain(db, engine, config)
if err != nil {
t.Fatalf("Failed to create chain: %v", err)
}
@ -228,7 +233,14 @@ func (snaptest *snapshotTest) test(t *testing.T) {
// Restart the chain normally
chain.Stop()
newchain, err := NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(snaptest.scheme)),
WithGenesis(snaptest.gspec),
WithVmConfig(&vm.Config{}),
)
newchain, err := NewBlockChain(snaptest.db, snaptest.engine, config)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}
@ -270,13 +282,19 @@ 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, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(snaptest.scheme)),
WithGenesis(snaptest.gspec),
WithVmConfig(&vm.Config{}),
)
newchain, err := NewBlockChain(newdb, snaptest.engine, config)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}
newchain.Stop()
newchain, err = NewBlockChain(newdb, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
newchain, err = NewBlockChain(newdb, snaptest.engine, config)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}
@ -313,15 +331,28 @@ func (snaptest *gappedSnapshotTest) test(t *testing.T) {
SnapshotLimit: 0,
StateScheme: snaptest.scheme,
}
newchain, err := NewBlockChain(snaptest.db, cacheConfig, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(cacheConfig),
WithGenesis(snaptest.gspec),
WithVmConfig(&vm.Config{}),
)
newchain, err := NewBlockChain(snaptest.db, snaptest.engine, config)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}
newchain.InsertChain(gappedBlocks)
newchain.Stop()
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(snaptest.scheme)),
WithGenesis(snaptest.gspec),
WithVmConfig(&vm.Config{}),
)
// Restart the chain with enabling the snapshot
newchain, err = NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
newchain, err = NewBlockChain(snaptest.db, snaptest.engine, config)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}
@ -349,7 +380,13 @@ func (snaptest *setHeadSnapshotTest) test(t *testing.T) {
chain.SetHead(snaptest.setHead)
chain.Stop()
newchain, err := NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(snaptest.scheme)),
WithGenesis(snaptest.gspec),
WithVmConfig(&vm.Config{}),
)
newchain, err := NewBlockChain(snaptest.db, snaptest.engine, config)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}
@ -385,7 +422,14 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
SnapshotLimit: 0,
StateScheme: snaptest.scheme,
}
newchain, err := NewBlockChain(snaptest.db, config, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
bcConfig := NewBlockChainConfig(
WithCacheConfig(config),
WithGenesis(snaptest.gspec),
WithVmConfig(&vm.Config{}),
)
newchain, err := NewBlockChain(snaptest.db, snaptest.engine, bcConfig)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}
@ -402,7 +446,14 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
SnapshotWait: false, // Don't wait rebuild
StateScheme: snaptest.scheme,
}
tmp, err := NewBlockChain(snaptest.db, config, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
bcConfig = NewBlockChainConfig(
WithCacheConfig(config),
WithGenesis(snaptest.gspec),
WithVmConfig(&vm.Config{}),
)
tmp, err := NewBlockChain(snaptest.db, snaptest.engine, bcConfig)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}
@ -411,7 +462,13 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
tmp.triedb.Close()
tmp.stopWithoutSaving()
newchain, err = NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil)
bcConfig = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(snaptest.scheme)),
WithGenesis(snaptest.gspec),
WithVmConfig(&vm.Config{}),
)
newchain, err = NewBlockChain(snaptest.db, snaptest.engine, bcConfig)
if err != nil {
t.Fatalf("Failed to recreate chain: %v", err)
}

View file

@ -53,14 +53,19 @@ var (
// header only chain. The database and genesis specification for block generation
// are also returned in case more test blocks are needed later.
func newCanonical(engine consensus.Engine, n int, full bool, scheme string) (ethdb.Database, *Genesis, *BlockChain, error) {
var (
genesis = &Genesis{
// Initialize a fresh chain with only a genesis block
genesis := &Genesis{
BaseFee: big.NewInt(params.InitialBaseFee),
Config: params.AllEthashProtocolChanges,
}
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(genesis),
WithVmConfig(&vm.Config{}),
)
// Initialize a fresh chain with only a genesis block
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), genesis, nil, engine, vm.Config{}, nil, nil)
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
// Create and inject the requested chain
if n == 0 {
@ -739,7 +744,13 @@ func testReorgBadHashes(t *testing.T, full bool, scheme string) {
blockchain.Stop()
// Create a new BlockChain and check that it rolled back the state.
ncm, err := NewBlockChain(blockchain.db, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
ncm, err := NewBlockChain(blockchain.db, ethash.NewFaker(), config)
if err != nil {
t.Fatalf("failed to create new chain manager: %v", err)
}
@ -842,6 +853,12 @@ func testFastVsFullChains(t *testing.T, scheme string) {
BaseFee: big.NewInt(params.InitialBaseFee),
}
signer = types.LatestSigner(gspec.Config)
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
)
_, blocks, receipts := GenerateChainWithGenesis(gspec, ethash.NewFaker(), 1024, func(i int, block *BlockGen) {
block.SetCoinbase(common.Address{0x00})
@ -863,7 +880,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, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
archive, _ := NewBlockChain(archiveDb, ethash.NewFaker(), config)
defer archive.Stop()
if n, err := archive.InsertChain(blocks); err != nil {
@ -871,7 +888,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, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
fast, _ := NewBlockChain(fastDb, ethash.NewFaker(), config)
defer fast.Stop()
headers := make([]*types.Header, len(blocks))
@ -891,7 +908,7 @@ func testFastVsFullChains(t *testing.T, scheme string) {
}
defer ancientDb.Close()
ancient, _ := NewBlockChain(ancientDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
ancient, _ := NewBlockChain(ancientDb, ethash.NewFaker(), config)
defer ancient.Stop()
if n, err := ancient.InsertHeaderChain(headers); err != nil {
@ -1011,7 +1028,13 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) {
archiveCaching.TrieDirtyDisabled = true
archiveCaching.StateScheme = scheme
archive, _ := NewBlockChain(archiveDb, &archiveCaching, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(&archiveCaching),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
archive, _ := NewBlockChain(archiveDb, ethash.NewFaker(), config)
if n, err := archive.InsertChain(blocks); err != nil {
t.Fatalf("failed to process block %d: %v", n, err)
}
@ -1024,7 +1047,14 @@ 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, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
fast, _ := NewBlockChain(fastDb, ethash.NewFaker(), config)
defer fast.Stop()
headers := make([]*types.Header, len(blocks))
@ -1044,7 +1074,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, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
ancient, _ := NewBlockChain(ancientDb, ethash.NewFaker(), config)
defer ancient.Stop()
if n, err := ancient.InsertHeaderChain(headers); err != nil {
@ -1063,7 +1093,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) {
// Import the chain as a light node and ensure all pointers are updated
lightDb := makeDb()
defer lightDb.Close()
light, _ := NewBlockChain(lightDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
light, _ := NewBlockChain(lightDb, ethash.NewFaker(), config)
if n, err := light.InsertHeaderChain(headers); err != nil {
t.Fatalf("failed to insert header %d: %v", n, err)
}
@ -1136,7 +1166,14 @@ func testChainTxReorgs(t *testing.T, scheme string) {
})
// Import the chain. This runs all block validation rules.
db := rawdb.NewMemoryDatabase()
blockchain, _ := NewBlockChain(db, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
blockchain, _ := NewBlockChain(db, ethash.NewFaker(), config)
if i, err := blockchain.InsertChain(chain); err != nil {
t.Fatalf("failed to insert original chain[%d]: %v", i, err)
}
@ -1210,7 +1247,13 @@ func testLogReorgs(t *testing.T, scheme string) {
signer = types.LatestSigner(gspec.Config)
)
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), config)
defer blockchain.Stop()
rmLogsCh := make(chan RemovedLogsEvent)
@ -1266,7 +1309,12 @@ func testLogRebirth(t *testing.T, scheme string) {
gspec = &Genesis{Config: params.TestChainConfig, Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}}
signer = types.LatestSigner(gspec.Config)
engine = ethash.NewFaker()
blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil, nil)
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
)
defer blockchain.Stop()
@ -1347,7 +1395,12 @@ func testSideLogRebirth(t *testing.T, scheme string) {
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
gspec = &Genesis{Config: params.TestChainConfig, Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}}
signer = types.LatestSigner(gspec.Config)
blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), config)
)
defer blockchain.Stop()
@ -1445,8 +1498,13 @@ func testReorgSideEvent(t *testing.T, scheme string) {
Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}},
}
signer = types.LatestSigner(gspec.Config)
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
)
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), config)
defer blockchain.Stop()
_, chain, _ := GenerateChainWithGenesis(gspec, ethash.NewFaker(), 3, func(i int, gen *BlockGen) {})
@ -1587,6 +1645,11 @@ func testEIP155Transition(t *testing.T, scheme string) {
},
Alloc: GenesisAlloc{address: {Balance: funds}, deleteAddr: {Balance: new(big.Int)}},
}
bcConfig = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
)
genDb, blocks, _ := GenerateChainWithGenesis(gspec, ethash.NewFaker(), 4, func(i int, block *BlockGen) {
var (
@ -1630,7 +1693,7 @@ func testEIP155Transition(t *testing.T, scheme string) {
}
})
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), bcConfig)
defer blockchain.Stop()
if _, err := blockchain.InsertChain(blocks); err != nil {
@ -1702,6 +1765,11 @@ func testEIP161AccountRemoval(t *testing.T, scheme string) {
},
Alloc: GenesisAlloc{address: {Balance: funds}},
}
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
)
_, blocks, _ := GenerateChainWithGenesis(gspec, ethash.NewFaker(), 3, func(i int, block *BlockGen) {
var (
@ -1723,7 +1791,7 @@ func testEIP161AccountRemoval(t *testing.T, scheme string) {
block.AddTx(tx)
})
// account must exist pre eip 161
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), config)
defer blockchain.Stop()
if _, err := blockchain.InsertChain(types.Blocks{blocks[0]}); err != nil {
@ -1767,6 +1835,11 @@ func testBlockchainHeaderchainReorgConsistency(t *testing.T, scheme string) {
Config: params.TestChainConfig,
BaseFee: big.NewInt(params.InitialBaseFee),
}
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(genesis),
WithVmConfig(&vm.Config{}),
)
genDb, blocks, _ := GenerateChainWithGenesis(genesis, engine, 64, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) })
// Generate a bunch of fork blocks, each side forking from the canonical chain
@ -1781,7 +1854,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(), DefaultCacheConfigWithScheme(scheme), genesis, nil, engine, vm.Config{}, nil, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -1812,6 +1885,10 @@ func TestTrieForkGC(t *testing.T) {
Config: params.TestChainConfig,
BaseFee: big.NewInt(params.InitialBaseFee),
}
config := NewBlockChainConfig(
WithGenesis(genesis),
WithVmConfig(&vm.Config{}),
)
genDb, blocks, _ := GenerateChainWithGenesis(genesis, engine, 2*TriesInMemory, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) })
// Generate a bunch of fork blocks, each side forking from the canonical chain
@ -1825,7 +1902,7 @@ func TestTrieForkGC(t *testing.T) {
forks[i] = fork[0]
}
// Import the canonical and fork chain side by side, forcing the trie cache to cache both
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, genesis, nil, engine, vm.Config{}, nil, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -1863,6 +1940,12 @@ func testLargeReorgTrieGC(t *testing.T, scheme string) {
Config: params.TestChainConfig,
BaseFee: big.NewInt(params.InitialBaseFee),
}
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(genesis),
WithVmConfig(&vm.Config{}),
)
genDb, shared, _ := GenerateChainWithGenesis(genesis, engine, 64, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) })
original, _ := GenerateChain(genesis.Config, shared[len(shared)-1], engine, genDb, 2*TriesInMemory, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{2}) })
competitor, _ := GenerateChain(genesis.Config, shared[len(shared)-1], engine, genDb, 2*TriesInMemory+1, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{3}) })
@ -1871,7 +1954,7 @@ func testLargeReorgTrieGC(t *testing.T, scheme string) {
db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), t.TempDir(), "", false)
defer db.Close()
chain, err := NewBlockChain(db, DefaultCacheConfigWithScheme(scheme), genesis, nil, engine, vm.Config{}, nil, nil)
chain, err := NewBlockChain(db, engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -1932,6 +2015,11 @@ func testBlockchainRecovery(t *testing.T, scheme string) {
address = crypto.PubkeyToAddress(key.PublicKey)
funds = big.NewInt(1000000000)
gspec = &Genesis{Config: params.TestChainConfig, Alloc: GenesisAlloc{address: {Balance: funds}}}
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
)
height := uint64(1024)
_, blocks, receipts := GenerateChainWithGenesis(gspec, ethash.NewFaker(), int(height), nil)
@ -1942,7 +2030,7 @@ func testBlockchainRecovery(t *testing.T, scheme string) {
t.Fatalf("failed to create temp freezer db: %v", err)
}
defer ancientDb.Close()
ancient, _ := NewBlockChain(ancientDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
ancient, _ := NewBlockChain(ancientDb, ethash.NewFaker(), config)
headers := make([]*types.Header, len(blocks))
for i, block := range blocks {
@ -1962,7 +2050,7 @@ func testBlockchainRecovery(t *testing.T, scheme string) {
rawdb.WriteHeadFastBlockHash(ancientDb, midBlock.Hash())
// Reopen broken blockchain again
ancient, _ = NewBlockChain(ancientDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
ancient, _ = NewBlockChain(ancientDb, ethash.NewFaker(), config)
defer ancient.Stop()
if num := ancient.CurrentBlock().Number.Uint64(); num != 0 {
t.Errorf("head block mismatch: have #%v, want #%v", num, 0)
@ -2014,7 +2102,12 @@ func testInsertReceiptChainRollback(t *testing.T, scheme string) {
}
defer ancientDb.Close()
ancientChain, _ := NewBlockChain(ancientDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
ancientChain, _ := NewBlockChain(ancientDb, ethash.NewFaker(), config)
defer ancientChain.Stop()
// Import the canonical header chain.
@ -2081,7 +2174,13 @@ func testLowDiffLongChain(t *testing.T, scheme string) {
diskdb, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), t.TempDir(), "", false)
defer diskdb.Close()
chain, err := NewBlockChain(diskdb, DefaultCacheConfigWithScheme(scheme), genesis, nil, engine, vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(genesis),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(diskdb, engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -2141,9 +2240,13 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon
}
signer = types.LatestSigner(gspec.Config)
mergeBlock = math.MaxInt32
config = NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
)
// Generate and import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{}, nil, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -2301,7 +2404,13 @@ func testInsertKnownChainData(t *testing.T, typ string, scheme string) {
}
defer chaindb.Close()
chain, err := NewBlockChain(chaindb, DefaultCacheConfigWithScheme(scheme), genesis, nil, engine, vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(genesis),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(chaindb, engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -2472,7 +2581,12 @@ func testInsertKnownChainDataWithMerging(t *testing.T, typ string, mergeHeight i
}
defer chaindb.Close()
chain, err := NewBlockChain(chaindb, nil, genesis, nil, engine, vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithGenesis(genesis),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(chaindb, engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -2586,7 +2700,14 @@ 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(), DefaultCacheConfigWithScheme(scheme), genesis, nil, engine, vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(genesis),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("failed to create tester chain: %v", err)
}
@ -2784,7 +2905,14 @@ func TestTransactionIndices(t *testing.T) {
rawdb.WriteAncientBlocks(ancientDb, append([]*types.Block{gspec.ToBlock()}, blocks...), append([]types.Receipts{{}}, receipts...), big.NewInt(0))
l := l
chain, err := NewBlockChain(ancientDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, &l)
config := NewBlockChainConfig(
WithGenesis(gspec),
WithTxLookupLimit(&l),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(ancientDb, ethash.NewFaker(), config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -2808,7 +2936,14 @@ func TestTransactionIndices(t *testing.T) {
limit = []uint64{0, 64 /* drop stale */, 32 /* shorten history */, 64 /* extend history */, 0 /* restore all */}
for _, l := range limit {
l := l
chain, err := NewBlockChain(ancientDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, &l)
config := NewBlockChainConfig(
WithGenesis(gspec),
WithTxLookupLimit(&l),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(ancientDb, ethash.NewFaker(), config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -2886,7 +3021,15 @@ func testSkipStaleTxIndicesInSnapSync(t *testing.T, scheme string) {
// Import all blocks into ancient db, only HEAD-32 indices are kept.
l := uint64(32)
chain, err := NewBlockChain(ancientDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, &l)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithTxLookupLimit(&l),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(ancientDb, ethash.NewFaker(), config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -2943,11 +3086,16 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in
}
_, shared, _ := GenerateChainWithGenesis(gspec, engine, numBlocks, blockGenerator)
config := NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
// Import the shared chain and the original canonical one
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{}, nil, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
b.Fatalf("failed to create tester chain: %v", err)
}
@ -3034,7 +3182,13 @@ func testSideImportPrunedBlocks(t *testing.T, scheme string) {
// Generate and import the canonical chain
_, blocks, _ := GenerateChainWithGenesis(genesis, engine, 2*TriesInMemory, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), genesis, nil, engine, vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(genesis),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -3120,6 +3274,11 @@ func testDeleteCreateRevert(t *testing.T, scheme string) {
},
},
}
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
)
_, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) {
@ -3134,7 +3293,7 @@ func testDeleteCreateRevert(t *testing.T, scheme string) {
b.AddTx(tx)
})
// Import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -3246,10 +3405,17 @@ func testDeleteRecreateSlots(t *testing.T, scheme string) {
big.NewInt(0), 100000, b.header.BaseFee, nil), types.HomesteadSigner{}, key)
b.AddTx(tx)
})
// Import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{
Tracer: logger.NewJSONLogger(nil, os.Stdout),
}, nil, nil)
}),
)
// Import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -3328,10 +3494,17 @@ func testDeleteRecreateAccount(t *testing.T, scheme string) {
big.NewInt(1), 100000, b.header.BaseFee, nil), types.HomesteadSigner{}, key)
b.AddTx(tx)
})
// Import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{
Tracer: logger.NewJSONLogger(nil, os.Stdout),
}, nil, nil)
}),
)
// Import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -3504,10 +3677,13 @@ func testDeleteRecreateSlotsAcrossManyBlocks(t *testing.T, scheme string) {
current = exp
})
// Import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{
//Debug: true,
//Tracer: vm.NewJSONLogger(nil, os.Stdout),
}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -3642,10 +3818,13 @@ func testInitThenFailCreateContract(t *testing.T, scheme string) {
})
// Import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{
//Debug: true,
//Tracer: vm.NewJSONLogger(nil, os.Stdout),
}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -3732,7 +3911,13 @@ func testEIP2718Transition(t *testing.T, scheme string) {
})
// Import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -3796,6 +3981,11 @@ func testEIP1559Transition(t *testing.T, scheme string) {
},
},
}
bcConfig = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
)
gspec.Config.BerlinBlock = common.Big0
@ -3826,7 +4016,7 @@ func testEIP1559Transition(t *testing.T, scheme string) {
b.AddTx(tx)
})
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, bcConfig)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -3926,6 +4116,11 @@ func testSetCanonical(t *testing.T, scheme string) {
}
signer = types.LatestSigner(gspec.Config)
engine = ethash.NewFaker()
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
)
// Generate and import the canonical chain
_, canon, _ := GenerateChainWithGenesis(gspec, engine, 2*TriesInMemory, func(i int, gen *BlockGen) {
@ -3938,7 +4133,7 @@ func testSetCanonical(t *testing.T, scheme string) {
diskdb, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), t.TempDir(), "", false)
defer diskdb.Close()
chain, err := NewBlockChain(diskdb, DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil, nil)
chain, err := NewBlockChain(diskdb, engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -4042,12 +4237,17 @@ func testCanonicalHashMarker(t *testing.T, scheme string) {
BaseFee: big.NewInt(params.InitialBaseFee),
}
engine = ethash.NewFaker()
config = NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
)
_, forkA, _ := GenerateChainWithGenesis(gspec, engine, c.forkA, func(i int, gen *BlockGen) {})
_, forkB, _ := GenerateChainWithGenesis(gspec, engine, c.forkB, func(i int, gen *BlockGen) {})
// Initialize test chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -4286,7 +4486,13 @@ func TestTxIndexer(t *testing.T) {
rawdb.WriteAncientBlocks(db, append([]*types.Block{gspec.ToBlock()}, blocks...), append([]types.Receipts{{}}, receipts...), big.NewInt(0))
// Index the initial blocks from ancient store
chain, _ := NewBlockChain(db, nil, gspec, nil, engine, vm.Config{}, nil, &c.limitA)
config := NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
WithTxLookupLimit(&c.limitA),
)
chain, _ := NewBlockChain(db, engine, config)
chain.indexBlocks(nil, 128, make(chan struct{}))
verify(db, c.tailA)
@ -4386,11 +4592,14 @@ func testCreateThenDelete(t *testing.T, config *params.ChainConfig) {
b.AddTx(tx)
nonce++
})
bcConfig := NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
// Import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{
//Debug: true,
//Tracer: logger.NewJSONLogger(nil, os.Stdout),
}, nil, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, bcConfig)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -4501,8 +4710,14 @@ func TestDeleteThenCreate(t *testing.T) {
nonce++
}
})
config := NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
// Import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{}, nil, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -4586,8 +4801,13 @@ func TestTransientStorageReset(t *testing.T) {
nonce++
})
config := NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vmConfig),
)
// Initialize the blockchain with 1153 enabled.
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vmConfig, nil, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, config)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
@ -4655,6 +4875,10 @@ func TestEIP3651(t *testing.T) {
},
},
}
bcConfig = NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vm.Config{Tracer: logger.NewMarkdownLogger(&logger.Config{}, os.Stderr)}),
)
)
gspec.Config.BerlinBlock = common.Big0
@ -4682,7 +4906,7 @@ func TestEIP3651(t *testing.T) {
b.AddTx(tx)
})
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{Tracer: logger.NewMarkdownLogger(&logger.Config{}, os.Stderr)}, nil, nil)
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), engine, bcConfig)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}

View file

@ -123,8 +123,13 @@ func TestGeneratePOSChain(t *testing.T) {
}
})
bcConfig := NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
// Import the chain. This runs all block validation rules.
blockchain, _ := NewBlockChain(db, nil, gspec, nil, beacon.NewFaker(), vm.Config{}, nil, nil)
blockchain, _ := NewBlockChain(db, beacon.NewFaker(), bcConfig)
defer blockchain.Stop()
if i, err := blockchain.InsertChain(genchain); err != nil {
@ -238,8 +243,14 @@ func ExampleGenerateChain() {
}
})
config := NewBlockChainConfig(
WithCacheConfig(DefaultCacheConfigWithScheme(rawdb.HashScheme)),
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
// Import the chain. This runs all block validation rules.
blockchain, _ := NewBlockChain(db, DefaultCacheConfigWithScheme(rawdb.HashScheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
blockchain, _ := NewBlockChain(db, ethash.NewFaker(), config)
defer blockchain.Stop()
if i, err := blockchain.InsertChain(chain); err != nil {

View file

@ -50,7 +50,13 @@ func TestDAOForkRangeExtradata(t *testing.T) {
BaseFee: big.NewInt(params.InitialBaseFee),
Config: &proConf,
}
proBc, _ := NewBlockChain(proDb, nil, progspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
progspecConfig := NewBlockChainConfig(
WithGenesis(progspec),
WithVmConfig(&vm.Config{}),
)
proBc, _ := NewBlockChain(proDb, ethash.NewFaker(), progspecConfig)
defer proBc.Stop()
conDb := rawdb.NewMemoryDatabase()
@ -62,7 +68,13 @@ func TestDAOForkRangeExtradata(t *testing.T) {
BaseFee: big.NewInt(params.InitialBaseFee),
Config: &conConf,
}
conBc, _ := NewBlockChain(conDb, nil, congspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
congspecConfig := NewBlockChainConfig(
WithGenesis(congspec),
WithVmConfig(&vm.Config{}),
)
conBc, _ := NewBlockChain(conDb, ethash.NewFaker(), congspecConfig)
defer conBc.Stop()
if _, err := proBc.InsertChain(prefix); err != nil {
@ -74,7 +86,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
// Try to expand both pro-fork and non-fork chains iteratively with other camp's blocks
for i := int64(0); i < params.DAOForkExtraRange.Int64(); i++ {
// Create a pro-fork block, and try to feed into the no-fork chain
bc, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, congspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
bc, _ := NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), congspecConfig)
blocks := conBc.GetBlocksFromHash(conBc.CurrentBlock().Hash(), int(conBc.CurrentBlock().Number.Uint64()))
for j := 0; j < len(blocks)/2; j++ {
@ -97,7 +109,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
t.Fatalf("contra-fork chain didn't accepted no-fork block: %v", err)
}
// Create a no-fork block, and try to feed into the pro-fork chain
bc, _ = NewBlockChain(rawdb.NewMemoryDatabase(), nil, progspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
bc, _ = NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), progspecConfig)
blocks = proBc.GetBlocksFromHash(proBc.CurrentBlock().Hash(), int(proBc.CurrentBlock().Number.Uint64()))
for j := 0; j < len(blocks)/2; j++ {
@ -121,7 +133,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
}
}
// Verify that contra-forkers accept pro-fork extra-datas after forking finishes
bc, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, congspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
bc, _ := NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), congspecConfig)
defer bc.Stop()
blocks := conBc.GetBlocksFromHash(conBc.CurrentBlock().Hash(), int(conBc.CurrentBlock().Number.Uint64()))
@ -139,7 +151,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
t.Fatalf("contra-fork chain didn't accept pro-fork block post-fork: %v", err)
}
// Verify that pro-forkers accept contra-fork extra-datas after forking finishes
bc, _ = NewBlockChain(rawdb.NewMemoryDatabase(), nil, progspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
bc, _ = NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), progspecConfig)
defer bc.Stop()
blocks = proBc.GetBlocksFromHash(proBc.CurrentBlock().Hash(), int(proBc.CurrentBlock().Number.Uint64()))

View file

@ -131,8 +131,12 @@ func testSetupGenesis(t *testing.T, scheme string) {
// Advance to block #4, past the homestead transition block of customg.
tdb := trie.NewDatabase(db, newDbConfig(scheme))
oldcustomg.Commit(db, tdb)
bc, _ := NewBlockChain(db, DefaultCacheConfigWithScheme(scheme), &oldcustomg, nil, ethash.NewFullFaker(), vm.Config{}, nil, nil)
config := NewBlockChainConfig(
WithGenesis(&oldcustomg),
WithCacheConfig(DefaultCacheConfigWithScheme(scheme)),
WithVmConfig(&vm.Config{}),
)
bc, _ := NewBlockChain(db, ethash.NewFullFaker(), config)
defer bc.Stop()
_, blocks, _ := GenerateChainWithGenesis(&oldcustomg, ethash.NewFaker(), 4, nil)

View file

@ -128,7 +128,11 @@ func TestStateProcessorErrors(t *testing.T) {
},
},
}
blockchain, _ = NewBlockChain(db, nil, gspec, nil, beacon.New(ethash.NewFaker()), vm.Config{}, nil, nil)
config = NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
blockchain, _ = NewBlockChain(db, beacon.New(ethash.NewFaker()), config)
tooBigInitCode = [params.MaxInitCodeSize + 1]byte{}
)
@ -288,7 +292,11 @@ func TestStateProcessorErrors(t *testing.T) {
},
},
}
blockchain, _ = NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config = NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
blockchain, _ = NewBlockChain(db, ethash.NewFaker(), config)
)
defer blockchain.Stop()
for i, tt := range []struct {
@ -327,7 +335,11 @@ func TestStateProcessorErrors(t *testing.T) {
},
},
}
blockchain, _ = NewBlockChain(db, nil, gspec, nil, beacon.New(ethash.NewFaker()), vm.Config{}, nil, nil)
config = NewBlockChainConfig(
WithGenesis(gspec),
WithVmConfig(&vm.Config{}),
)
blockchain, _ = NewBlockChain(db, beacon.New(ethash.NewFaker()), config)
)
defer blockchain.Stop()
for i, tt := range []struct {

View file

@ -213,7 +213,17 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if config.OverrideVerkle != nil {
overrides.OverrideVerkle = config.OverrideVerkle
}
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TransactionHistory)
bcConfig := core.NewBlockChainConfig(
core.WithCacheConfig(cacheConfig),
core.WithGenesis(config.Genesis),
core.WithOverrides(&overrides),
core.WithShouldPreserve(eth.shouldPreserve),
core.WithTxLookupLimit(&config.TransactionHistory),
core.WithVmConfig(&vmConfig),
)
eth.blockchain, err = core.NewBlockChain(chainDb, eth.engine, bcConfig)
if err != nil {
return nil, err
}

View file

@ -72,7 +72,13 @@ func newTesterWithNotification(t *testing.T, success func()) *downloadTester {
Alloc: core.GenesisAlloc{testAddress: {Balance: big.NewInt(1000000000000000)}},
BaseFee: big.NewInt(params.InitialBaseFee),
}
chain, err := core.NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config := core.NewBlockChainConfig(
core.WithGenesis(gspec),
core.WithVmConfig(&vm.Config{}),
)
chain, err := core.NewBlockChain(db, ethash.NewFaker(), config)
if err != nil {
panic(err)
}

View file

@ -218,7 +218,13 @@ func newTestBlockchain(blocks []*types.Block) *core.BlockChain {
if pregenerated {
panic("Requested chain generation outside of init")
}
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, testGspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
bcConfig := core.NewBlockChainConfig(
core.WithGenesis(testGspec),
core.WithVmConfig(&vm.Config{}),
)
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), bcConfig)
if err != nil {
panic(err)
}

View file

@ -249,7 +249,14 @@ func TestFilters(t *testing.T) {
}
})
var l uint64
bc, err := core.NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, &l)
config := core.NewBlockChainConfig(
core.WithGenesis(gspec),
core.WithVmConfig(&vm.Config{}),
core.WithTxLookupLimit(&l),
)
bc, err := core.NewBlockChain(db, ethash.NewFaker(), config)
if err != nil {
t.Fatal(err)
}

View file

@ -163,8 +163,15 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
}
b.AddTx(types.MustSignNewTx(key, signer, txdata))
})
bcConfig := core.NewBlockChainConfig(
core.WithCacheConfig(&core.CacheConfig{TrieCleanNoPrefetch: true}),
core.WithGenesis(gspec),
core.WithVmConfig(&vm.Config{}),
)
// Construct testing chain
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), &core.CacheConfig{TrieCleanNoPrefetch: true}, gspec, nil, engine, vm.Config{}, nil, nil)
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), engine, bcConfig)
if err != nil {
t.Fatalf("Failed to create local chain, %v", err)
}

View file

@ -104,8 +104,17 @@ func testForkIDSplit(t *testing.T, protocol uint) {
gspecNoFork = &core.Genesis{Config: configNoFork}
gspecProFork = &core.Genesis{Config: configProFork}
chainNoFork, _ = core.NewBlockChain(dbNoFork, nil, gspecNoFork, nil, engine, vm.Config{}, nil, nil)
chainProFork, _ = core.NewBlockChain(dbProFork, nil, gspecProFork, nil, engine, vm.Config{}, nil, nil)
noForkConfig = core.NewBlockChainConfig(
core.WithGenesis(gspecNoFork),
core.WithVmConfig(&vm.Config{}),
)
chainNoFork, _ = core.NewBlockChain(dbNoFork, engine, noForkConfig)
proForkConfig = core.NewBlockChainConfig(
core.WithGenesis(gspecProFork),
core.WithVmConfig(&vm.Config{}),
)
chainProFork, _ = core.NewBlockChain(dbProFork, engine, proForkConfig)
_, blocksNoFork, _ = core.GenerateChainWithGenesis(gspecNoFork, engine, 2, nil)
_, blocksProFork, _ = core.GenerateChainWithGenesis(gspecProFork, engine, 2, nil)

View file

@ -151,7 +151,13 @@ func newTestHandlerWithBlocks(blocks int) *testHandler {
Config: params.TestChainConfig,
Alloc: core.GenesisAlloc{testAddr: {Balance: big.NewInt(1000000)}},
}
chain, _ := core.NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
config := core.NewBlockChainConfig(
core.WithGenesis(gspec),
core.WithVmConfig(&vm.Config{}),
)
chain, _ := core.NewBlockChain(db, ethash.NewFaker(), config)
_, bs, _ := core.GenerateChainWithGenesis(gspec, ethash.NewFaker(), blocks, nil)
if _, err := chain.InsertChain(bs); err != nil {

View file

@ -104,7 +104,12 @@ func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int,
Config: config,
Alloc: core.GenesisAlloc{testAddr: {Balance: big.NewInt(100_000_000_000_000_000)}},
}
chain, _ := core.NewBlockChain(db, nil, gspec, nil, engine, vm.Config{}, nil, nil)
bcConfig := core.NewBlockChainConfig(
core.WithGenesis(gspec),
core.WithVmConfig(&vm.Config{}),
)
chain, _ := core.NewBlockChain(db, engine, bcConfig)
_, bs, _ := core.GenerateChainWithGenesis(gspec, engine, blocks, generator)
if _, err := chain.InsertChain(bs); err != nil {

View file

@ -125,7 +125,13 @@ func getChain() *core.BlockChain {
SnapshotWait: true,
}
trieRoot = blocks[len(blocks)-1].Root()
bc, _ := core.NewBlockChain(rawdb.NewMemoryDatabase(), cacheConf, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
bcConfig := core.NewBlockChainConfig(
core.WithCacheConfig(cacheConf),
core.WithGenesis(gspec),
core.WithVmConfig(&vm.Config{}),
)
bc, _ := core.NewBlockChain(rawdb.NewMemoryDatabase(), ethash.NewFaker(), bcConfig)
if _, err := bc.InsertChain(blocks); err != nil {
panic(err)
}

View file

@ -80,7 +80,14 @@ func newTestBackend(t *testing.T, n int, gspec *core.Genesis, generator func(i i
SnapshotLimit: 0,
TrieDirtyDisabled: true, // Archive mode
}
chain, err := core.NewBlockChain(backend.chaindb, cacheConfig, gspec, nil, backend.engine, vm.Config{}, nil, nil)
bcConfig := core.NewBlockChainConfig(
core.WithCacheConfig(cacheConfig),
core.WithGenesis(gspec),
core.WithVmConfig(&vm.Config{}),
)
chain, err := core.NewBlockChain(backend.chaindb, backend.engine, bcConfig)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}

View file

@ -422,7 +422,15 @@ func newTestBackend(t *testing.T, n int, gspec *core.Genesis, engine consensus.E
// Generate blocks for testing
db, blocks, _ := core.GenerateChainWithGenesis(gspec, engine, n, generator)
txlookupLimit := uint64(0)
chain, err := core.NewBlockChain(db, cacheConfig, gspec, nil, engine, vm.Config{}, nil, &txlookupLimit)
bcConfig := core.NewBlockChainConfig(
core.WithCacheConfig(cacheConfig),
core.WithGenesis(gspec),
core.WithVmConfig(&vm.Config{}),
core.WithTxLookupLimit(&txlookupLimit),
)
chain, err := core.NewBlockChain(db, engine, bcConfig)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}

View file

@ -309,7 +309,12 @@ func createMiner(t *testing.T) (*Miner, *event.TypeMux, func(skipMiner bool)) {
// Create consensus engine
engine := clique.New(chainConfig.Clique, chainDB)
// Create Ethereum backend
bc, err := core.NewBlockChain(chainDB, nil, genesis, nil, engine, vm.Config{}, nil, nil)
bcConfig := core.NewBlockChainConfig(
core.WithGenesis(genesis),
core.WithVmConfig(&vm.Config{}),
)
bc, err := core.NewBlockChain(chainDB, engine, bcConfig)
if err != nil {
t.Fatalf("can't create new chain %v", err)
}

View file

@ -129,7 +129,14 @@ func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine
default:
t.Fatalf("unexpected consensus engine type: %T", engine)
}
chain, err := core.NewBlockChain(db, &core.CacheConfig{TrieDirtyDisabled: true}, gspec, nil, engine, vm.Config{}, nil, nil)
config := core.NewBlockChainConfig(
core.WithCacheConfig(&core.CacheConfig{TrieDirtyDisabled: true}),
core.WithGenesis(gspec),
core.WithVmConfig(&vm.Config{}),
)
chain, err := core.NewBlockChain(db, engine, config)
if err != nil {
t.Fatalf("core.NewBlockChain failed: %v", err)
}
@ -179,7 +186,12 @@ func TestGenerateAndImportBlock(t *testing.T) {
defer w.close()
// This test chain imports the mined blocks.
chain, _ := core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, b.genesis, nil, engine, vm.Config{}, nil, nil)
bcConfig := core.NewBlockChainConfig(
core.WithGenesis(b.genesis),
core.WithVmConfig(&vm.Config{}),
)
chain, _ := core.NewBlockChain(rawdb.NewMemoryDatabase(), engine, bcConfig)
defer chain.Stop()
// Ignore empty commit here for less noise.

View file

@ -148,9 +148,14 @@ func (t *BlockTest) Run(snapshotter bool, scheme string, tracer vm.EVMLogger, po
cache.SnapshotLimit = 1
cache.SnapshotWait = true
}
chain, err := core.NewBlockChain(db, cache, gspec, nil, engine, vm.Config{
Tracer: tracer,
}, nil, nil)
bcConfig := core.NewBlockChainConfig(
core.WithCacheConfig(cache),
core.WithGenesis(gspec),
core.WithVmConfig(&vm.Config{Tracer: tracer}),
)
chain, err := core.NewBlockChain(db, engine, bcConfig)
if err != nil {
return err
}