From 1214302a194bc1cda024f528f8f5c46840d80c60 Mon Sep 17 00:00:00 2001 From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com> Date: Sun, 31 Oct 2021 14:31:18 +0100 Subject: [PATCH] Arrow Glacier network upgrade (#2896) --- consensus/ethash/consensus.go | 9 +++++-- consensus/misc/eip1559_test.go | 1 + core/forkid/forkid_test.go | 10 +++++--- core/vm/runtime/runtime.go | 1 + params/config.go | 45 +++++++++++++++++----------------- 5 files changed, 38 insertions(+), 28 deletions(-) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index eafc3220c2e..fea876d5f3d 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -50,6 +50,11 @@ var ( maxUncles = 2 // Maximum number of uncles allowed in a single block allowedFutureBlockTimeSeconds = int64(15) // Max seconds from current time allowed for blocks, before they're considered future blocks + // calcDifficultyEip4345 is the difficulty adjustment algorithm as specified by EIP 4345. + // It offsets the bomb a total of 10.7M blocks. + // Specification EIP-4345: https://eips.ethereum.org/EIPS/eip-4345 + calcDifficultyEip4345 = makeDifficultyCalculator(10700000) + // calcDifficultyEip3554 is the difficulty adjustment algorithm as specified by EIP 3554. // It offsets the bomb a total of 9.7M blocks. // Specification EIP-3554: https://eips.ethereum.org/EIPS/eip-3554 @@ -345,8 +350,8 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainHeaderReader, time, pa func CalcDifficulty(config *params.ChainConfig, time, parentTime uint64, parentDifficulty *big.Int, parentNumber uint64, parentUncleHash common.Hash) *big.Int { next := parentNumber + 1 switch { - case config.IsCatalyst(next): - return big.NewInt(1) + case config.IsArrowGlacier(next): + return calcDifficultyEip4345(time, parentTime, parentDifficulty, parentNumber, parentUncleHash) case config.IsLondon(next): return calcDifficultyEip3554(time, parentTime, parentDifficulty, parentNumber, parentUncleHash) case config.IsMuirGlacier(next): diff --git a/consensus/misc/eip1559_test.go b/consensus/misc/eip1559_test.go index 6ea0c0086e4..186cb653dad 100644 --- a/consensus/misc/eip1559_test.go +++ b/consensus/misc/eip1559_test.go @@ -44,6 +44,7 @@ func copyConfig(original *params.ChainConfig) *params.ChainConfig { MuirGlacierBlock: original.MuirGlacierBlock, BerlinBlock: original.BerlinBlock, LondonBlock: original.LondonBlock, + ArrowGlacierBlock: original.ArrowGlacierBlock, Ethash: original.Ethash, Clique: original.Clique, } diff --git a/core/forkid/forkid_test.go b/core/forkid/forkid_test.go index cc22b6313ca..21f6f84f1bd 100644 --- a/core/forkid/forkid_test.go +++ b/core/forkid/forkid_test.go @@ -63,8 +63,10 @@ func TestCreation(t *testing.T) { {12243999, ID{Hash: checksumToBytes(0xe029e991), Next: 12244000}}, // Last Muir Glacier block {12244000, ID{Hash: checksumToBytes(0x0eb440f6), Next: 12965000}}, // First Berlin block {12964999, ID{Hash: checksumToBytes(0x0eb440f6), Next: 12965000}}, // Last Berlin block - {12965000, ID{Hash: checksumToBytes(0xb715077d), Next: 0}}, // First London block - {20000000, ID{Hash: checksumToBytes(0xb715077d), Next: 0}}, // Future London block + {12965000, ID{Hash: checksumToBytes(0xb715077d), Next: 13773000}}, // First London block + {13772999, ID{Hash: checksumToBytes(0xb715077d), Next: 13773000}}, // Last London block + {13773000, ID{Hash: checksumToBytes(0x20c327fc), Next: 0}}, // First Arrow Glacier block + {20000000, ID{Hash: checksumToBytes(0x20c327fc), Next: 0}}, // Future Arrow Glacier block }, }, // Ropsten test cases @@ -201,11 +203,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 London, far in the future. Remote announces Gopherium (non existing fork) + // Local is mainnet Arrow 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(0xb715077d), Next: 88888888}, ErrLocalIncompatibleOrStale}, + {88888888, ID{Hash: checksumToBytes(0x20c327fc), 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. diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 82757cabde1..44b372f302f 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -75,6 +75,7 @@ func setDefaults(cfg *Config) { MuirGlacierBlock: new(big.Int), BerlinBlock: new(big.Int), LondonBlock: new(big.Int), + ArrowGlacierBlock: new(big.Int), } } diff --git a/params/config.go b/params/config.go index 01c4802d3b8..b9ebbd919db 100644 --- a/params/config.go +++ b/params/config.go @@ -87,6 +87,7 @@ var ( MuirGlacierBlock: big.NewInt(9_200_000), BerlinBlock: big.NewInt(12_244_000), LondonBlock: big.NewInt(12_965_000), + ArrowGlacierBlock: big.NewInt(13_773_000), Ethash: new(EthashConfig), } @@ -178,6 +179,8 @@ var ( IstanbulBlock: big.NewInt(0), MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), + LondonBlock: nil, + ArrowGlacierBlock: nil, Ethash: new(EthashConfig), } @@ -241,8 +244,8 @@ var ( MuirGlacierBlock: nil, BerlinBlock: big.NewInt(21050600), //LondonBlock: big.NewInt(21050600), - CatalystBlock: nil, - Aura: &AuRaConfig{}, + ArrowGlacierBlock: nil, + Aura: &AuRaConfig{}, } KovanChainConfig = &ChainConfig{ @@ -262,7 +265,7 @@ var ( MuirGlacierBlock: nil, BerlinBlock: big.NewInt(24770900), LondonBlock: big.NewInt(26741100), - CatalystBlock: nil, + ArrowGlacierBlock: nil, Aura: &AuRaConfig{}, } @@ -283,7 +286,7 @@ var ( MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - CatalystBlock: nil, + ArrowGlacierBlock: nil, Clique: &CliqueConfig{ Period: 15, Epoch: 30000, @@ -292,9 +295,6 @@ var ( // AllEthashProtocolChanges contains every protocol change (EIPs) introduced // and accepted by the Ethereum core developers into the Ethash consensus. - // - // 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{ ChainID: big.NewInt(1337), Consensus: EtHashConsensus, @@ -312,16 +312,13 @@ var ( MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: nil, - CatalystBlock: nil, + ArrowGlacierBlock: nil, Ethash: new(EthashConfig), Clique: 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{ ChainID: big.NewInt(1337), Consensus: CliqueConsensus, @@ -339,7 +336,7 @@ var ( MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - CatalystBlock: nil, + ArrowGlacierBlock: nil, Ethash: nil, Clique: &CliqueConfig{Period: 0, Epoch: 30000}, } @@ -363,7 +360,7 @@ var ( MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: nil, - CatalystBlock: nil, + ArrowGlacierBlock: nil, Ethash: new(EthashConfig), Clique: nil, } @@ -385,7 +382,7 @@ var ( MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: nil, - CatalystBlock: nil, + ArrowGlacierBlock: nil, Aura: &AuRaConfig{}, } @@ -419,10 +416,10 @@ 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) - MuirGlacierBlock *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) BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin) LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 0 = already on london) - CatalystBlock *big.Int `json:"catalystBlock,omitempty"` // Catalyst switch block (nil = no fork, 0 = already on catalyst) + ArrowGlacierBlock *big.Int `json:"arrowGlacierBlock,omitempty"` // EIP-4345 (bomb delay) switch block (nil = no fork, 0 = already activated) // Various consensus engines Ethash *EthashConfig `json:"ethash,omitempty"` @@ -467,7 +464,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, Muir Glacier: %v, Berlin: %v, London: %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, Berlin: %v, London: %v, Arrow Glacier: %v, Engine: %v}", c.ChainID, c.HomesteadBlock, c.DAOForkBlock, @@ -482,6 +479,7 @@ func (c *ChainConfig) String() string { c.MuirGlacierBlock, c.BerlinBlock, c.LondonBlock, + c.ArrowGlacierBlock, engine, ) } @@ -576,9 +574,9 @@ func (c *ChainConfig) IsLondon(num uint64) bool { return isForked(c.LondonBlock, num) } -// IsCatalyst returns whether num is either equal to the Merge fork block or greater. -func (c *ChainConfig) IsCatalyst(num uint64) bool { - return isForked(c.CatalystBlock, num) +// IsArrowGlacier returns whether num is either equal to the Arrow Glacier (EIP-4345) fork block or greater. +func (c *ChainConfig) IsArrowGlacier(num uint64) bool { + return isForked(c.ArrowGlacierBlock, num) } // CheckCompatible checks whether scheduled fork transitions have been imported @@ -624,6 +622,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "muirGlacierBlock", block: c.MuirGlacierBlock, optional: true}, {name: "berlinBlock", block: c.BerlinBlock}, {name: "londonBlock", block: c.LondonBlock}, + {name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true}, } { if lastFork.name != "" { // Next one must be higher number @@ -693,6 +692,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head uint64) *ConfigC if isForkIncompatible(c.LondonBlock, newcfg.LondonBlock, head) { return newCompatError("London fork block", c.LondonBlock, newcfg.LondonBlock) } + if isForkIncompatible(c.ArrowGlacierBlock, newcfg.ArrowGlacierBlock, head) { + return newCompatError("Arrow Glacier fork block", c.ArrowGlacierBlock, newcfg.ArrowGlacierBlock) + } return nil } @@ -760,7 +762,7 @@ type Rules struct { ChainID *big.Int IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool - IsBerlin, IsLondon, IsCatalyst bool + IsBerlin, IsLondon bool } // Rules ensures c's ChainID is not nil. @@ -781,6 +783,5 @@ func (c *ChainConfig) Rules(num uint64) Rules { IsIstanbul: c.IsIstanbul(num), IsBerlin: c.IsBerlin(num), IsLondon: c.IsLondon(num), - IsCatalyst: c.IsCatalyst(num), } }