Skip to content

Commit f0dbec0

Browse files
committed
cmd, params: only set default fork configs for test and mainnet
1 parent 8639b0f commit f0dbec0

4 files changed

Lines changed: 43 additions & 31 deletions

File tree

‎cmd/geth/dao_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,19 @@ func TestDAOInitOldPrivnet(t *testing.T) {
116116
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{}, nil, false)
117117
}
118118
func TestDAODefaultOldPrivnet(t *testing.T) {
119-
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{false, false}}, params.MainNetDAOForkBlock, true)
119+
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{false, false}}, nil, false)
120120
}
121121
func TestDAOSupportOldPrivnet(t *testing.T) {
122-
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{true, false}}, params.MainNetDAOForkBlock, true)
122+
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{true, false}}, nil, true)
123123
}
124124
func TestDAOOpposeOldPrivnet(t *testing.T) {
125-
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{false, true}}, params.MainNetDAOForkBlock, false)
125+
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{false, true}}, nil, false)
126126
}
127127
func TestDAOSwitchToSupportOldPrivnet(t *testing.T) {
128-
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{false, true}, {true, false}}, params.MainNetDAOForkBlock, true)
128+
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{false, true}, {true, false}}, nil, true)
129129
}
130130
func TestDAOSwitchToOpposeOldPrivnet(t *testing.T) {
131-
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{true, false}, {false, true}}, params.MainNetDAOForkBlock, false)
131+
testDAOForkBlockNewChain(t, false, daoOldGenesis, [][2]bool{{true, false}, {false, true}}, nil, false)
132132
}
133133
func TestDAOInitNoForkPrivnet(t *testing.T) {
134134
testDAOForkBlockNewChain(t, false, daoNoForkGenesis, [][2]bool{}, daoGenesisForkBlock, false)

‎cmd/utils/flags.go‎

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -781,34 +781,43 @@ func MakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfi
781781
Fatalf("Could not make chain configuration: %v", err)
782782
}
783783
}
784-
// Set any missing fields due to them being unset or system upgrade
785-
if config.HomesteadBlock == nil {
786-
if ctx.GlobalBool(TestNetFlag.Name) {
787-
config.HomesteadBlock = params.TestNetHomesteadBlock
788-
} else {
789-
config.HomesteadBlock = params.MainNetHomesteadBlock
784+
// Check whether we are allowed to set default config params or not:
785+
// - If no genesis is set, we're running either mainnet or testnet (private nets use `geth init`)
786+
// - If a genesis is already set, ensure we have a configuration for it (mainnet or testnet)
787+
defaults := genesis == nil ||
788+
(genesis.Hash() == params.MainNetGenesisHash && !ctx.GlobalBool(TestNetFlag.Name)) ||
789+
(genesis.Hash() == params.TestNetGenesisHash && ctx.GlobalBool(TestNetFlag.Name))
790+
791+
// Set any missing chainConfig fields due to them being unset or system upgrade
792+
if defaults {
793+
if config.HomesteadBlock == nil {
794+
if ctx.GlobalBool(TestNetFlag.Name) {
795+
config.HomesteadBlock = params.TestNetHomesteadBlock
796+
} else {
797+
config.HomesteadBlock = params.MainNetHomesteadBlock
798+
}
790799
}
791-
}
792-
if config.DAOForkBlock == nil {
793-
if ctx.GlobalBool(TestNetFlag.Name) {
794-
config.DAOForkBlock = params.TestNetDAOForkBlock
795-
} else {
796-
config.DAOForkBlock = params.MainNetDAOForkBlock
800+
if config.DAOForkBlock == nil {
801+
if ctx.GlobalBool(TestNetFlag.Name) {
802+
config.DAOForkBlock = params.TestNetDAOForkBlock
803+
} else {
804+
config.DAOForkBlock = params.MainNetDAOForkBlock
805+
}
806+
config.DAOForkSupport = true
797807
}
798-
config.DAOForkSupport = true
799-
}
800-
if config.HomesteadGasRepriceBlock == nil {
801-
if ctx.GlobalBool(TestNetFlag.Name) {
802-
config.HomesteadGasRepriceBlock = params.TestNetHomesteadGasRepriceBlock
803-
} else {
804-
config.HomesteadGasRepriceBlock = params.MainNetHomesteadGasRepriceBlock
808+
if config.HomesteadGasRepriceBlock == nil {
809+
if ctx.GlobalBool(TestNetFlag.Name) {
810+
config.HomesteadGasRepriceBlock = params.TestNetHomesteadGasRepriceBlock
811+
} else {
812+
config.HomesteadGasRepriceBlock = params.MainNetHomesteadGasRepriceBlock
813+
}
805814
}
806-
}
807-
if config.HomesteadGasRepriceHash == (common.Hash{}) {
808-
if ctx.GlobalBool(TestNetFlag.Name) {
809-
config.HomesteadGasRepriceHash = params.TestNetHomesteadGasRepriceHash
810-
} else {
811-
config.HomesteadGasRepriceHash = params.MainNetHomesteadGasRepriceHash
815+
if config.HomesteadGasRepriceHash == (common.Hash{}) {
816+
if ctx.GlobalBool(TestNetFlag.Name) {
817+
config.HomesteadGasRepriceHash = params.TestNetHomesteadGasRepriceHash
818+
} else {
819+
config.HomesteadGasRepriceHash = params.MainNetHomesteadGasRepriceHash
820+
}
812821
}
813822
}
814823
// Force override any existing configs if explicitly requested

‎core/block_validator.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func ValidateHeader(config *ChainConfig, pow pow.PoW, header *types.Header, pare
253253
}
254254
if config.HomesteadGasRepriceBlock != nil && config.HomesteadGasRepriceBlock.Cmp(header.Number) == 0 {
255255
if config.HomesteadGasRepriceHash != (common.Hash{}) && config.HomesteadGasRepriceHash != header.Hash() {
256-
return ValidationError("Homestead gas reprice fork hash mismatch: have 0x%x, want 0x%x", header.Hash(), config.HomesteadGasRepriceBlock)
256+
return ValidationError("Homestead gas reprice fork hash mismatch: have 0x%x, want 0x%x", header.Hash(), config.HomesteadGasRepriceHash)
257257
}
258258
}
259259
return nil

‎params/util.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import (
2323
)
2424

2525
var (
26+
TestNetGenesisHash = common.HexToHash("0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303") // Testnet genesis hash to enforce below configs on
27+
MainNetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3") // Mainnet genesis hash to enforce below configs on
28+
2629
TestNetHomesteadBlock = big.NewInt(494000) // Testnet homestead block
2730
MainNetHomesteadBlock = big.NewInt(1150000) // Mainnet homestead block
2831

0 commit comments

Comments
 (0)