Skip to content

Commit bc01593

Browse files
holimankaralabe
authored andcommitted
consensus/ethash, params: eip-2384: bump difficulty bomb (#20347)
* consensus/ethash, params: implement eip-2384: bump difficulty bomb * params: EIP 2384 compat checks * consensus, params: add Muir Glacier block number (mainnet,ropsten) + official name * core/forkid: forkid tests for muir glacier * params/config: address review concerns * params, core/forkid: review nitpicks * cmd/geth,eth,les: add override option for muir glacier * params: nit fix
1 parent c9dce0b commit bc01593

File tree

10 files changed

+53
-14
lines changed

10 files changed

+53
-14
lines changed

cmd/geth/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ func makeFullNode(ctx *cli.Context) *node.Node {
150150
if ctx.GlobalIsSet(utils.OverrideIstanbulFlag.Name) {
151151
cfg.Eth.OverrideIstanbul = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideIstanbulFlag.Name))
152152
}
153+
if ctx.GlobalIsSet(utils.OverrideMuirGlacierFlag.Name) {
154+
cfg.Eth.OverrideMuirGlacier = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideMuirGlacierFlag.Name))
155+
}
153156
utils.RegisterEthService(stack, &cfg.Eth)
154157

155158
// Whisper must be explicitly enabled by specifying at least 1 whisper flag or in dev mode

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ var (
7070
utils.NoUSBFlag,
7171
utils.SmartCardDaemonPathFlag,
7272
utils.OverrideIstanbulFlag,
73+
utils.OverrideMuirGlacierFlag,
7374
utils.EthashCacheDirFlag,
7475
utils.EthashCachesInMemoryFlag,
7576
utils.EthashCachesOnDiskFlag,

cmd/utils/flags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ var (
237237
Name: "override.istanbul",
238238
Usage: "Manually specify Istanbul fork-block, overriding the bundled setting",
239239
}
240+
OverrideMuirGlacierFlag = cli.Uint64Flag{
241+
Name: "override.muirglacier",
242+
Usage: "Manually specify Muir Glacier fork-block, overriding the bundled setting",
243+
}
240244
// Light server and client settings
241245
LightLegacyServFlag = cli.IntFlag{ // Deprecated in favor of light.serve, remove in 2021
242246
Name: "lightserv",

consensus/ethash/consensus.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ var (
4444
maxUncles = 2 // Maximum number of uncles allowed in a single block
4545
allowedFutureBlockTime = 15 * time.Second // Max time from current time allowed for blocks, before they're considered future blocks
4646

47+
// calcDifficultyEip2384 is the difficulty adjustment algorithm as specified by EIP 2384.
48+
// It offsets the bomb 4M blocks from Constantinople, so in total 9M blocks.
49+
// Specification EIP-2384: https://eips.ethereum.org/EIPS/eip-2384
50+
calcDifficultyEip2384 = makeDifficultyCalculator(big.NewInt(9000000))
51+
4752
// calcDifficultyConstantinople is the difficulty adjustment algorithm for Constantinople.
4853
// It returns the difficulty that a new block should have when created at time given the
4954
// parent block's time and difficulty. The calculation uses the Byzantium rules, but with
@@ -311,6 +316,8 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, p
311316
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
312317
next := new(big.Int).Add(parent.Number, big1)
313318
switch {
319+
case config.IsMuirGlacier(next):
320+
return calcDifficultyEip2384(time, parent)
314321
case config.IsConstantinople(next):
315322
return calcDifficultyConstantinople(time, parent)
316323
case config.IsByzantium(next):

core/forkid/forkid_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ func TestCreation(t *testing.T) {
5757
{7279999, ID{Hash: checksumToBytes(0xa00bc324), Next: 7280000}}, // Last Byzantium block
5858
{7280000, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // First and last Constantinople, first Petersburg block
5959
{9068999, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // Last Petersburg block
60-
{9069000, ID{Hash: checksumToBytes(0x879d6e30), Next: 0}}, // Today Istanbul block
61-
{10000000, ID{Hash: checksumToBytes(0x879d6e30), Next: 0}}, // Future Istanbul block
60+
{9069000, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // First Istanbul and first Muir Glacier block
61+
{9199999, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // Last Istanbul and first Muir Glacier block
62+
{9200000, ID{Hash: checksumToBytes(0xe029e991), Next: 0}}, // First Muir Glacier block
63+
{10000000, ID{Hash: checksumToBytes(0xe029e991), Next: 0}}, // Future Muir Glacier block
6264
},
6365
},
6466
// Ropsten test cases
@@ -76,8 +78,10 @@ func TestCreation(t *testing.T) {
7678
{4939393, ID{Hash: checksumToBytes(0x97b544f3), Next: 4939394}}, // Last Constantinople block
7779
{4939394, ID{Hash: checksumToBytes(0xd6e2149b), Next: 6485846}}, // First Petersburg block
7880
{6485845, ID{Hash: checksumToBytes(0xd6e2149b), Next: 6485846}}, // Last Petersburg block
79-
{6485846, ID{Hash: checksumToBytes(0x4bc66396), Next: 0}}, // First Istanbul block
80-
{7500000, ID{Hash: checksumToBytes(0x4bc66396), Next: 0}}, // Future Istanbul block
81+
{6485846, ID{Hash: checksumToBytes(0x4bc66396), Next: 7117117}}, // First Istanbul block
82+
{7117116, ID{Hash: checksumToBytes(0x4bc66396), Next: 7117117}}, // Last Istanbul block
83+
{7117117, ID{Hash: checksumToBytes(0x6727ef90), Next: 0}}, // First Muir Glacier block
84+
{7500000, ID{Hash: checksumToBytes(0x6727ef90), Next: 0}}, // Future
8185
},
8286
},
8387
// Rinkeby test cases
@@ -181,11 +185,11 @@ func TestValidation(t *testing.T) {
181185
// Local is mainnet Petersburg, remote is Rinkeby Petersburg.
182186
{7987396, ID{Hash: checksumToBytes(0xafec6b27), Next: 0}, ErrLocalIncompatibleOrStale},
183187

184-
// Local is mainnet Istanbul, far in the future. Remote announces Gopherium (non existing fork)
188+
// Local is mainnet Muir Glacier, far in the future. Remote announces Gopherium (non existing fork)
185189
// at some future block 88888888, for itself, but past block for local. Local is incompatible.
186190
//
187191
// This case detects non-upgraded nodes with majority hash power (typical Ropsten mess).
188-
{88888888, ID{Hash: checksumToBytes(0x879d6e30), Next: 88888888}, ErrLocalIncompatibleOrStale},
192+
{88888888, ID{Hash: checksumToBytes(0xe029e991), Next: 88888888}, ErrLocalIncompatibleOrStale},
189193

190194
// Local is mainnet Byzantium. Remote is also in Byzantium, but announces Gopherium (non existing
191195
// fork) at block 7279999, before Petersburg. Local is incompatible.

core/genesis.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ func (e *GenesisMismatchError) Error() string {
152152
//
153153
// The returned chain configuration is never nil.
154154
func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) {
155-
return SetupGenesisBlockWithOverride(db, genesis, nil)
155+
return SetupGenesisBlockWithOverride(db, genesis, nil, nil)
156156
}
157157

158-
func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideIstanbul *big.Int) (*params.ChainConfig, common.Hash, error) {
158+
func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideIstanbul, overrideMuirGlacier *big.Int) (*params.ChainConfig, common.Hash, error) {
159159
if genesis != nil && genesis.Config == nil {
160160
return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
161161
}
@@ -207,6 +207,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
207207
if overrideIstanbul != nil {
208208
newcfg.IstanbulBlock = overrideIstanbul
209209
}
210+
if overrideMuirGlacier != nil {
211+
newcfg.MuirGlacierBlock = overrideMuirGlacier
212+
}
210213
if err := newcfg.CheckConfigForkOrder(); err != nil {
211214
return newcfg, common.Hash{}, err
212215
}

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
135135
if err != nil {
136136
return nil, err
137137
}
138-
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideIstanbul)
138+
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideIstanbul, config.OverrideMuirGlacier)
139139
if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok {
140140
return nil, genesisErr
141141
}

eth/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,7 @@ type Config struct {
157157

158158
// Istanbul block override (TODO: remove after the fork)
159159
OverrideIstanbul *big.Int
160+
161+
// MuirGlacier block override (TODO: remove after the fork)
162+
OverrideMuirGlacier *big.Int
160163
}

les/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
7272
if err != nil {
7373
return nil, err
7474
}
75-
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideIstanbul)
75+
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis,
76+
config.OverrideIstanbul, config.OverrideMuirGlacier)
7677
if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat {
7778
return nil, genesisErr
7879
}

params/config.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var (
6666
ConstantinopleBlock: big.NewInt(7280000),
6767
PetersburgBlock: big.NewInt(7280000),
6868
IstanbulBlock: big.NewInt(9069000),
69+
MuirGlacierBlock: big.NewInt(9200000),
6970
Ethash: new(EthashConfig),
7071
}
7172

@@ -104,6 +105,7 @@ var (
104105
ConstantinopleBlock: big.NewInt(4230000),
105106
PetersburgBlock: big.NewInt(4939394),
106107
IstanbulBlock: big.NewInt(6485846),
108+
MuirGlacierBlock: big.NewInt(7117117),
107109
Ethash: new(EthashConfig),
108110
}
109111

@@ -213,16 +215,16 @@ var (
213215
//
214216
// This configuration is intentionally not using keyed fields to force anyone
215217
// adding flags to the config to also have to set these fields.
216-
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}
218+
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}
217219

218220
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
219221
// and accepted by the Ethereum core developers into the Clique consensus.
220222
//
221223
// This configuration is intentionally not using keyed fields to force anyone
222224
// adding flags to the config to also have to set these fields.
223-
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}}
225+
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}}
224226

