From 3291235711082759cd7b70253c02150a80d57011 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= <peterke@gmail.com>
Date: Thu, 14 Jul 2016 18:17:03 +0300
Subject: accounts, core, eth: pass chain config for chain maker to test DAO

---
 core/bench_test.go           |   2 +-
 core/block_validator_test.go | 105 ----------------------------------
 core/blockchain_test.go      |  16 +++---
 core/chain_makers.go         |  28 ++++++++-
 core/chain_makers_test.go    |   2 +-
 core/chain_pow_test.go       |   6 +-
 core/dao_test.go             | 132 +++++++++++++++++++++++++++++++++++++++++++
 core/database_util_test.go   |   2 +-
 core/state_processor.go      |   2 +-
 9 files changed, 172 insertions(+), 123 deletions(-)
 create mode 100644 core/dao_test.go

(limited to 'core')

diff --git a/core/bench_test.go b/core/bench_test.go
index c6029499a..344e7e3c5 100644
--- a/core/bench_test.go
+++ b/core/bench_test.go
@@ -163,7 +163,7 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
 	// Generate a chain of b.N blocks using the supplied block
 	// generator function.
 	genesis := WriteGenesisBlockForTesting(db, GenesisAccount{benchRootAddr, benchRootFunds})
-	chain, _ := GenerateChain(genesis, db, b.N, gen)
+	chain, _ := GenerateChain(nil, genesis, db, b.N, gen)
 
 	// Time the insertion of the new chain.
 	// State and blocks are stored in the same DB.
diff --git a/core/block_validator_test.go b/core/block_validator_test.go
index 5320c3f8d..c6daf9e7f 100644
--- a/core/block_validator_test.go
+++ b/core/block_validator_test.go
@@ -27,7 +27,6 @@ import (
 	"github.com/ethereum/go-ethereum/core/vm"
 	"github.com/ethereum/go-ethereum/ethdb"
 	"github.com/ethereum/go-ethereum/event"
-	"github.com/ethereum/go-ethereum/params"
 	"github.com/ethereum/go-ethereum/pow/ezp"
 )
 
@@ -93,107 +92,3 @@ func TestPutReceipt(t *testing.T) {
 		t.Error("expected to get 1 receipt, got none.")
 	}
 }
