Skip to content

Commit

Permalink
Add network upgrade config
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbuchwald committed Jul 20, 2024
1 parent 4929986 commit d6720a2
Show file tree
Hide file tree
Showing 14 changed files with 241 additions and 205 deletions.
12 changes: 7 additions & 5 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
"github.com/ava-labs/avalanchego/utils/metric"
"github.com/ava-labs/avalanchego/utils/perms"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms"
"github.com/ava-labs/avalanchego/vms/fx"
"github.com/ava-labs/avalanchego/vms/metervm"
Expand Down Expand Up @@ -235,6 +234,9 @@ type ManagerConfig struct {

ApricotPhase4Time time.Time
ApricotPhase4MinPChainHeight uint64
CortinaTime time.Time
CortinaXChainStopVertexID ids.ID
DurangoTime time.Time

// Tracks CPU/disk usage caused by each peer.
ResourceTracker timetracker.ResourceTracker
Expand Down Expand Up @@ -730,7 +732,7 @@ func (m *manager) createAvalancheChain(
VM: dagVM,
DB: vertexDB,
Log: ctx.Log,
CortinaTime: version.GetCortinaTime(ctx.NetworkID),
CortinaTime: m.CortinaTime,
},
)

Expand Down Expand Up @@ -795,7 +797,7 @@ func (m *manager) createAvalancheChain(
vmWrappedInsideProposerVM,
proposervm.Config{
ActivationTime: m.ApricotPhase4Time,
DurangoTime: version.GetDurangoTime(m.NetworkID),
DurangoTime: m.DurangoTime,
MinimumPChainHeight: m.ApricotPhase4MinPChainHeight,
MinBlkDelay: minBlockDelay,
NumHistoricalBlocks: numHistoricalBlocks,
Expand Down Expand Up @@ -1010,7 +1012,7 @@ func (m *manager) createAvalancheChain(
VM: linearizableVM,
}
if ctx.ChainID == m.XChainID {
avalancheBootstrapperConfig.StopVertexID = version.CortinaXChainStopVertexID[ctx.NetworkID]
avalancheBootstrapperConfig.StopVertexID = m.CortinaXChainStopVertexID
}

avalancheBootstrapper, err := avbootstrap.New(
Expand Down Expand Up @@ -1192,7 +1194,7 @@ func (m *manager) createSnowmanChain(
vm,
proposervm.Config{
ActivationTime: m.ApricotPhase4Time,
DurangoTime: version.GetDurangoTime(m.NetworkID),
DurangoTime: m.DurangoTime,
MinimumPChainHeight: m.ApricotPhase4MinPChainHeight,
MinBlkDelay: minBlockDelay,
NumHistoricalBlocks: numHistoricalBlocks,
Expand Down
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/ava-labs/avalanchego/staking"
"github.com/ava-labs/avalanchego/subnets"
"github.com/ava-labs/avalanchego/trace"
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils/compression"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
Expand Down Expand Up @@ -779,6 +780,10 @@ func getTxFeeConfig(v *viper.Viper, networkID uint32) fee.StaticConfig {
return genesis.GetTxFeeConfig(networkID)
}

func getUpgradeConfig(v *viper.Viper, networkID uint32) upgrade.Config {
return upgrade.GetConfig(networkID)
}

func getGenesisData(v *viper.Viper, networkID uint32, stakingCfg *genesis.StakingConfig) ([]byte, ids.ID, error) {
// try first loading genesis content directly from flag/env-var
if v.IsSet(GenesisFileContentKey) {
Expand Down Expand Up @@ -1294,6 +1299,9 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
return node.Config{}, err
}

// Upgrade config
nodeConfig.UpgradeConfig = getUpgradeConfig(v, nodeConfig.NetworkID)

// Network Config
nodeConfig.NetworkConfig, err = getNetworkConfig(
v,
Expand Down
3 changes: 2 additions & 1 deletion network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type network struct {
// NewNetwork returns a new Network implementation with the provided parameters.
func NewNetwork(
config *Config,
minCompatibleTime time.Time,
msgCreator message.Creator,
metricsRegisterer prometheus.Registerer,
log logging.Logger,
Expand Down Expand Up @@ -261,7 +262,7 @@ func NewNetwork(
InboundMsgThrottler: inboundMsgThrottler,
Network: nil, // This is set below.
Router: router,
VersionCompatibility: version.GetCompatibility(config.NetworkID),
VersionCompatibility: version.GetCompatibility(config.NetworkID, minCompatibleTime),
MySubnets: config.TrackedSubnets,
Beacons: config.Beacons,
Validators: config.Validators,
Expand Down
5 changes: 5 additions & 0 deletions network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/staking"
"github.com/ava-labs/avalanchego/subnets"
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
Expand Down Expand Up @@ -237,6 +238,7 @@ func newFullyConnectedTestNetwork(t *testing.T, handlers []router.InboundHandler
var connected set.Set[ids.NodeID]
net, err := NewNetwork(
config,
upgrade.DefaultUpgradeTime,
msgCreator,
registry,
logging.NoLog{},
Expand Down Expand Up @@ -466,6 +468,7 @@ func TestTrackDoesNotDialPrivateIPs(t *testing.T) {

net, err := NewNetwork(
config,
upgrade.DefaultUpgradeTime,
msgCreator,
registry,
logging.NoLog{},
Expand Down Expand Up @@ -545,6 +548,7 @@ func TestDialDeletesNonValidators(t *testing.T) {

net, err := NewNetwork(
config,
upgrade.DefaultUpgradeTime,
msgCreator,
registry,
logging.NoLog{},
Expand Down Expand Up @@ -699,6 +703,7 @@ func TestAllowConnectionAsAValidator(t *testing.T) {

net, err := NewNetwork(
config,
upgrade.DefaultUpgradeTime,
msgCreator,
registry,
logging.NoLog{},
Expand Down
31 changes: 16 additions & 15 deletions network/peer/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/ava-labs/avalanchego/snow/uptime"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/staking"
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
Expand Down Expand Up @@ -83,7 +84,7 @@ func newConfig(t *testing.T) Config {
InboundMsgThrottler: throttling.NewNoInboundThrottler(),
Network: TestNetwork,
Router: nil,
VersionCompatibility: version.GetCompatibility(constants.LocalID),
VersionCompatibility: version.GetCompatibility(constants.LocalID, upgrade.DefaultUpgradeTime),
MySubnets: nil,
Beacons: validators.NewManager(),
Validators: validators.NewManager(),
Expand Down Expand Up @@ -451,7 +452,7 @@ func TestShouldDisconnect(t *testing.T) {
initialPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
},
version: &version.Application{
Name: version.Client,
Expand All @@ -463,7 +464,7 @@ func TestShouldDisconnect(t *testing.T) {
expectedPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
},
version: &version.Application{
Name: version.Client,
Expand All @@ -479,15 +480,15 @@ func TestShouldDisconnect(t *testing.T) {
initialPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: validators.NewManager(),
},
version: version.CurrentApp,
},
expectedPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: validators.NewManager(),
},
version: version.CurrentApp,
Expand All @@ -499,7 +500,7 @@ func TestShouldDisconnect(t *testing.T) {
initialPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
Expand All @@ -518,7 +519,7 @@ func TestShouldDisconnect(t *testing.T) {
expectedPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
Expand All @@ -541,7 +542,7 @@ func TestShouldDisconnect(t *testing.T) {
initialPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
Expand All @@ -561,7 +562,7 @@ func TestShouldDisconnect(t *testing.T) {
expectedPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
Expand All @@ -585,7 +586,7 @@ func TestShouldDisconnect(t *testing.T) {
initialPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
Expand All @@ -605,7 +606,7 @@ func TestShouldDisconnect(t *testing.T) {
expectedPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
Expand All @@ -629,7 +630,7 @@ func TestShouldDisconnect(t *testing.T) {
initialPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
Expand All @@ -651,7 +652,7 @@ func TestShouldDisconnect(t *testing.T) {
expectedPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
Expand All @@ -677,7 +678,7 @@ func TestShouldDisconnect(t *testing.T) {
initialPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
Expand All @@ -699,7 +700,7 @@ func TestShouldDisconnect(t *testing.T) {
expectedPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(constants.UnitTestID, upgrade.DefaultUpgradeTime),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
Expand Down
3 changes: 2 additions & 1 deletion network/peer/test_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ava-labs/avalanchego/snow/uptime"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/staking"
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
Expand Down Expand Up @@ -113,7 +114,7 @@ func StartTestPeer(
InboundMsgThrottler: throttling.NewNoInboundThrottler(),
Network: TestNetwork,
Router: router,
VersionCompatibility: version.GetCompatibility(networkID),
VersionCompatibility: version.GetCompatibility(networkID, upgrade.DefaultUpgradeTime),
MySubnets: set.Set[ids.ID]{},
Beacons: validators.NewManager(),
Validators: validators.NewManager(),
Expand Down
2 changes: 2 additions & 0 deletions network/test_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/staking"
"github.com/ava-labs/avalanchego/subnets"
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
Expand Down Expand Up @@ -216,6 +217,7 @@ func NewTestNetwork(
resourceTracker.DiskTracker(),
),
},
upgrade.DefaultUpgradeTime,
msgCreator,
metrics,
log,
Expand Down
3 changes: 3 additions & 0 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ava-labs/avalanchego/snow/networking/tracker"
"github.com/ava-labs/avalanchego/subnets"
"github.com/ava-labs/avalanchego/trace"
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/profiler"
Expand Down Expand Up @@ -131,6 +132,8 @@ type Config struct {
BootstrapConfig `json:"bootstrapConfig"`
DatabaseConfig `json:"databaseConfig"`

UpgradeConfig upgrade.Config `json:"upgradeConfig"`

// Genesis information
GenesisBytes []byte `json:"-"`
AvaxAssetID ids.ID `json:"avaxAssetID"`
Expand Down
Loading

0 comments on commit d6720a2

Please sign in to comment.