Skip to content

Commit 64359c9

Browse files
karalabefjl
authored andcommitted
cmd/utils, mobile, params: set the correct field on testnet EIP 155 (#3272)
1 parent 5a3853f commit 64359c9

File tree

4 files changed

+35
-50
lines changed

4 files changed

+35
-50
lines changed

cmd/utils/flags.go

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -847,61 +847,40 @@ func MakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *params.ChainCon
847847
(genesis.Hash() == params.MainNetGenesisHash && !ctx.GlobalBool(TestNetFlag.Name)) ||
848848
(genesis.Hash() == params.TestNetGenesisHash && ctx.GlobalBool(TestNetFlag.Name))
849849

850-
// Set any missing chainConfig fields due to them being unset or system upgrade
851850
if defaults {
852-
if config.HomesteadBlock == nil {
853-
if ctx.GlobalBool(TestNetFlag.Name) {
854-
config.HomesteadBlock = params.TestNetHomesteadBlock
855-
} else {
856-
config.HomesteadBlock = params.MainNetHomesteadBlock
857-
}
858-
}
859-
if config.DAOForkBlock == nil {
860-
if ctx.GlobalBool(TestNetFlag.Name) {
861-
config.DAOForkBlock = params.TestNetDAOForkBlock
862-
} else {
863-
config.DAOForkBlock = params.MainNetDAOForkBlock
864-
}
865-
config.DAOForkSupport = true
866-
}
867-
if config.EIP150Block == nil {
868-
if ctx.GlobalBool(TestNetFlag.Name) {
869-
config.EIP150Block = params.TestNetHomesteadGasRepriceBlock
870-
} else {
871-
config.EIP150Block = params.MainNetHomesteadGasRepriceBlock
872-
}
873-
}
874-
if config.EIP150Hash == (common.Hash{}) {
875-
if ctx.GlobalBool(TestNetFlag.Name) {
876-
config.EIP150Hash = params.TestNetHomesteadGasRepriceHash
877-
} else {
878-
config.EIP150Hash = params.MainNetHomesteadGasRepriceHash
879-
}
851+
// Homestead fork
852+
if ctx.GlobalBool(TestNetFlag.Name) {
853+
config.HomesteadBlock = params.TestNetHomesteadBlock
854+
} else {
855+
config.HomesteadBlock = params.MainNetHomesteadBlock
880856
}
881-
if config.EIP155Block == nil {
882-
if ctx.GlobalBool(TestNetFlag.Name) {
883-
config.EIP150Block = params.TestNetSpuriousDragon
884-
} else {
885-
config.EIP155Block = params.MainNetSpuriousDragon
886-
}
857+
// DAO fork
858+
if ctx.GlobalBool(TestNetFlag.Name) {
859+
config.DAOForkBlock = params.TestNetDAOForkBlock
860+
} else {
861+
config.DAOForkBlock = params.MainNetDAOForkBlock
887862
}
888-
if config.EIP158Block == nil {
889-
if ctx.GlobalBool(TestNetFlag.Name) {
890-
config.EIP158Block = params.TestNetSpuriousDragon
891-
} else {
892-
config.EIP158Block = params.MainNetSpuriousDragon
893-
}
863+
config.DAOForkSupport = true
864+
865+
// DoS reprice fork
866+
if ctx.GlobalBool(TestNetFlag.Name) {
867+
config.EIP150Block = params.TestNetHomesteadGasRepriceBlock
868+
config.EIP150Hash = params.TestNetHomesteadGasRepriceHash
869+
} else {
870+
config.EIP150Block = params.MainNetHomesteadGasRepriceBlock
871+
config.EIP150Hash = params.MainNetHomesteadGasRepriceHash
894872
}
895-
if config.ChainId.BitLen() == 0 {
896-
if ctx.GlobalBool(TestNetFlag.Name) {
897-
config.ChainId = params.TestNetChainID
898-
} else {
899-
config.ChainId = params.MainNetChainID
900-
}
873+
// DoS state cleanup fork
874+
if ctx.GlobalBool(TestNetFlag.Name) {
875+
config.EIP155Block = params.TestNetSpuriousDragon
876+
config.EIP158Block = params.TestNetSpuriousDragon
877+
config.ChainId = params.TestNetChainID
878+
} else {
879+
config.EIP155Block = params.MainNetSpuriousDragon
880+
config.EIP158Block = params.MainNetSpuriousDragon
881+
config.ChainId = params.MainNetChainID
901882
}
902-
config.DAOForkSupport = true
903883
}
904-
905884
// Force override any existing configs if explicitly requested
906885
switch {
907886
case ctx.GlobalBool(SupportDAOFork.Name):

mobile/geth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) {
130130
if config.EthereumEnabled {
131131
ethConf := &eth.Config{
132132
ChainConfig: &params.ChainConfig{
133+
ChainId: big.NewInt(config.EthereumChainConfig.ChainID),
133134
HomesteadBlock: big.NewInt(config.EthereumChainConfig.HomesteadBlock),
134135
DAOForkBlock: big.NewInt(config.EthereumChainConfig.DAOForkBlock),
135136
DAOForkSupport: config.EthereumChainConfig.DAOForkSupport,

mobile/params.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
// MainnetChainConfig returns the chain configurations for the main Ethereum network.
2828
func MainnetChainConfig() *ChainConfig {
2929
return &ChainConfig{
30+
ChainID: params.MainNetChainID.Int64(),
3031
HomesteadBlock: params.MainNetHomesteadBlock.Int64(),
3132
DAOForkBlock: params.MainNetDAOForkBlock.Int64(),
3233
DAOForkSupport: true,
@@ -46,9 +47,10 @@ func MainnetGenesis() string {
4647
// TestnetChainConfig returns the chain configurations for the Ethereum test network.
4748
func TestnetChainConfig() *ChainConfig {
4849
return &ChainConfig{
50+
ChainID: params.TestNetChainID.Int64(),
4951
HomesteadBlock: params.TestNetHomesteadBlock.Int64(),
5052
DAOForkBlock: 0,
51-
DAOForkSupport: false,
53+
DAOForkSupport: true,
5254
EIP150Block: params.TestNetHomesteadGasRepriceBlock.Int64(),
5355
EIP150Hash: Hash{params.TestNetHomesteadGasRepriceHash},
5456
EIP155Block: params.TestNetSpuriousDragon.Int64(),
@@ -63,6 +65,7 @@ func TestnetGenesis() string {
6365

6466
// ChainConfig is the core config which determines the blockchain settings.
6567
type ChainConfig struct {
68+
ChainID int64 // Chain ID for replay protection
6669
HomesteadBlock int64 // Homestead switch block
6770
DAOForkBlock int64 // TheDAO hard-fork switch block
6871
DAOForkSupport bool // Whether the nodes supports or opposes the DAO hard-fork

params/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
// MainnetChainConfig is the chain parameters to run a node on the main network.
2626
var MainnetChainConfig = &ChainConfig{
27+
ChainId: MainNetChainID,
2728
HomesteadBlock: MainNetHomesteadBlock,
2829
DAOForkBlock: MainNetDAOForkBlock,
2930
DAOForkSupport: true,
@@ -35,6 +36,7 @@ var MainnetChainConfig = &ChainConfig{
3536

3637
// TestnetChainConfig is the chain parameters to run a node on the test network.
3738
var TestnetChainConfig = &ChainConfig{
39+
ChainId: TestNetChainID,
3840
HomesteadBlock: TestNetHomesteadBlock,
3941
DAOForkBlock: TestNetDAOForkBlock,
4042
DAOForkSupport: false,

0 commit comments

Comments
 (0)