diff options
-rw-r--r-- | cmd/geth/dao_test.go | 87 | ||||
-rw-r--r-- | cmd/geth/main.go | 2 | ||||
-rw-r--r-- | cmd/utils/flags.go | 18 | ||||
-rw-r--r-- | eth/api_backend.go | 4 | ||||
-rw-r--r-- | miner/miner.go | 9 | ||||
-rw-r--r-- | miner/worker.go | 15 | ||||
-rw-r--r-- | node/api.go | 6 |
7 files changed, 47 insertions, 94 deletions
diff --git a/cmd/geth/dao_test.go b/cmd/geth/dao_test.go index 06578b612..f9ce80218 100644 --- a/cmd/geth/dao_test.go +++ b/cmd/geth/dao_test.go @@ -83,75 +83,28 @@ var daoGenesisForkBlock = big.NewInt(314) // TestDAOForkBlockNewChain 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 TestDAOForkBlockNewChain(t *testing.T) { - for _, arg := range []struct { + for i, arg := range []struct { testnet bool genesis string - votes [][2]bool expectBlock *big.Int expectVote bool }{ // Test DAO Default Mainnet - {false, "", [][2]bool{{false, false}}, params.MainNetDAOForkBlock, true}, - // test DAO Support Mainnet - {false, "", [][2]bool{{true, false}}, params.MainNetDAOForkBlock, true}, - // test DAO Oppose Mainnet - {false, "", [][2]bool{{false, true}}, params.MainNetDAOForkBlock, false}, - // test DAO Switch To Support Mainnet - {false, "", [][2]bool{{false, true}, {true, false}}, params.MainNetDAOForkBlock, true}, - // test DAO Switch To Oppose Mainnet - {false, "", [][2]bool{{true, false}, {false, true}}, params.MainNetDAOForkBlock, false}, + {false, "", params.MainNetDAOForkBlock, true}, // test DAO Default Testnet - {true, "", [][2]bool{{false, false}}, params.TestNetDAOForkBlock, true}, - // test DAO Support Testnet - {true, "", [][2]bool{{true, false}}, params.TestNetDAOForkBlock, true}, - // test DAO Oppose Testnet - {true, "", [][2]bool{{false, true}}, params.TestNetDAOForkBlock, false}, - // test DAO Switch To Support Testnet - {true, "", [][2]bool{{false, true}, {true, false}}, params.TestNetDAOForkBlock, true}, - // test DAO Switch To Oppose Testnet - {true, "", [][2]bool{{true, false}, {false, true}}, params.TestNetDAOForkBlock, false}, + {true, "", params.TestNetDAOForkBlock, true}, // test DAO Init Old Privnet - {false, daoOldGenesis, [][2]bool{}, nil, false}, - // test DAO Default Old Privnet - {false, daoOldGenesis, [][2]bool{{false, false}}, nil, false}, - // test DAO Support Old Privnet - {false, daoOldGenesis, [][2]bool{{true, false}}, nil, true}, - // test DAO Oppose Old Privnet - {false, daoOldGenesis, [][2]bool{{false, true}}, nil, false}, - // test DAO Switch To Support Old Privnet - {false, daoOldGenesis, [][2]bool{{false, true}, {true, false}}, nil, true}, - // test DAO Switch To Oppose Old Privnet - {false, daoOldGenesis, [][2]bool{{true, false}, {false, true}}, nil, false}, - // test DAO Init No Fork Privnet - {false, daoNoForkGenesis, [][2]bool{}, daoGenesisForkBlock, false}, + {false, daoOldGenesis, nil, false}, // test DAO Default No Fork Privnet - {false, daoNoForkGenesis, [][2]bool{{false, false}}, daoGenesisForkBlock, false}, - // test DAO Support No Fork Privnet - {false, daoNoForkGenesis, [][2]bool{{true, false}}, daoGenesisForkBlock, true}, - // test DAO Oppose No Fork Privnet - {false, daoNoForkGenesis, [][2]bool{{false, true}}, daoGenesisForkBlock, false}, - // test DAO Switch To Support No Fork Privnet - {false, daoNoForkGenesis, [][2]bool{{false, true}, {true, false}}, daoGenesisForkBlock, true}, - // test DAO Switch To Oppose No Fork Privnet - {false, daoNoForkGenesis, [][2]bool{{true, false}, {false, true}}, daoGenesisForkBlock, false}, - // test DAO Init Pro Fork Privnet - {false, daoProForkGenesis, [][2]bool{}, daoGenesisForkBlock, true}, + {false, daoNoForkGenesis, daoGenesisForkBlock, false}, // test DAO Default Pro Fork Privnet - {false, daoProForkGenesis, [][2]bool{{false, false}}, daoGenesisForkBlock, true}, - // test DAO Support Pro Fork Privnet - {false, daoProForkGenesis, [][2]bool{{true, false}}, daoGenesisForkBlock, true}, - // test DAO Oppose Pro Fork Privnet - {false, daoProForkGenesis, [][2]bool{{false, true}}, daoGenesisForkBlock, false}, - // test DAO Switch To Support Pro Fork Privnet - {false, daoProForkGenesis, [][2]bool{{false, true}, {true, false}}, daoGenesisForkBlock, true}, - // test DAO Switch To Oppose Pro Fork Privnet - {false, daoProForkGenesis, [][2]bool{{true, false}, {false, true}}, daoGenesisForkBlock, false}, + {false, daoProForkGenesis, daoGenesisForkBlock, true}, } { - testDAOForkBlockNewChain(t, arg.testnet, arg.genesis, arg.votes, arg.expectBlock, arg.expectVote) + testDAOForkBlockNewChain(t, i, arg.testnet, arg.genesis, arg.expectBlock, arg.expectVote) } } -func testDAOForkBlockNewChain(t *testing.T, testnet bool, genesis string, votes [][2]bool, expectBlock *big.Int, expectVote bool) { +func testDAOForkBlockNewChain(t *testing.T, test int, testnet bool, genesis string, expectBlock *big.Int, expectVote bool) { // Create a temporary data directory to use and inspect later datadir := tmpdir(t) defer os.RemoveAll(datadir) @@ -160,21 +113,15 @@ func testDAOForkBlockNewChain(t *testing.T, testnet bool, genesis string, votes 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) + t.Fatalf("test %d: failed to write genesis file: %v", test, err) } runGeth(t, "--datadir", datadir, "init", json).cmd.Wait() - } - for _, vote := range votes { + } else { + // Force chain initialization 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() } @@ -185,7 +132,7 @@ func testDAOForkBlockNewChain(t *testing.T, testnet bool, genesis string, votes } db, err := ethdb.NewLDBDatabase(path, 0, 0) if err != nil { - t.Fatalf("failed to open test database: %v", err) + t.Fatalf("test %d: failed to open test database: %v", test, err) } defer db.Close() @@ -198,20 +145,20 @@ func testDAOForkBlockNewChain(t *testing.T, testnet bool, genesis string, votes } config, err := core.GetChainConfig(db, genesisHash) if err != nil { - t.Errorf("failed to retrieve chain config: %v", err) + t.Errorf("test %d: failed to retrieve chain config: %v", test, err) return // we want to return here, the other checks can't make it past this point (nil panic). } // 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) + t.Errorf("test %d: dao hard-fork block mismatch: have nil, want %v", test, expectBlock) } } else if expectBlock == nil { - t.Errorf("dao hard-fork block mismatch: have %v, want nil", config.DAOForkBlock) + t.Errorf("test %d: dao hard-fork block mismatch: have %v, want nil", test, config.DAOForkBlock) } else if config.DAOForkBlock.Cmp(expectBlock) != 0 { - t.Errorf("dao hard-fork block mismatch: have %v, want %v", config.DAOForkBlock, expectBlock) + t.Errorf("test %d: dao hard-fork block mismatch: have %v, want %v", test, config.DAOForkBlock, expectBlock) } if config.DAOForkSupport != expectVote { - t.Errorf("dao hard-fork support mismatch: have %v, want %v", config.DAOForkSupport, expectVote) + t.Errorf("test %d: dao hard-fork support mismatch: have %v, want %v", test, config.DAOForkSupport, expectVote) } } diff --git a/cmd/geth/main.go b/cmd/geth/main.go index bcf9edbf0..4164d4383 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -140,8 +140,6 @@ participating. utils.MaxPendingPeersFlag, utils.EtherbaseFlag, utils.GasPriceFlag, - utils.SupportDAOFork, - utils.OpposeDAOFork, utils.MinerThreadsFlag, utils.MiningEnabledFlag, utils.AutoDAGFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index abd344df0..9df891f78 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -125,7 +125,7 @@ var ( } TestNetFlag = cli.BoolFlag{ Name: "testnet", - Usage: "Morden network: pre-configured test network with modified starting nonces (replay protection)", + Usage: "Ropsten network: pre-configured test network", } DevModeFlag = cli.BoolFlag{ Name: "dev", @@ -177,15 +177,6 @@ var ( Usage: "Number of trie node generations to keep in memory", Value: int(state.MaxTrieCacheGen), } - // 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 MiningEnabledFlag = cli.BoolFlag{ Name: "mine", @@ -901,13 +892,6 @@ func MakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *params.ChainCon config.ChainId = params.MainNetChainID } } - // 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 } diff --git a/eth/api_backend.go b/eth/api_backend.go index 0925132ef..7858dee2e 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -56,7 +56,7 @@ func (b *EthApiBackend) SetHead(number uint64) { func (b *EthApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) { // Pending block is only known by the miner if blockNr == rpc.PendingBlockNumber { - block, _ := b.eth.miner.Pending() + block := b.eth.miner.PendingBlock() return block.Header(), nil } // Otherwise resolve and return the block @@ -69,7 +69,7 @@ func (b *EthApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNum func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) { // Pending block is only known by the miner if blockNr == rpc.PendingBlockNumber { - block, _ := b.eth.miner.Pending() + block := b.eth.miner.PendingBlock() return block, nil } // Otherwise resolve and return the block diff --git a/miner/miner.go b/miner/miner.go index c85a1cd8e..87568ac18 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -187,6 +187,15 @@ func (self *Miner) Pending() (*types.Block, *state.StateDB) { return self.worker.pending() } +// PendingBlock returns the currently pending block. +// +// Note, to access both the pending block and the pending state +// simultaneously, please use Pending(), as the pending state can +// change between multiple method calls +func (self *Miner) PendingBlock() *types.Block { + return self.worker.pendingBlock() +} + func (self *Miner) SetEtherbase(addr common.Address) { self.coinbase = addr self.worker.setEtherbase(addr) diff --git a/miner/worker.go b/miner/worker.go index ca00c7229..edbd502c1 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -176,6 +176,21 @@ func (self *worker) pending() (*types.Block, *state.StateDB) { return self.current.Block, self.current.state.Copy() } +func (self *worker) pendingBlock() *types.Block { + self.currentMu.Lock() + defer self.currentMu.Unlock() + + if atomic.LoadInt32(&self.mining) == 0 { + return types.NewBlock( + self.current.header, + self.current.txs, + nil, + self.current.receipts, + ) + } + return self.current.Block +} + func (self *worker) start() { self.mu.Lock() defer self.mu.Unlock() diff --git a/node/api.go b/node/api.go index 631e92c8e..7c9ad601a 100644 --- a/node/api.go +++ b/node/api.go @@ -21,7 +21,7 @@ import ( "strings" "time" - "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" @@ -331,6 +331,6 @@ func (s *PublicWeb3API) ClientVersion() string { // Sha3 applies the ethereum sha3 implementation on the input. // It assumes the input is hex encoded. -func (s *PublicWeb3API) Sha3(input string) string { - return common.ToHex(crypto.Keccak256(common.FromHex(input))) +func (s *PublicWeb3API) Sha3(input hexutil.Bytes) hexutil.Bytes { + return crypto.Keccak256(input) } |