Skip to content

Commit

Permalink
Upgrade configs use ctx (#635)
Browse files Browse the repository at this point in the history
* get upgrade configs from context

* fix chainIDs

* fix avago version

* commment out override

* Remove comment out code

* use network ID rather than chain ID

* refactor params config

* update avago

* rename

* fix runtime networks

* override netowrk upgrades from context

* Update params/network_upgrades.go

Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com>

* remove comment

* use chainID copy

* bump avago

* remove debug logs

* update avago version

---------

Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com>
  • Loading branch information
ceyonur authored Aug 20, 2024
1 parent e6e182d commit 5fce143
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 34 deletions.
5 changes: 4 additions & 1 deletion eth/tracers/internal/tracetest/calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"strings"
"testing"

"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/coreth/core"
"github.com/ava-labs/coreth/core/rawdb"
"github.com/ava-labs/coreth/core/types"
Expand Down Expand Up @@ -275,6 +277,7 @@ func benchTracer(tracerName string, test *callTracerTest, b *testing.B) {

func TestInternals(t *testing.T) {
var (
config = params.GetChainConfig(upgrade.GetConfig(constants.MainnetID), params.AvalancheMainnetChainID)
to = common.HexToAddress("0x00000000000000000000000000000000deadbeef")
origin = common.HexToAddress("0x00000000000000000000000000000000feed")
txContext = vm.TxContext{
Expand Down Expand Up @@ -388,7 +391,7 @@ func TestInternals(t *testing.T) {
}, false, rawdb.HashScheme)
defer triedb.Close()

evm := vm.NewEVM(context, txContext, statedb, params.AvalancheMainnetChainConfig, vm.Config{Tracer: tc.tracer})
evm := vm.NewEVM(context, txContext, statedb, config, vm.Config{Tracer: tc.tracer})
msg := &core.Message{
To: &to,
From: origin,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.12

require (
github.com/VictoriaMetrics/fastcache v1.12.1
github.com/ava-labs/avalanchego v1.11.11-0.20240813203340-ab83fb41528d
github.com/ava-labs/avalanchego v1.11.11-0.20240814145500-1ac532af76df
github.com/cespare/cp v0.1.0
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233
github.com/davecgh/go-spew v1.1.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.11.11-0.20240813203340-ab83fb41528d h1:LyrKJL9avIIxBY3uTcS2dFtUMBFmI2QpAgG6qYTdA6s=
github.com/ava-labs/avalanchego v1.11.11-0.20240813203340-ab83fb41528d/go.mod h1:UkyrRDXK2E15Lq2abyae2Pt+JsWvgsg1pe0/AtoMyAM=
github.com/ava-labs/avalanchego v1.11.11-0.20240814145500-1ac532af76df h1:Yp9rCHpgEsPFzpx2MXxpb/T+/NbP2NpS1EDwFquffLQ=
github.com/ava-labs/avalanchego v1.11.11-0.20240814145500-1ac532af76df/go.mod h1:Kw2GKwTaCkLwq2z3zSVH4V2eiAmq2FohHmN3AIDWjvY=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down
11 changes: 0 additions & 11 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
"fmt"
"math/big"

"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/coreth/precompile/modules"
"github.com/ava-labs/coreth/precompile/precompileconfig"
"github.com/ava-labs/coreth/utils"
Expand All @@ -53,15 +51,6 @@ var (
)

var (
// AvalancheMainnetChainConfig is the configuration for Avalanche Main Network
AvalancheMainnetChainConfig = GetChainConfig(upgrade.GetConfig(constants.MainnetID), AvalancheMainnetChainID)

// AvalancheFujiChainConfig is the configuration for the Fuji Test Network
AvalancheFujiChainConfig = GetChainConfig(upgrade.GetConfig(constants.FujiID), AvalancheFujiChainID)

// AvalancheLocalChainConfig is the configuration for the Avalanche Local Network
AvalancheLocalChainConfig = GetChainConfig(upgrade.GetConfig(constants.LocalID), AvalancheLocalChainID)

TestChainConfig = &ChainConfig{
AvalancheContext: AvalancheContext{utils.TestSnowContext()},
ChainID: big.NewInt(1),
Expand Down
15 changes: 1 addition & 14 deletions params/config_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,7 @@ func GetChainConfig(agoUpgrade upgrade.Config, chainID *big.Int) *ChainConfig {
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
NetworkUpgrades: NetworkUpgrades{
ApricotPhase1BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase1Time),
ApricotPhase2BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase2Time),
ApricotPhase3BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase3Time),
ApricotPhase4BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase4Time),
ApricotPhase5BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase5Time),
ApricotPhasePre6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePre6Time),
ApricotPhase6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase6Time),
ApricotPhasePost6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePost6Time),
BanffBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.BanffTime),
CortinaBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.CortinaTime),
DurangoBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.DurangoTime),
EtnaTimestamp: utils.TimeToNewUint64(agoUpgrade.EtnaTime),
},
NetworkUpgrades: getNetworkUpgrades(agoUpgrade),
}
}

