Skip to content

Commit

Permalink
Arrow Glacier network upgrade (#2896)
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis authored Oct 31, 2021
1 parent 3d63c93 commit 1214302
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
9 changes: 7 additions & 2 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions consensus/misc/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
10 changes: 6 additions & 4 deletions core/forkid/forkid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func setDefaults(cfg *Config) {
MuirGlacierBlock: new(big.Int),
BerlinBlock: new(big.Int),
LondonBlock: new(big.Int),
ArrowGlacierBlock: new(big.Int),
}
}

Expand Down
45 changes: 23 additions & 22 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down Expand Up @@ -178,6 +179,8 @@ var (
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: nil,
ArrowGlacierBlock: nil,
Ethash: new(EthashConfig),
}

Expand Down Expand Up @@ -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{
Expand All @@ -262,7 +265,7 @@ var (
MuirGlacierBlock: nil,
BerlinBlock: big.NewInt(24770900),
LondonBlock: big.NewInt(26741100),
CatalystBlock: nil,
ArrowGlacierBlock: nil,
Aura: &AuRaConfig{},
}

Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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},
}
Expand All @@ -363,7 +360,7 @@ var (
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: nil,
CatalystBlock: nil,
ArrowGlacierBlock: nil,
Ethash: new(EthashConfig),
Clique: nil,
}
Expand All @@ -385,7 +382,7 @@ var (
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: nil,
CatalystBlock: nil,
ArrowGlacierBlock: nil,
Aura: &AuRaConfig{},
}

Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand All @@ -482,6 +479,7 @@ func (c *ChainConfig) String() string {
c.MuirGlacierBlock,
c.BerlinBlock,
c.LondonBlock,
c.ArrowGlacierBlock,
engine,
)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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.
Expand All @@ -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),
}
}

0 comments on commit 1214302

Please sign in to comment.