diff --git a/core/genesis.go b/core/genesis.go index 494a16f81c..fd13831505 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -171,7 +171,11 @@ func SetupGenesisBlock( rawdb.WriteChainConfig(db, stored, newcfg) return newcfg, stored, nil } - storedcfg.SetEthUpgrades() + var networkID uint32 + if newcfg.SnowCtx != nil { + networkID = newcfg.SnowCtx.NetworkID + } + storedcfg.SetEthUpgrades(networkID) 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/core/genesis_extra_test.go b/core/genesis_extra_test.go index e87ae3fd4b..2cca33c420 100644 --- a/core/genesis_extra_test.go +++ b/core/genesis_extra_test.go @@ -31,7 +31,6 @@ import ( "testing" "time" - "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/coreth/core/rawdb" "github.com/ava-labs/coreth/core/types" @@ -45,11 +44,6 @@ import ( func TestGenesisEthUpgrades(t *testing.T) { db := rawdb.NewMemoryDatabase() preEthUpgrades := ¶ms.ChainConfig{ - AvalancheContext: params.AvalancheContext{ - // This UT intentionally uses MainnetID to verify a code path only - // triggered by MainnetID/TestnetID - SnowCtx: &snow.Context{NetworkID: constants.MainnetID}, - }, HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, DAOForkSupport: false, @@ -90,7 +84,9 @@ func TestGenesisEthUpgrades(t *testing.T) { // We should still be able to re-initialize config = *preEthUpgrades - config.SetEthUpgrades() // New versions will set additional fields eg, LondonBlock + // This UT intentionally uses MainnetID to trigger a case only triggerred for + // Mainnet/Testnet. Note new versions will set additional fields, eg BerlinBlock. + config.SetEthUpgrades(constants.MainnetID) _, _, err = SetupGenesisBlock(db, tdb, &Genesis{Config: &config}, block.Hash(), false) require.NoError(t, err) } diff --git a/params/config_extra.go b/params/config_extra.go index 53e37e7f1d..d438b2c739 100644 --- a/params/config_extra.go +++ b/params/config_extra.go @@ -40,11 +40,11 @@ type AvalancheContext struct { // TODO: Prior to Cancun, Avalanche upgrades are referenced inline in the // code in place of their Ethereum counterparts. The original Ethereum names // should be restored for maintainability. -func (c *ChainConfig) SetEthUpgrades() { - if c.SnowCtx != nil && c.SnowCtx.NetworkID == constants.TestnetID { +func (c *ChainConfig) SetEthUpgrades(networkID uint32) { + if networkID == constants.TestnetID { 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.SnowCtx != nil && c.SnowCtx.NetworkID == constants.MainnetID { + } else if networkID == constants.MainnetID { 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 { diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index e113252e05..41283f763a 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -496,7 +496,7 @@ func (vm *VM) Initialize( vm.chainID = g.Config.ChainID - g.Config.SetEthUpgrades() + g.Config.SetEthUpgrades(g.Config.SnowCtx.NetworkID) vm.ethConfig = ethconfig.NewDefaultConfig() vm.ethConfig.Genesis = g