Expand Down
20 changes: 20 additions & 0 deletions params/network_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package params
import (
"fmt"
"reflect"

"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/coreth/utils"
)

type NetworkUpgrades struct {
Expand Down Expand Up @@ -191,6 +194,23 @@ func (n *NetworkUpgrades) Description() string {
return banner
}

func getNetworkUpgrades(agoUpgrade upgrade.Config) NetworkUpgrades {
return NetworkUpgrades{
ApricotPhase1BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase1Time),
ApricotPhase2BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase2Time),
ApricotPhase3BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase3Time),
ApricotPhase4BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase4Time),
ApricotPhase5BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase5Time),
ApricotPhasePre6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePre6Time),
ApricotPhase6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhase6Time),
ApricotPhasePost6BlockTimestamp: utils.TimeToNewUint64(agoUpgrade.ApricotPhasePost6Time),
BanffBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.BanffTime),
CortinaBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.CortinaTime),
DurangoBlockTimestamp: utils.TimeToNewUint64(agoUpgrade.DurangoTime),
EtnaTimestamp: utils.TimeToNewUint64(agoUpgrade.EtnaTime),
}
}

type AvalancheRules struct {
IsApricotPhase1, IsApricotPhase2, IsApricotPhase3, IsApricotPhase4, IsApricotPhase5 bool
IsApricotPhasePre6, IsApricotPhase6, IsApricotPhasePost6 bool
Expand Down
20 changes: 14 additions & 6 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/ava-labs/avalanchego/network/p2p"
"github.com/ava-labs/avalanchego/network/p2p/gossip"
"github.com/ava-labs/avalanchego/upgrade"
avalanchegoConstants "github.com/ava-labs/avalanchego/utils/constants"
"github.com/prometheus/client_golang/prometheus"

Expand Down Expand Up @@ -448,20 +449,27 @@ func (vm *VM) Initialize(
}

var extDataHashes map[common.Hash]common.Hash
var chainID *big.Int
// Set the chain config for mainnet/fuji chain IDs
switch chainCtx.NetworkID {
case avalanchegoConstants.MainnetID:
config := *params.AvalancheMainnetChainConfig
g.Config = &config
chainID = params.AvalancheMainnetChainID
extDataHashes = mainnetExtDataHashes
case avalanchegoConstants.FujiID:
config := *params.AvalancheFujiChainConfig
g.Config = &config
chainID = params.AvalancheFujiChainID
extDataHashes = fujiExtDataHashes
case avalanchegoConstants.LocalID:
config := *params.AvalancheLocalChainConfig
g.Config = &config
chainID = params.AvalancheLocalChainID
default:
chainID = g.Config.ChainID
}

// if the chainCtx.NetworkUpgrades is not empty, set the chain config
// normally it should not be empty, but some tests may not set it
if chainCtx.NetworkUpgrades != (upgrade.Config{}) {
g.Config = params.GetChainConfig(chainCtx.NetworkUpgrades, new(big.Int).Set(chainID))
}

// If the Durango is activated, activate the Warp Precompile at the same time
if g.Config.DurangoBlockTimestamp != nil {
g.Config.PrecompileUpgrades = append(g.Config.PrecompileUpgrades, params.PrecompileUpgrade{
Expand Down
2 changes: 1 addition & 1 deletion scripts/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
set -euo pipefail

# Don't export them as they're used in the context of other calls
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'ab83fb41528de93c1790301cdd67a07dda9299f0'}
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'1ac532af76df'}

0 comments on commit 5fce143

Please sign in to comment.