mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
Merge 3067d7a651 into aa1e052cb4
This commit is contained in:
commit
e174a83c60
22 changed files with 2691 additions and 100 deletions
|
|
@ -74,9 +74,9 @@ func runTestWithReader(test string, r io.Reader) error {
|
||||||
var err error
|
var err error
|
||||||
switch strings.ToLower(test) {
|
switch strings.ToLower(test) {
|
||||||
case "bk", "block", "blocktest", "blockchaintest", "blocktests", "blockchaintests":
|
case "bk", "block", "blocktest", "blockchaintest", "blocktests", "blockchaintests":
|
||||||
err = tests.RunBlockTestWithReader(params.MainNetHomesteadBlock, r, skipTests)
|
err = tests.RunBlockTestWithReader(params.MainNetHomesteadBlock, params.MainNetDAOForkBlock, r, skipTests)
|
||||||
case "st", "state", "statetest", "statetests":
|
case "st", "state", "statetest", "statetests":
|
||||||
rs := tests.RuleSet{HomesteadBlock: params.MainNetHomesteadBlock}
|
rs := tests.RuleSet{HomesteadBlock: params.MainNetHomesteadBlock, DAOForkBlock: params.MainNetDAOForkBlock, DAOForkSupport: true}
|
||||||
err = tests.RunStateTestWithReader(rs, r, skipTests)
|
err = tests.RunStateTestWithReader(rs, r, skipTests)
|
||||||
case "tx", "transactiontest", "transactiontests":
|
case "tx", "transactiontest", "transactiontests":
|
||||||
err = tests.RunTransactionTestsWithReader(r, skipTests)
|
err = tests.RunTransactionTestsWithReader(r, skipTests)
|
||||||
|
|
|
||||||
232
cmd/geth/dao_test.go
Normal file
232
cmd/geth/dao_test.go
Normal file
|
|
@ -0,0 +1,232 @@
|
||||||
|
// Copyright 2016 The go-ethereum Authors
|
||||||
|
// This file is part of go-ethereum.
|
||||||
|
//
|
||||||
|
// go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// go-ethereum 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 General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"math/big"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Genesis block for nodes which don't care about the DAO fork (i.e. not configured)
|
||||||
|
var daoOldGenesis = `{
|
||||||
|
"alloc" : {},
|
||||||
|
"coinbase" : "0x0000000000000000000000000000000000000000",
|
||||||
|
"difficulty" : "0x20000",
|
||||||
|
"extraData" : "",
|
||||||
|
"gasLimit" : "0x2fefd8",
|
||||||
|
"nonce" : "0x0000000000000042",
|
||||||
|
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"timestamp" : "0x00",
|
||||||
|
"config" : {}
|
||||||
|
}`
|
||||||
|
|
||||||
|
// Genesis block for nodes which actively oppose the DAO fork
|
||||||
|
var daoNoForkGenesis = `{
|
||||||
|
"alloc" : {},
|
||||||
|
"coinbase" : "0x0000000000000000000000000000000000000000",
|
||||||
|
"difficulty" : "0x20000",
|
||||||
|
"extraData" : "",
|
||||||
|
"gasLimit" : "0x2fefd8",
|
||||||
|
"nonce" : "0x0000000000000042",
|
||||||
|
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"timestamp" : "0x00",
|
||||||
|
"config" : {
|
||||||
|
"daoForkBlock" : 314,
|
||||||
|
"daoForkSupport" : false
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
// Genesis block for nodes which actively support the DAO fork
|
||||||
|
var daoProForkGenesis = `{
|
||||||
|
"alloc" : {},
|
||||||
|
"coinbase" : "0x0000000000000000000000000000000000000000",
|
||||||
|
"difficulty" : "0x20000",
|
||||||
|
"extraData" : "",
|
||||||
|
"gasLimit" : "0x2fefd8",
|
||||||
|
"nonce" : "0x0000000000000042",
|
||||||
|
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"timestamp" : "0x00",
|
||||||
|
"config" : {
|
||||||
|
"daoForkBlock" : 314,
|
||||||
|
"daoForkSupport" : true
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
var daoGenesisHash = common.HexToHash("5e1fc79cb4ffa4739177b5408045cd5d51c6cf766133f23f7cd72ee1f8d790e0")
|
||||||
|
var daoGenesisForkBlock = big.NewInt(314)
|
||||||
|
|
||||||
|
// Tests that the DAO hard-fork number and the nodes support/opposition is correctly
|
||||||
|
// set in the database after various initialization procedures and invocations.
|
||||||
|
func TestDAODefaultMainnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, "", [][2]bool{{false, false}}, params.MainNetDAOForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOSupportMainnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, "", [][2]bool{{true, false}}, params.MainNetDAOForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAOOpposeMainnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, "", [][2]bool{{false, true}}, params.MainNetDAOForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOSwitchToSupportMainnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, "", [][2]bool{{false, true}, {true, false}}, params.MainNetDAOForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAOSwitchToOpposeMainnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, "", [][2]bool{{true, false}, {false, true}}, params.MainNetDAOForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAODefaultTestnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, true, "", [][2]bool{{false, false}}, params.TestNetDAOForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOSupportTestnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, true, "", [][2]bool{{true, false}}, params.TestNetDAOForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAOOpposeTestnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, true, "", [][2]bool{{false, true}}, params.TestNetDAOForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOSwitchToSupportTestnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, true, "", [][2]bool{{false, true}, {true, false}}, params.TestNetDAOForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAOSwitchToOpposeTestnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, true, "", [][2]bool{{true, false}, {false, true}}, params.TestNetDAOForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOInitOldPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{}, nil, false)
|
||||||
|
}
|
||||||
|
func TestDAODefaultOldPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{false, false}}, params.MainNetDAOForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOSupportOldPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{true, false}}, params.MainNetDAOForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAOOpposeOldPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{false, true}}, params.MainNetDAOForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOSwitchToSupportOldPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{false, true}, {true, false}}, params.MainNetDAOForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAOSwitchToOpposeOldPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{true, false}, {false, true}}, params.MainNetDAOForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOInitNoForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoNoForkGenesis, [][2]bool{}, daoGenesisForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAODefaultNoForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoNoForkGenesis, [][2]bool{{false, false}}, daoGenesisForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOSupportNoForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoNoForkGenesis, [][2]bool{{true, false}}, daoGenesisForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAOOpposeNoForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoNoForkGenesis, [][2]bool{{false, true}}, daoGenesisForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOSwitchToSupportNoForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoNoForkGenesis, [][2]bool{{false, true}, {true, false}}, daoGenesisForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAOSwitchToOpposeNoForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoNoForkGenesis, [][2]bool{{true, false}, {false, true}}, daoGenesisForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOInitProForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoProForkGenesis, [][2]bool{}, daoGenesisForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAODefaultProForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoProForkGenesis, [][2]bool{{false, false}}, daoGenesisForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAOSupportProForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoProForkGenesis, [][2]bool{{true, false}}, daoGenesisForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAOOpposeProForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoProForkGenesis, [][2]bool{{false, true}}, daoGenesisForkBlock, false)
|
||||||
|
}
|
||||||
|
func TestDAOSwitchToSupportProForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoProForkGenesis, [][2]bool{{false, true}, {true, false}}, daoGenesisForkBlock, true)
|
||||||
|
}
|
||||||
|
func TestDAOSwitchToOpposeProForkPrivnet(t *testing.T) {
|
||||||
|
testDAOForkBlockNewChain(t, false, daoProForkGenesis, [][2]bool{{true, false}, {false, true}}, daoGenesisForkBlock, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testDAOForkBlockNewChain(t *testing.T, testnet bool, genesis string, votes [][2]bool, expectBlock *big.Int, expectVote bool) {
|
||||||
|
// Create a temporary data directory to use and inspect later
|
||||||
|
datadir := tmpdir(t)
|
||||||
|
defer os.RemoveAll(datadir)
|
||||||
|
|
||||||
|
// Start a Geth instance with the requested flags set and immediately terminate
|
||||||
|
if genesis != "" {
|
||||||
|
json := filepath.Join(datadir, "genesis.json")
|
||||||
|
if err := ioutil.WriteFile(json, []byte(genesis), 0600); err != nil {
|
||||||
|
t.Fatalf("failed to write genesis file: %v", err)
|
||||||
|
}
|
||||||
|
runGeth(t, "--datadir", datadir, "init", json).cmd.Wait()
|
||||||
|
}
|
||||||
|
for _, vote := range votes {
|
||||||
|
args := []string{"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--ipcdisable", "--datadir", datadir}
|
||||||
|
if testnet {
|
||||||
|
args = append(args, "--testnet")
|
||||||
|
}
|
||||||
|
if vote[0] {
|
||||||
|
args = append(args, "--support-dao-fork")
|
||||||
|
}
|
||||||
|
if vote[1] {
|
||||||
|
args = append(args, "--oppose-dao-fork")
|
||||||
|
}
|
||||||
|
geth := runGeth(t, append(args, []string{"--exec", "2+2", "console"}...)...)
|
||||||
|
geth.cmd.Wait()
|
||||||
|
}
|
||||||
|
// Retrieve the DAO config flag from the database
|
||||||
|
path := filepath.Join(datadir, "chaindata")
|
||||||
|
if testnet && genesis == "" {
|
||||||
|
path = filepath.Join(datadir, "testnet", "chaindata")
|
||||||
|
}
|
||||||
|
db, err := ethdb.NewLDBDatabase(path, 0, 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to open test database: %v", err)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
genesisHash := common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
|
||||||
|
if testnet {
|
||||||
|
genesisHash = common.HexToHash("0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303")
|
||||||
|
}
|
||||||
|
if genesis != "" {
|
||||||
|
genesisHash = daoGenesisHash
|
||||||
|
}
|
||||||
|
config, err := core.GetChainConfig(db, genesisHash)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to retrieve chain config: %v", err)
|
||||||
|
}
|
||||||
|
// Validate the DAO hard-fork block number against the expected value
|
||||||
|
if config.DAOForkBlock == nil {
|
||||||
|
if expectBlock != nil {
|
||||||
|
t.Errorf("dao hard-fork block mismatch: have nil, want %v", expectBlock)
|
||||||
|
}
|
||||||
|
} else if expectBlock == nil {
|
||||||
|
t.Errorf("dao hard-fork block mismatch: have %v, want nil", config.DAOForkBlock)
|
||||||
|
} else if config.DAOForkBlock.Cmp(expectBlock) != 0 {
|
||||||
|
t.Errorf("dao hard-fork block mismatch: have %v, want %v", config.DAOForkBlock, expectBlock)
|
||||||
|
}
|
||||||
|
if config.DAOForkSupport != expectVote {
|
||||||
|
t.Errorf("dao hard-fork support mismatch: have %v, want %v", config.DAOForkSupport, expectVote)
|
||||||
|
}
|
||||||
|
}
|
||||||
107
cmd/geth/genesis_test.go
Normal file
107
cmd/geth/genesis_test.go
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
// Copyright 2016 The go-ethereum Authors
|
||||||
|
// This file is part of go-ethereum.
|
||||||
|
//
|
||||||
|
// go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// go-ethereum 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 General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var customGenesisTests = []struct {
|
||||||
|
genesis string
|
||||||
|
query string
|
||||||
|
result string
|
||||||
|
}{
|
||||||
|
// Plain genesis file without anything extra
|
||||||
|
{
|
||||||
|
genesis: `{
|
||||||
|
"alloc" : {},
|
||||||
|
"coinbase" : "0x0000000000000000000000000000000000000000",
|
||||||
|
"difficulty" : "0x20000",
|
||||||
|
"extraData" : "",
|
||||||
|
"gasLimit" : "0x2fefd8",
|
||||||
|
"nonce" : "0x0000000000000042",
|
||||||
|
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"timestamp" : "0x00"
|
||||||
|
}`,
|
||||||
|
query: "eth.getBlock(0).nonce",
|
||||||
|
result: "0x0000000000000042",
|
||||||
|
},
|
||||||
|
// Genesis file with an empty chain configuration (ensure missing fields work)
|
||||||
|
{
|
||||||
|
genesis: `{
|
||||||
|
"alloc" : {},
|
||||||
|
"coinbase" : "0x0000000000000000000000000000000000000000",
|
||||||
|
"difficulty" : "0x20000",
|
||||||
|
"extraData" : "",
|
||||||
|
"gasLimit" : "0x2fefd8",
|
||||||
|
"nonce" : "0x0000000000000042",
|
||||||
|
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"timestamp" : "0x00",
|
||||||
|
"config" : {}
|
||||||
|
}`,
|
||||||
|
query: "eth.getBlock(0).nonce",
|
||||||
|
result: "0x0000000000000042",
|
||||||
|
},
|
||||||
|
// Genesis file with specific chain configurations
|
||||||
|
{
|
||||||
|
genesis: `{
|
||||||
|
"alloc" : {},
|
||||||
|
"coinbase" : "0x0000000000000000000000000000000000000000",
|
||||||
|
"difficulty" : "0x20000",
|
||||||
|
"extraData" : "",
|
||||||
|
"gasLimit" : "0x2fefd8",
|
||||||
|
"nonce" : "0x0000000000000042",
|
||||||
|
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"timestamp" : "0x00",
|
||||||
|
"config" : {
|
||||||
|
"homesteadBlock" : 314,
|
||||||
|
"daoForkBlock" : 141,
|
||||||
|
"daoForkSupport" : true
|
||||||
|
},
|
||||||
|
}`,
|
||||||
|
query: "eth.getBlock(0).nonce",
|
||||||
|
result: "0x0000000000000042",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests that initializing Geth with a custom genesis block and chain definitions
|
||||||
|
// work properly.
|
||||||
|
func TestCustomGenesis(t *testing.T) {
|
||||||
|
for i, tt := range customGenesisTests {
|
||||||
|
// Create a temporary data directory to use and inspect later
|
||||||
|
datadir := tmpdir(t)
|
||||||
|
defer os.RemoveAll(datadir)
|
||||||
|
|
||||||
|
// Initialize the data directory with the custom genesis block
|
||||||
|
json := filepath.Join(datadir, "genesis.json")
|
||||||
|
if err := ioutil.WriteFile(json, []byte(tt.genesis), 0600); err != nil {
|
||||||
|
t.Fatalf("test %d: failed to write genesis file: %v", i, err)
|
||||||
|
}
|
||||||
|
runGeth(t, "--datadir", datadir, "init", json).cmd.Wait()
|
||||||
|
|
||||||
|
// Query the custom genesis block
|
||||||
|
geth := runGeth(t, "--datadir", datadir, "--maxpeers", "0", "--nodiscover", "--nat", "none", "--ipcdisable", "--exec", tt.query, "console")
|
||||||
|
geth.expectRegexp(tt.result)
|
||||||
|
geth.expectExit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -150,7 +150,6 @@ participating.
|
||||||
utils.IdentityFlag,
|
utils.IdentityFlag,
|
||||||
utils.UnlockedAccountFlag,
|
utils.UnlockedAccountFlag,
|
||||||
utils.PasswordFileFlag,
|
utils.PasswordFileFlag,
|
||||||
utils.GenesisFileFlag,
|
|
||||||
utils.BootnodesFlag,
|
utils.BootnodesFlag,
|
||||||
utils.DataDirFlag,
|
utils.DataDirFlag,
|
||||||
utils.KeyStoreDirFlag,
|
utils.KeyStoreDirFlag,
|
||||||
|
|
@ -165,6 +164,8 @@ participating.
|
||||||
utils.MaxPendingPeersFlag,
|
utils.MaxPendingPeersFlag,
|
||||||
utils.EtherbaseFlag,
|
utils.EtherbaseFlag,
|
||||||
utils.GasPriceFlag,
|
utils.GasPriceFlag,
|
||||||
|
utils.SupportDAOFork,
|
||||||
|
utils.OpposeDAOFork,
|
||||||
utils.MinerThreadsFlag,
|
utils.MinerThreadsFlag,
|
||||||
utils.MiningEnabledFlag,
|
utils.MiningEnabledFlag,
|
||||||
utils.MiningGPUFlag,
|
utils.MiningGPUFlag,
|
||||||
|
|
@ -225,12 +226,6 @@ participating.
|
||||||
eth.EnableBadBlockReporting = true
|
eth.EnableBadBlockReporting = true
|
||||||
|
|
||||||
utils.SetupNetwork(ctx)
|
utils.SetupNetwork(ctx)
|
||||||
|
|
||||||
// Deprecation warning.
|
|
||||||
if ctx.GlobalIsSet(utils.GenesisFileFlag.Name) {
|
|
||||||
common.PrintDepricationWarning("--genesis is deprecated. Switch to use 'geth init /path/to/file'")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,6 @@ var AppHelpFlagGroups = []flagGroup{
|
||||||
utils.OlympicFlag,
|
utils.OlympicFlag,
|
||||||
utils.TestNetFlag,
|
utils.TestNetFlag,
|
||||||
utils.DevModeFlag,
|
utils.DevModeFlag,
|
||||||
utils.GenesisFileFlag,
|
|
||||||
utils.IdentityFlag,
|
utils.IdentityFlag,
|
||||||
utils.FastSyncFlag,
|
utils.FastSyncFlag,
|
||||||
utils.LightKDFFlag,
|
utils.LightKDFFlag,
|
||||||
|
|
|
||||||
|
|
@ -126,10 +126,6 @@ var (
|
||||||
Name: "dev",
|
Name: "dev",
|
||||||
Usage: "Developer mode: pre-configured private network with several debugging flags",
|
Usage: "Developer mode: pre-configured private network with several debugging flags",
|
||||||
}
|
}
|
||||||
GenesisFileFlag = cli.StringFlag{
|
|
||||||
Name: "genesis",
|
|
||||||
Usage: "Insert/overwrite the genesis block (JSON format)",
|
|
||||||
}
|
|
||||||
IdentityFlag = cli.StringFlag{
|
IdentityFlag = cli.StringFlag{
|
||||||
Name: "identity",
|
Name: "identity",
|
||||||
Usage: "Custom node name",
|
Usage: "Custom node name",
|
||||||
|
|
@ -161,6 +157,15 @@ var (
|
||||||
Name: "lightkdf",
|
Name: "lightkdf",
|
||||||
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
|
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
|
||||||
}
|
}
|
||||||
|
// Fork settings
|
||||||
|
SupportDAOFork = cli.BoolFlag{
|
||||||
|
Name: "support-dao-fork",
|
||||||
|
Usage: "Updates the chain rules to support the DAO hard-fork",
|
||||||
|
}
|
||||||
|
OpposeDAOFork = cli.BoolFlag{
|
||||||
|
Name: "oppose-dao-fork",
|
||||||
|
Usage: "Updates the chain rules to oppose the DAO hard-fork",
|
||||||
|
}
|
||||||
// Miner settings
|
// Miner settings
|
||||||
// TODO: refactor CPU vs GPU mining flags
|
// TODO: refactor CPU vs GPU mining flags
|
||||||
MiningEnabledFlag = cli.BoolFlag{
|
MiningEnabledFlag = cli.BoolFlag{
|
||||||
|
|
@ -534,20 +539,6 @@ func MakeWSRpcHost(ctx *cli.Context) string {
|
||||||
return ctx.GlobalString(WSListenAddrFlag.Name)
|
return ctx.GlobalString(WSListenAddrFlag.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeGenesisBlock loads up a genesis block from an input file specified in the
|
|
||||||
// command line, or returns the empty string if none set.
|
|
||||||
func MakeGenesisBlock(ctx *cli.Context) string {
|
|
||||||
genesis := ctx.GlobalString(GenesisFileFlag.Name)
|
|
||||||
if genesis == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
data, err := ioutil.ReadFile(genesis)
|
|
||||||
if err != nil {
|
|
||||||
Fatalf("Failed to load custom genesis file: %v", err)
|
|
||||||
}
|
|
||||||
return string(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MakeDatabaseHandles raises out the number of allowed file handles per process
|
// MakeDatabaseHandles raises out the number of allowed file handles per process
|
||||||
// for Geth and returns half of the allowance to assign to the database.
|
// for Geth and returns half of the allowance to assign to the database.
|
||||||
func MakeDatabaseHandles() int {
|
func MakeDatabaseHandles() int {
|
||||||
|
|
@ -689,7 +680,6 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
|
||||||
|
|
||||||
ethConf := ð.Config{
|
ethConf := ð.Config{
|
||||||
ChainConfig: MustMakeChainConfig(ctx),
|
ChainConfig: MustMakeChainConfig(ctx),
|
||||||
Genesis: MakeGenesisBlock(ctx),
|
|
||||||
FastSync: ctx.GlobalBool(FastSyncFlag.Name),
|
FastSync: ctx.GlobalBool(FastSyncFlag.Name),
|
||||||
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
|
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
|
||||||
DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
|
DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
|
||||||
|
|
@ -722,17 +712,13 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
|
||||||
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
||||||
ethConf.NetworkId = 1
|
ethConf.NetworkId = 1
|
||||||
}
|
}
|
||||||
if !ctx.GlobalIsSet(GenesisFileFlag.Name) {
|
ethConf.Genesis = core.OlympicGenesisBlock()
|
||||||
ethConf.Genesis = core.OlympicGenesisBlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
case ctx.GlobalBool(TestNetFlag.Name):
|
case ctx.GlobalBool(TestNetFlag.Name):
|
||||||
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
||||||
ethConf.NetworkId = 2
|
ethConf.NetworkId = 2
|
||||||
}
|
}
|
||||||
if !ctx.GlobalIsSet(GenesisFileFlag.Name) {
|
ethConf.Genesis = core.TestNetGenesisBlock()
|
||||||
ethConf.Genesis = core.TestNetGenesisBlock()
|
|
||||||
}
|
|
||||||
state.StartingNonce = 1048576 // (2**20)
|
state.StartingNonce = 1048576 // (2**20)
|
||||||
|
|
||||||
case ctx.GlobalBool(DevModeFlag.Name):
|
case ctx.GlobalBool(DevModeFlag.Name):
|
||||||
|
|
@ -747,9 +733,7 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
|
||||||
stackConf.ListenAddr = ":0"
|
stackConf.ListenAddr = ":0"
|
||||||
}
|
}
|
||||||
// Override the Ethereum protocol configs
|
// Override the Ethereum protocol configs
|
||||||
if !ctx.GlobalIsSet(GenesisFileFlag.Name) {
|
ethConf.Genesis = core.OlympicGenesisBlock()
|
||||||
ethConf.Genesis = core.OlympicGenesisBlock()
|
|
||||||
}
|
|
||||||
if !ctx.GlobalIsSet(GasPriceFlag.Name) {
|
if !ctx.GlobalIsSet(GasPriceFlag.Name) {
|
||||||
ethConf.GasPrice = new(big.Int)
|
ethConf.GasPrice = new(big.Int)
|
||||||
}
|
}
|
||||||
|
|
@ -813,24 +797,43 @@ func MustMakeChainConfig(ctx *cli.Context) *core.ChainConfig {
|
||||||
|
|
||||||
// MustMakeChainConfigFromDb reads the chain configuration from the given database.
|
// MustMakeChainConfigFromDb reads the chain configuration from the given database.
|
||||||
func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfig {
|
func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfig {
|
||||||
genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0), 0)
|
// If the chain is already initialized, use any existing chain configs
|
||||||
|
config := new(core.ChainConfig)
|
||||||
|
|
||||||
if genesis != nil {
|
if genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0), 0); genesis != nil {
|
||||||
// Existing genesis block, use stored config if available.
|
|
||||||
storedConfig, err := core.GetChainConfig(db, genesis.Hash())
|
storedConfig, err := core.GetChainConfig(db, genesis.Hash())
|
||||||
if err == nil {
|
switch err {
|
||||||
return storedConfig
|
case nil:
|
||||||
} else if err != core.ChainConfigNotFoundErr {
|
config = storedConfig
|
||||||
|
case core.ChainConfigNotFoundErr:
|
||||||
|
// No configs found, use empty, will populate below
|
||||||
|
default:
|
||||||
Fatalf("Could not make chain configuration: %v", err)
|
Fatalf("Could not make chain configuration: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var homesteadBlockNo *big.Int
|
// Set any missing fields due to them being unset or system upgrade
|
||||||
if ctx.GlobalBool(TestNetFlag.Name) {
|
if config.HomesteadBlock == nil {
|
||||||
homesteadBlockNo = params.TestNetHomesteadBlock
|
if ctx.GlobalBool(TestNetFlag.Name) {
|
||||||
} else {
|
config.HomesteadBlock = new(big.Int).Set(params.TestNetHomesteadBlock)
|
||||||
homesteadBlockNo = params.MainNetHomesteadBlock
|
} else {
|
||||||
|
config.HomesteadBlock = new(big.Int).Set(params.MainNetHomesteadBlock)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return &core.ChainConfig{HomesteadBlock: homesteadBlockNo}
|
if config.DAOForkBlock == nil {
|
||||||
|
if ctx.GlobalBool(TestNetFlag.Name) {
|
||||||
|
config.DAOForkBlock = new(big.Int).Set(params.TestNetDAOForkBlock)
|
||||||
|
} else {
|
||||||
|
config.DAOForkBlock = new(big.Int).Set(params.MainNetDAOForkBlock)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Force override any existing configs if explicitly requested
|
||||||
|
switch {
|
||||||
|
case ctx.GlobalBool(SupportDAOFork.Name):
|
||||||
|
config.DAOForkSupport = true
|
||||||
|
case ctx.GlobalBool(OpposeDAOFork.Name):
|
||||||
|
config.DAOForkSupport = false
|
||||||
|
}
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
|
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -247,6 +248,33 @@ func ValidateHeader(config *ChainConfig, pow pow.PoW, header *types.Header, pare
|
||||||
return &BlockNonceErr{header.Number, header.Hash(), header.Nonce.Uint64()}
|
return &BlockNonceErr{header.Number, header.Hash(), header.Nonce.Uint64()}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If all checks passed, validate the extra-data field for hard forks
|
||||||
|
return ValidateHeaderExtraData(config, header)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidateHeaderExtraData validates the extra-data field of a block header to
|
||||||
|
// ensure it conforms to hard-fork rules.
|
||||||
|
func ValidateHeaderExtraData(config *ChainConfig, header *types.Header) error {
|
||||||
|
// DAO hard-fork extension to the header validity: a) if the node is no-fork,
|
||||||
|
// do not accept blocks in the [fork, fork+10) range with the fork specific
|
||||||
|
// extra-data set; b) if the node is pro-fork, require blocks in the specific
|
||||||
|
// range to have the unique extra-data set.
|
||||||
|
if daoBlock := config.DAOForkBlock; daoBlock != nil {
|
||||||
|
// Check whether the block is among the fork extra-override range
|
||||||
|
limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange)
|
||||||
|
if daoBlock.Cmp(header.Number) <= 0 && header.Number.Cmp(limit) < 0 {
|
||||||
|
// Depending whether we support or oppose the fork, verrift the extra-data contents
|
||||||
|
if config.DAOForkSupport {
|
||||||
|
if bytes.Compare(header.Extra, params.DAOForkBlockExtra) != 0 {
|
||||||
|
return ValidationError("DAO pro-fork bad block extra-data: 0x%x", header.Extra)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if bytes.Compare(header.Extra, params.DAOForkBlockExtra) == 0 {
|
||||||
|
return ValidationError("DAO no-fork bad block extra-data: 0x%x", header.Extra)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/pow/ezp"
|
"github.com/ethereum/go-ethereum/pow/ezp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -92,3 +93,107 @@ func TestPutReceipt(t *testing.T) {
|
||||||
t.Error("expected to get 1 receipt, got none.")
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,16 +31,17 @@ var ChainConfigNotFoundErr = errors.New("ChainConfig not found") // general conf
|
||||||
// that any network, identified by its genesis block, can have its own
|
// that any network, identified by its genesis block, can have its own
|
||||||
// set of configuration options.
|
// set of configuration options.
|
||||||
type ChainConfig struct {
|
type ChainConfig struct {
|
||||||
HomesteadBlock *big.Int // homestead switch block
|
HomesteadBlock *big.Int `json:"homesteadBlock"` // Homestead switch block (nil = no fork, 0 = already homestead)
|
||||||
|
DAOForkBlock *big.Int `json:"daoForkBlock"` // TheDAO hard-fork switch block (nil = no fork)
|
||||||
|
DAOForkSupport bool `json:"daoForkSupport"` // Whether the nodes supports or opposes the DAO hard-fork
|
||||||
|
|
||||||
VmConfig vm.Config `json:"-"`
|
VmConfig vm.Config `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsHomestead returns whether num is either equal to the homestead block or greater.
|
// IsHomestead returns whether num is either equal to the homestead block or greater.
|
||||||
func (c *ChainConfig) IsHomestead(num *big.Int) bool {
|
func (c *ChainConfig) IsHomestead(num *big.Int) bool {
|
||||||
if num == nil {
|
if c.HomesteadBlock == nil || num == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return num.Cmp(c.HomesteadBlock) >= 0
|
return num.Cmp(c.HomesteadBlock) >= 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -65,7 +66,11 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
||||||
allLogs vm.Logs
|
allLogs vm.Logs
|
||||||
gp = new(GasPool).AddGas(block.GasLimit())
|
gp = new(GasPool).AddGas(block.GasLimit())
|
||||||
)
|
)
|
||||||
|
// Mutate the statedb according to any hard-fork specs
|
||||||
|
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
|
||||||
|
ApplyDAOHardFork(statedb)
|
||||||
|
}
|
||||||
|
// Iterate over and process the individual transactions
|
||||||
for i, tx := range block.Transactions() {
|
for i, tx := range block.Transactions() {
|
||||||
statedb.StartRecord(tx.Hash(), block.Hash(), i)
|
statedb.StartRecord(tx.Hash(), block.Hash(), i)
|
||||||
receipt, logs, _, err := ApplyTransaction(p.config, p.bc, gp, statedb, header, tx, totalUsedGas, cfg)
|
receipt, logs, _, err := ApplyTransaction(p.config, p.bc, gp, statedb, header, tx, totalUsedGas, cfg)
|
||||||
|
|
@ -129,3 +134,19 @@ func AccumulateRewards(statedb *state.StateDB, header *types.Header, uncles []*t
|
||||||
}
|
}
|
||||||
statedb.AddBalance(header.Coinbase, reward)
|
statedb.AddBalance(header.Coinbase, reward)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApplyDAOHardFork modifies the state database according to the DAO hard-fork
|
||||||
|
// rules, transferring all balances of a set of DAO accounts to a single refund
|
||||||
|
// contract.
|
||||||
|
func ApplyDAOHardFork(statedb *state.StateDB) {
|
||||||
|
// Retrieve the contract to refund balances into
|
||||||
|
refund := statedb.GetOrNewStateObject(params.DAORefundContract)
|
||||||
|
|
||||||
|
// Move every DAO account and extra-balance account funds into the refund contract
|
||||||
|
for _, addr := range params.DAODrainList {
|
||||||
|
if account := statedb.GetStateObject(addr); account != nil {
|
||||||
|
refund.AddBalance(account.Balance())
|
||||||
|
account.SetBalance(new(big.Int))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
if config.ChainConfig == nil {
|
if config.ChainConfig == nil {
|
||||||
return nil, errors.New("missing chain config")
|
return nil, errors.New("missing chain config")
|
||||||
}
|
}
|
||||||
|
core.WriteChainConfig(chainDb, genesis.Hash(), config.ChainConfig)
|
||||||
|
|
||||||
eth.chainConfig = config.ChainConfig
|
eth.chainConfig = config.ChainConfig
|
||||||
eth.chainConfig.VmConfig = vm.Config{
|
eth.chainConfig.VmConfig = vm.Config{
|
||||||
EnableJit: config.EnableJit,
|
EnableJit: config.EnableJit,
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,10 @@ const (
|
||||||
estHeaderRlpSize = 500 // Approximate size of an RLP encoded block header
|
estHeaderRlpSize = 500 // Approximate size of an RLP encoded block header
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
daoChallengeTimeout = 15 * time.Second // Time allowance for a node to reply to the DAO handshake challenge
|
||||||
|
)
|
||||||
|
|
||||||
// errIncompatibleConfig is returned if the requested protocols and configs are
|
// errIncompatibleConfig is returned if the requested protocols and configs are
|
||||||
// not compatible (low protocol version restrictions and high requirements).
|
// not compatible (low protocol version restrictions and high requirements).
|
||||||
var errIncompatibleConfig = errors.New("incompatible configuration")
|
var errIncompatibleConfig = errors.New("incompatible configuration")
|
||||||
|
|
@ -62,9 +66,10 @@ type ProtocolManager struct {
|
||||||
fastSync uint32 // Flag whether fast sync is enabled (gets disabled if we already have blocks)
|
fastSync uint32 // Flag whether fast sync is enabled (gets disabled if we already have blocks)
|
||||||
synced uint32 // Flag whether we're considered synchronised (enables transaction processing)
|
synced uint32 // Flag whether we're considered synchronised (enables transaction processing)
|
||||||
|
|
||||||
txpool txPool
|
txpool txPool
|
||||||
blockchain *core.BlockChain
|
blockchain *core.BlockChain
|
||||||
chaindb ethdb.Database
|
chaindb ethdb.Database
|
||||||
|
chainconfig *core.ChainConfig
|
||||||
|
|
||||||
downloader *downloader.Downloader
|
downloader *downloader.Downloader
|
||||||
fetcher *fetcher.Fetcher
|
fetcher *fetcher.Fetcher
|
||||||
|
|
@ -99,6 +104,7 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int,
|
||||||
txpool: txpool,
|
txpool: txpool,
|
||||||
blockchain: blockchain,
|
blockchain: blockchain,
|
||||||
chaindb: chaindb,
|
chaindb: chaindb,
|
||||||
|
chainconfig: config,
|
||||||
peers: newPeerSet(),
|
peers: newPeerSet(),
|
||||||
newPeerCh: make(chan *peer),
|
newPeerCh: make(chan *peer),
|
||||||
noMorePeers: make(chan struct{}),
|
noMorePeers: make(chan struct{}),
|
||||||
|
|
@ -278,6 +284,18 @@ func (pm *ProtocolManager) handle(p *peer) error {
|
||||||
// after this will be sent via broadcasts.
|
// after this will be sent via broadcasts.
|
||||||
pm.syncTransactions(p)
|
pm.syncTransactions(p)
|
||||||
|
|
||||||
|
// If we're DAO hard-fork aware, validate any remote peer with regard to the hard-fork
|
||||||
|
if daoBlock := pm.chainconfig.DAOForkBlock; daoBlock != nil {
|
||||||
|
// Request the peer's DAO fork header for extra-data validation
|
||||||
|
if err := p.RequestHeadersByNumber(daoBlock.Uint64(), 1, 0, false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Start a timer to disconnect if the peer doesn't reply in time
|
||||||
|
p.forkDrop = time.AfterFunc(daoChallengeTimeout, func() {
|
||||||
|
glog.V(logger.Warn).Infof("%v: timed out DAO fork-check, dropping", p)
|
||||||
|
pm.removePeer(p.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
// main loop. handle incoming messages.
|
// main loop. handle incoming messages.
|
||||||
for {
|
for {
|
||||||
if err := pm.handleMsg(p); err != nil {
|
if err := pm.handleMsg(p); err != nil {
|
||||||
|
|
@ -481,9 +499,43 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
||||||
if err := msg.Decode(&headers); err != nil {
|
if err := msg.Decode(&headers); err != nil {
|
||||||
return errResp(ErrDecode, "msg %v: %v", msg, err)
|
return errResp(ErrDecode, "msg %v: %v", msg, err)
|
||||||
}
|
}
|
||||||
|
// If no headers were received, but we're expending a DAO fork check, maybe it's that
|
||||||
|
if len(headers) == 0 && p.forkDrop != nil {
|
||||||
|
// Possibly an empty reply to the fork header checks, sanity check TDs
|
||||||
|
verifyDAO := true
|
||||||
|
|
||||||
|
// If we already have a DAO header, we can check the peer's TD against it. If
|
||||||
|
// the peer's ahead of this, it too must have a reply to the DAO check
|
||||||
|
if daoHeader := pm.blockchain.GetHeaderByNumber(pm.chainconfig.DAOForkBlock.Uint64()); daoHeader != nil {
|
||||||
|
if p.Td().Cmp(pm.blockchain.GetTd(daoHeader.Hash(), daoHeader.Number.Uint64())) >= 0 {
|
||||||
|
verifyDAO = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If we're seemingly on the same chain, disable the drop timer
|
||||||
|
if verifyDAO {
|
||||||
|
glog.V(logger.Info).Infof("%v: seems to be on the same side of the DAO fork", p)
|
||||||
|
p.forkDrop.Stop()
|
||||||
|
p.forkDrop = nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
// Filter out any explicitly requested headers, deliver the rest to the downloader
|
// Filter out any explicitly requested headers, deliver the rest to the downloader
|
||||||
filter := len(headers) == 1
|
filter := len(headers) == 1
|
||||||
if filter {
|
if filter {
|
||||||
|
// If it's a potential DAO fork check, validate against the rules
|
||||||
|
if p.forkDrop != nil && pm.chainconfig.DAOForkBlock.Cmp(headers[0].Number) == 0 {
|
||||||
|
// Disable the fork drop timer
|
||||||
|
p.forkDrop.Stop()
|
||||||
|
p.forkDrop = nil
|
||||||
|
|
||||||
|
// Validate the header and either drop the peer or continue
|
||||||
|
if err := core.ValidateHeaderExtraData(pm.chainconfig, headers[0]); err != nil {
|
||||||
|
glog.V(logger.Info).Infof("%v: verified to be on the other side of the DAO fork, dropping", p)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
glog.V(logger.Info).Infof("%v: verified to be on the same side of the DAO fork", p)
|
||||||
|
}
|
||||||
|
// Irrelevant of the fork checks, send the header to the fetcher just in case
|
||||||
headers = pm.fetcher.FilterHeaders(headers, time.Now())
|
headers = pm.fetcher.FilterHeaders(headers, time.Now())
|
||||||
}
|
}
|
||||||
if len(headers) > 0 || !filter {
|
if len(headers) > 0 || !filter {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
|
@ -28,6 +29,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
@ -580,3 +582,74 @@ func testGetReceipt(t *testing.T, protocol int) {
|
||||||
t.Errorf("receipts mismatch: %v", err)
|
t.Errorf("receipts mismatch: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests that post eth protocol handshake, DAO fork-enabled clients also execute
|
||||||
|
// a DAO "challenge" verifying each others' DAO fork headers to ensure they're on
|
||||||
|
// compatible chains.
|
||||||
|
func TestDAOChallengeNoVsNo(t *testing.T) { testDAOChallenge(t, false, false, false) }
|
||||||
|
func TestDAOChallengeNoVsPro(t *testing.T) { testDAOChallenge(t, false, true, false) }
|
||||||
|
func TestDAOChallengeProVsNo(t *testing.T) { testDAOChallenge(t, true, false, false) }
|
||||||
|
func TestDAOChallengeProVsPro(t *testing.T) { testDAOChallenge(t, true, true, false) }
|
||||||
|
func TestDAOChallengeNoVsTimeout(t *testing.T) { testDAOChallenge(t, false, false, true) }
|
||||||
|
func TestDAOChallengeProVsTimeout(t *testing.T) { testDAOChallenge(t, true, true, true) }
|
||||||
|
|
||||||
|
func testDAOChallenge(t *testing.T, localForked, remoteForked bool, timeout bool) {
|
||||||
|
// Reduce the DAO handshake challenge timeout
|
||||||
|
if timeout {
|
||||||
|
defer func(old time.Duration) { daoChallengeTimeout = old }(daoChallengeTimeout)
|
||||||
|
daoChallengeTimeout = 500 * time.Millisecond
|
||||||
|
}
|
||||||
|
// Create a DAO aware protocol manager
|
||||||
|
var (
|
||||||
|
evmux = new(event.TypeMux)
|
||||||
|
pow = new(core.FakePow)
|
||||||
|
db, _ = ethdb.NewMemDatabase()
|
||||||
|
genesis = core.WriteGenesisBlockForTesting(db)
|
||||||
|
config = &core.ChainConfig{DAOForkBlock: big.NewInt(1), DAOForkSupport: localForked}
|
||||||
|
blockchain, _ = core.NewBlockChain(db, config, pow, evmux)
|
||||||
|
)
|
||||||
|
pm, err := NewProtocolManager(config, false, NetworkId, evmux, new(testTxPool), pow, blockchain, db)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to start test protocol manager: %v", err)
|
||||||
|
}
|
||||||
|
pm.Start()
|
||||||
|
defer pm.Stop()
|
||||||
|
|
||||||
|
// Connect a new peer and check that we receive the DAO challenge
|
||||||
|
peer, _ := newTestPeer("peer", eth63, pm, true)
|
||||||
|
defer peer.close()
|
||||||
|
|
||||||
|
challenge := &getBlockHeadersData{
|
||||||
|
Origin: hashOrNumber{Number: config.DAOForkBlock.Uint64()},
|
||||||
|
Amount: 1,
|
||||||
|
Skip: 0,
|
||||||
|
Reverse: false,
|
||||||
|
}
|
||||||
|
if err := p2p.ExpectMsg(peer.app, GetBlockHeadersMsg, challenge); err != nil {
|
||||||
|
t.Fatalf("challenge mismatch: %v", err)
|
||||||
|
}
|
||||||
|
// Create a block to reply to the challenge if no timeout is simualted
|
||||||
|
if !timeout {
|
||||||
|
blocks, _ := core.GenerateChain(genesis, db, 1, func(i int, block *core.BlockGen) {
|
||||||
|
if remoteForked {
|
||||||
|
block.SetExtra(params.DAOForkBlockExtra)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if err := p2p.Send(peer.app, BlockHeadersMsg, []*types.Header{blocks[0].Header()}); err != nil {
|
||||||
|
t.Fatalf("failed to answer challenge: %v", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Otherwise wait until the test timeout passes
|
||||||
|
time.Sleep(daoChallengeTimeout + 500*time.Millisecond)
|
||||||
|
}
|
||||||
|
// Verify that depending on fork side, the remote peer is maintained or dropped
|
||||||
|
if localForked == remoteForked && !timeout {
|
||||||
|
if peers := pm.peers.Len(); peers != 1 {
|
||||||
|
t.Fatalf("peer count mismatch: have %d, want %d", peers, 1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if peers := pm.peers.Len(); peers != 0 {
|
||||||
|
t.Fatalf("peer count mismatch: have %d, want %d", peers, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
10
eth/peer.go
10
eth/peer.go
|
|
@ -59,10 +59,12 @@ type peer struct {
|
||||||
*p2p.Peer
|
*p2p.Peer
|
||||||
rw p2p.MsgReadWriter
|
rw p2p.MsgReadWriter
|
||||||
|
|
||||||
version int // Protocol version negotiated
|
version int // Protocol version negotiated
|
||||||
head common.Hash
|
forkDrop *time.Timer // Timed connection dropper if forks aren't validated in time
|
||||||
td *big.Int
|
|
||||||
lock sync.RWMutex
|
head common.Hash
|
||||||
|
td *big.Int
|
||||||
|
lock sync.RWMutex
|
||||||
|
|
||||||
knownTxs *set.Set // Set of transaction hashes known to be known by this peer
|
knownTxs *set.Set // Set of transaction hashes known to be known by this peer
|
||||||
knownBlocks *set.Set // Set of block hashes known to be known by this peer
|
knownBlocks *set.Set // Set of block hashes known to be known by this peer
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package miner
|
package miner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -33,6 +34,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
"gopkg.in/fatih/set.v0"
|
"gopkg.in/fatih/set.v0"
|
||||||
)
|
)
|
||||||
|
|
@ -468,7 +470,19 @@ func (self *worker) commitNewWork() {
|
||||||
Extra: self.extra,
|
Extra: self.extra,
|
||||||
Time: big.NewInt(tstamp),
|
Time: big.NewInt(tstamp),
|
||||||
}
|
}
|
||||||
|
// If we are care about TheDAO hard-fork check whether to override the extra-data or not
|
||||||
|
if daoBlock := self.config.DAOForkBlock; daoBlock != nil {
|
||||||
|
// Check whether the block is among the fork extra-override range
|
||||||
|
limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange)
|
||||||
|
if daoBlock.Cmp(header.Number) <= 0 && header.Number.Cmp(limit) < 0 {
|
||||||
|
// Depending whether we support or oppose the fork, override differently
|
||||||
|
if self.config.DAOForkSupport {
|
||||||
|
header.Extra = common.CopyBytes(params.DAOForkBlockExtra)
|
||||||
|
} else if bytes.Compare(header.Extra, params.DAOForkBlockExtra) == 0 {
|
||||||
|
header.Extra = []byte{} // If miner opposes, don't let it use the reserved extra-data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
previous := self.current
|
previous := self.current
|
||||||
// Could potentially happen if starting to mine in an odd state.
|
// Could potentially happen if starting to mine in an odd state.
|
||||||
err := self.makeCurrent(parent, header)
|
err := self.makeCurrent(parent, header)
|
||||||
|
|
@ -476,7 +490,11 @@ func (self *worker) commitNewWork() {
|
||||||
glog.V(logger.Info).Infoln("Could not create new env for mining, retrying on next block.")
|
glog.V(logger.Info).Infoln("Could not create new env for mining, retrying on next block.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Create the current work task and check any fork transitions needed
|
||||||
work := self.current
|
work := self.current
|
||||||
|
if self.config.DAOForkSupport && self.config.DAOForkBlock != nil && self.config.DAOForkBlock.Cmp(header.Number) == 0 {
|
||||||
|
core.ApplyDAOHardFork(work.state)
|
||||||
|
}
|
||||||
|
|
||||||
/* //approach 1
|
/* //approach 1
|
||||||
transactions := self.eth.TxPool().GetTransactions()
|
transactions := self.eth.TxPool().GetTransactions()
|
||||||
|
|
|
||||||
108
params/dao_list.go
Normal file
108
params/dao_list.go
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
// 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 params
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DAODrainList is the list of accounts whose full balances will be moved into a
|
||||||
|
// refund contract at the beginning of the dao-fork block.
|
||||||
|
var DAODrainList []common.Address
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// Parse the list of DAO accounts to drain
|
||||||
|
var list []map[string]string
|
||||||
|
if err := json.Unmarshal([]byte(daoDrainListJSON), &list); err != nil {
|
||||||
|
panic(fmt.Errorf("Failed to parse DAO drain list: %v", err))
|
||||||
|
}
|
||||||
|
// Collect all the accounts that need draining
|
||||||
|
for _, dao := range list {
|
||||||
|
DAODrainList = append(DAODrainList, common.HexToAddress(dao["address"]))
|
||||||
|
DAODrainList = append(DAODrainList, common.HexToAddress(dao["extraBalanceAccount"]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// daoDrainListJSON is the JSON encoded list of accounts whose full balances will
|
||||||
|
// be moved into a refund contract at the beginning of the dao-fork block.
|
||||||
|
const daoDrainListJSON = `
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"address":"0x304a554a310c7e546dfe434669c62820b7d83490",
|
||||||
|
"balance":"30328a3f333ac2fb5f509",
|
||||||
|
"extraBalance":"9184e72a000",
|
||||||
|
"extraBalanceAccount":"0x914d1b8b43e92723e64fd0a06f5bdb8dd9b10c79"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address":"0xfe24cdd8648121a43a7c86d289be4dd2951ed49f",
|
||||||
|
"balance":"ea0b1bdc78f500a43",
|
||||||
|
"extraBalance":"0",
|
||||||
|
"extraBalanceAccount":"0x17802f43a0137c506ba92291391a8a8f207f487d"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address":"0xb136707642a4ea12fb4bae820f03d2562ebff487",
|
||||||
|
"balance":"6050bdeb3354b5c98adc3",
|
||||||
|
"extraBalance":"0",
|
||||||
|
"extraBalanceAccount":"0xdbe9b615a3ae8709af8b93336ce9b477e4ac0940"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address":"0xf14c14075d6c4ed84b86798af0956deef67365b5",
|
||||||
|
"balance":"1d77844e94c25ba2",
|
||||||
|
"extraBalance":"0",
|
||||||
|
"extraBalanceAccount":"0xca544e5c4687d109611d0f8f928b53a25af72448"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address":"0xaeeb8ff27288bdabc0fa5ebb731b6f409507516c",
|
||||||
|
"balance":"2e93a72de4fc5ec0ed",
|
||||||
|
"extraBalance":"0",
|
||||||
|
"extraBalanceAccount":"0xcbb9d3703e651b0d496cdefb8b92c25aeb2171f7"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address":"0xaccc230e8a6e5be9160b8cdf2864dd2a001c28b6",
|
||||||
|
"balance":"14d0944eb3be947a8",
|
||||||
|
"extraBalance":"0",
|
||||||
|
"extraBalanceAccount":"0x2b3455ec7fedf16e646268bf88846bd7a2319bb2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address":"0x4613f3bca5c44ea06337a9e439fbc6d42e501d0a",
|
||||||
|
"balance":"275eaa8345ced6523a8",
|
||||||
|
"extraBalance":"0",
|
||||||
|
"extraBalanceAccount":"0xd343b217de44030afaa275f54d31a9317c7f441e"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address":"0x84ef4b2357079cd7a7c69fd7a37cd0609a679106",
|
||||||
|
"balance":"4accfbf922fd046baa05",
|
||||||
|
"extraBalance":"0",
|
||||||
|
"extraBalanceAccount":"0xda2fef9e4a3230988ff17df2165440f37e8b1708"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address":"0xf4c64518ea10f995918a454158c6b61407ea345c",
|
||||||
|
"balance":"38d275b0ed7862ba4f13",
|
||||||
|
"extraBalance":"0",
|
||||||
|
"extraBalanceAccount":"0x7602b46df5390e432ef1c307d4f2c9ff6d65cc97"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
|
||||||
|
"balance":"1",
|
||||||
|
"extraBalance":"49097c66ae78c50e4d3c",
|
||||||
|
"extraBalanceAccount":"0x807640a13483f8ac783c557fcdf27be11ea4ac7a"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
`
|
||||||
|
|
@ -16,9 +16,19 @@
|
||||||
|
|
||||||
package params
|
package params
|
||||||
|
|
||||||
import "math/big"
|
import (
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
TestNetHomesteadBlock = big.NewInt(494000) // testnet homestead block
|
TestNetHomesteadBlock = big.NewInt(494000) // Testnet homestead block
|
||||||
MainNetHomesteadBlock = big.NewInt(1150000) // mainnet homestead block
|
MainNetHomesteadBlock = big.NewInt(1150000) // Mainnet homestead block
|
||||||
|
|
||||||
|
TestNetDAOForkBlock = big.NewInt(8888888) // Testnet dao hard-fork block
|
||||||
|
MainNetDAOForkBlock = big.NewInt(9999999) // Mainnet dao hard-fork block
|
||||||
|
DAOForkBlockExtra = common.FromHex("0x64616f2d686172642d666f726b") // Block extradata to signel the fork with ("dao-hard-fork")
|
||||||
|
DAOForkExtraRange = big.NewInt(10) // Number of blocks to override the extradata (prevent no-fork attacks)
|
||||||
|
DAORefundContract = common.HexToAddress("0x0000000000000000000000000000000000000000") // Address of the refund contract to send DAO balances to
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -20,66 +20,69 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBcValidBlockTests(t *testing.T) {
|
func TestBcValidBlockTests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcValidBlockTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcValidBlockTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBcUncleHeaderValidityTests(t *testing.T) {
|
func TestBcUncleHeaderValidityTests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcUncleHeaderValiditiy.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcUncleHeaderValiditiy.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBcUncleTests(t *testing.T) {
|
func TestBcUncleTests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcUncleTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcUncleTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBcForkUncleTests(t *testing.T) {
|
func TestBcForkUncleTests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcForkUncle.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcForkUncle.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBcInvalidHeaderTests(t *testing.T) {
|
func TestBcInvalidHeaderTests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcInvalidHeaderTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcInvalidHeaderTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBcInvalidRLPTests(t *testing.T) {
|
func TestBcInvalidRLPTests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcInvalidRLPTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcInvalidRLPTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBcRPCAPITests(t *testing.T) {
|
func TestBcRPCAPITests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcRPC_API_Test.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcRPC_API_Test.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBcForkBlockTests(t *testing.T) {
|
func TestBcForkBlockTests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcForkBlockTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcForkBlockTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBcForkStress(t *testing.T) {
|
func TestBcForkStress(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcForkStressTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcForkStressTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -89,21 +92,21 @@ func TestBcTotalDifficulty(t *testing.T) {
|
||||||
// skip because these will fail due to selfish mining fix
|
// skip because these will fail due to selfish mining fix
|
||||||
t.Skip()
|
t.Skip()
|
||||||
|
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcTotalDifficultyTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcTotalDifficultyTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBcWallet(t *testing.T) {
|
func TestBcWallet(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcWalletTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcWalletTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBcGasPricer(t *testing.T) {
|
func TestBcGasPricer(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcGasPricerTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcGasPricerTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +114,7 @@ func TestBcGasPricer(t *testing.T) {
|
||||||
|
|
||||||
// TODO: iterate over files once we got more than a few
|
// TODO: iterate over files once we got more than a few
|
||||||
func TestBcRandom(t *testing.T) {
|
func TestBcRandom(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "RandomTests/bl201507071825GO.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "RandomTests/bl201507071825GO.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -121,14 +124,14 @@ func TestBcMultiChain(t *testing.T) {
|
||||||
// skip due to selfish mining
|
// skip due to selfish mining
|
||||||
t.Skip()
|
t.Skip()
|
||||||
|
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcMultiChainTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcMultiChainTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBcState(t *testing.T) {
|
func TestBcState(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(1000000), filepath.Join(blockTestDir, "bcStateTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(1000000), nil, filepath.Join(blockTestDir, "bcStateTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -136,77 +139,89 @@ func TestBcState(t *testing.T) {
|
||||||
|
|
||||||
// Homestead tests
|
// Homestead tests
|
||||||
func TestHomesteadBcValidBlockTests(t *testing.T) {
|
func TestHomesteadBcValidBlockTests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcValidBlockTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(0), nil, filepath.Join(blockTestDir, "Homestead", "bcValidBlockTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHomesteadBcUncleHeaderValidityTests(t *testing.T) {
|
func TestHomesteadBcUncleHeaderValidityTests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcUncleHeaderValiditiy.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(0), nil, filepath.Join(blockTestDir, "Homestead", "bcUncleHeaderValiditiy.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHomesteadBcUncleTests(t *testing.T) {
|
func TestHomesteadBcUncleTests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcUncleTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(0), nil, filepath.Join(blockTestDir, "Homestead", "bcUncleTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHomesteadBcInvalidHeaderTests(t *testing.T) {
|
func TestHomesteadBcInvalidHeaderTests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcInvalidHeaderTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(0), nil, filepath.Join(blockTestDir, "Homestead", "bcInvalidHeaderTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHomesteadBcRPCAPITests(t *testing.T) {
|
func TestHomesteadBcRPCAPITests(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcRPC_API_Test.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(0), nil, filepath.Join(blockTestDir, "Homestead", "bcRPC_API_Test.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHomesteadBcForkStress(t *testing.T) {
|
func TestHomesteadBcForkStress(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcForkStressTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(0), nil, filepath.Join(blockTestDir, "Homestead", "bcForkStressTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHomesteadBcTotalDifficulty(t *testing.T) {
|
func TestHomesteadBcTotalDifficulty(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcTotalDifficultyTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(0), nil, filepath.Join(blockTestDir, "Homestead", "bcTotalDifficultyTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHomesteadBcWallet(t *testing.T) {
|
func TestHomesteadBcWallet(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcWalletTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(0), nil, filepath.Join(blockTestDir, "Homestead", "bcWalletTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHomesteadBcGasPricer(t *testing.T) {
|
func TestHomesteadBcGasPricer(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcGasPricerTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(0), nil, filepath.Join(blockTestDir, "Homestead", "bcGasPricerTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHomesteadBcMultiChain(t *testing.T) {
|
func TestHomesteadBcMultiChain(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcMultiChainTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(0), nil, filepath.Join(blockTestDir, "Homestead", "bcMultiChainTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHomesteadBcState(t *testing.T) {
|
func TestHomesteadBcState(t *testing.T) {
|
||||||
err := RunBlockTest(big.NewInt(0), filepath.Join(blockTestDir, "Homestead", "bcStateTest.json"), BlockSkipTests)
|
err := RunBlockTest(big.NewInt(0), nil, filepath.Join(blockTestDir, "Homestead", "bcStateTest.json"), BlockSkipTests)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DAO hard-fork tests
|
||||||
|
func TestDAOBcTheDao(t *testing.T) {
|
||||||
|
// Temporarilly override the hard-fork specs
|
||||||
|
defer func(old common.Address) { params.DAORefundContract = old }(params.DAORefundContract)
|
||||||
|
params.DAORefundContract = common.HexToAddress("0xabcabcabcabcabcabcabcabcabcabcabcabcabca")
|
||||||
|
|
||||||
|
err := RunBlockTest(big.NewInt(5), big.NewInt(8), filepath.Join(blockTestDir, "TestNetwork", "bcTheDaoTest.json"), BlockSkipTests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ type btTransaction struct {
|
||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunBlockTestWithReader(homesteadBlock *big.Int, r io.Reader, skipTests []string) error {
|
func RunBlockTestWithReader(homesteadBlock, daoForkBlock *big.Int, r io.Reader, skipTests []string) error {
|
||||||
btjs := make(map[string]*btJSON)
|
btjs := make(map[string]*btJSON)
|
||||||
if err := readJson(r, &btjs); err != nil {
|
if err := readJson(r, &btjs); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -114,13 +114,13 @@ func RunBlockTestWithReader(homesteadBlock *big.Int, r io.Reader, skipTests []st
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := runBlockTests(homesteadBlock, bt, skipTests); err != nil {
|
if err := runBlockTests(homesteadBlock, daoForkBlock, bt, skipTests); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunBlockTest(homesteadBlock *big.Int, file string, skipTests []string) error {
|
func RunBlockTest(homesteadBlock, daoForkBlock *big.Int, file string, skipTests []string) error {
|
||||||
btjs := make(map[string]*btJSON)
|
btjs := make(map[string]*btJSON)
|
||||||
if err := readJsonFile(file, &btjs); err != nil {
|
if err := readJsonFile(file, &btjs); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -130,13 +130,13 @@ func RunBlockTest(homesteadBlock *big.Int, file string, skipTests []string) erro
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := runBlockTests(homesteadBlock, bt, skipTests); err != nil {
|
if err := runBlockTests(homesteadBlock, daoForkBlock, bt, skipTests); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func runBlockTests(homesteadBlock *big.Int, bt map[string]*BlockTest, skipTests []string) error {
|
func runBlockTests(homesteadBlock, daoForkBlock *big.Int, bt map[string]*BlockTest, skipTests []string) error {
|
||||||
skipTest := make(map[string]bool, len(skipTests))
|
skipTest := make(map[string]bool, len(skipTests))
|
||||||
for _, name := range skipTests {
|
for _, name := range skipTests {
|
||||||
skipTest[name] = true
|
skipTest[name] = true
|
||||||
|
|
@ -148,7 +148,7 @@ func runBlockTests(homesteadBlock *big.Int, bt map[string]*BlockTest, skipTests
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// test the block
|
// test the block
|
||||||
if err := runBlockTest(homesteadBlock, test); err != nil {
|
if err := runBlockTest(homesteadBlock, daoForkBlock, test); err != nil {
|
||||||
return fmt.Errorf("%s: %v", name, err)
|
return fmt.Errorf("%s: %v", name, err)
|
||||||
}
|
}
|
||||||
glog.Infoln("Block test passed: ", name)
|
glog.Infoln("Block test passed: ", name)
|
||||||
|
|
@ -157,7 +157,7 @@ func runBlockTests(homesteadBlock *big.Int, bt map[string]*BlockTest, skipTests
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func runBlockTest(homesteadBlock *big.Int, test *BlockTest) error {
|
func runBlockTest(homesteadBlock, daoForkBlock *big.Int, test *BlockTest) error {
|
||||||
// import pre accounts & construct test genesis block & state root
|
// import pre accounts & construct test genesis block & state root
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
if _, err := test.InsertPreState(db); err != nil {
|
if _, err := test.InsertPreState(db); err != nil {
|
||||||
|
|
@ -169,7 +169,7 @@ func runBlockTest(homesteadBlock *big.Int, test *BlockTest) error {
|
||||||
core.WriteCanonicalHash(db, test.Genesis.Hash(), test.Genesis.NumberU64())
|
core.WriteCanonicalHash(db, test.Genesis.Hash(), test.Genesis.NumberU64())
|
||||||
core.WriteHeadBlockHash(db, test.Genesis.Hash())
|
core.WriteHeadBlockHash(db, test.Genesis.Hash())
|
||||||
evmux := new(event.TypeMux)
|
evmux := new(event.TypeMux)
|
||||||
config := &core.ChainConfig{HomesteadBlock: homesteadBlock}
|
config := &core.ChainConfig{HomesteadBlock: homesteadBlock, DAOForkBlock: daoForkBlock, DAOForkSupport: true}
|
||||||
chain, err := core.NewBlockChain(db, config, ethash.NewShared(), evmux)
|
chain, err := core.NewBlockChain(db, config, ethash.NewShared(), evmux)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
1818
tests/files/BlockchainTests/TestNetwork/bcTheDaoTest.json
Normal file
1818
tests/files/BlockchainTests/TestNetwork/bcTheDaoTest.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -141,6 +141,8 @@ type VmTest struct {
|
||||||
|
|
||||||
type RuleSet struct {
|
type RuleSet struct {
|
||||||
HomesteadBlock *big.Int
|
HomesteadBlock *big.Int
|
||||||
|
DAOForkBlock *big.Int
|
||||||
|
DAOForkSupport bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r RuleSet) IsHomestead(n *big.Int) bool {
|
func (r RuleSet) IsHomestead(n *big.Int) bool {
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, vm.Logs,
|
||||||
|
|
||||||
caller := state.GetOrNewStateObject(from)
|
caller := state.GetOrNewStateObject(from)
|
||||||
|
|
||||||
vmenv := NewEnvFromMap(RuleSet{params.MainNetHomesteadBlock}, state, env, exec)
|
vmenv := NewEnvFromMap(RuleSet{params.MainNetHomesteadBlock, params.MainNetDAOForkBlock, true}, state, env, exec)
|
||||||
vmenv.vmTest = true
|
vmenv.vmTest = true
|
||||||
vmenv.skipTransfer = true
|
vmenv.skipTransfer = true
|
||||||
vmenv.initial = true
|
vmenv.initial = true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue