From 43dde819a13c748281a9b659636fbd295b0de930 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Wed, 2 Oct 2024 17:42:43 -0700 Subject: [PATCH] fix genesis EthUpgrades --- core/genesis.go | 1 + params/config_extra.go | 42 +++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 74650526f4..b7906f440e 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -171,6 +171,7 @@ func SetupGenesisBlock( rawdb.WriteChainConfig(db, stored, newcfg) return newcfg, stored, nil } + params.SetEthUpgrades(storedcfg) storedData, _ := json.Marshal(storedcfg) // Check config compatibility and write the config. Compatibility errors // are returned to the caller unless we're already at block zero. diff --git a/params/config_extra.go b/params/config_extra.go index c8575a920b..15828d6c1e 100644 --- a/params/config_extra.go +++ b/params/config_extra.go @@ -43,11 +43,30 @@ type AvalancheContext struct { // code in place of their Ethereum counterparts. The original Ethereum names // should be restored for maintainability. func SetEthUpgrades(c *ChainConfig) { + if c.ChainID != nil && AvalancheFujiChainID.Cmp(c.ChainID) == 0 { + c.BerlinBlock = big.NewInt(184985) // https://testnet.snowtrace.io/block/184985?chainid=43113, AP2 activation block + c.LondonBlock = big.NewInt(805078) // https://testnet.snowtrace.io/block/805078?chainid=43113, AP3 activation block + } else if c.ChainID != nil && AvalancheMainnetChainID.Cmp(c.ChainID) == 0 { + c.BerlinBlock = big.NewInt(1640340) // https://snowtrace.io/block/1640340?chainid=43114, AP2 activation block + c.LondonBlock = big.NewInt(3308552) // https://snowtrace.io/block/3308552?chainid=43114, AP3 activation block + } else { + // In testing or local networks, we only support enabling Berlin and London prior + // to the initially active time. This is likely to correspond to an intended block + // number of 0 as well. + initiallyActive := uint64(upgrade.InitiallyActiveTime.Unix()) + extra := GetExtra(c) + if extra != nil && extra.ApricotPhase2BlockTimestamp != nil && *extra.ApricotPhase2BlockTimestamp <= initiallyActive && c.BerlinBlock == nil { + c.BerlinBlock = big.NewInt(0) + } + if extra != nil && extra.ApricotPhase3BlockTimestamp != nil && *extra.ApricotPhase3BlockTimestamp <= initiallyActive && c.LondonBlock == nil { + c.LondonBlock = big.NewInt(0) + } + } extra := GetExtra(c) - if extra.DurangoBlockTimestamp != nil { + if extra != nil && extra.DurangoBlockTimestamp != nil { c.ShanghaiTime = utils.NewUint64(*extra.DurangoBlockTimestamp) } - if extra.EtnaTimestamp != nil { + if extra != nil && extra.EtnaTimestamp != nil { c.CancunTime = utils.NewUint64(*extra.EtnaTimestamp) } } @@ -184,25 +203,6 @@ func GetChainConfig(agoUpgrade upgrade.Config, chainID *big.Int) *ChainConfig { NetworkUpgrades: getNetworkUpgrades(agoUpgrade), }, ) - if AvalancheFujiChainID.Cmp(c.ChainID) == 0 { - c.BerlinBlock = big.NewInt(184985) // https://testnet.snowtrace.io/block/184985?chainid=43113, AP2 activation block - c.LondonBlock = big.NewInt(805078) // https://testnet.snowtrace.io/block/805078?chainid=43113, AP3 activation block - } else if AvalancheMainnetChainID.Cmp(c.ChainID) == 0 { - c.BerlinBlock = big.NewInt(1640340) // https://snowtrace.io/block/1640340?chainid=43114, AP2 activation block - c.LondonBlock = big.NewInt(3308552) // https://snowtrace.io/block/3308552?chainid=43114, AP3 activation block - } else { - // In testing or local networks, we only support enabling Berlin and London prior - // to the initially active time. This is likely to correspond to an intended block - // number of 0 as well. - initiallyActive := uint64(upgrade.InitiallyActiveTime.Unix()) - extra := GetExtra(c) - if extra.ApricotPhase2BlockTimestamp != nil && *extra.ApricotPhase2BlockTimestamp <= initiallyActive && c.BerlinBlock == nil { - c.BerlinBlock = big.NewInt(0) - } - if extra.ApricotPhase3BlockTimestamp != nil && *extra.ApricotPhase3BlockTimestamp <= initiallyActive && c.LondonBlock == nil { - c.LondonBlock = big.NewInt(0) - } - } return c }