@ -22,6 +22,7 @@ import (
"math/big"
"math/big"
"math/rand"
"math/rand"
"os"
"os"
"path"
"sync"
"sync"
"testing"
"testing"
"time"
"time"
@ -61,7 +62,7 @@ func newCanonical(engine consensus.Engine, n int, full bool, scheme string) (eth
}
}
)
)
// Initialize a fresh chain with only a genesis block
// Initialize a fresh chain with only a genesis block
blockchain , _ := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil , nil )
blockchain , _ := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil )
// Create and inject the requested chain
// Create and inject the requested chain
if n == 0 {
if n == 0 {
@ -763,7 +764,7 @@ func testFastVsFullChains(t *testing.T, scheme string) {
} )
} )
// Import the chain as an archive node for the comparison baseline
// Import the chain as an archive node for the comparison baseline
archiveDb := rawdb . NewMemoryDatabase ( )
archiveDb := rawdb . NewMemoryDatabase ( )
archive , _ := NewBlockChain ( archiveDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
archive , _ := NewBlockChain ( archiveDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
defer archive . Stop ( )
defer archive . Stop ( )
if n , err := archive . InsertChain ( blocks ) ; err != nil {
if n , err := archive . InsertChain ( blocks ) ; err != nil {
@ -771,7 +772,7 @@ func testFastVsFullChains(t *testing.T, scheme string) {
}
}
// Fast import the chain as a non-archive node to test
// Fast import the chain as a non-archive node to test
fastDb := rawdb . NewMemoryDatabase ( )
fastDb := rawdb . NewMemoryDatabase ( )
fast , _ := NewBlockChain ( fastDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
fast , _ := NewBlockChain ( fastDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
defer fast . Stop ( )
defer fast . Stop ( )
headers := make ( [ ] * types . Header , len ( blocks ) )
headers := make ( [ ] * types . Header , len ( blocks ) )
@ -791,7 +792,7 @@ func testFastVsFullChains(t *testing.T, scheme string) {
}
}
defer ancientDb . Close ( )
defer ancientDb . Close ( )
ancient , _ := NewBlockChain ( ancientDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
ancient , _ := NewBlockChain ( ancientDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
defer ancient . Stop ( )
defer ancient . Stop ( )
if n , err := ancient . InsertHeaderChain ( headers ) ; err != nil {
if n , err := ancient . InsertHeaderChain ( headers ) ; err != nil {
@ -911,7 +912,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) {
archiveCaching . TrieDirtyDisabled = true
archiveCaching . TrieDirtyDisabled = true
archiveCaching . StateScheme = scheme
archiveCaching . StateScheme = scheme
archive , _ := NewBlockChain ( archiveDb , & archiveCaching , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
archive , _ := NewBlockChain ( archiveDb , & archiveCaching , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
if n , err := archive . InsertChain ( blocks ) ; err != nil {
if n , err := archive . InsertChain ( blocks ) ; err != nil {
t . Fatalf ( "failed to process block %d: %v" , n , err )
t . Fatalf ( "failed to process block %d: %v" , n , err )
}
}
@ -924,7 +925,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) {
// Import the chain as a non-archive node and ensure all pointers are updated
// Import the chain as a non-archive node and ensure all pointers are updated
fastDb := makeDb ( )
fastDb := makeDb ( )
defer fastDb . Close ( )
defer fastDb . Close ( )
fast , _ := NewBlockChain ( fastDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
fast , _ := NewBlockChain ( fastDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
defer fast . Stop ( )
defer fast . Stop ( )
headers := make ( [ ] * types . Header , len ( blocks ) )
headers := make ( [ ] * types . Header , len ( blocks ) )
@ -944,7 +945,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) {
// Import the chain as a ancient-first node and ensure all pointers are updated
// Import the chain as a ancient-first node and ensure all pointers are updated
ancientDb := makeDb ( )
ancientDb := makeDb ( )
defer ancientDb . Close ( )
defer ancientDb . Close ( )
ancient , _ := NewBlockChain ( ancientDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
ancient , _ := NewBlockChain ( ancientDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
defer ancient . Stop ( )
defer ancient . Stop ( )
if n , err := ancient . InsertHeaderChain ( headers ) ; err != nil {
if n , err := ancient . InsertHeaderChain ( headers ) ; err != nil {
@ -963,7 +964,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) {
// Import the chain as a light node and ensure all pointers are updated
// Import the chain as a light node and ensure all pointers are updated
lightDb := makeDb ( )
lightDb := makeDb ( )
defer lightDb . Close ( )
defer lightDb . Close ( )
light , _ := NewBlockChain ( lightDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
light , _ := NewBlockChain ( lightDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
if n , err := light . InsertHeaderChain ( headers ) ; err != nil {
if n , err := light . InsertHeaderChain ( headers ) ; err != nil {
t . Fatalf ( "failed to insert header %d: %v" , n , err )
t . Fatalf ( "failed to insert header %d: %v" , n , err )
}
}
@ -1036,7 +1037,7 @@ func testChainTxReorgs(t *testing.T, scheme string) {
} )
} )
// Import the chain. This runs all block validation rules.
// Import the chain. This runs all block validation rules.
db := rawdb . NewMemoryDatabase ( )
db := rawdb . NewMemoryDatabase ( )
blockchain , _ := NewBlockChain ( db , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
blockchain , _ := NewBlockChain ( db , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
if i , err := blockchain . InsertChain ( chain ) ; err != nil {
if i , err := blockchain . InsertChain ( chain ) ; err != nil {
t . Fatalf ( "failed to insert original chain[%d]: %v" , i , err )
t . Fatalf ( "failed to insert original chain[%d]: %v" , i , err )
}
}
@ -1110,7 +1111,7 @@ func testLogReorgs(t *testing.T, scheme string) {
signer = types . LatestSigner ( gspec . Config )
signer = types . LatestSigner ( gspec . Config )
)
)
blockchain , _ := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
blockchain , _ := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
defer blockchain . Stop ( )
defer blockchain . Stop ( )
rmLogsCh := make ( chan RemovedLogsEvent )
rmLogsCh := make ( chan RemovedLogsEvent )
@ -1166,7 +1167,7 @@ func testLogRebirth(t *testing.T, scheme string) {
gspec = & Genesis { Config : params . TestChainConfig , Alloc : types . GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000000 ) } } }
gspec = & Genesis { Config : params . TestChainConfig , Alloc : types . GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000000 ) } } }
signer = types . LatestSigner ( gspec . Config )
signer = types . LatestSigner ( gspec . Config )
engine = ethash . NewFaker ( )
engine = ethash . NewFaker ( )
blockchain , _ = NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil , nil )
blockchain , _ = NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil )
)
)
defer blockchain . Stop ( )
defer blockchain . Stop ( )
@ -1247,7 +1248,7 @@ func testSideLogRebirth(t *testing.T, scheme string) {
addr1 = crypto . PubkeyToAddress ( key1 . PublicKey )
addr1 = crypto . PubkeyToAddress ( key1 . PublicKey )
gspec = & Genesis { Config : params . TestChainConfig , Alloc : types . GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000000 ) } } }
gspec = & Genesis { Config : params . TestChainConfig , Alloc : types . GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000000 ) } } }
signer = types . LatestSigner ( gspec . Config )
signer = types . LatestSigner ( gspec . Config )
blockchain , _ = NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
blockchain , _ = NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
)
)
defer blockchain . Stop ( )
defer blockchain . Stop ( )
@ -1266,7 +1267,7 @@ func testSideLogRebirth(t *testing.T, scheme string) {
}
}
checkLogEvents ( t , newLogCh , rmLogsCh , 0 , 0 )
checkLogEvents ( t , newLogCh , rmLogsCh , 0 , 0 )
// Generate side chain with lower difficulty
// Generate side chain with lower difficulty, after the merge, the chain will be accepted even if it is lower difficulty
genDb , sideChain , _ := GenerateChainWithGenesis ( gspec , ethash . NewFaker ( ) , 2 , func ( i int , gen * BlockGen ) {
genDb , sideChain , _ := GenerateChainWithGenesis ( gspec , ethash . NewFaker ( ) , 2 , func ( i int , gen * BlockGen ) {
if i == 1 {
if i == 1 {
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , gen . header . BaseFee , logCode ) , signer , key1 )
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , gen . header . BaseFee , logCode ) , signer , key1 )
@ -1279,14 +1280,14 @@ func testSideLogRebirth(t *testing.T, scheme string) {
if _ , err := blockchain . InsertChain ( sideChain ) ; err != nil {
if _ , err := blockchain . InsertChain ( sideChain ) ; err != nil {
t . Fatalf ( "failed to insert forked chain: %v" , err )
t . Fatalf ( "failed to insert forked chain: %v" , err )
}
}
checkLogEvents ( t , newLogCh , rmLogsCh , 0 , 0 )
checkLogEvents ( t , newLogCh , rmLogsCh , 1 , 0 )
// Generate a new block based on side chain.
// Generate a new block based on side chain. Should not emit any events anymore.
newBlocks , _ := GenerateChain ( gspec . Config , sideChain [ len ( sideChain ) - 1 ] , ethash . NewFaker ( ) , genDb , 1 , func ( i int , gen * BlockGen ) { } )
newBlocks , _ := GenerateChain ( gspec . Config , sideChain [ len ( sideChain ) - 1 ] , ethash . NewFaker ( ) , genDb , 1 , func ( i int , gen * BlockGen ) { } )
if _ , err := blockchain . InsertChain ( newBlocks ) ; err != nil {
if _ , err := blockchain . InsertChain ( newBlocks ) ; err != nil {
t . Fatalf ( "failed to insert forked chain: %v" , err )
t . Fatalf ( "failed to insert forked chain: %v" , err )
}
}
checkLogEvents ( t , newLogCh , rmLogsCh , 1 , 0 )
checkLogEvents ( t , newLogCh , rmLogsCh , 0 , 0 )
}
}
func checkLogEvents ( t * testing . T , logsCh <- chan [ ] * types . Log , rmLogsCh <- chan RemovedLogsEvent , wantNew , wantRemoved int ) {
func checkLogEvents ( t * testing . T , logsCh <- chan [ ] * types . Log , rmLogsCh <- chan RemovedLogsEvent , wantNew , wantRemoved int ) {
@ -1346,7 +1347,7 @@ func testReorgSideEvent(t *testing.T, scheme string) {
}
}
signer = types . LatestSigner ( gspec . Config )
signer = types . LatestSigner ( gspec . Config )
)
)
blockchain , _ := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
blockchain , _ := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
defer blockchain . Stop ( )
defer blockchain . Stop ( )
_ , chain , _ := GenerateChainWithGenesis ( gspec , ethash . NewFaker ( ) , 3 , func ( i int , gen * BlockGen ) { } )
_ , chain , _ := GenerateChainWithGenesis ( gspec , ethash . NewFaker ( ) , 3 , func ( i int , gen * BlockGen ) { } )
@ -1370,12 +1371,7 @@ func testReorgSideEvent(t *testing.T, scheme string) {
t . Fatalf ( "failed to insert chain: %v" , err )
t . Fatalf ( "failed to insert chain: %v" , err )
}
}
// first two block of the secondary chain are for a brief moment considered
// side chains because up to that point the first one is considered the
// heavier chain.
expectedSideHashes := map [ common . Hash ] bool {
expectedSideHashes := map [ common . Hash ] bool {
replacementBlocks [ 0 ] . Hash ( ) : true ,
replacementBlocks [ 1 ] . Hash ( ) : true ,
chain [ 0 ] . Hash ( ) : true ,
chain [ 0 ] . Hash ( ) : true ,
chain [ 1 ] . Hash ( ) : true ,
chain [ 1 ] . Hash ( ) : true ,
chain [ 2 ] . Hash ( ) : true ,
chain [ 2 ] . Hash ( ) : true ,
@ -1403,7 +1399,7 @@ done:
timeout . Reset ( timeoutDura )
timeout . Reset ( timeoutDura )
case <- timeout . C :
case <- timeout . C :
t . Fatal ( "Timeout. Possibly not all blocks were triggered for sideevent" )
t . Fatalf ( "Timeout. Possibly not all blocks were triggered for sideevent: %v " , i )
}
}
}
}
@ -1530,7 +1526,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 ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
defer blockchain . Stop ( )
defer blockchain . Stop ( )
if _ , err := blockchain . InsertChain ( blocks ) ; err != nil {
if _ , err := blockchain . InsertChain ( blocks ) ; err != nil {
@ -1623,7 +1619,7 @@ func testEIP161AccountRemoval(t *testing.T, scheme string) {
block . AddTx ( tx )
block . AddTx ( tx )
} )
} )
// account must exist pre eip 161
// account must exist pre eip 161
blockchain , _ := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
blockchain , _ := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
defer blockchain . Stop ( )
defer blockchain . Stop ( )
if _ , err := blockchain . InsertChain ( types . Blocks { blocks [ 0 ] } ) ; err != nil {
if _ , err := blockchain . InsertChain ( types . Blocks { blocks [ 0 ] } ) ; err != nil {
@ -1681,7 +1677,7 @@ func testBlockchainHeaderchainReorgConsistency(t *testing.T, scheme string) {
}
}
// Import the canonical and fork chain side by side, verifying the current block
// Import the canonical and fork chain side by side, verifying the current block
// and current header consistency
// and current header consistency
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -1725,7 +1721,7 @@ func TestTrieForkGC(t *testing.T) {
forks [ i ] = fork [ 0 ]
forks [ i ] = fork [ 0 ]
}
}
// Import the canonical and fork chain side by side, forcing the trie cache to cache both
// 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 ( ) , nil , genesis , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -1771,7 +1767,7 @@ func testLargeReorgTrieGC(t *testing.T, scheme string) {
db , _ := rawdb . NewDatabaseWithFreezer ( rawdb . NewMemoryDatabase ( ) , "" , "" , false )
db , _ := rawdb . NewDatabaseWithFreezer ( rawdb . NewMemoryDatabase ( ) , "" , "" , false )
defer db . Close ( )
defer db . Close ( )
chain , err := NewBlockChain ( db , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( db , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -1787,18 +1783,15 @@ func testLargeReorgTrieGC(t *testing.T, scheme string) {
if chain . HasState ( shared [ len ( shared ) - 1 ] . Root ( ) ) {
if chain . HasState ( shared [ len ( shared ) - 1 ] . Root ( ) ) {
t . Fatalf ( "common-but-old ancestor still cache" )
t . Fatalf ( "common-but-old ancestor still cache" )
}
}
// Import the competitor chain without exceeding the canonical's TD and ensure
// Import the competitor chain without exceeding the canonical's TD.
// we have not processed any of the blocks (protection against malicious blocks)
// Post-merge the side chain should be executed
if _ , err := chain . InsertChain ( competitor [ : len ( competitor ) - 2 ] ) ; err != nil {
if _ , err := chain . InsertChain ( competitor [ : len ( competitor ) - 2 ] ) ; err != nil {
t . Fatalf ( "failed to insert competitor chain: %v" , err )
t . Fatalf ( "failed to insert competitor chain: %v" , err )
}
}
for i , block := range competitor [ : len ( competitor ) - 2 ] {
if ! chain . HasState ( competitor [ len ( competitor ) - 3 ] . Root ( ) ) {
if chain . HasState ( block . Root ( ) ) {
t . Fatalf ( "failed to insert low-TD chain" )
t . Fatalf ( "competitor %d: low TD chain became processed" , i )
}
}
}
// Import the head of the competitor chain, triggering the reorg and ensure we
// Import the head of the competitor chain.
// successfully reprocess all the stashed away blocks.
if _ , err := chain . InsertChain ( competitor [ len ( competitor ) - 2 : ] ) ; err != nil {
if _ , err := chain . InsertChain ( competitor [ len ( competitor ) - 2 : ] ) ; err != nil {
t . Fatalf ( "failed to finalize competitor chain: %v" , err )
t . Fatalf ( "failed to finalize competitor chain: %v" , err )
}
}
@ -1842,7 +1835,7 @@ func testBlockchainRecovery(t *testing.T, scheme string) {
t . Fatalf ( "failed to create temp freezer db: %v" , err )
t . Fatalf ( "failed to create temp freezer db: %v" , err )
}
}
defer ancientDb . Close ( )
defer ancientDb . Close ( )
ancient , _ := NewBlockChain ( ancientDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
ancient , _ := NewBlockChain ( ancientDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
headers := make ( [ ] * types . Header , len ( blocks ) )
headers := make ( [ ] * types . Header , len ( blocks ) )
for i , block := range blocks {
for i , block := range blocks {
@ -1862,7 +1855,7 @@ func testBlockchainRecovery(t *testing.T, scheme string) {
rawdb . WriteHeadFastBlockHash ( ancientDb , midBlock . Hash ( ) )
rawdb . WriteHeadFastBlockHash ( ancientDb , midBlock . Hash ( ) )
// Reopen broken blockchain again
// Reopen broken blockchain again
ancient , _ = NewBlockChain ( ancientDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
ancient , _ = NewBlockChain ( ancientDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
defer ancient . Stop ( )
defer ancient . Stop ( )
if num := ancient . CurrentBlock ( ) . Number . Uint64 ( ) ; num != 0 {
if num := ancient . CurrentBlock ( ) . Number . Uint64 ( ) ; num != 0 {
t . Errorf ( "head block mismatch: have #%v, want #%v" , num , 0 )
t . Errorf ( "head block mismatch: have #%v, want #%v" , num , 0 )
@ -1914,7 +1907,7 @@ func testInsertReceiptChainRollback(t *testing.T, scheme string) {
}
}
defer ancientDb . Close ( )
defer ancientDb . Close ( )
ancientChain , _ := NewBlockChain ( ancientDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
ancientChain , _ := NewBlockChain ( ancientDb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , ethash . NewFaker ( ) , vm . Config { } , nil )
defer ancientChain . Stop ( )
defer ancientChain . Stop ( )
// Import the canonical header chain.
// Import the canonical header chain.
@ -1981,7 +1974,7 @@ func testLowDiffLongChain(t *testing.T, scheme string) {
diskdb , _ := rawdb . NewDatabaseWithFreezer ( rawdb . NewMemoryDatabase ( ) , "" , "" , false )
diskdb , _ := rawdb . NewDatabaseWithFreezer ( rawdb . NewMemoryDatabase ( ) , "" , "" , false )
defer diskdb . Close ( )
defer diskdb . Close ( )
chain , err := NewBlockChain ( diskdb , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( diskdb , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -2042,7 +2035,7 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon
mergeBlock = math . MaxInt32
mergeBlock = math . MaxInt32
)
)
// Generate and import the canonical chain
// Generate and import the canonical chain
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , nil , gspec , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , nil , gspec , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -2196,7 +2189,7 @@ func testInsertKnownChainData(t *testing.T, typ string, scheme string) {
}
}
defer chaindb . Close ( )
defer chaindb . Close ( )
chain , err := NewBlockChain ( chaindb , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( chaindb , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -2280,10 +2273,10 @@ func testInsertKnownChainData(t *testing.T, typ string, scheme string) {
if err := inserter ( append ( blocks , blocks2 ... ) , append ( receipts , receipts2 ... ) ) ; err != nil {
if err := inserter ( append ( blocks , blocks2 ... ) , append ( receipts , receipts2 ... ) ) ; err != nil {
t . Fatalf ( "failed to insert chain data: %v" , err )
t . Fatalf ( "failed to insert chain data: %v" , err )
}
}
// The head shouldn't change .
// Post-merge the chain should change even if td is lower .
asserter ( t , blocks3 [ len ( blocks3 ) - 1 ] )
asserter ( t , blocks2 [ len ( blocks2 ) - 1 ] )
// Rollback the heavier chain and re-insert the longer chain again
// Rollback the heavier chain and re-insert the longer chain again.
chain . SetHead ( rollback - 1 )
chain . SetHead ( rollback - 1 )
if err := inserter ( append ( blocks , blocks2 ... ) , append ( receipts , receipts2 ... ) ) ; err != nil {
if err := inserter ( append ( blocks , blocks2 ... ) , append ( receipts , receipts2 ... ) ) ; err != nil {
t . Fatalf ( "failed to insert chain data: %v" , err )
t . Fatalf ( "failed to insert chain data: %v" , err )
@ -2367,7 +2360,7 @@ func testInsertKnownChainDataWithMerging(t *testing.T, typ string, mergeHeight i
}
}
defer chaindb . Close ( )
defer chaindb . Close ( )
chain , err := NewBlockChain ( chaindb , nil , genesis , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( chaindb , nil , genesis , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -2481,7 +2474,7 @@ func getLongAndShortChains(scheme string) (*BlockChain, []*types.Block, []*types
genDb , longChain , _ := GenerateChainWithGenesis ( genesis , engine , 80 , func ( i int , b * BlockGen ) {
genDb , longChain , _ := GenerateChainWithGenesis ( genesis , engine , 80 , func ( i int , b * BlockGen ) {
b . SetCoinbase ( common . Address { 1 } )
b . SetCoinbase ( common . Address { 1 } )
} )
} )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
return nil , nil , nil , nil , fmt . Errorf ( "failed to create tester chain: %v" , err )
return nil , nil , nil , nil , fmt . Errorf ( "failed to create tester chain: %v" , err )
}
}
@ -2657,7 +2650,7 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in
b . ResetTimer ( )
b . ResetTimer ( )
for i := 0 ; i < b . N ; i ++ {
for i := 0 ; i < b . N ; i ++ {
// Import the shared chain and the original canonical one
// 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 ( ) , nil , gspec , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
b . Fatalf ( "failed to create tester chain: %v" , err )
b . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -2744,7 +2737,21 @@ func testSideImportPrunedBlocks(t *testing.T, scheme string) {
// Generate and import the canonical chain
// Generate and import the canonical chain
_ , blocks , _ := GenerateChainWithGenesis ( genesis , engine , 2 * state . TriesInMemory , nil )
_ , blocks , _ := GenerateChainWithGenesis ( genesis , engine , 2 * state . TriesInMemory , nil )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil , nil )
// Construct a database with freezer enabled
datadir := t . TempDir ( )
ancient := path . Join ( datadir , "ancient" )
db , err := rawdb . Open ( rawdb . OpenOptions {
Directory : datadir ,
AncientsDirectory : ancient ,
Ephemeral : true ,
} )
if err != nil {
t . Fatalf ( "Failed to create persistent database: %v" , err )
}
defer db . Close ( )
chain , err := NewBlockChain ( db , DefaultCacheConfigWithScheme ( scheme ) , genesis , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -2771,7 +2778,6 @@ func testSideImportPrunedBlocks(t *testing.T, scheme string) {
if ! chain . HasBlockAndState ( firstNonPrunedBlock . Hash ( ) , firstNonPrunedBlock . NumberU64 ( ) ) {
if ! chain . HasBlockAndState ( firstNonPrunedBlock . Hash ( ) , firstNonPrunedBlock . NumberU64 ( ) ) {
t . Errorf ( "Block %d pruned" , firstNonPrunedBlock . NumberU64 ( ) )
t . Errorf ( "Block %d pruned" , firstNonPrunedBlock . NumberU64 ( ) )
}
}
// Now re-import some old blocks
blockToReimport := blocks [ 5 : 8 ]
blockToReimport := blocks [ 5 : 8 ]
_ , err = chain . InsertChain ( blockToReimport )
_ , err = chain . InsertChain ( blockToReimport )
if err != nil {
if err != nil {
@ -2844,7 +2850,7 @@ func testDeleteCreateRevert(t *testing.T, scheme string) {
b . AddTx ( tx )
b . AddTx ( tx )
} )
} )
// Import the canonical chain
// Import the canonical chain
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -2959,7 +2965,7 @@ func testDeleteRecreateSlots(t *testing.T, scheme string) {
// Import the canonical chain
// Import the canonical chain
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config {
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config {
Tracer : logger . NewJSONLogger ( nil , os . Stdout ) ,
Tracer : logger . NewJSONLogger ( nil , os . Stdout ) ,
} , nil , nil )
} , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -3041,7 +3047,7 @@ func testDeleteRecreateAccount(t *testing.T, scheme string) {
// Import the canonical chain
// Import the canonical chain
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config {
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config {
Tracer : logger . NewJSONLogger ( nil , os . Stdout ) ,
Tracer : logger . NewJSONLogger ( nil , os . Stdout ) ,
} , nil , nil )
} , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -3217,7 +3223,7 @@ func testDeleteRecreateSlotsAcrossManyBlocks(t *testing.T, scheme string) {
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config {
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config {
//Debug: true,
//Debug: true,
//Tracer: vm.NewJSONLogger(nil, os.Stdout),
//Tracer: vm.NewJSONLogger(nil, os.Stdout),
} , nil , nil )
} , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -3355,7 +3361,7 @@ func testInitThenFailCreateContract(t *testing.T, scheme string) {
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config {
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config {
//Debug: true,
//Debug: true,
//Tracer: vm.NewJSONLogger(nil, os.Stdout),
//Tracer: vm.NewJSONLogger(nil, os.Stdout),
} , nil , nil )
} , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -3442,7 +3448,7 @@ func testEIP2718Transition(t *testing.T, scheme string) {
} )
} )
// Import the canonical chain
// Import the canonical chain
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -3536,7 +3542,7 @@ func testEIP1559Transition(t *testing.T, scheme string) {
b . AddTx ( tx )
b . AddTx ( tx )
} )
} )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -3649,7 +3655,7 @@ func testSetCanonical(t *testing.T, scheme string) {
diskdb , _ := rawdb . NewDatabaseWithFreezer ( rawdb . NewMemoryDatabase ( ) , "" , "" , false )
diskdb , _ := rawdb . NewDatabaseWithFreezer ( rawdb . NewMemoryDatabase ( ) , "" , "" , false )
defer diskdb . Close ( )
defer diskdb . Close ( )
chain , err := NewBlockChain ( diskdb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( diskdb , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -3758,7 +3764,7 @@ func testCanonicalHashMarker(t *testing.T, scheme string) {
_ , forkB , _ := GenerateChainWithGenesis ( gspec , engine , c . forkB , func ( i int , gen * BlockGen ) { } )
_ , forkB , _ := GenerateChainWithGenesis ( gspec , engine , c . forkB , func ( i int , gen * BlockGen ) { } )
// Initialize test chain
// Initialize test chain
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , DefaultCacheConfigWithScheme ( scheme ) , gspec , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -3895,7 +3901,7 @@ func testCreateThenDelete(t *testing.T, config *params.ChainConfig) {
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , nil , gspec , nil , engine , vm . Config {
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , nil , gspec , nil , engine , vm . Config {
//Debug: true,
//Debug: true,
//Tracer: logger.NewJSONLogger(nil, os.Stdout),
//Tracer: logger.NewJSONLogger(nil, os.Stdout),
} , nil , nil )
} , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -4007,7 +4013,7 @@ func TestDeleteThenCreate(t *testing.T) {
}
}
} )
} )
// Import the canonical chain
// Import the canonical chain
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , nil , gspec , nil , engine , vm . Config { } , nil , nil )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , nil , gspec , nil , engine , vm . Config { } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -4092,7 +4098,7 @@ func TestTransientStorageReset(t *testing.T) {
} )
} )
// Initialize the blockchain with 1153 enabled.
// Initialize the blockchain with 1153 enabled.
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , nil , gspec , nil , engine , vmConfig , nil , nil )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , nil , gspec , nil , engine , vmConfig , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}
@ -4187,7 +4193,7 @@ func TestEIP3651(t *testing.T) {
b . AddTx ( tx )
b . AddTx ( tx )
} )
} )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , nil , gspec , nil , engine , vm . Config { Tracer : logger . NewMarkdownLogger ( & logger . Config { } , os . Stderr ) . Hooks ( ) } , nil , nil )
chain , err := NewBlockChain ( rawdb . NewMemoryDatabase ( ) , nil , gspec , nil , engine , vm . Config { Tracer : logger . NewMarkdownLogger ( & logger . Config { } , os . Stderr ) . Hooks ( ) } , nil )
if err != nil {
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
t . Fatalf ( "failed to create tester chain: %v" , err )
}
}