225-
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}
227+
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}
226228
TestRules = TestChainConfig.Rules(new(big.Int))
227229
)
228230

@@ -292,6 +294,7 @@ type ChainConfig struct {
292294
ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated)
293295
PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople)
294296
IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul)
297+
MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated)
295298
EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated)
296299

297300
// Various consensus engines
@@ -329,7 +332,7 @@ func (c *ChainConfig) String() string {
329332
default:
330333
engine = "unknown"
331334
}
332-
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}",
335+
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}",
333336
c.ChainID,
334337
c.HomesteadBlock,
335338
c.DAOForkBlock,
@@ -341,6 +344,7 @@ func (c *ChainConfig) String() string {
341344
c.ConstantinopleBlock,
342345
c.PetersburgBlock,
343346
c.IstanbulBlock,
347+
c.MuirGlacierBlock,
344348
engine,
345349
)
346350
}
@@ -380,6 +384,11 @@ func (c *ChainConfig) IsConstantinople(num *big.Int) bool {
380384
return isForked(c.ConstantinopleBlock, num)
381385
}
382386

387+
// IsMuirGlacier returns whether num is either equal to the Muir Glacier (EIP-2384) fork block or greater.
388+
func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool {
389+
return isForked(c.MuirGlacierBlock, num)
390+
}
391+
383392
// IsPetersburg returns whether num is either
384393
// - equal to or greater than the PetersburgBlock fork block,
385394
// - OR is nil, and Constantinople is active
@@ -432,6 +441,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
432441
{"constantinopleBlock", c.ConstantinopleBlock},
433442
{"petersburgBlock", c.PetersburgBlock},
434443
{"istanbulBlock", c.IstanbulBlock},
444+
{"muirGlacierBlock", c.MuirGlacierBlock},
435445
} {
436446
if lastFork.name != "" {
437447
// Next one must be higher number
@@ -485,6 +495,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
485495
if isForkIncompatible(c.IstanbulBlock, newcfg.IstanbulBlock, head) {
486496
return newCompatError("Istanbul fork block", c.IstanbulBlock, newcfg.IstanbulBlock)
487497
}
498+
if isForkIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, head) {
499+
return newCompatError("Muir Glacier fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock)
500+
}
488501
if isForkIncompatible(c.EWASMBlock, newcfg.EWASMBlock, head) {
489502
return newCompatError("ewasm fork block", c.EWASMBlock, newcfg.EWASMBlock)
490503
}

0 commit comments

Comments
 (0)