Skip to content

Commit

Permalink
use active (not stored) network id
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Oct 3, 2024
1 parent 8d15814 commit f735c1e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 5 additions & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 3 additions & 7 deletions core/genesis_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -45,11 +44,6 @@ import (
func TestGenesisEthUpgrades(t *testing.T) {
db := rawdb.NewMemoryDatabase()
preEthUpgrades := &params.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,
Expand Down Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions params/config_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f735c1e

Please sign in to comment.