-
-// Tests that DAO-fork enabled clients can properly filter out fork-commencing
-// blocks based on their extradata fields.
-func TestDAOForkRangeExtradata(t *testing.T) {
-	forkBlock := big.NewInt(32)
-
-	// Generate a common prefix for both pro-forkers and non-forkers
-	db, _ := ethdb.NewMemDatabase()
-	genesis := WriteGenesisBlockForTesting(db)
-	prefix, _ := GenerateChain(genesis, db, int(forkBlock.Int64()-1), func(i int, gen *BlockGen) {})
-
-	// Create the concurrent, conflicting two nodes
-	proDb, _ := ethdb.NewMemDatabase()
-	WriteGenesisBlockForTesting(proDb)
-	proBc, _ := NewBlockChain(proDb, &ChainConfig{HomesteadBlock: big.NewInt(0), DAOForkBlock: forkBlock, DAOForkSupport: true}, new(FakePow), new(event.TypeMux))
-
-	conDb, _ := ethdb.NewMemDatabase()
-	WriteGenesisBlockForTesting(conDb)
-	conBc, _ := NewBlockChain(conDb, &ChainConfig{HomesteadBlock: big.NewInt(0), DAOForkBlock: forkBlock, DAOForkSupport: false}, new(FakePow), new(event.TypeMux))
-
-	if _, err := proBc.InsertChain(prefix); err != nil {
-		t.Fatalf("pro-fork: failed to import chain prefix: %v", err)
-	}
-	if _, err := conBc.InsertChain(prefix); err != nil {
-		t.Fatalf("con-fork: failed to import chain prefix: %v", err)
-	}
-	// Try to expand both pro-fork and non-fork chains iteratively with other camp's blocks
-	for i := int64(0); i < params.DAOForkExtraRange.Int64(); i++ {
-		// Create a pro-fork block, and try to feed into the no-fork chain
-		db, _ = ethdb.NewMemDatabase()
-		WriteGenesisBlockForTesting(db)
-		bc, _ := NewBlockChain(db, &ChainConfig{HomesteadBlock: big.NewInt(0)}, new(FakePow), new(event.TypeMux))
-
-		blocks := conBc.GetBlocksFromHash(conBc.CurrentBlock().Hash(), int(conBc.CurrentBlock().NumberU64()+1))
-		for j := 0; j < len(blocks)/2; j++ {
-			blocks[j], blocks[len(blocks)-1-j] = blocks[len(blocks)-1-j], blocks[j]
-		}
-		if _, err := bc.InsertChain(blocks); err != nil {
-			t.Fatalf("failed to import contra-fork chain for expansion: %v", err)
-		}
-		blocks, _ = GenerateChain(conBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) { gen.SetExtra(params.DAOForkBlockExtra) })
-		if _, err := conBc.InsertChain(blocks); err == nil {
-			t.Fatalf("contra-fork chain accepted pro-fork block: %v", blocks[0])
-		}
-		// Create a proper no-fork block for the contra-forker
-		blocks, _ = GenerateChain(conBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) {})
-		if _, err := conBc.InsertChain(blocks); err != nil {
-			t.Fatalf("contra-fork chain didn't accepted no-fork block: %v", err)
-		}
-		// Create a no-fork block, and try to feed into the pro-fork chain
-		db, _ = ethdb.NewMemDatabase()
-		WriteGenesisBlockForTesting(db)
-		bc, _ = NewBlockChain(db, &ChainConfig{HomesteadBlock: big.NewInt(0)}, new(FakePow), new(event.TypeMux))
-
-		blocks = proBc.GetBlocksFromHash(proBc.CurrentBlock().Hash(), int(proBc.CurrentBlock().NumberU64()+1))
-		for j := 0; j < len(blocks)/2; j++ {
-			blocks[j], blocks[len(blocks)-1-j] = blocks[len(blocks)-1-j], blocks[j]
-		}
-		if _, err := bc.InsertChain(blocks); err != nil {
-			t.Fatalf("failed to import pro-fork chain for expansion: %v", err)
-		}
-		blocks, _ = GenerateChain(proBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) {})
-		if _, err := proBc.InsertChain(blocks); err == nil {
-			t.Fatalf("pro-fork chain accepted contra-fork block: %v", blocks[0])
-		}
-		// Create a proper pro-fork block for the pro-forker
-		blocks, _ = GenerateChain(proBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) { gen.SetExtra(params.DAOForkBlockExtra) })
-		if _, err := proBc.InsertChain(blocks); err != nil {
-			t.Fatalf("pro-fork chain didn't accepted pro-fork block: %v", err)
-		}
-	}
-	// Verify that contra-forkers accept pro-fork extra-datas after forking finishes
-	db, _ = ethdb.NewMemDatabase()
-	WriteGenesisBlockForTesting(db)
-	bc, _ := NewBlockChain(db, &ChainConfig{HomesteadBlock: big.NewInt(0)}, new(FakePow), new(event.TypeMux))
-
-	blocks := conBc.GetBlocksFromHash(conBc.CurrentBlock().Hash(), int(conBc.CurrentBlock().NumberU64()+1))
-	for j := 0; j < len(blocks)/2; j++ {
-		blocks[j], blocks[len(blocks)-1-j] = blocks[len(blocks)-1-j], blocks[j]
-	}
-	if _, err := bc.InsertChain(blocks); err != nil {
-		t.Fatalf("failed to import contra-fork chain for expansion: %v", err)
-	}
-	blocks, _ = GenerateChain(conBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) { gen.SetExtra(params.DAOForkBlockExtra) })
-	if _, err := conBc.InsertChain(blocks); err != nil {
-		t.Fatalf("contra-fork chain didn't accept pro-fork block post-fork: %v", err)
-	}
-	// Verify that pro-forkers accept contra-fork extra-datas after forking finishes
-	db, _ = ethdb.NewMemDatabase()
-	WriteGenesisBlockForTesting(db)
-	bc, _ = NewBlockChain(db, &ChainConfig{HomesteadBlock: big.NewInt(0)}, new(FakePow), new(event.TypeMux))
-
-	blocks = proBc.GetBlocksFromHash(proBc.CurrentBlock().Hash(), int(proBc.CurrentBlock().NumberU64()+1))
-	for j := 0; j < len(blocks)/2; j++ {
-		blocks[j], blocks[len(blocks)-1-j] = blocks[len(blocks)-1-j], blocks[j]
-	}
-	if _, err := bc.InsertChain(blocks); err != nil {
-		t.Fatalf("failed to import pro-fork chain for expansion: %v", err)
-	}
-	blocks, _ = GenerateChain(proBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) {})
-	if _, err := proBc.InsertChain(blocks); err != nil {
-		t.Fatalf("pro-fork chain didn't accept contra-fork block post-fork: %v", err)
-	}
-}
diff --git a/core/blockchain_test.go b/core/blockchain_test.go
index a26fe4a1b..c3e4d352d 100644
--- a/core/blockchain_test.go
+++ b/core/blockchain_test.go
@@ -712,7 +712,7 @@ func TestFastVsFullChains(t *testing.T) {
 		funds    = big.NewInt(1000000000)
 		genesis  = GenesisBlockForTesting(gendb, address, funds)
 	)
