|
|
|
@ -53,12 +53,16 @@ var ( |
|
|
|
|
// header only chain.
|
|
|
|
|
func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *BlockChain, error) { |
|
|
|
|
var ( |
|
|
|
|
db = rawdb.NewMemoryDatabase() |
|
|
|
|
genesis = (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db) |
|
|
|
|
db = rawdb.NewMemoryDatabase() |
|
|
|
|
gspec = &Genesis{ |
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee), |
|
|
|
|
Config: params.AllEthashProtocolChanges, |
|
|
|
|
} |
|
|
|
|
genesis = gspec.MustCommit(db) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Initialize a fresh chain with only a genesis block
|
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, params.AllEthashProtocolChanges, engine, vm.Config{}, nil, nil) |
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
// Create and inject the requested chain
|
|
|
|
|
if n == 0 { |
|
|
|
|
return db, blockchain, nil |
|
|
|
@ -654,7 +658,11 @@ func testReorgBadHashes(t *testing.T, full bool) { |
|
|
|
|
blockchain.Stop() |
|
|
|
|
|
|
|
|
|
// Create a new BlockChain and check that it rolled back the state.
|
|
|
|
|
ncm, err := NewBlockChain(blockchain.db, nil, blockchain.chainConfig, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
gspec := &Genesis{ |
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee), |
|
|
|
|
Config: params.AllEthashProtocolChanges, |
|
|
|
|
} |
|
|
|
|
ncm, err := NewBlockChain(blockchain.db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create new chain manager: %v", err) |
|
|
|
|
} |
|
|
|
@ -767,7 +775,7 @@ func TestFastVsFullChains(t *testing.T) { |
|
|
|
|
// Import the chain as an archive node for the comparison baseline
|
|
|
|
|
archiveDb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(archiveDb) |
|
|
|
|
archive, _ := NewBlockChain(archiveDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
archive, _ := NewBlockChain(archiveDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
defer archive.Stop() |
|
|
|
|
|
|
|
|
|
if n, err := archive.InsertChain(blocks); err != nil { |
|
|
|
@ -776,7 +784,7 @@ func TestFastVsFullChains(t *testing.T) { |
|
|
|
|
// Fast import the chain as a non-archive node to test
|
|
|
|
|
fastDb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(fastDb) |
|
|
|
|
fast, _ := NewBlockChain(fastDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
fast, _ := NewBlockChain(fastDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
defer fast.Stop() |
|
|
|
|
|
|
|
|
|
headers := make([]*types.Header, len(blocks)) |
|
|
|
@ -797,7 +805,7 @@ func TestFastVsFullChains(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
defer ancientDb.Close() |
|
|
|
|
gspec.MustCommit(ancientDb) |
|
|
|
|
ancient, _ := NewBlockChain(ancientDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
ancient, _ := NewBlockChain(ancientDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
defer ancient.Stop() |
|
|
|
|
|
|
|
|
|
if n, err := ancient.InsertHeaderChain(headers, 1); err != nil { |
|
|
|
@ -915,7 +923,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) { |
|
|
|
|
archiveCaching := *defaultCacheConfig |
|
|
|
|
archiveCaching.TrieDirtyDisabled = true |
|
|
|
|
|
|
|
|
|
archive, _ := NewBlockChain(archiveDb, &archiveCaching, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
archive, _ := NewBlockChain(archiveDb, &archiveCaching, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
if n, err := archive.InsertChain(blocks); err != nil { |
|
|
|
|
t.Fatalf("failed to process block %d: %v", n, err) |
|
|
|
|
} |
|
|
|
@ -928,7 +936,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) { |
|
|
|
|
// Import the chain as a non-archive node and ensure all pointers are updated
|
|
|
|
|
fastDb := makeDb() |
|
|
|
|
defer fastDb.Close() |
|
|
|
|
fast, _ := NewBlockChain(fastDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
fast, _ := NewBlockChain(fastDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
defer fast.Stop() |
|
|
|
|
|
|
|
|
|
headers := make([]*types.Header, len(blocks)) |
|
|
|
@ -948,7 +956,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) { |
|
|
|
|
// Import the chain as a ancient-first node and ensure all pointers are updated
|
|
|
|
|
ancientDb := makeDb() |
|
|
|
|
defer ancientDb.Close() |
|
|
|
|
ancient, _ := NewBlockChain(ancientDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
ancient, _ := NewBlockChain(ancientDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
defer ancient.Stop() |
|
|
|
|
|
|
|
|
|
if n, err := ancient.InsertHeaderChain(headers, 1); err != nil { |
|
|
|
@ -967,7 +975,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) { |
|
|
|
|
// Import the chain as a light node and ensure all pointers are updated
|
|
|
|
|
lightDb := makeDb() |
|
|
|
|
defer lightDb.Close() |
|
|
|
|
light, _ := NewBlockChain(lightDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
light, _ := NewBlockChain(lightDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
if n, err := light.InsertHeaderChain(headers, 1); err != nil { |
|
|
|
|
t.Fatalf("failed to insert header %d: %v", n, err) |
|
|
|
|
} |
|
|
|
@ -1036,7 +1044,7 @@ func TestChainTxReorgs(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
// Import the chain. This runs all block validation rules.
|
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
if i, err := blockchain.InsertChain(chain); err != nil { |
|
|
|
|
t.Fatalf("failed to insert original chain[%d]: %v", i, err) |
|
|
|
|
} |
|
|
|
@ -1106,7 +1114,7 @@ func TestLogReorgs(t *testing.T) { |
|
|
|
|
signer = types.LatestSigner(gspec.Config) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
defer blockchain.Stop() |
|
|
|
|
|
|
|
|
|
rmLogsCh := make(chan RemovedLogsEvent) |
|
|
|
@ -1159,7 +1167,7 @@ func TestLogRebirth(t *testing.T) { |
|
|
|
|
genesis = gspec.MustCommit(db) |
|
|
|
|
signer = types.LatestSigner(gspec.Config) |
|
|
|
|
engine = ethash.NewFaker() |
|
|
|
|
blockchain, _ = NewBlockChain(db, nil, gspec.Config, engine, vm.Config{}, nil, nil) |
|
|
|
|
blockchain, _ = NewBlockChain(db, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
defer blockchain.Stop() |
|
|
|
@ -1222,7 +1230,7 @@ func TestSideLogRebirth(t *testing.T) { |
|
|
|
|
gspec = &Genesis{Config: params.TestChainConfig, Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}} |
|
|
|
|
genesis = gspec.MustCommit(db) |
|
|
|
|
signer = types.LatestSigner(gspec.Config) |
|
|
|
|
blockchain, _ = NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
blockchain, _ = NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
defer blockchain.Stop() |
|
|
|
@ -1296,7 +1304,7 @@ func TestReorgSideEvent(t *testing.T) { |
|
|
|
|
signer = types.LatestSigner(gspec.Config) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
defer blockchain.Stop() |
|
|
|
|
|
|
|
|
|
chain, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 3, func(i int, gen *BlockGen) {}) |
|
|
|
@ -1427,7 +1435,7 @@ func TestEIP155Transition(t *testing.T) { |
|
|
|
|
genesis = gspec.MustCommit(db) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
defer blockchain.Stop() |
|
|
|
|
|
|
|
|
|
blocks, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 4, func(i int, block *BlockGen) { |
|
|
|
@ -1535,7 +1543,7 @@ func TestEIP161AccountRemoval(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
genesis = gspec.MustCommit(db) |
|
|
|
|
) |
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
blockchain, _ := NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
defer blockchain.Stop() |
|
|
|
|
|
|
|
|
|
blocks, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 3, func(i int, block *BlockGen) { |
|
|
|
@ -1592,7 +1600,11 @@ func TestBlockchainHeaderchainReorgConsistency(t *testing.T) { |
|
|
|
|
engine := ethash.NewFaker() |
|
|
|
|
|
|
|
|
|
db := rawdb.NewMemoryDatabase() |
|
|
|
|
genesis := (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db) |
|
|
|
|
gspec := &Genesis{ |
|
|
|
|
Config: params.TestChainConfig, |
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee), |
|
|
|
|
} |
|
|
|
|
genesis := gspec.MustCommit(db) |
|
|
|
|
blocks, _ := GenerateChain(params.TestChainConfig, genesis, engine, db, 64, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) }) |
|
|
|
|
|
|
|
|
|
// Generate a bunch of fork blocks, each side forking from the canonical chain
|
|
|
|
@ -1610,7 +1622,7 @@ func TestBlockchainHeaderchainReorgConsistency(t *testing.T) { |
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
(&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(diskdb) |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -1637,7 +1649,11 @@ func TestTrieForkGC(t *testing.T) { |
|
|
|
|
engine := ethash.NewFaker() |
|
|
|
|
|
|
|
|
|
db := rawdb.NewMemoryDatabase() |
|
|
|
|
genesis := (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db) |
|
|
|
|
gspec := &Genesis{ |
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee), |
|
|
|
|
Config: params.TestChainConfig, |
|
|
|
|
} |
|
|
|
|
genesis := gspec.MustCommit(db) |
|
|
|
|
blocks, _ := GenerateChain(params.TestChainConfig, genesis, engine, db, 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
|
|
|
|
@ -1652,9 +1668,9 @@ func TestTrieForkGC(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
// Import the canonical and fork chain side by side, forcing the trie cache to cache both
|
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
(&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(diskdb) |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -1683,7 +1699,11 @@ func TestLargeReorgTrieGC(t *testing.T) { |
|
|
|
|
engine := ethash.NewFaker() |
|
|
|
|
|
|
|
|
|
db := rawdb.NewMemoryDatabase() |
|
|
|
|
genesis := (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db) |
|
|
|
|
gspec := &Genesis{ |
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee), |
|
|
|
|
Config: params.TestChainConfig, |
|
|
|
|
} |
|
|
|
|
genesis := gspec.MustCommit(db) |
|
|
|
|
|
|
|
|
|
shared, _ := GenerateChain(params.TestChainConfig, genesis, engine, db, 64, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) }) |
|
|
|
|
original, _ := GenerateChain(params.TestChainConfig, shared[len(shared)-1], engine, db, 2*TriesInMemory, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{2}) }) |
|
|
|
@ -1691,9 +1711,9 @@ func TestLargeReorgTrieGC(t *testing.T) { |
|
|
|
|
|
|
|
|
|
// Import the shared chain and the original canonical one
|
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
(&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(diskdb) |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -1751,7 +1771,7 @@ func TestBlockchainRecovery(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
defer ancientDb.Close() |
|
|
|
|
gspec.MustCommit(ancientDb) |
|
|
|
|
ancient, _ := NewBlockChain(ancientDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
ancient, _ := NewBlockChain(ancientDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
|
|
|
|
|
headers := make([]*types.Header, len(blocks)) |
|
|
|
|
for i, block := range blocks { |
|
|
|
@ -1771,7 +1791,7 @@ func TestBlockchainRecovery(t *testing.T) { |
|
|
|
|
rawdb.WriteHeadFastBlockHash(ancientDb, midBlock.Hash()) |
|
|
|
|
|
|
|
|
|
// Reopen broken blockchain again
|
|
|
|
|
ancient, _ = NewBlockChain(ancientDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
ancient, _ = NewBlockChain(ancientDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
defer ancient.Stop() |
|
|
|
|
if num := ancient.CurrentBlock().NumberU64(); num != 0 { |
|
|
|
|
t.Errorf("head block mismatch: have #%v, want #%v", num, 0) |
|
|
|
@ -1812,15 +1832,15 @@ func TestInsertReceiptChainRollback(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set up a BlockChain that uses the ancient store.
|
|
|
|
|
frdir := t.TempDir() |
|
|
|
|
ancientDb, err := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), frdir, "", false) |
|
|
|
|
ancientDb, err := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), t.TempDir(), "", false) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create temp freezer db: %v", err) |
|
|
|
|
} |
|
|
|
|
defer ancientDb.Close() |
|
|
|
|
|
|
|
|
|
gspec := Genesis{Config: params.AllEthashProtocolChanges} |
|
|
|
|
gspec.MustCommit(ancientDb) |
|
|
|
|
ancientChain, _ := NewBlockChain(ancientDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
ancientChain, _ := NewBlockChain(ancientDb, nil, &gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) |
|
|
|
|
defer ancientChain.Stop() |
|
|
|
|
|
|
|
|
|
// Import the canonical header chain.
|
|
|
|
@ -1868,7 +1888,11 @@ func TestLowDiffLongChain(t *testing.T) { |
|
|
|
|
// Generate a canonical chain to act as the main dataset
|
|
|
|
|
engine := ethash.NewFaker() |
|
|
|
|
db := rawdb.NewMemoryDatabase() |
|
|
|
|
genesis := (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db) |
|
|
|
|
gspec := &Genesis{ |
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee), |
|
|
|
|
Config: params.TestChainConfig, |
|
|
|
|
} |
|
|
|
|
genesis := gspec.MustCommit(db) |
|
|
|
|
|
|
|
|
|
// We must use a pretty long chain to ensure that the fork doesn't overtake us
|
|
|
|
|
// until after at least 128 blocks post tip
|
|
|
|
@ -1879,9 +1903,9 @@ func TestLowDiffLongChain(t *testing.T) { |
|
|
|
|
|
|
|
|
|
// Import the canonical chain
|
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
(&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(diskdb) |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -1947,7 +1971,7 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon |
|
|
|
|
// Generate and import the canonical chain
|
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, &chainConfig, runEngine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, runEngine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -2063,7 +2087,11 @@ func testInsertKnownChainData(t *testing.T, typ string) { |
|
|
|
|
engine := ethash.NewFaker() |
|
|
|
|
|
|
|
|
|
db := rawdb.NewMemoryDatabase() |
|
|
|
|
genesis := (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db) |
|
|
|
|
gspec := &Genesis{ |
|
|
|
|
Config: params.TestChainConfig, |
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee), |
|
|
|
|
} |
|
|
|
|
genesis := gspec.MustCommit(db) |
|
|
|
|
|
|
|
|
|
blocks, receipts := GenerateChain(params.TestChainConfig, genesis, engine, db, 32, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) }) |
|
|
|
|
// A longer chain but total difficulty is lower.
|
|
|
|
@ -2074,15 +2102,14 @@ func testInsertKnownChainData(t *testing.T, typ string) { |
|
|
|
|
b.OffsetTime(-9) // A higher difficulty
|
|
|
|
|
}) |
|
|
|
|
// Import the shared chain and the original canonical one
|
|
|
|
|
dir := t.TempDir() |
|
|
|
|
chaindb, err := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), dir, "", false) |
|
|
|
|
chaindb, err := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), t.TempDir(), "", false) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create temp freezer db: %v", err) |
|
|
|
|
} |
|
|
|
|
(&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(chaindb) |
|
|
|
|
gspec.MustCommit(chaindb) |
|
|
|
|
defer chaindb.Close() |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(chaindb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(chaindb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -2202,8 +2229,12 @@ func testInsertKnownChainDataWithMerging(t *testing.T, typ string, mergeHeight i |
|
|
|
|
// Copy the TestChainConfig so we can modify it during tests
|
|
|
|
|
chainConfig := *params.TestChainConfig |
|
|
|
|
var ( |
|
|
|
|
db = rawdb.NewMemoryDatabase() |
|
|
|
|
genesis = (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee), Config: &chainConfig}).MustCommit(db) |
|
|
|
|
db = rawdb.NewMemoryDatabase() |
|
|
|
|
gspec = &Genesis{ |
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee), |
|
|
|
|
Config: &chainConfig, |
|
|
|
|
} |
|
|
|
|
genesis = gspec.MustCommit(db) |
|
|
|
|
runMerger = consensus.NewMerger(db) |
|
|
|
|
runEngine = beacon.New(ethash.NewFaker()) |
|
|
|
|
genEngine = beacon.New(ethash.NewFaker()) |
|
|
|
@ -2242,7 +2273,7 @@ func testInsertKnownChainDataWithMerging(t *testing.T, typ string, mergeHeight i |
|
|
|
|
(&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(chaindb) |
|
|
|
|
defer chaindb.Close() |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(chaindb, nil, &chainConfig, runEngine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(chaindb, nil, gspec, nil, runEngine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -2350,7 +2381,11 @@ func getLongAndShortChains() (bc *BlockChain, longChain []*types.Block, heavyCha |
|
|
|
|
// Generate a canonical chain to act as the main dataset
|
|
|
|
|
engine := ethash.NewFaker() |
|
|
|
|
db := rawdb.NewMemoryDatabase() |
|
|
|
|
genesis := (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db) |
|
|
|
|
gspec := &Genesis{ |
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee), |
|
|
|
|
Config: params.TestChainConfig, |
|
|
|
|
} |
|
|
|
|
genesis := gspec.MustCommit(db) |
|
|
|
|
|
|
|
|
|
// Generate and import the canonical chain,
|
|
|
|
|
// Offset the time, to keep the difficulty low
|
|
|
|
@ -2358,9 +2393,9 @@ func getLongAndShortChains() (bc *BlockChain, longChain []*types.Block, heavyCha |
|
|
|
|
b.SetCoinbase(common.Address{1}) |
|
|
|
|
}) |
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
(&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(diskdb) |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, nil, nil, fmt.Errorf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -2390,12 +2425,12 @@ func getLongAndShortChains() (bc *BlockChain, longChain []*types.Block, heavyCha |
|
|
|
|
shorterTd.Add(shorterTd, b.Difficulty()) |
|
|
|
|
} |
|
|
|
|
if shorterTd.Cmp(longerTd) <= 0 { |
|
|
|
|
return nil, nil, nil, fmt.Errorf("Test is moot, heavyChain td (%v) must be larger than canon td (%v)", shorterTd, longerTd) |
|
|
|
|
return nil, nil, nil, fmt.Errorf("test is moot, heavyChain td (%v) must be larger than canon td (%v)", shorterTd, longerTd) |
|
|
|
|
} |
|
|
|
|
longerNum := longChain[len(longChain)-1].NumberU64() |
|
|
|
|
shorterNum := heavyChain[len(heavyChain)-1].NumberU64() |
|
|
|
|
if shorterNum >= longerNum { |
|
|
|
|
return nil, nil, nil, fmt.Errorf("Test is moot, heavyChain num (%v) must be lower than canon num (%v)", shorterNum, longerNum) |
|
|
|
|
return nil, nil, nil, fmt.Errorf("test is moot, heavyChain num (%v) must be lower than canon num (%v)", shorterNum, longerNum) |
|
|
|
|
} |
|
|
|
|
return chain, longChain, heavyChain, nil |
|
|
|
|
} |
|
|
|
@ -2549,7 +2584,7 @@ func TestTransactionIndices(t *testing.T) { |
|
|
|
|
|
|
|
|
|
// Import all blocks into ancient db
|
|
|
|
|
l := uint64(0) |
|
|
|
|
chain, err := NewBlockChain(ancientDb, nil, params.TestChainConfig, ethash.NewFaker(), vm.Config{}, nil, &l) |
|
|
|
|
chain, err := NewBlockChain(ancientDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, &l) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -2575,7 +2610,7 @@ func TestTransactionIndices(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
gspec.MustCommit(ancientDb) |
|
|
|
|
l := l |
|
|
|
|
chain, err = NewBlockChain(ancientDb, nil, params.TestChainConfig, ethash.NewFaker(), vm.Config{}, nil, &l) |
|
|
|
|
chain, err = NewBlockChain(ancientDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, &l) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -2601,7 +2636,7 @@ func TestTransactionIndices(t *testing.T) { |
|
|
|
|
tails := []uint64{0, 67 /* 130 - 64 + 1 */, 100 /* 131 - 32 + 1 */, 69 /* 132 - 64 + 1 */, 0} |
|
|
|
|
for i, l := range limit { |
|
|
|
|
l := l |
|
|
|
|
chain, err = NewBlockChain(ancientDb, nil, params.TestChainConfig, ethash.NewFaker(), vm.Config{}, nil, &l) |
|
|
|
|
chain, err = NewBlockChain(ancientDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, &l) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -2676,7 +2711,7 @@ func TestSkipStaleTxIndicesInSnapSync(t *testing.T) { |
|
|
|
|
|
|
|
|
|
// Import all blocks into ancient db, only HEAD-32 indices are kept.
|
|
|
|
|
l := uint64(32) |
|
|
|
|
chain, err := NewBlockChain(ancientDb, nil, params.TestChainConfig, ethash.NewFaker(), vm.Config{}, nil, &l) |
|
|
|
|
chain, err := NewBlockChain(ancientDb, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, &l) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -2702,7 +2737,7 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in |
|
|
|
|
testBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") |
|
|
|
|
testBankAddress = crypto.PubkeyToAddress(testBankKey.PublicKey) |
|
|
|
|
bankFunds = big.NewInt(100000000000000000) |
|
|
|
|
gspec = Genesis{ |
|
|
|
|
gspec = &Genesis{ |
|
|
|
|
Config: params.TestChainConfig, |
|
|
|
|
Alloc: GenesisAlloc{ |
|
|
|
|
testBankAddress: {Balance: bankFunds}, |
|
|
|
@ -2740,7 +2775,7 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in |
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
b.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -2815,14 +2850,18 @@ func TestSideImportPrunedBlocks(t *testing.T) { |
|
|
|
|
// Generate a canonical chain to act as the main dataset
|
|
|
|
|
engine := ethash.NewFaker() |
|
|
|
|
db := rawdb.NewMemoryDatabase() |
|
|
|
|
genesis := (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db) |
|
|
|
|
gspec := &Genesis{ |
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee), |
|
|
|
|
Config: params.TestChainConfig, |
|
|
|
|
} |
|
|
|
|
genesis := gspec.MustCommit(db) |
|
|
|
|
|
|
|
|
|
// Generate and import the canonical chain
|
|
|
|
|
blocks, _ := GenerateChain(params.TestChainConfig, genesis, engine, db, 2*TriesInMemory, nil) |
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
|
|
|
|
|
(&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(diskdb) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -2916,7 +2955,7 @@ func TestDeleteCreateRevert(t *testing.T) { |
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -3027,7 +3066,7 @@ func TestDeleteRecreateSlots(t *testing.T) { |
|
|
|
|
// Import the canonical chain
|
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{ |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{ |
|
|
|
|
Debug: true, |
|
|
|
|
Tracer: logger.NewJSONLogger(nil, os.Stdout), |
|
|
|
|
}, nil, nil) |
|
|
|
@ -3107,7 +3146,7 @@ func TestDeleteRecreateAccount(t *testing.T) { |
|
|
|
|
// Import the canonical chain
|
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{ |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{ |
|
|
|
|
Debug: true, |
|
|
|
|
Tracer: logger.NewJSONLogger(nil, os.Stdout), |
|
|
|
|
}, nil, nil) |
|
|
|
@ -3280,7 +3319,7 @@ func TestDeleteRecreateSlotsAcrossManyBlocks(t *testing.T) { |
|
|
|
|
// Import the canonical chain
|
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{ |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{ |
|
|
|
|
//Debug: true,
|
|
|
|
|
//Tracer: vm.NewJSONLogger(nil, os.Stdout),
|
|
|
|
|
}, nil, nil) |
|
|
|
@ -3414,7 +3453,7 @@ func TestInitThenFailCreateContract(t *testing.T) { |
|
|
|
|
// Import the canonical chain
|
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{ |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{ |
|
|
|
|
//Debug: true,
|
|
|
|
|
//Tracer: vm.NewJSONLogger(nil, os.Stdout),
|
|
|
|
|
}, nil, nil) |
|
|
|
@ -3504,7 +3543,7 @@ func TestEIP2718Transition(t *testing.T) { |
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec.Config, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -3598,7 +3637,7 @@ func TestEIP1559Transition(t *testing.T) { |
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec.Config, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -3705,7 +3744,7 @@ func TestSetCanonical(t *testing.T) { |
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
|
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -3811,7 +3850,7 @@ func TestCanonicalHashMarker(t *testing.T) { |
|
|
|
|
// Initialize test chain
|
|
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
|
gspec.MustCommit(diskdb) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, params.TestChainConfig, engine, vm.Config{}, nil, nil) |
|
|
|
|
chain, err := NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
} |
|
|
|
|