From b039981dff8df0251a5ff72e24e7637de5751ef2 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 21 Nov 2019 10:12:38 +0100 Subject: [PATCH 1/8] consensus/ethash, params: implement eip-2384: bump difficulty bomb --- consensus/ethash/consensus.go | 8 ++++++++ params/config.go | 12 +++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 3cff2d9fe5d4..9ed146705298 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -44,6 +44,12 @@ var ( maxUncles = 2 // Maximum number of uncles allowed in a single block allowedFutureBlockTime = 15 * time.Second // Max time from current time allowed for blocks, before they're considered future blocks + // calcDifficultyEip2384 is the difficulty adjustment algorithm as specified by EIP 2384. + // It offsets the bomb 4M blocks from Constantinople, so in total 9M blocks. + // Specification EIP-2384 :https://github.com/ethereum/EIPs/pull/2384 + // TODO: change link once it's merged + calcDifficultyEip2384 = makeDifficultyCalculator(big.NewInt(9000000)) + // calcDifficultyConstantinople is the difficulty adjustment algorithm for Constantinople. // It returns the difficulty that a new block should have when created at time given the // parent block's time and difficulty. The calculation uses the Byzantium rules, but with @@ -311,6 +317,8 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, p func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int { next := new(big.Int).Add(parent.Number, big1) switch { + case config.IsEip2384(next): + return calcDifficultyEip2384(time, parent) case config.IsConstantinople(next): return calcDifficultyConstantinople(time, parent) case config.IsByzantium(next): diff --git a/params/config.go b/params/config.go index 176247a30ab2..591226da7619 100644 --- a/params/config.go +++ b/params/config.go @@ -213,16 +213,16 @@ var ( // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil} + AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil} // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced // and accepted by the Ethereum core developers into the Clique consensus. // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}} + AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}} - TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil} + TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil} TestRules = TestChainConfig.Rules(new(big.Int)) ) @@ -293,6 +293,7 @@ type ChainConfig struct { PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople) IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul) EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated) + EIP2384Block *big.Int `json:"eip2384Block,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated) // Various consensus engines Ethash *EthashConfig `json:"ethash,omitempty"` @@ -380,6 +381,10 @@ func (c *ChainConfig) IsConstantinople(num *big.Int) bool { return isForked(c.ConstantinopleBlock, num) } +func (c *ChainConfig) IsEip2384(num *big.Int) bool { + return isForked(c.EIP2384Block, num) +} + // IsPetersburg returns whether num is either // - equal to or greater than the PetersburgBlock fork block, // - OR is nil, and Constantinople is active @@ -432,6 +437,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {"constantinopleBlock", c.ConstantinopleBlock}, {"petersburgBlock", c.PetersburgBlock}, {"istanbulBlock", c.IstanbulBlock}, + {"eip2384Block", c.EIP2384Block}, } { if lastFork.name != "" { // Next one must be higher number From cdeba1406e8e94ba6c026afb6931545e54df82dd Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 21 Nov 2019 10:41:46 +0100 Subject: [PATCH 2/8] params: EIP 2384 compat checks --- params/config.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/params/config.go b/params/config.go index 591226da7619..d84c4e954cfc 100644 --- a/params/config.go +++ b/params/config.go @@ -292,8 +292,8 @@ type ChainConfig struct { ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated) PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople) IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul) - EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated) EIP2384Block *big.Int `json:"eip2384Block,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated) + EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated) // Various consensus engines Ethash *EthashConfig `json:"ethash,omitempty"` @@ -330,7 +330,7 @@ func (c *ChainConfig) String() string { default: engine = "unknown" } - return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v Engine: %v}", + return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, EIP-2384: %v, Engine: %v}", c.ChainID, c.HomesteadBlock, c.DAOForkBlock, @@ -342,6 +342,7 @@ func (c *ChainConfig) String() string { c.ConstantinopleBlock, c.PetersburgBlock, c.IstanbulBlock, + c.EIP2384Block, engine, ) } @@ -491,6 +492,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi if isForkIncompatible(c.IstanbulBlock, newcfg.IstanbulBlock, head) { return newCompatError("Istanbul fork block", c.IstanbulBlock, newcfg.IstanbulBlock) } + if isForkIncompatible(c.EIP2384Block, newcfg.EIP2384Block, head) { + return newCompatError("EIP-2348 fork block", c.EIP2384Block, newcfg.EIP2384Block) + } if isForkIncompatible(c.EWASMBlock, newcfg.EWASMBlock, head) { return newCompatError("ewasm fork block", c.EWASMBlock, newcfg.EWASMBlock) } From a966a37e5975569a1b195f9caa5ad4fc5c6ce59d Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 2 Dec 2019 09:54:21 +0100 Subject: [PATCH 3/8] consensus, params: add Muir Glacier block number (mainnet,ropsten) + official name --- consensus/ethash/consensus.go | 3 +-- params/config.go | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 9ed146705298..077c73692675 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -46,8 +46,7 @@ var ( // calcDifficultyEip2384 is the difficulty adjustment algorithm as specified by EIP 2384. // It offsets the bomb 4M blocks from Constantinople, so in total 9M blocks. - // Specification EIP-2384 :https://github.com/ethereum/EIPs/pull/2384 - // TODO: change link once it's merged + // Specification EIP-2384: https://eips.ethereum.org/EIPS/eip-2384 calcDifficultyEip2384 = makeDifficultyCalculator(big.NewInt(9000000)) // calcDifficultyConstantinople is the difficulty adjustment algorithm for Constantinople. diff --git a/params/config.go b/params/config.go index d84c4e954cfc..62554cc8fb8e 100644 --- a/params/config.go +++ b/params/config.go @@ -66,6 +66,7 @@ var ( ConstantinopleBlock: big.NewInt(7280000), PetersburgBlock: big.NewInt(7280000), IstanbulBlock: big.NewInt(9069000), + EIP2384Block: big.NewInt(9200000), Ethash: new(EthashConfig), } @@ -104,6 +105,7 @@ var ( ConstantinopleBlock: big.NewInt(4230000), PetersburgBlock: big.NewInt(4939394), IstanbulBlock: big.NewInt(6485846), + EIP2384Block: big.NewInt(7117117), Ethash: new(EthashConfig), } @@ -292,7 +294,7 @@ type ChainConfig struct { ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated) PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople) IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul) - EIP2384Block *big.Int `json:"eip2384Block,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated) + EIP2384Block *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated) EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated) // Various consensus engines @@ -382,6 +384,7 @@ func (c *ChainConfig) IsConstantinople(num *big.Int) bool { return isForked(c.ConstantinopleBlock, num) } +// IsEip2384 returns whether num is equal or greater than the EIP 2384 block func (c *ChainConfig) IsEip2384(num *big.Int) bool { return isForked(c.EIP2384Block, num) } From da43f2c81f8a64e2adb9ee94bc02b5bee02f3a5b Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 5 Dec 2019 10:47:29 +0100 Subject: [PATCH 4/8] core/forkid: forkid tests for muir glacier --- core/forkid/forkid_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/forkid/forkid_test.go b/core/forkid/forkid_test.go index ee201ae9ae3d..4d4dd0b6f428 100644 --- a/core/forkid/forkid_test.go +++ b/core/forkid/forkid_test.go @@ -57,8 +57,10 @@ func TestCreation(t *testing.T) { {7279999, ID{Hash: checksumToBytes(0xa00bc324), Next: 7280000}}, // Last Byzantium block {7280000, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // First and last Constantinople, first Petersburg block {9068999, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // Last Petersburg block - {9069000, ID{Hash: checksumToBytes(0x879d6e30), Next: 0}}, // Today Istanbul block - {10000000, ID{Hash: checksumToBytes(0x879d6e30), Next: 0}}, // Future Istanbul block + {9069000, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // Muir Glacier block + {9199999, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // Muir Glacier block + {9200000, ID{Hash: checksumToBytes(0xe029e991), Next: 0}}, // Future Istanbul block + {10000000, ID{Hash: checksumToBytes(0xe029e991), Next: 0}}, // Future Istanbul block }, }, // Ropsten test cases @@ -76,8 +78,10 @@ func TestCreation(t *testing.T) { {4939393, ID{Hash: checksumToBytes(0x97b544f3), Next: 4939394}}, // Last Constantinople block {4939394, ID{Hash: checksumToBytes(0xd6e2149b), Next: 6485846}}, // First Petersburg block {6485845, ID{Hash: checksumToBytes(0xd6e2149b), Next: 6485846}}, // Last Petersburg block - {6485846, ID{Hash: checksumToBytes(0x4bc66396), Next: 0}}, // First Istanbul block - {7500000, ID{Hash: checksumToBytes(0x4bc66396), Next: 0}}, // Future Istanbul block + {6485846, ID{Hash: checksumToBytes(0x4bc66396), Next: 7117117}}, // First Istanbul block + {7117116, ID{Hash: checksumToBytes(0x4bc66396), Next: 7117117}}, // Last Istanbul block + {7117117, ID{Hash: checksumToBytes(0x6727ef90), Next: 0}}, // First Muir Glacier block + {7500000, ID{Hash: checksumToBytes(0x6727ef90), Next: 0}}, // Future }, }, // Rinkeby test cases @@ -181,11 +185,11 @@ func TestValidation(t *testing.T) { // Local is mainnet Petersburg, remote is Rinkeby Petersburg. {7987396, ID{Hash: checksumToBytes(0xafec6b27), Next: 0}, ErrLocalIncompatibleOrStale}, - // Local is mainnet Istanbul, far in the future. Remote announces Gopherium (non existing fork) + // Local is mainnet Muir Glacier, far in the future. Remote announces Gopherium (non existing fork) // at some future block 88888888, for itself, but past block for local. Local is incompatible. // // This case detects non-upgraded nodes with majority hash power (typical Ropsten mess). - {88888888, ID{Hash: checksumToBytes(0x879d6e30), Next: 88888888}, ErrLocalIncompatibleOrStale}, + {88888888, ID{Hash: checksumToBytes(0xe029e991), Next: 88888888}, ErrLocalIncompatibleOrStale}, // Local is mainnet Byzantium. Remote is also in Byzantium, but announces Gopherium (non existing // fork) at block 7279999, before Petersburg. Local is incompatible. From de424f357e78fc28fafec08147e8f99c1868f51c Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 5 Dec 2019 10:57:10 +0100 Subject: [PATCH 5/8] params/config: address review concerns --- consensus/ethash/consensus.go | 2 +- params/config.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 077c73692675..270c5358dd0e 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -316,7 +316,7 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, p func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int { next := new(big.Int).Add(parent.Number, big1) switch { - case config.IsEip2384(next): + case config.IsMuirGlacier(next): return calcDifficultyEip2384(time, parent) case config.IsConstantinople(next): return calcDifficultyConstantinople(time, parent) diff --git a/params/config.go b/params/config.go index 62554cc8fb8e..9b3935bc903c 100644 --- a/params/config.go +++ b/params/config.go @@ -384,8 +384,8 @@ func (c *ChainConfig) IsConstantinople(num *big.Int) bool { return isForked(c.ConstantinopleBlock, num) } -// IsEip2384 returns whether num is equal or greater than the EIP 2384 block -func (c *ChainConfig) IsEip2384(num *big.Int) bool { +// IsMuirGlacier returns whether num is either equal to the Muir Glacier (EIP-2384) fork block or greater. +func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool { return isForked(c.EIP2384Block, num) } From 51172f0a8805849d3e00d2ce82bbeeb2c72138ee Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 5 Dec 2019 19:31:58 +0100 Subject: [PATCH 6/8] params, core/forkid: review nitpicks --- core/forkid/forkid_test.go | 8 ++++---- params/config.go | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/forkid/forkid_test.go b/core/forkid/forkid_test.go index 4d4dd0b6f428..f3364c3d6964 100644 --- a/core/forkid/forkid_test.go +++ b/core/forkid/forkid_test.go @@ -57,10 +57,10 @@ func TestCreation(t *testing.T) { {7279999, ID{Hash: checksumToBytes(0xa00bc324), Next: 7280000}}, // Last Byzantium block {7280000, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // First and last Constantinople, first Petersburg block {9068999, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // Last Petersburg block - {9069000, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // Muir Glacier block - {9199999, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // Muir Glacier block - {9200000, ID{Hash: checksumToBytes(0xe029e991), Next: 0}}, // Future Istanbul block - {10000000, ID{Hash: checksumToBytes(0xe029e991), Next: 0}}, // Future Istanbul block + {9069000, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // First Istanbul and first Muir Glacier block + {9199999, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // Last Istanbul and first Muir Glacier block + {9200000, ID{Hash: checksumToBytes(0xe029e991), Next: 0}}, // First Muir Glacier block + {10000000, ID{Hash: checksumToBytes(0xe029e991), Next: 0}}, // Future Muir Glacier block }, }, // Ropsten test cases diff --git a/params/config.go b/params/config.go index 9b3935bc903c..7e11f7df73ac 100644 --- a/params/config.go +++ b/params/config.go @@ -66,7 +66,7 @@ var ( ConstantinopleBlock: big.NewInt(7280000), PetersburgBlock: big.NewInt(7280000), IstanbulBlock: big.NewInt(9069000), - EIP2384Block: big.NewInt(9200000), + MuirGlacierBlock: big.NewInt(9200000), Ethash: new(EthashConfig), } @@ -105,7 +105,7 @@ var ( ConstantinopleBlock: big.NewInt(4230000), PetersburgBlock: big.NewInt(4939394), IstanbulBlock: big.NewInt(6485846), - EIP2384Block: big.NewInt(7117117), + MuirGlacierBlock: big.NewInt(7117117), Ethash: new(EthashConfig), } @@ -294,7 +294,7 @@ type ChainConfig struct { ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated) PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople) IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul) - EIP2384Block *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated) + MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated) EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated) // Various consensus engines @@ -332,7 +332,7 @@ func (c *ChainConfig) String() string { default: engine = "unknown" } - return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, EIP-2384: %v, Engine: %v}", + return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Engine: %v}", c.ChainID, c.HomesteadBlock, c.DAOForkBlock, @@ -344,7 +344,7 @@ func (c *ChainConfig) String() string { c.ConstantinopleBlock, c.PetersburgBlock, c.IstanbulBlock, - c.EIP2384Block, + c.MuirGlacierBlock, engine, ) } @@ -386,7 +386,7 @@ func (c *ChainConfig) IsConstantinople(num *big.Int) bool { // IsMuirGlacier returns whether num is either equal to the Muir Glacier (EIP-2384) fork block or greater. func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool { - return isForked(c.EIP2384Block, num) + return isForked(c.MuirGlacierBlock, num) } // IsPetersburg returns whether num is either @@ -441,7 +441,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {"constantinopleBlock", c.ConstantinopleBlock}, {"petersburgBlock", c.PetersburgBlock}, {"istanbulBlock", c.IstanbulBlock}, - {"eip2384Block", c.EIP2384Block}, + {"muirGlacierBlock", c.MuirGlacierBlock}, } { if lastFork.name != "" { // Next one must be higher number @@ -495,8 +495,8 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi if isForkIncompatible(c.IstanbulBlock, newcfg.IstanbulBlock, head) { return newCompatError("Istanbul fork block", c.IstanbulBlock, newcfg.IstanbulBlock) } - if isForkIncompatible(c.EIP2384Block, newcfg.EIP2384Block, head) { - return newCompatError("EIP-2348 fork block", c.EIP2384Block, newcfg.EIP2384Block) + if isForkIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, head) { + return newCompatError("EIP-2348 fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock) } if isForkIncompatible(c.EWASMBlock, newcfg.EWASMBlock, head) { return newCompatError("ewasm fork block", c.EWASMBlock, newcfg.EWASMBlock) From ae43a4752fe149bfee59e92102bf1ba6e53e492e Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Fri, 6 Dec 2019 09:41:33 +0100 Subject: [PATCH 7/8] cmd/geth,eth,les: add override option for muir glacier --- cmd/geth/config.go | 3 +++ cmd/geth/main.go | 1 + cmd/utils/flags.go | 4 ++++ core/genesis.go | 7 +++++-- eth/backend.go | 2 +- eth/config.go | 3 +++ les/client.go | 3 ++- 7 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 3fe8bd76683a..b450dd9c8bd4 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -150,6 +150,9 @@ func makeFullNode(ctx *cli.Context) *node.Node { if ctx.GlobalIsSet(utils.OverrideIstanbulFlag.Name) { cfg.Eth.OverrideIstanbul = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideIstanbulFlag.Name)) } + if ctx.GlobalIsSet(utils.OverrideMuirGlacierFlag.Name) { + cfg.Eth.OverrideMuirGlacier = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideMuirGlacierFlag.Name)) + } utils.RegisterEthService(stack, &cfg.Eth) // Whisper must be explicitly enabled by specifying at least 1 whisper flag or in dev mode diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 7cfa3e8adf5c..80ab0a44d86c 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -70,6 +70,7 @@ var ( utils.NoUSBFlag, utils.SmartCardDaemonPathFlag, utils.OverrideIstanbulFlag, + utils.OverrideMuirGlacierFlag, utils.EthashCacheDirFlag, utils.EthashCachesInMemoryFlag, utils.EthashCachesOnDiskFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 4780a81373b1..238577ee6efd 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -226,6 +226,10 @@ var ( Name: "override.istanbul", Usage: "Manually specify Istanbul fork-block, overriding the bundled setting", } + OverrideMuirGlacierFlag = cli.Uint64Flag{ + Name: "override.muirglacier", + Usage: "Manually specify Muir Glacier fork-block, overriding the bundled setting", + } // Light server and client settings LightLegacyServFlag = cli.IntFlag{ // Deprecated in favor of light.serve, remove in 2021 Name: "lightserv", diff --git a/core/genesis.go b/core/genesis.go index df0c96798031..e15cffda6baf 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -152,10 +152,10 @@ func (e *GenesisMismatchError) Error() string { // // The returned chain configuration is never nil. func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) { - return SetupGenesisBlockWithOverride(db, genesis, nil) + return SetupGenesisBlockWithOverride(db, genesis, nil, nil) } -func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideIstanbul *big.Int) (*params.ChainConfig, common.Hash, error) { +func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideIstanbul, overrideMuirGlacier *big.Int) (*params.ChainConfig, common.Hash, error) { if genesis != nil && genesis.Config == nil { return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig } @@ -207,6 +207,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override if overrideIstanbul != nil { newcfg.IstanbulBlock = overrideIstanbul } + if overrideMuirGlacier != nil { + newcfg.MuirGlacierBlock = overrideMuirGlacier + } if err := newcfg.CheckConfigForkOrder(); err != nil { return newcfg, common.Hash{}, err } diff --git a/eth/backend.go b/eth/backend.go index 83e05e96a88e..adde609de096 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -135,7 +135,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { if err != nil { return nil, err } - chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideIstanbul) + chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideIstanbul, config.OverrideMuirGlacier) if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok { return nil, genesisErr } diff --git a/eth/config.go b/eth/config.go index 5094a533bf4b..82403911148e 100644 --- a/eth/config.go +++ b/eth/config.go @@ -157,4 +157,7 @@ type Config struct { // Istanbul block override (TODO: remove after the fork) OverrideIstanbul *big.Int + + // MuirGlacier block override (TODO: remove after the fork) + OverrideMuirGlacier *big.Int } diff --git a/les/client.go b/les/client.go index 1ad44e16d7ef..c460f4c09d5d 100644 --- a/les/client.go +++ b/les/client.go @@ -72,7 +72,8 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) { if err != nil { return nil, err } - chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideIstanbul) + chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, + config.OverrideIstanbul, config.OverrideMuirGlacier) if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat { return nil, genesisErr } From b7261254a1ed077bed2cdefa6f456954b2b84099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 6 Dec 2019 11:27:25 +0200 Subject: [PATCH 8/8] params: nit fix --- params/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/config.go b/params/config.go index 7e11f7df73ac..f7a55701f12e 100644 --- a/params/config.go +++ b/params/config.go @@ -496,7 +496,7 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi return newCompatError("Istanbul fork block", c.IstanbulBlock, newcfg.IstanbulBlock) } if isForkIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, head) { - return newCompatError("EIP-2348 fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock) + return newCompatError("Muir Glacier fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock) } if isForkIncompatible(c.EWASMBlock, newcfg.EWASMBlock, head) { return newCompatError("ewasm fork block", c.EWASMBlock, newcfg.EWASMBlock)