-	blocks, receipts := GenerateChain(genesis, gendb, 1024, func(i int, block *BlockGen) {
+	blocks, receipts := GenerateChain(nil, genesis, gendb, 1024, func(i int, block *BlockGen) {
 		block.SetCoinbase(common.Address{0x00})
 
 		// If the block number is multiple of 3, send a few bonus transactions to the miner
@@ -795,7 +795,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) {
 		genesis  = GenesisBlockForTesting(gendb, address, funds)
 	)
 	height := uint64(1024)
-	blocks, receipts := GenerateChain(genesis, gendb, int(height), nil)
+	blocks, receipts := GenerateChain(nil, genesis, gendb, int(height), nil)
 
 	// Configure a subchain to roll back
 	remove := []common.Hash{}
@@ -895,7 +895,7 @@ func TestChainTxReorgs(t *testing.T) {
 	//  - futureAdd: transaction added after the reorg has already finished
 	var pastAdd, freshAdd, futureAdd *types.Transaction
 
-	chain, _ := GenerateChain(genesis, db, 3, func(i int, gen *BlockGen) {
+	chain, _ := GenerateChain(nil, genesis, db, 3, func(i int, gen *BlockGen) {
 		switch i {
 		case 0:
 			pastDrop, _ = types.NewTransaction(gen.TxNonce(addr2), addr2, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(key2)
@@ -920,7 +920,7 @@ func TestChainTxReorgs(t *testing.T) {
 	}
 
 	// overwrite the old chain
-	chain, _ = GenerateChain(genesis, db, 5, func(i int, gen *BlockGen) {
+	chain, _ = GenerateChain(nil, genesis, db, 5, func(i int, gen *BlockGen) {
 		switch i {
 		case 0:
 			pastAdd, _ = types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(key3)
@@ -990,7 +990,7 @@ func TestLogReorgs(t *testing.T) {
 	blockchain, _ := NewBlockChain(db, testChainConfig(), FakePow{}, evmux)
 
 	subs := evmux.Subscribe(RemovedLogsEvent{})
-	chain, _ := GenerateChain(genesis, db, 2, func(i int, gen *BlockGen) {
+	chain, _ := GenerateChain(nil, genesis, db, 2, func(i int, gen *BlockGen) {
 		if i == 1 {
 			tx, err := types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), big.NewInt(1000000), new(big.Int), code).SignECDSA(key1)
 			if err != nil {
@@ -1003,7 +1003,7 @@ func TestLogReorgs(t *testing.T) {
 		t.Fatalf("failed to insert chain: %v", err)
 	}
 
-	chain, _ = GenerateChain(genesis, db, 3, func(i int, gen *BlockGen) {})
+	chain, _ = GenerateChain(nil, genesis, db, 3, func(i int, gen *BlockGen) {})
 	if _, err := blockchain.InsertChain(chain); err != nil {
 		t.Fatalf("failed to insert forked chain: %v", err)
 	}
@@ -1025,12 +1025,12 @@ func TestReorgSideEvent(t *testing.T) {
 	evmux := &event.TypeMux{}
 	blockchain, _ := NewBlockChain(db, testChainConfig(), FakePow{}, evmux)
 
-	chain, _ := GenerateChain(genesis, db, 3, func(i int, gen *BlockGen) {})
+	chain, _ := GenerateChain(nil, genesis, db, 3, func(i int, gen *BlockGen) {})
 	if _, err := blockchain.InsertChain(chain); err != nil {
 		t.Fatalf("failed to insert chain: %v", err)
 	}
 
-	replacementBlocks, _ := GenerateChain(genesis, db, 4, func(i int, gen *BlockGen) {
+	replacementBlocks, _ := GenerateChain(nil, genesis, db, 4, func(i int, gen *BlockGen) {
 		tx, err := types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), big.NewInt(1000000), new(big.Int), nil).SignECDSA(key1)
 		if i == 2 {
 			gen.OffsetTime(-1)
diff --git a/core/chain_makers.go b/core/chain_makers.go
index ef0ac66d1..0b9a5f75d 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -26,6 +26,7 @@ import (
 	"github.com/ethereum/go-ethereum/core/vm"
 	"github.com/ethereum/go-ethereum/ethdb"
 	"github.com/ethereum/go-ethereum/event"
+	"github.com/ethereum/go-ethereum/params"
 	"github.com/ethereum/go-ethereum/pow"
 )
 
@@ -35,7 +36,11 @@ import (
 
 // MakeChainConfig returns a new ChainConfig with the ethereum default chain settings.
 func MakeChainConfig() *ChainConfig {
-	return &ChainConfig{HomesteadBlock: big.NewInt(0)}
+	return &ChainConfig{
+		HomesteadBlock: big.NewInt(0),
+		DAOForkBlock:   nil,
+		DAOForkSupport: true,
+	}
 }
 
 // FakePow is a non-validating proof of work implementation.
@@ -173,10 +178,27 @@ func (b *BlockGen) OffsetTime(seconds int64) {
 // Blocks created by GenerateChain do not contain valid proof of work
 // values. Inserting them into BlockChain requires use of FakePow or
 // a similar non-validating proof of work implementation.
-func GenerateChain(parent *types.Block, db ethdb.Database, n int, gen func(int, *BlockGen)) ([]*types.Block, []types.Receipts) {
+func GenerateChain(config *ChainConfig, parent *types.Block, db ethdb.Database, n int, gen func(int, *BlockGen)) ([]*types.Block, []types.Receipts) {
 	blocks, receipts := make(types.Blocks, n), make([]types.Receipts, n)
 	genblock := func(i int, h *types.Header, statedb *state.StateDB) (*types.Block, types.Receipts) {
 		b := &BlockGen{parent: parent, i: i, chain: blocks, header: h, statedb: statedb}
+
+		// Mutate the state and block according to any hard-fork specs
+		if config == nil {
+			config = MakeChainConfig()
+		}
+		if daoBlock := config.DAOForkBlock; daoBlock != nil {
+			limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange)
+			if h.Number.Cmp(daoBlock) >= 0 && h.Number.Cmp(limit) < 0 {
+				if config.DAOForkSupport {
+					h.Extra = common.CopyBytes(params.DAOForkBlockExtra)
+				}
+			}
+		}
+		if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(h.Number) == 0 {
+			ApplyDAOHardFork(statedb)
+		}
+		// Execute any user modifications to the block and finalize it
 		if gen != nil {
 			gen(i, b)
 		}
@@ -261,7 +283,7 @@ func makeHeaderChain(parent *types.Header, n int, db ethdb.Database, seed int) [
 
 // makeBlockChain creates a deterministic chain of blocks rooted at parent.
 func makeBlockChain(parent *types.Block, n int, db ethdb.Database, seed int) []*types.Block {
-	blocks, _ := GenerateChain(parent, db, n, func(i int, b *BlockGen) {
+	blocks, _ := GenerateChain(nil, parent, db, n, func(i int, b *BlockGen) {
 		b.SetCoinbase(common.Address{0: byte(seed), 19: byte(i)})
 	})
 	return blocks
diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go
index 32c3efe8d..f52b09ad9 100644
--- a/core/chain_makers_test.go
+++ b/core/chain_makers_test.go
@@ -47,7 +47,7 @@ func ExampleGenerateChain() {
 	// This call generates a chain of 5 blocks. The function runs for
 	// each block and adds different features to gen based on the
 	// block index.
-	chain, _ := GenerateChain(genesis, db, 5, func(i int, gen *BlockGen) {
+	chain, _ := GenerateChain(nil, genesis, db, 5, func(i int, gen *BlockGen) {
 		switch i {
 		case 0:
 			// In block 1, addr1 sends addr2 some ether.
diff --git a/core/chain_pow_test.go b/core/chain_pow_test.go
index d2b0bd144..2e26c8211 100644
--- a/core/chain_pow_test.go
+++ b/core/chain_pow_test.go
@@ -60,7 +60,7 @@ func TestPowVerification(t *testing.T) {
 	var (
 		testdb, _ = ethdb.NewMemDatabase()
 		genesis   = GenesisBlockForTesting(testdb, common.Address{}, new(big.Int))
-		blocks, _ = GenerateChain(genesis, testdb, 8, nil)
+		blocks, _ = GenerateChain(nil, genesis, testdb, 8, nil)
 	)
 	headers := make([]*types.Header, len(blocks))
 	for i, block := range blocks {
@@ -115,7 +115,7 @@ func testPowConcurrentVerification(t *testing.T, threads int) {
 	var (
 		testdb, _ = ethdb.NewMemDatabase()
 		genesis   = GenesisBlockForTesting(testdb, common.Address{}, new(big.Int))
-		blocks, _ = GenerateChain(genesis, testdb, 8, nil)
+		blocks, _ = GenerateChain(nil, genesis, testdb, 8, nil)
 	)
 	headers := make([]*types.Header, len(blocks))
 	for i, block := range blocks {
@@ -186,7 +186,7 @@ func testPowConcurrentAbortion(t *testing.T, threads int) {
 	var (
 		testdb, _ = ethdb.NewMemDatabase()
 		genesis   = GenesisBlockForTesting(testdb, common.Address{}, new(big.Int))
-		blocks, _ = GenerateChain(genesis, testdb, 1024, nil)
+		blocks, _ = GenerateChain(nil, genesis, testdb, 1024, nil)
 	)
 	headers := make([]*types.Header, len(blocks))
 	for i, block := range blocks {
diff --git a/core/dao_test.go b/core/dao_test.go
new file mode 100644
index 000000000..0830b1231
--- /dev/null
+++ b/core/dao_test.go
@@ -0,0 +1,132 @@
+// Copyright 2016 The go-ethereum Authors
+// This file is part of the go-ethereum library.
+//
+// The go-ethereum library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The go-ethereum library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
+
+package core
+
+import (
+	"math/big"
+	"testing"
+
+	"github.com/ethereum/go-ethereum/ethdb"
+	"github.com/ethereum/go-ethereum/event"
+	"github.com/ethereum/go-ethereum/params"
+)
+
+// Tests that DAO-fork enabled clients can properly filter out fork-commencing
+// blocks based on their extradata fields.
+func TestDAOForkRangeExtradata(t *testing.T) {
+	forkBlock := big.NewInt(32)
+
+	// Generate a common prefix for both pro-forkers and non-forkers
+	db, _ := ethdb.NewMemDatabase()
+	genesis := WriteGenesisBlockForTesting(db)
+	prefix, _ := GenerateChain(nil, genesis, db, int(forkBlock.Int64()-1), func(i int, gen *BlockGen) {})
+
+	// Create the concurrent, conflicting two nodes
+	proDb, _ := ethdb.NewMemDatabase()
+	WriteGenesisBlockForTesting(proDb)
+	proConf := &ChainConfig{HomesteadBlock: big.NewInt(0), DAOForkBlock: forkBlock, DAOForkSupport: true}
+	proBc, _ := NewBlockChain(proDb, proConf, new(FakePow), new(event.TypeMux))
+
+	conDb, _ := ethdb.NewMemDatabase()
+	WriteGenesisBlockForTesting(conDb)
+	conConf := &ChainConfig{HomesteadBlock: big.NewInt(0), DAOForkBlock: forkBlock, DAOForkSupport: false}
+	conBc, _ := NewBlockChain(conDb, conConf, new(FakePow), new(event.TypeMux))
+
+	if _, err := proBc.InsertChain(prefix); err != nil {
+		t.Fatalf("pro-fork: failed to import chain prefix: %v", err)
+	}
+	if _, err := conBc.InsertChain(prefix); err != nil {
+		t.Fatalf("con-fork: failed to import chain prefix: %v", err)
+	}
+	// Try to expand both pro-fork and non-fork chains iteratively with other camp's blocks
+	for i := int64(0); i < params.DAOForkExtraRange.Int64(); i++ {
+		// Create a pro-fork block, and try to feed into the no-fork chain
+		db, _ = ethdb.NewMemDatabase()
+		WriteGenesisBlockForTesting(db)
+		bc, _ := NewBlockChain(db, conConf, new(FakePow), new(event.TypeMux))
+
+		blocks := conBc.GetBlocksFromHash(conBc.CurrentBlock().Hash(), int(conBc.CurrentBlock().NumberU64()+1))
+		for j := 0; j < len(blocks)/2; j++ {
+			blocks[j], blocks[len(blocks)-1-j] = blocks[len(blocks)-1-j], blocks[j]
+		}
+		if _, err := bc.InsertChain(blocks); err != nil {
+			t.Fatalf("failed to import contra-fork chain for expansion: %v", err)
+		}
+		blocks, _ = GenerateChain(proConf, conBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) {})
+		if _, err := conBc.InsertChain(blocks); err == nil {
+			t.Fatalf("contra-fork chain accepted pro-fork block: %v", blocks[0])
+		}
+		// Create a proper no-fork block for the contra-forker
+		blocks, _ = GenerateChain(conConf, conBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) {})
+		if _, err := conBc.InsertChain(blocks); err != nil {
+			t.Fatalf("contra-fork chain didn't accepted no-fork block: %v", err)
+		}
+		// Create a no-fork block, and try to feed into the pro-fork chain
+		db, _ = ethdb.NewMemDatabase()
+		WriteGenesisBlockForTesting(db)
+		bc, _ = NewBlockChain(db, proConf, new(FakePow), new(event.TypeMux))
+
+		blocks = proBc.GetBlocksFromHash(proBc.CurrentBlock().Hash(), int(proBc.CurrentBlock().NumberU64()+1))
+		for j := 0; j < len(blocks)/2; j++ {
+			blocks[j], blocks[len(blocks)-1-j] = blocks[len(blocks)-1-j], blocks[j]
+		}
+		if _, err := bc.InsertChain(blocks); err != nil {
+			t.Fatalf("failed to import pro-fork chain for expansion: %v", err)
+		}
+		blocks, _ = GenerateChain(conConf, proBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) {})
+		if _, err := proBc.InsertChain(blocks); err == nil {
+			t.Fatalf("pro-fork chain accepted contra-fork block: %v", blocks[0])
+		}
+		// Create a proper pro-fork block for the pro-forker
+		blocks, _ = GenerateChain(proConf, proBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) {})
+		if _, err := proBc.InsertChain(blocks); err != nil {
+			t.Fatalf("pro-fork chain didn't accepted pro-fork block: %v", err)
+		}
+	}
+	// Verify that contra-forkers accept pro-fork extra-datas after forking finishes
+	db, _ = ethdb.NewMemDatabase()
+	WriteGenesisBlockForTesting(db)
+	bc, _ := NewBlockChain(db, conConf, new(FakePow), new(event.TypeMux))
+
+	blocks := conBc.GetBlocksFromHash(conBc.CurrentBlock().Hash(), int(conBc.CurrentBlock().NumberU64()+1))
+	for j := 0; j < len(blocks)/2; j++ {
+		blocks[j], blocks[len(blocks)-1-j] = blocks[len(blocks)-1-j], blocks[j]
+	}
+	if _, err := bc.InsertChain(blocks); err != nil {
+		t.Fatalf("failed to import contra-fork chain for expansion: %v", err)
+	}
+	blocks, _ = GenerateChain(proConf, conBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) {})
+	if _, err := conBc.InsertChain(blocks); err != nil {
+		t.Fatalf("contra-fork chain didn't accept pro-fork block post-fork: %v", err)
+	}
+	// Verify that pro-forkers accept contra-fork extra-datas after forking finishes
+	db, _ = ethdb.NewMemDatabase()
+	WriteGenesisBlockForTesting(db)
+	bc, _ = NewBlockChain(db, proConf, new(FakePow), new(event.TypeMux))
+
+	blocks = proBc.GetBlocksFromHash(proBc.CurrentBlock().Hash(), int(proBc.CurrentBlock().NumberU64()+1))
+	for j := 0; j < len(blocks)/2; j++ {
+		blocks[j], blocks[len(blocks)-1-j] = blocks[len(blocks)-1-j], blocks[j]
+	}
+	if _, err := bc.InsertChain(blocks); err != nil {
+		t.Fatalf("failed to import pro-fork chain for expansion: %v", err)
+	}
+	blocks, _ = GenerateChain(conConf, proBc.CurrentBlock(), db, 1, func(i int, gen *BlockGen) {})
+	if _, err := proBc.InsertChain(blocks); err != nil {
+		t.Fatalf("pro-fork chain didn't accept contra-fork block post-fork: %v", err)
+	}
+}
diff --git a/core/database_util_test.go b/core/database_util_test.go
index 6c19f78c8..280270ac8 100644
--- a/core/database_util_test.go
+++ b/core/database_util_test.go
@@ -561,7 +561,7 @@ func TestMipmapChain(t *testing.T) {
 	defer db.Close()
 
 	genesis := WriteGenesisBlockForTesting(db, GenesisAccount{addr, big.NewInt(1000000)})
-	chain, receipts := GenerateChain(genesis, db, 1010, func(i int, gen *BlockGen) {
+	chain, receipts := GenerateChain(nil, genesis, db, 1010, func(i int, gen *BlockGen) {
 		var receipts types.Receipts
 		switch i {
 		case 1:
diff --git a/core/state_processor.go b/core/state_processor.go
index a9c2d1e18..6a418a62d 100644
--- a/core/state_processor.go
+++ b/core/state_processor.go
@@ -66,7 +66,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
 		allLogs      vm.Logs
 		gp           = new(GasPool).AddGas(block.GasLimit())
 	)
-	// Mutate the statedb according to any hard-fork specs
+	// Mutate the the block and state according to any hard-fork specs
 	if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
 		ApplyDAOHardFork(statedb)
 	}
-- 
cgit v1.2.3