Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eupgrade: base definitions #603

Merged
merged 6 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var (
BanffBlockTimestamp: utils.NewUint64(0),
CortinaBlockTimestamp: utils.NewUint64(0),
DurangoBlockTimestamp: utils.NewUint64(0),
EUpgradeTime: utils.NewUint64(0),
}

TestLaunchConfig = &ChainConfig{
Expand Down Expand Up @@ -116,6 +117,7 @@ var (
BanffBlockTimestamp: nil,
CortinaBlockTimestamp: nil,
DurangoBlockTimestamp: nil,
EUpgradeTime: nil,
}

TestApricotPhase1Config = &ChainConfig{
Expand Down Expand Up @@ -143,6 +145,7 @@ var (
BanffBlockTimestamp: nil,
CortinaBlockTimestamp: nil,
DurangoBlockTimestamp: nil,
EUpgradeTime: nil,
}

TestApricotPhase2Config = &ChainConfig{
Expand Down Expand Up @@ -170,6 +173,7 @@ var (
BanffBlockTimestamp: nil,
CortinaBlockTimestamp: nil,
DurangoBlockTimestamp: nil,
EUpgradeTime: nil,
}

TestApricotPhase3Config = &ChainConfig{
Expand Down Expand Up @@ -197,6 +201,7 @@ var (
BanffBlockTimestamp: nil,
CortinaBlockTimestamp: nil,
DurangoBlockTimestamp: nil,
EUpgradeTime: nil,
}

TestApricotPhase4Config = &ChainConfig{
Expand Down Expand Up @@ -224,6 +229,7 @@ var (
BanffBlockTimestamp: nil,
CortinaBlockTimestamp: nil,
DurangoBlockTimestamp: nil,
EUpgradeTime: nil,
}

TestApricotPhase5Config = &ChainConfig{
Expand Down Expand Up @@ -251,6 +257,7 @@ var (
BanffBlockTimestamp: nil,
CortinaBlockTimestamp: nil,
DurangoBlockTimestamp: nil,
EUpgradeTime: nil,
}

TestApricotPhasePre6Config = &ChainConfig{
Expand Down Expand Up @@ -278,6 +285,7 @@ var (
BanffBlockTimestamp: nil,
CortinaBlockTimestamp: nil,
DurangoBlockTimestamp: nil,
EUpgradeTime: nil,
}

TestApricotPhase6Config = &ChainConfig{
Expand Down Expand Up @@ -305,6 +313,7 @@ var (
BanffBlockTimestamp: nil,
CortinaBlockTimestamp: nil,
DurangoBlockTimestamp: nil,
EUpgradeTime: nil,
}

TestApricotPhasePost6Config = &ChainConfig{
Expand Down Expand Up @@ -332,6 +341,7 @@ var (
BanffBlockTimestamp: nil,
CortinaBlockTimestamp: nil,
DurangoBlockTimestamp: nil,
EUpgradeTime: nil,
}

TestBanffChainConfig = &ChainConfig{
Expand Down Expand Up @@ -359,6 +369,7 @@ var (
BanffBlockTimestamp: utils.NewUint64(0),
CortinaBlockTimestamp: nil,
DurangoBlockTimestamp: nil,
EUpgradeTime: nil,
}

TestCortinaChainConfig = &ChainConfig{
Expand Down Expand Up @@ -386,6 +397,7 @@ var (
BanffBlockTimestamp: utils.NewUint64(0),
CortinaBlockTimestamp: utils.NewUint64(0),
DurangoBlockTimestamp: nil,
EUpgradeTime: nil,
}

TestDurangoChainConfig = &ChainConfig{
Expand All @@ -412,6 +424,36 @@ var (
ApricotPhasePost6BlockTimestamp: utils.NewUint64(0),
BanffBlockTimestamp: utils.NewUint64(0),
CortinaBlockTimestamp: utils.NewUint64(0),
DurangoBlockTimestamp: utils.NewUint64(0),
EUpgradeTime: nil,
}

TestEUpgradeChainConfig = &ChainConfig{
AvalancheContext: AvalancheContext{utils.TestSnowContext()},
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: false,
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
ApricotPhase1BlockTimestamp: utils.NewUint64(0),
ApricotPhase2BlockTimestamp: utils.NewUint64(0),
ApricotPhase3BlockTimestamp: utils.NewUint64(0),
ApricotPhase4BlockTimestamp: utils.NewUint64(0),
ApricotPhase5BlockTimestamp: utils.NewUint64(0),
ApricotPhasePre6BlockTimestamp: utils.NewUint64(0),
ApricotPhase6BlockTimestamp: utils.NewUint64(0),
ApricotPhasePost6BlockTimestamp: utils.NewUint64(0),
BanffBlockTimestamp: utils.NewUint64(0),
CortinaBlockTimestamp: utils.NewUint64(0),
DurangoBlockTimestamp: utils.NewUint64(0),
EUpgradeTime: utils.NewUint64(0),
}

TestRules = TestChainConfig.Rules(new(big.Int), 0)
Expand Down Expand Up @@ -442,6 +484,7 @@ func getChainConfig(networkID uint32, chainID *big.Int) *ChainConfig {
BanffBlockTimestamp: getUpgradeTime(networkID, version.BanffTimes),
CortinaBlockTimestamp: getUpgradeTime(networkID, version.CortinaTimes),
DurangoBlockTimestamp: getUpgradeTime(networkID, version.DurangoTimes),
EUpgradeTime: getUpgradeTime(networkID, version.EUpgradeTimes),
}
}

Expand Down Expand Up @@ -496,6 +539,10 @@ type ChainConfig struct {
// and Avalanche Warp Messaging. (nil = no fork, 0 = already activated)
// Note: EIP-4895 is excluded since withdrawals are not relevant to the Avalanche C-Chain or Subnets running the EVM.
DurangoBlockTimestamp *uint64 `json:"durangoBlockTimestamp,omitempty"`
// EUpgrade on the Avalanche network. (nil = no fork, 0 = already activated)
// It activates Cancun (TODO) and modifies the min base fee (TODO).
EUpgradeTime *uint64 `json:"eUpgradeTime,omitempty"`

// Cancun activates the Cancun upgrade from Ethereum. (nil = no fork, 0 = already activated)
CancunTime *uint64 `json:"cancunTime,omitempty"`
// Verkle activates the Verkle upgrade from Ethereum. (nil = no fork, 0 = already activated)
Expand Down Expand Up @@ -546,6 +593,7 @@ func (c *ChainConfig) Description() string {
banner += fmt.Sprintf(" - Banff Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.9.0)\n", ptrToString(c.BanffBlockTimestamp))
banner += fmt.Sprintf(" - Cortina Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0)\n", ptrToString(c.CortinaBlockTimestamp))
banner += fmt.Sprintf(" - Durango Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.11.0)\n", ptrToString(c.DurangoBlockTimestamp))
banner += fmt.Sprintf(" - EUpgrade Timestamp: @%-10v (https://github.com/ava-labs/avalanchego/releases/tag/v1.12.0)\n", ptrToString(c.EUpgradeTime))
banner += "\n"

upgradeConfigBytes, err := json.Marshal(c.UpgradeConfig)
Expand Down Expand Up @@ -677,6 +725,12 @@ func (c *ChainConfig) IsDurango(time uint64) bool {
return utils.IsTimestampForked(c.DurangoBlockTimestamp, time)
}

// IsEUpgrade returns whether [time] represents a block
// with a timestamp after the EUpgrade upgrade time.
func (c *ChainConfig) IsEUpgrade(time uint64) bool {
return utils.IsTimestampForked(c.EUpgradeTime, time)
}

// IsCancun returns whether [time] represents a block
// with a timestamp after the Cancun upgrade time.
func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool {
Expand Down Expand Up @@ -907,9 +961,15 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, height *big.Int, time
if isForkTimestampIncompatible(c.DurangoBlockTimestamp, newcfg.DurangoBlockTimestamp, time) {
return newTimestampCompatError("Durango fork block timestamp", c.DurangoBlockTimestamp, newcfg.DurangoBlockTimestamp)
}
if isForkTimestampIncompatible(c.EUpgradeTime, newcfg.EUpgradeTime, time) {
return newTimestampCompatError("EUpgrade fork block timestamp", c.EUpgradeTime, newcfg.EUpgradeTime)
}
if isForkTimestampIncompatible(c.CancunTime, newcfg.CancunTime, time) {
return newTimestampCompatError("Cancun fork block timestamp", c.CancunTime, newcfg.CancunTime)
}
if isForkTimestampIncompatible(c.VerkleTime, newcfg.VerkleTime, time) {
return newTimestampCompatError("Verkle fork block timestamp", c.VerkleTime, newcfg.VerkleTime)
}

return nil
}
Expand Down
3 changes: 3 additions & 0 deletions params/network_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func (c *ChainConfig) forkOrder() []fork {
{name: "banffBlockTimestamp", timestamp: c.BanffBlockTimestamp},
{name: "cortinaBlockTimestamp", timestamp: c.CortinaBlockTimestamp},
{name: "durangoBlockTimestamp", timestamp: c.DurangoBlockTimestamp},
{name: "eUpgradeTime", timestamp: c.EUpgradeTime},
}
}

Expand All @@ -25,6 +26,7 @@ type AvalancheRules struct {
IsBanff bool
IsCortina bool
IsDurango bool
IsEUpgrade bool
}

func (c *ChainConfig) GetAvalancheRules(timestamp uint64) AvalancheRules {
Expand All @@ -40,6 +42,7 @@ func (c *ChainConfig) GetAvalancheRules(timestamp uint64) AvalancheRules {
rules.IsBanff = c.IsBanff(timestamp)
rules.IsCortina = c.IsCortina(timestamp)
rules.IsDurango = c.IsDurango(timestamp)
rules.IsEUpgrade = c.IsEUpgrade(timestamp)

return rules
}
Loading
Loading