From 4a439c2359991bdc49463ae66da11da895cc6eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 14 Nov 2016 13:03:29 +0200 Subject: [PATCH] mobile: port wrappers to EIP155 and EIP158 fork --- cmd/utils/bootnodes.go | 20 ------------------ mobile/bind.go | 4 ++-- mobile/geth.go | 16 ++++++++------- mobile/{core.go => params.go} | 38 ++++++++++++++++++++--------------- mobile/types.go | 6 +++--- params/config.go | 22 ++++++++++++++++++++ 6 files changed, 58 insertions(+), 48 deletions(-) rename mobile/{core.go => params.go} (61%) diff --git a/cmd/utils/bootnodes.go b/cmd/utils/bootnodes.go index 50b6584678..07e64b25f9 100644 --- a/cmd/utils/bootnodes.go +++ b/cmd/utils/bootnodes.go @@ -17,10 +17,8 @@ package utils import ( - "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/discv5" - "github.com/ethereum/go-ethereum/params" ) // MainnetBootnodes are the enode URLs of the P2P bootstrap nodes running on @@ -52,21 +50,3 @@ var DiscoveryV5Bootnodes = []*discv5.Node{ discv5.MustParseNode("enode://1c7a64d76c0334b0418c004af2f67c50e36a3be60b5e4790bdac0439d21603469a85fad36f2473c9a80eb043ae60936df905fa28f1ff614c3e5dc34f15dcd2dc@40.118.3.223:30308"), discv5.MustParseNode("enode://85c85d7143ae8bb96924f2b54f1b3e70d8c4d367af305325d30a61385a432f247d2c75c45c6b4a60335060d072d7f5b35dd1d4c45f76941f62a4f83b6e75daaf@40.118.3.223:30309"), } - -// MainnetChainConfig is the chain parameters to run a node on the main network. -var MainnetChainConfig = &core.ChainConfig{ - HomesteadBlock: params.MainNetHomesteadBlock, - DAOForkBlock: params.MainNetDAOForkBlock, - DAOForkSupport: true, - HomesteadGasRepriceBlock: params.MainNetHomesteadGasRepriceBlock, - HomesteadGasRepriceHash: params.MainNetHomesteadGasRepriceHash, -} - -// TestnetChainConfig is the chain parameters to run a node on the test network. -var TestnetChainConfig = &core.ChainConfig{ - HomesteadBlock: params.TestNetHomesteadBlock, - DAOForkBlock: params.TestNetDAOForkBlock, - DAOForkSupport: false, - HomesteadGasRepriceBlock: params.TestNetHomesteadGasRepriceBlock, - HomesteadGasRepriceHash: params.TestNetHomesteadGasRepriceHash, -} diff --git a/mobile/bind.go b/mobile/bind.go index 79fb0e0e89..50adc6b0f1 100644 --- a/mobile/bind.go +++ b/mobile/bind.go @@ -39,7 +39,7 @@ type signer struct { } func (s *signer) Sign(addr *Address, tx *Transaction) (*Transaction, error) { - sig, err := s.sign(addr.address, tx.tx) + sig, err := s.sign(types.HomesteadSigner{}, addr.address, tx.tx) if err != nil { return nil, err } @@ -89,7 +89,7 @@ func (opts *TransactOpts) GetGasLimit() int64 { return opts.opts.GasLimit.Int6 func (opts *TransactOpts) SetFrom(from *Address) { opts.opts.From = from.address } func (opts *TransactOpts) SetNonce(nonce int64) { opts.opts.Nonce = big.NewInt(nonce) } func (opts *TransactOpts) SetSigner(s Signer) { - opts.opts.Signer = func(addr common.Address, tx *types.Transaction) (*types.Transaction, error) { + opts.opts.Signer = func(signer types.Signer, addr common.Address, tx *types.Transaction) (*types.Transaction, error) { sig, err := s.Sign(&Address{addr}, &Transaction{tx}) if err != nil { return nil, err diff --git a/mobile/geth.go b/mobile/geth.go index 4d1f48ec3d..d7f0800e0b 100644 --- a/mobile/geth.go +++ b/mobile/geth.go @@ -25,7 +25,6 @@ import ( "path/filepath" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethclient" @@ -33,6 +32,7 @@ import ( "github.com/ethereum/go-ethereum/light" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p/nat" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/whisper/whisperv2" ) @@ -129,12 +129,14 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) { // Register the Ethereum protocol if requested if config.EthereumEnabled { ethConf := ð.Config{ - ChainConfig: &core.ChainConfig{ - HomesteadBlock: big.NewInt(config.EthereumChainConfig.HomesteadBlock), - DAOForkBlock: big.NewInt(config.EthereumChainConfig.DAOForkBlock), - DAOForkSupport: config.EthereumChainConfig.DAOForkSupport, - HomesteadGasRepriceBlock: big.NewInt(config.EthereumChainConfig.HomesteadGasRepriceBlock), - HomesteadGasRepriceHash: config.EthereumChainConfig.HomesteadGasRepriceHash.hash, + ChainConfig: ¶ms.ChainConfig{ + HomesteadBlock: big.NewInt(config.EthereumChainConfig.HomesteadBlock), + DAOForkBlock: big.NewInt(config.EthereumChainConfig.DAOForkBlock), + DAOForkSupport: config.EthereumChainConfig.DAOForkSupport, + EIP150Block: big.NewInt(config.EthereumChainConfig.EIP150Block), + EIP150Hash: config.EthereumChainConfig.EIP150Hash.hash, + EIP155Block: big.NewInt(config.EthereumChainConfig.EIP155Block), + EIP158Block: big.NewInt(config.EthereumChainConfig.EIP158Block), }, Genesis: config.EthereumGenesis, LightMode: true, diff --git a/mobile/core.go b/mobile/params.go similarity index 61% rename from mobile/core.go rename to mobile/params.go index a49a4e6600..bf0df70141 100644 --- a/mobile/core.go +++ b/mobile/params.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -// Contains all the wrappers from the core package. +// Contains all the wrappers from the params package. package geth @@ -26,11 +26,13 @@ import ( // MainnetChainConfig returns the chain configurations for the main Ethereum network. func MainnetChainConfig() *ChainConfig { return &ChainConfig{ - HomesteadBlock: params.MainNetHomesteadBlock.Int64(), - DAOForkBlock: params.MainNetDAOForkBlock.Int64(), - DAOForkSupport: true, - HomesteadGasRepriceBlock: params.MainNetHomesteadGasRepriceBlock.Int64(), - HomesteadGasRepriceHash: Hash{params.MainNetHomesteadGasRepriceHash}, + HomesteadBlock: params.MainNetHomesteadBlock.Int64(), + DAOForkBlock: params.MainNetDAOForkBlock.Int64(), + DAOForkSupport: true, + EIP150Block: params.MainNetHomesteadGasRepriceBlock.Int64(), + EIP150Hash: Hash{params.MainNetHomesteadGasRepriceHash}, + EIP155Block: params.MainNetSpuriousDragon.Int64(), + EIP158Block: params.MainNetSpuriousDragon.Int64(), } } @@ -43,11 +45,13 @@ func MainnetGenesis() string { // TestnetChainConfig returns the chain configurations for the Ethereum test network. func TestnetChainConfig() *ChainConfig { return &ChainConfig{ - HomesteadBlock: params.TestNetHomesteadBlock.Int64(), - DAOForkBlock: 0, - DAOForkSupport: false, - HomesteadGasRepriceBlock: params.TestNetHomesteadGasRepriceBlock.Int64(), - HomesteadGasRepriceHash: Hash{params.TestNetHomesteadGasRepriceHash}, + HomesteadBlock: params.TestNetHomesteadBlock.Int64(), + DAOForkBlock: 0, + DAOForkSupport: false, + EIP150Block: params.TestNetHomesteadGasRepriceBlock.Int64(), + EIP150Hash: Hash{params.TestNetHomesteadGasRepriceHash}, + EIP155Block: params.TestNetSpuriousDragon.Int64(), + EIP158Block: params.TestNetSpuriousDragon.Int64(), } } @@ -58,11 +62,13 @@ func TestnetGenesis() string { // ChainConfig is the core config which determines the blockchain settings. type ChainConfig struct { - HomesteadBlock int64 // Homestead switch block - DAOForkBlock int64 // TheDAO hard-fork switch block - DAOForkSupport bool // Whether the nodes supports or opposes the DAO hard-fork - HomesteadGasRepriceBlock int64 // Homestead gas reprice switch block - HomesteadGasRepriceHash Hash // Homestead gas reprice switch block hash + HomesteadBlock int64 // Homestead switch block + DAOForkBlock int64 // TheDAO hard-fork switch block + DAOForkSupport bool // Whether the nodes supports or opposes the DAO hard-fork + EIP150Block int64 // Homestead gas reprice switch block + EIP150Hash Hash // Homestead gas reprice switch block hash + EIP155Block int64 // Replay protection switch block + EIP158Block int64 // Empty account pruning switch block } // NewChainConfig creates a new chain configuration that transitions immediately diff --git a/mobile/types.go b/mobile/types.go index 8f54d36f0d..bb5ccc6251 100644 --- a/mobile/types.go +++ b/mobile/types.go @@ -139,11 +139,11 @@ func (tx *Transaction) GetValue() *BigInt { return &BigInt{tx.tx.Value()} } func (tx *Transaction) GetNonce() int64 { return int64(tx.tx.Nonce()) } func (tx *Transaction) GetHash() *Hash { return &Hash{tx.tx.Hash()} } -func (tx *Transaction) GetSigHash() *Hash { return &Hash{tx.tx.SigHash()} } +func (tx *Transaction) GetSigHash() *Hash { return &Hash{tx.tx.SigHash(types.HomesteadSigner{})} } func (tx *Transaction) GetCost() *BigInt { return &BigInt{tx.tx.Cost()} } func (tx *Transaction) GetFrom() (*Address, error) { - from, err := tx.tx.From() + from, err := types.Sender(types.HomesteadSigner{}, tx.tx) return &Address{from}, err } @@ -155,7 +155,7 @@ func (tx *Transaction) GetTo() *Address { } func (tx *Transaction) WithSignature(sig []byte) (*Transaction, error) { - t, err := tx.tx.WithSignature(sig) + t, err := tx.tx.WithSignature(types.HomesteadSigner{}, sig) return &Transaction{t}, err } diff --git a/params/config.go b/params/config.go index d63236ef83..d27973a329 100644 --- a/params/config.go +++ b/params/config.go @@ -22,6 +22,28 @@ import ( "github.com/ethereum/go-ethereum/common" ) +// MainnetChainConfig is the chain parameters to run a node on the main network. +var MainnetChainConfig = &ChainConfig{ + HomesteadBlock: MainNetHomesteadBlock, + DAOForkBlock: MainNetDAOForkBlock, + DAOForkSupport: true, + EIP150Block: MainNetHomesteadGasRepriceBlock, + EIP150Hash: MainNetHomesteadGasRepriceHash, + EIP155Block: MainNetSpuriousDragon, + EIP158Block: MainNetSpuriousDragon, +} + +// TestnetChainConfig is the chain parameters to run a node on the test network. +var TestnetChainConfig = &ChainConfig{ + HomesteadBlock: TestNetHomesteadBlock, + DAOForkBlock: TestNetDAOForkBlock, + DAOForkSupport: false, + EIP150Block: TestNetHomesteadGasRepriceBlock, + EIP150Hash: TestNetHomesteadGasRepriceHash, + EIP155Block: TestNetSpuriousDragon, + EIP158Block: TestNetSpuriousDragon, +} + // ChainConfig is the core config which determines the blockchain settings. // // ChainConfig is stored in the database on a per block basis. This means