|
@@ -43,7 +43,8 @@ import (
|
|
|
// So we can deterministically seed different blockchains
|
|
// So we can deterministically seed different blockchains
|
|
|
var (
|
|
var (
|
|
|
canonicalSeed = 1
|
|
canonicalSeed = 1
|
|
|
- forkSeed = 2
|
|
|
|
|
|
|
+ forkSeed1 = 2
|
|
|
|
|
+ forkSeed2 = 3
|
|
|
|
|
|
|
|
TestTriesInMemory = 128
|
|
TestTriesInMemory = 128
|
|
|
)
|
|
)
|
|
@@ -51,14 +52,18 @@ var (
|
|
|
// newCanonical creates a chain database, and injects a deterministic canonical
|
|
// newCanonical creates a chain database, and injects a deterministic canonical
|
|
|
// chain. Depending on the full flag, if creates either a full block chain or a
|
|
// chain. Depending on the full flag, if creates either a full block chain or a
|
|
|
// header only chain.
|
|
// header only chain.
|
|
|
-func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *BlockChain, error) {
|
|
|
|
|
|
|
+func newCanonical(engine consensus.Engine, n int, full, pipeline bool) (ethdb.Database, *BlockChain, error) {
|
|
|
var (
|
|
var (
|
|
|
db = rawdb.NewMemoryDatabase()
|
|
db = rawdb.NewMemoryDatabase()
|
|
|
genesis = new(Genesis).MustCommit(db)
|
|
genesis = new(Genesis).MustCommit(db)
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// Initialize a fresh chain with only a genesis block
|
|
// Initialize a fresh chain with only a genesis block
|
|
|
- blockchain, _ := NewBlockChain(db, nil, params.AllEthashProtocolChanges, engine, vm.Config{}, nil, nil)
|
|
|
|
|
|
|
+ var ops []BlockChainOption
|
|
|
|
|
+ if pipeline {
|
|
|
|
|
+ ops = append(ops, EnablePipelineCommit)
|
|
|
|
|
+ }
|
|
|
|
|
+ blockchain, _ := NewBlockChain(db, nil, params.AllEthashProtocolChanges, engine, vm.Config{}, nil, nil, ops...)
|
|
|
// Create and inject the requested chain
|
|
// Create and inject the requested chain
|
|
|
if n == 0 {
|
|
if n == 0 {
|
|
|
return db, blockchain, nil
|
|
return db, blockchain, nil
|
|
@@ -76,9 +81,53 @@ func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *B
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Test fork of length N starting from block i
|
|
// Test fork of length N starting from block i
|
|
|
-func testFork(t *testing.T, blockchain *BlockChain, i, n int, full bool, comparator func(td1, td2 *big.Int)) {
|
|
|
|
|
|
|
+func testInvalidStateRootBlockImport(t *testing.T, blockchain *BlockChain, i, n int, pipeline bool) {
|
|
|
// Copy old chain up to #i into a new db
|
|
// Copy old chain up to #i into a new db
|
|
|
- db, blockchain2, err := newCanonical(ethash.NewFaker(), i, full)
|
|
|
|
|
|
|
+ db, blockchain2, err := newCanonical(ethash.NewFaker(), i, true, pipeline)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ t.Fatal("could not make new canonical in testFork", err)
|
|
|
|
|
+ }
|
|
|
|
|
+ defer blockchain2.Stop()
|
|
|
|
|
+
|
|
|
|
|
+ // Assert the chains have the same header/block at #i
|
|
|
|
|
+ hash1 := blockchain.GetBlockByNumber(uint64(i)).Hash()
|
|
|
|
|
+ hash2 := blockchain2.GetBlockByNumber(uint64(i)).Hash()
|
|
|
|
|
+ if hash1 != hash2 {
|
|
|
|
|
+ t.Errorf("chain content mismatch at %d: have hash %v, want hash %v", i, hash2, hash1)
|
|
|
|
|
+ }
|
|
|
|
|
+ // Extend the newly created chain
|
|
|
|
|
+ blockChainB := makeBlockChain(blockchain2.CurrentBlock(), n, ethash.NewFaker(), db, forkSeed1)
|
|
|
|
|
+ for idx, block := range blockChainB {
|
|
|
|
|
+ block.SetRoot(common.Hash{0: byte(forkSeed1), 19: byte(idx)})
|
|
|
|
|
+ }
|
|
|
|
|
+ previousBlock := blockchain.CurrentBlock()
|
|
|
|
|
+ // Sanity check that the forked chain can be imported into the original
|
|
|
|
|
+ if _, err := blockchain.InsertChain(blockChainB); err == nil {
|
|
|
|
|
+ t.Fatalf("failed to report insert error")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ time.Sleep(2 * rewindBadBlockInterval)
|
|
|
|
|
+ latestBlock := blockchain.CurrentBlock()
|
|
|
|
|
+ if latestBlock.Hash() != previousBlock.Hash() || latestBlock.NumberU64() != previousBlock.NumberU64() {
|
|
|
|
|
+ t.Fatalf("rewind do not take effect")
|
|
|
|
|
+ }
|
|
|
|
|
+ db, blockchain3, err := newCanonical(ethash.NewFaker(), i, true, pipeline)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ t.Fatal("could not make new canonical in testFork", err)
|
|
|
|
|
+ }
|
|
|
|
|
+ defer blockchain3.Stop()
|
|
|
|
|
+
|
|
|
|
|
+ blockChainC := makeBlockChain(blockchain3.CurrentBlock(), n, ethash.NewFaker(), db, forkSeed2)
|
|
|
|
|
+
|
|
|
|
|
+ if _, err := blockchain.InsertChain(blockChainC); err != nil {
|
|
|
|
|
+ t.Fatalf("failed to insert forking chain: %v", err)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// Test fork of length N starting from block i
|
|
|
|
|
+func testFork(t *testing.T, blockchain *BlockChain, i, n int, full, pipeline bool, comparator func(td1, td2 *big.Int)) {
|
|
|
|
|
+ // Copy old chain up to #i into a new db
|
|
|
|
|
+ db, blockchain2, err := newCanonical(ethash.NewFaker(), i, full, pipeline)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal("could not make new canonical in testFork", err)
|
|
t.Fatal("could not make new canonical in testFork", err)
|
|
|
}
|
|
}
|
|
@@ -102,12 +151,12 @@ func testFork(t *testing.T, blockchain *BlockChain, i, n int, full bool, compara
|
|
|
headerChainB []*types.Header
|
|
headerChainB []*types.Header
|
|
|
)
|
|
)
|
|
|
if full {
|
|
if full {
|
|
|
- blockChainB = makeBlockChain(blockchain2.CurrentBlock(), n, ethash.NewFaker(), db, forkSeed)
|
|
|
|
|
|
|
+ blockChainB = makeBlockChain(blockchain2.CurrentBlock(), n, ethash.NewFaker(), db, forkSeed1)
|
|
|
if _, err := blockchain2.InsertChain(blockChainB); err != nil {
|
|
if _, err := blockchain2.InsertChain(blockChainB); err != nil {
|
|
|
t.Fatalf("failed to insert forking chain: %v", err)
|
|
t.Fatalf("failed to insert forking chain: %v", err)
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- headerChainB = makeHeaderChain(blockchain2.CurrentHeader(), n, ethash.NewFaker(), db, forkSeed)
|
|
|
|
|
|
|
+ headerChainB = makeHeaderChain(blockchain2.CurrentHeader(), n, ethash.NewFaker(), db, forkSeed1)
|
|
|
if _, err := blockchain2.InsertHeaderChain(headerChainB, 1); err != nil {
|
|
if _, err := blockchain2.InsertHeaderChain(headerChainB, 1); err != nil {
|
|
|
t.Fatalf("failed to insert forking chain: %v", err)
|
|
t.Fatalf("failed to insert forking chain: %v", err)
|
|
|
}
|
|
}
|
|
@@ -117,7 +166,7 @@ func testFork(t *testing.T, blockchain *BlockChain, i, n int, full bool, compara
|
|
|
|
|
|
|
|
if full {
|
|
if full {
|
|
|
tdPre = blockchain.GetTdByHash(blockchain.CurrentBlock().Hash())
|
|
tdPre = blockchain.GetTdByHash(blockchain.CurrentBlock().Hash())
|
|
|
- if err := testBlockChainImport(blockChainB, blockchain); err != nil {
|
|
|
|
|
|
|
+ if err := testBlockChainImport(blockChainB, pipeline, blockchain); err != nil {
|
|
|
t.Fatalf("failed to import forked block chain: %v", err)
|
|
t.Fatalf("failed to import forked block chain: %v", err)
|
|
|
}
|
|
}
|
|
|
tdPost = blockchain.GetTdByHash(blockChainB[len(blockChainB)-1].Hash())
|
|
tdPost = blockchain.GetTdByHash(blockChainB[len(blockChainB)-1].Hash())
|
|
@@ -134,7 +183,7 @@ func testFork(t *testing.T, blockchain *BlockChain, i, n int, full bool, compara
|
|
|
|
|
|
|
|
// testBlockChainImport tries to process a chain of blocks, writing them into
|
|
// testBlockChainImport tries to process a chain of blocks, writing them into
|
|
|
// the database if successful.
|
|
// the database if successful.
|
|
|
-func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error {
|
|
|
|
|
|
|
+func testBlockChainImport(chain types.Blocks, pipelineCommit bool, blockchain *BlockChain) error {
|
|
|
for _, block := range chain {
|
|
for _, block := range chain {
|
|
|
// Try and process the block
|
|
// Try and process the block
|
|
|
err := blockchain.engine.VerifyHeader(blockchain, block.Header(), true)
|
|
err := blockchain.engine.VerifyHeader(blockchain, block.Header(), true)
|
|
@@ -151,12 +200,16 @@ func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
+ statedb.SetExpectedStateRoot(block.Root())
|
|
|
|
|
+ if pipelineCommit {
|
|
|
|
|
+ statedb.EnablePipeCommit()
|
|
|
|
|
+ }
|
|
|
statedb, receipts, _, usedGas, err := blockchain.processor.Process(block, statedb, vm.Config{})
|
|
statedb, receipts, _, usedGas, err := blockchain.processor.Process(block, statedb, vm.Config{})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
blockchain.reportBlock(block, receipts, err)
|
|
blockchain.reportBlock(block, receipts, err)
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
- err = blockchain.validator.ValidateState(block, statedb, receipts, usedGas)
|
|
|
|
|
|
|
+ err = blockchain.validator.ValidateState(block, statedb, receipts, usedGas, pipelineCommit)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
blockchain.reportBlock(block, receipts, err)
|
|
blockchain.reportBlock(block, receipts, err)
|
|
|
return err
|
|
return err
|
|
@@ -164,7 +217,9 @@ func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error {
|
|
|
blockchain.chainmu.Lock()
|
|
blockchain.chainmu.Lock()
|
|
|
rawdb.WriteTd(blockchain.db, block.Hash(), block.NumberU64(), new(big.Int).Add(block.Difficulty(), blockchain.GetTdByHash(block.ParentHash())))
|
|
rawdb.WriteTd(blockchain.db, block.Hash(), block.NumberU64(), new(big.Int).Add(block.Difficulty(), blockchain.GetTdByHash(block.ParentHash())))
|
|
|
rawdb.WriteBlock(blockchain.db, block)
|
|
rawdb.WriteBlock(blockchain.db, block)
|
|
|
- statedb.Commit(false)
|
|
|
|
|
|
|
+ statedb.Finalise(false)
|
|
|
|
|
+ statedb.AccountsIntermediateRoot()
|
|
|
|
|
+ statedb.Commit(nil)
|
|
|
blockchain.chainmu.Unlock()
|
|
blockchain.chainmu.Unlock()
|
|
|
}
|
|
}
|
|
|
return nil
|
|
return nil
|
|
@@ -187,8 +242,22 @@ func testHeaderChainImport(chain []*types.Header, blockchain *BlockChain) error
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func TestBlockImportVerification(t *testing.T) {
|
|
|
|
|
+ length := 5
|
|
|
|
|
+
|
|
|
|
|
+ // Make first chain starting from genesis
|
|
|
|
|
+ _, processor, err := newCanonical(ethash.NewFaker(), length, true, true)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ t.Fatalf("failed to make new canonical chain: %v", err)
|
|
|
|
|
+ }
|
|
|
|
|
+ defer processor.Stop()
|
|
|
|
|
+ // Start fork from current height
|
|
|
|
|
+ processor = EnablePipelineCommit(processor)
|
|
|
|
|
+ testInvalidStateRootBlockImport(t, processor, length, 10, true)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func TestLastBlock(t *testing.T) {
|
|
func TestLastBlock(t *testing.T) {
|
|
|
- _, blockchain, err := newCanonical(ethash.NewFaker(), 0, true)
|
|
|
|
|
|
|
+ _, blockchain, err := newCanonical(ethash.NewFaker(), 0, true, false)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
|
}
|
|
}
|
|
@@ -205,14 +274,20 @@ func TestLastBlock(t *testing.T) {
|
|
|
|
|
|
|
|
// Tests that given a starting canonical chain of a given size, it can be extended
|
|
// Tests that given a starting canonical chain of a given size, it can be extended
|
|
|
// with various length chains.
|
|
// with various length chains.
|
|
|
-func TestExtendCanonicalHeaders(t *testing.T) { testExtendCanonical(t, false) }
|
|
|
|
|
-func TestExtendCanonicalBlocks(t *testing.T) { testExtendCanonical(t, true) }
|
|
|
|
|
|
|
+func TestExtendCanonicalHeaders(t *testing.T) {
|
|
|
|
|
+ testExtendCanonical(t, false, false)
|
|
|
|
|
|
|
|
-func testExtendCanonical(t *testing.T, full bool) {
|
|
|
|
|
|
|
+}
|
|
|
|
|
+func TestExtendCanonicalBlocks(t *testing.T) {
|
|
|
|
|
+ testExtendCanonical(t, true, false)
|
|
|
|
|
+ testExtendCanonical(t, true, true)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func testExtendCanonical(t *testing.T, full, pipeline bool) {
|
|
|
length := 5
|
|
length := 5
|
|
|
|
|
|
|
|
// Make first chain starting from genesis
|
|
// Make first chain starting from genesis
|
|
|
- _, processor, err := newCanonical(ethash.NewFaker(), length, full)
|
|
|
|
|
|
|
+ _, processor, err := newCanonical(ethash.NewFaker(), length, full, pipeline)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to make new canonical chain: %v", err)
|
|
t.Fatalf("failed to make new canonical chain: %v", err)
|
|
|
}
|
|
}
|
|
@@ -225,22 +300,25 @@ func testExtendCanonical(t *testing.T, full bool) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// Start fork from current height
|
|
// Start fork from current height
|
|
|
- testFork(t, processor, length, 1, full, better)
|
|
|
|
|
- testFork(t, processor, length, 2, full, better)
|
|
|
|
|
- testFork(t, processor, length, 5, full, better)
|
|
|
|
|
- testFork(t, processor, length, 10, full, better)
|
|
|
|
|
|
|
+ testFork(t, processor, length, 1, full, pipeline, better)
|
|
|
|
|
+ testFork(t, processor, length, 2, full, pipeline, better)
|
|
|
|
|
+ testFork(t, processor, length, 5, full, pipeline, better)
|
|
|
|
|
+ testFork(t, processor, length, 10, full, pipeline, better)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Tests that given a starting canonical chain of a given size, creating shorter
|
|
// Tests that given a starting canonical chain of a given size, creating shorter
|
|
|
// forks do not take canonical ownership.
|
|
// forks do not take canonical ownership.
|
|
|
-func TestShorterForkHeaders(t *testing.T) { testShorterFork(t, false) }
|
|
|
|
|
-func TestShorterForkBlocks(t *testing.T) { testShorterFork(t, true) }
|
|
|
|
|
|
|
+func TestShorterForkHeaders(t *testing.T) { testShorterFork(t, false, false) }
|
|
|
|
|
+func TestShorterForkBlocks(t *testing.T) {
|
|
|
|
|
+ testShorterFork(t, true, false)
|
|
|
|
|
+ testShorterFork(t, true, true)
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-func testShorterFork(t *testing.T, full bool) {
|
|
|
|
|
|
|
+func testShorterFork(t *testing.T, full, pipeline bool) {
|
|
|
length := 10
|
|
length := 10
|
|
|
|
|
|
|
|
// Make first chain starting from genesis
|
|
// Make first chain starting from genesis
|
|
|
- _, processor, err := newCanonical(ethash.NewFaker(), length, full)
|
|
|
|
|
|
|
+ _, processor, err := newCanonical(ethash.NewFaker(), length, full, pipeline)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to make new canonical chain: %v", err)
|
|
t.Fatalf("failed to make new canonical chain: %v", err)
|
|
|
}
|
|
}
|
|
@@ -253,24 +331,30 @@ func testShorterFork(t *testing.T, full bool) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// Sum of numbers must be less than `length` for this to be a shorter fork
|
|
// Sum of numbers must be less than `length` for this to be a shorter fork
|
|
|
- testFork(t, processor, 0, 3, full, worse)
|
|
|
|
|
- testFork(t, processor, 0, 7, full, worse)
|
|
|
|
|
- testFork(t, processor, 1, 1, full, worse)
|
|
|
|
|
- testFork(t, processor, 1, 7, full, worse)
|
|
|
|
|
- testFork(t, processor, 5, 3, full, worse)
|
|
|
|
|
- testFork(t, processor, 5, 4, full, worse)
|
|
|
|
|
|
|
+ testFork(t, processor, 0, 3, full, pipeline, worse)
|
|
|
|
|
+ testFork(t, processor, 0, 7, full, pipeline, worse)
|
|
|
|
|
+ testFork(t, processor, 1, 1, full, pipeline, worse)
|
|
|
|
|
+ testFork(t, processor, 1, 7, full, pipeline, worse)
|
|
|
|
|
+ testFork(t, processor, 5, 3, full, pipeline, worse)
|
|
|
|
|
+ testFork(t, processor, 5, 4, full, pipeline, worse)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Tests that given a starting canonical chain of a given size, creating longer
|
|
// Tests that given a starting canonical chain of a given size, creating longer
|
|
|
// forks do take canonical ownership.
|
|
// forks do take canonical ownership.
|
|
|
-func TestLongerForkHeaders(t *testing.T) { testLongerFork(t, false) }
|
|
|
|
|
-func TestLongerForkBlocks(t *testing.T) { testLongerFork(t, true) }
|
|
|
|
|
|
|
+func TestLongerForkHeaders(t *testing.T) {
|
|
|
|
|
+ testLongerFork(t, false, false)
|
|
|
|
|
+}
|
|
|
|
|
+func TestLongerForkBlocks(t *testing.T) {
|
|
|
|
|
+ testLongerFork(t, true, false)
|
|
|
|
|
+ testLongerFork(t, true, true)
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-func testLongerFork(t *testing.T, full bool) {
|
|
|
|
|
|
|
+func testLongerFork(t *testing.T, full, pipeline bool) {
|
|
|
length := 10
|
|
length := 10
|
|
|
|
|
|
|
|
// Make first chain starting from genesis
|
|
// Make first chain starting from genesis
|
|
|
- _, processor, err := newCanonical(ethash.NewFaker(), length, full)
|
|
|
|
|
|
|
+ _, processor, err := newCanonical(ethash.NewFaker(), length, full, pipeline)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to make new canonical chain: %v", err)
|
|
t.Fatalf("failed to make new canonical chain: %v", err)
|
|
|
}
|
|
}
|
|
@@ -283,24 +367,28 @@ func testLongerFork(t *testing.T, full bool) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// Sum of numbers must be greater than `length` for this to be a longer fork
|
|
// Sum of numbers must be greater than `length` for this to be a longer fork
|
|
|
- testFork(t, processor, 0, 11, full, better)
|
|
|
|
|
- testFork(t, processor, 0, 15, full, better)
|
|
|
|
|
- testFork(t, processor, 1, 10, full, better)
|
|
|
|
|
- testFork(t, processor, 1, 12, full, better)
|
|
|
|
|
- testFork(t, processor, 5, 6, full, better)
|
|
|
|
|
- testFork(t, processor, 5, 8, full, better)
|
|
|
|
|
|
|
+ testFork(t, processor, 0, 11, full, pipeline, better)
|
|
|
|
|
+ testFork(t, processor, 0, 15, full, pipeline, better)
|
|
|
|
|
+ testFork(t, processor, 1, 10, full, pipeline, better)
|
|
|
|
|
+ testFork(t, processor, 1, 12, full, pipeline, better)
|
|
|
|
|
+ testFork(t, processor, 5, 6, full, pipeline, better)
|
|
|
|
|
+ testFork(t, processor, 5, 8, full, pipeline, better)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Tests that given a starting canonical chain of a given size, creating equal
|
|
// Tests that given a starting canonical chain of a given size, creating equal
|
|
|
// forks do take canonical ownership.
|
|
// forks do take canonical ownership.
|
|
|
-func TestEqualForkHeaders(t *testing.T) { testEqualFork(t, false) }
|
|
|
|
|
-func TestEqualForkBlocks(t *testing.T) { testEqualFork(t, true) }
|
|
|
|
|
|
|
+func TestEqualForkHeaders(t *testing.T) { testEqualFork(t, false, false) }
|
|
|
|
|
+func TestEqualForkBlocks(t *testing.T) {
|
|
|
|
|
+ testEqualFork(t, true, true)
|
|
|
|
|
+ testEqualFork(t, true, false)
|
|
|
|
|
|
|
|
-func testEqualFork(t *testing.T, full bool) {
|
|
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func testEqualFork(t *testing.T, full, pipeline bool) {
|
|
|
length := 10
|
|
length := 10
|
|
|
|
|
|
|
|
// Make first chain starting from genesis
|
|
// Make first chain starting from genesis
|
|
|
- _, processor, err := newCanonical(ethash.NewFaker(), length, full)
|
|
|
|
|
|
|
+ _, processor, err := newCanonical(ethash.NewFaker(), length, full, pipeline)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to make new canonical chain: %v", err)
|
|
t.Fatalf("failed to make new canonical chain: %v", err)
|
|
|
}
|
|
}
|
|
@@ -313,21 +401,24 @@ func testEqualFork(t *testing.T, full bool) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// Sum of numbers must be equal to `length` for this to be an equal fork
|
|
// Sum of numbers must be equal to `length` for this to be an equal fork
|
|
|
- testFork(t, processor, 0, 10, full, equal)
|
|
|
|
|
- testFork(t, processor, 1, 9, full, equal)
|
|
|
|
|
- testFork(t, processor, 2, 8, full, equal)
|
|
|
|
|
- testFork(t, processor, 5, 5, full, equal)
|
|
|
|
|
- testFork(t, processor, 6, 4, full, equal)
|
|
|
|
|
- testFork(t, processor, 9, 1, full, equal)
|
|
|
|
|
|
|
+ testFork(t, processor, 0, 10, full, pipeline, equal)
|
|
|
|
|
+ testFork(t, processor, 1, 9, full, pipeline, equal)
|
|
|
|
|
+ testFork(t, processor, 2, 8, full, pipeline, equal)
|
|
|
|
|
+ testFork(t, processor, 5, 5, full, pipeline, equal)
|
|
|
|
|
+ testFork(t, processor, 6, 4, full, pipeline, equal)
|
|
|
|
|
+ testFork(t, processor, 9, 1, full, pipeline, equal)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Tests that chains missing links do not get accepted by the processor.
|
|
// Tests that chains missing links do not get accepted by the processor.
|
|
|
-func TestBrokenHeaderChain(t *testing.T) { testBrokenChain(t, false) }
|
|
|
|
|
-func TestBrokenBlockChain(t *testing.T) { testBrokenChain(t, true) }
|
|
|
|
|
|
|
+func TestBrokenHeaderChain(t *testing.T) { testBrokenChain(t, false, false) }
|
|
|
|
|
+func TestBrokenBlockChain(t *testing.T) {
|
|
|
|
|
+ testBrokenChain(t, true, false)
|
|
|
|
|
+ testBrokenChain(t, true, true)
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-func testBrokenChain(t *testing.T, full bool) {
|
|
|
|
|
|
|
+func testBrokenChain(t *testing.T, full, pipeline bool) {
|
|
|
// Make chain starting from genesis
|
|
// Make chain starting from genesis
|
|
|
- db, blockchain, err := newCanonical(ethash.NewFaker(), 10, full)
|
|
|
|
|
|
|
+ db, blockchain, err := newCanonical(ethash.NewFaker(), 10, full, pipeline)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to make new canonical chain: %v", err)
|
|
t.Fatalf("failed to make new canonical chain: %v", err)
|
|
|
}
|
|
}
|
|
@@ -335,12 +426,12 @@ func testBrokenChain(t *testing.T, full bool) {
|
|
|
|
|
|
|
|
// Create a forked chain, and try to insert with a missing link
|
|
// Create a forked chain, and try to insert with a missing link
|
|
|
if full {
|
|
if full {
|
|
|
- chain := makeBlockChain(blockchain.CurrentBlock(), 5, ethash.NewFaker(), db, forkSeed)[1:]
|
|
|
|
|
- if err := testBlockChainImport(chain, blockchain); err == nil {
|
|
|
|
|
|
|
+ chain := makeBlockChain(blockchain.CurrentBlock(), 5, ethash.NewFaker(), db, forkSeed1)[1:]
|
|
|
|
|
+ if err := testBlockChainImport(chain, pipeline, blockchain); err == nil {
|
|
|
t.Errorf("broken block chain not reported")
|
|
t.Errorf("broken block chain not reported")
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- chain := makeHeaderChain(blockchain.CurrentHeader(), 5, ethash.NewFaker(), db, forkSeed)[1:]
|
|
|
|
|
|
|
+ chain := makeHeaderChain(blockchain.CurrentHeader(), 5, ethash.NewFaker(), db, forkSeed1)[1:]
|
|
|
if err := testHeaderChainImport(chain, blockchain); err == nil {
|
|
if err := testHeaderChainImport(chain, blockchain); err == nil {
|
|
|
t.Errorf("broken header chain not reported")
|
|
t.Errorf("broken header chain not reported")
|
|
|
}
|
|
}
|
|
@@ -349,19 +440,25 @@ func testBrokenChain(t *testing.T, full bool) {
|
|
|
|
|
|
|
|
// Tests that reorganising a long difficult chain after a short easy one
|
|
// Tests that reorganising a long difficult chain after a short easy one
|
|
|
// overwrites the canonical numbers and links in the database.
|
|
// overwrites the canonical numbers and links in the database.
|
|
|
-func TestReorgLongHeaders(t *testing.T) { testReorgLong(t, false) }
|
|
|
|
|
-func TestReorgLongBlocks(t *testing.T) { testReorgLong(t, true) }
|
|
|
|
|
|
|
+func TestReorgLongHeaders(t *testing.T) { testReorgLong(t, false, false) }
|
|
|
|
|
+func TestReorgLongBlocks(t *testing.T) {
|
|
|
|
|
+ testReorgLong(t, true, false)
|
|
|
|
|
+ testReorgLong(t, true, true)
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-func testReorgLong(t *testing.T, full bool) {
|
|
|
|
|
- testReorg(t, []int64{0, 0, -9}, []int64{0, 0, 0, -9}, 393280, full)
|
|
|
|
|
|
|
+func testReorgLong(t *testing.T, full, pipeline bool) {
|
|
|
|
|
+ testReorg(t, []int64{0, 0, -9}, []int64{0, 0, 0, -9}, 393280, full, pipeline)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Tests that reorganising a short difficult chain after a long easy one
|
|
// Tests that reorganising a short difficult chain after a long easy one
|
|
|
// overwrites the canonical numbers and links in the database.
|
|
// overwrites the canonical numbers and links in the database.
|
|
|
-func TestReorgShortHeaders(t *testing.T) { testReorgShort(t, false) }
|
|
|
|
|
-func TestReorgShortBlocks(t *testing.T) { testReorgShort(t, true) }
|
|
|
|
|
|
|
+func TestReorgShortHeaders(t *testing.T) { testReorgShort(t, false, false) }
|
|
|
|
|
+func TestReorgShortBlocks(t *testing.T) {
|
|
|
|
|
+ testReorgShort(t, true, false)
|
|
|
|
|
+ testReorgShort(t, true, true)
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-func testReorgShort(t *testing.T, full bool) {
|
|
|
|
|
|
|
+func testReorgShort(t *testing.T, full, pipeline bool) {
|
|
|
// Create a long easy chain vs. a short heavy one. Due to difficulty adjustment
|
|
// Create a long easy chain vs. a short heavy one. Due to difficulty adjustment
|
|
|
// we need a fairly long chain of blocks with different difficulties for a short
|
|
// we need a fairly long chain of blocks with different difficulties for a short
|
|
|
// one to become heavyer than a long one. The 96 is an empirical value.
|
|
// one to become heavyer than a long one. The 96 is an empirical value.
|
|
@@ -373,12 +470,12 @@ func testReorgShort(t *testing.T, full bool) {
|
|
|
for i := 0; i < len(diff); i++ {
|
|
for i := 0; i < len(diff); i++ {
|
|
|
diff[i] = -9
|
|
diff[i] = -9
|
|
|
}
|
|
}
|
|
|
- testReorg(t, easy, diff, 12615120, full)
|
|
|
|
|
|
|
+ testReorg(t, easy, diff, 12615120, full, pipeline)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func testReorg(t *testing.T, first, second []int64, td int64, full bool) {
|
|
|
|
|
|
|
+func testReorg(t *testing.T, first, second []int64, td int64, full, pipeline bool) {
|
|
|
// Create a pristine chain and database
|
|
// Create a pristine chain and database
|
|
|
- db, blockchain, err := newCanonical(ethash.NewFaker(), 0, full)
|
|
|
|
|
|
|
+ db, blockchain, err := newCanonical(ethash.NewFaker(), 0, full, pipeline)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
|
}
|
|
}
|
|
@@ -444,12 +541,16 @@ func testReorg(t *testing.T, first, second []int64, td int64, full bool) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Tests that the insertion functions detect banned hashes.
|
|
// Tests that the insertion functions detect banned hashes.
|
|
|
-func TestBadHeaderHashes(t *testing.T) { testBadHashes(t, false) }
|
|
|
|
|
-func TestBadBlockHashes(t *testing.T) { testBadHashes(t, true) }
|
|
|
|
|
|
|
+func TestBadHeaderHashes(t *testing.T) { testBadHashes(t, false, false) }
|
|
|
|
|
+func TestBadBlockHashes(t *testing.T) {
|
|
|
|
|
+ testBadHashes(t, true, true)
|
|
|
|
|
+ testBadHashes(t, true, false)
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-func testBadHashes(t *testing.T, full bool) {
|
|
|
|
|
|
|
+func testBadHashes(t *testing.T, full, pipeline bool) {
|
|
|
// Create a pristine chain and database
|
|
// Create a pristine chain and database
|
|
|
- db, blockchain, err := newCanonical(ethash.NewFaker(), 0, full)
|
|
|
|
|
|
|
+ db, blockchain, err := newCanonical(ethash.NewFaker(), 0, full, pipeline)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
|
}
|
|
}
|
|
@@ -478,12 +579,16 @@ func testBadHashes(t *testing.T, full bool) {
|
|
|
|
|
|
|
|
// Tests that bad hashes are detected on boot, and the chain rolled back to a
|
|
// Tests that bad hashes are detected on boot, and the chain rolled back to a
|
|
|
// good state prior to the bad hash.
|
|
// good state prior to the bad hash.
|
|
|
-func TestReorgBadHeaderHashes(t *testing.T) { testReorgBadHashes(t, false) }
|
|
|
|
|
-func TestReorgBadBlockHashes(t *testing.T) { testReorgBadHashes(t, true) }
|
|
|
|
|
|
|
+func TestReorgBadHeaderHashes(t *testing.T) { testReorgBadHashes(t, false, false) }
|
|
|
|
|
+func TestReorgBadBlockHashes(t *testing.T) {
|
|
|
|
|
+ testReorgBadHashes(t, true, false)
|
|
|
|
|
+ testReorgBadHashes(t, true, true)
|
|
|
|
|
|
|
|
-func testReorgBadHashes(t *testing.T, full bool) {
|
|
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func testReorgBadHashes(t *testing.T, full, pipeline bool) {
|
|
|
// Create a pristine chain and database
|
|
// Create a pristine chain and database
|
|
|
- db, blockchain, err := newCanonical(ethash.NewFaker(), 0, full)
|
|
|
|
|
|
|
+ db, blockchain, err := newCanonical(ethash.NewFaker(), 0, full, pipeline)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
|
}
|
|
}
|
|
@@ -533,13 +638,16 @@ func testReorgBadHashes(t *testing.T, full bool) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Tests chain insertions in the face of one entity containing an invalid nonce.
|
|
// Tests chain insertions in the face of one entity containing an invalid nonce.
|
|
|
-func TestHeadersInsertNonceError(t *testing.T) { testInsertNonceError(t, false) }
|
|
|
|
|
-func TestBlocksInsertNonceError(t *testing.T) { testInsertNonceError(t, true) }
|
|
|
|
|
|
|
+func TestHeadersInsertNonceError(t *testing.T) { testInsertNonceError(t, false, false) }
|
|
|
|
|
+func TestBlocksInsertNonceError(t *testing.T) {
|
|
|
|
|
+ testInsertNonceError(t, true, false)
|
|
|
|
|
+ testInsertNonceError(t, true, true)
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-func testInsertNonceError(t *testing.T, full bool) {
|
|
|
|
|
|
|
+func testInsertNonceError(t *testing.T, full, pipeline bool) {
|
|
|
for i := 1; i < 25 && !t.Failed(); i++ {
|
|
for i := 1; i < 25 && !t.Failed(); i++ {
|
|
|
// Create a pristine chain and database
|
|
// Create a pristine chain and database
|
|
|
- db, blockchain, err := newCanonical(ethash.NewFaker(), 0, full)
|
|
|
|
|
|
|
+ db, blockchain, err := newCanonical(ethash.NewFaker(), 0, full, pipeline)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
|
}
|
|
}
|
|
@@ -1212,7 +1320,7 @@ done:
|
|
|
|
|
|
|
|
// Tests if the canonical block can be fetched from the database during chain insertion.
|
|
// Tests if the canonical block can be fetched from the database during chain insertion.
|
|
|
func TestCanonicalBlockRetrieval(t *testing.T) {
|
|
func TestCanonicalBlockRetrieval(t *testing.T) {
|
|
|
- _, blockchain, err := newCanonical(ethash.NewFaker(), 0, true)
|
|
|
|
|
|
|
+ _, blockchain, err := newCanonical(ethash.NewFaker(), 0, true, false)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
t.Fatalf("failed to create pristine chain: %v", err)
|
|
|
}
|
|
}
|