Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add network upgrade config #3207

Merged
merged 17 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ 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/buffer"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/logging"
"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 @@ -233,8 +233,7 @@ type ManagerConfig struct {
// containers in an ancestors message it receives.
BootstrapAncestorsMaxContainersReceived int

ApricotPhase4Time time.Time
ApricotPhase4MinPChainHeight uint64
Upgrades upgrade.Config

// Tracks CPU/disk usage caused by each peer.
ResourceTracker timetracker.ResourceTracker
Expand Down Expand Up @@ -726,11 +725,10 @@ func (m *manager) createAvalancheChain(
// persistence of vertices
vtxManager := state.NewSerializer(
state.SerializerConfig{
ChainID: ctx.ChainID,
VM: dagVM,
DB: vertexDB,
Log: ctx.Log,
CortinaTime: version.GetCortinaTime(ctx.NetworkID),
ChainID: ctx.ChainID,
VM: dagVM,
DB: vertexDB,
Log: ctx.Log,
},
)

Expand Down Expand Up @@ -767,8 +765,8 @@ func (m *manager) createAvalancheChain(
numHistoricalBlocks = subnetCfg.ProposerNumHistoricalBlocks
}
m.Log.Info("creating proposervm wrapper",
zap.Time("activationTime", m.ApricotPhase4Time),
zap.Uint64("minPChainHeight", m.ApricotPhase4MinPChainHeight),
zap.Time("activationTime", m.Upgrades.ApricotPhase4Time),
zap.Uint64("minPChainHeight", m.Upgrades.ApricotPhase4MinPChainHeight),
zap.Duration("minBlockDelay", minBlockDelay),
zap.Uint64("numHistoricalBlocks", numHistoricalBlocks),
)
Expand All @@ -794,9 +792,7 @@ func (m *manager) createAvalancheChain(
var vmWrappingProposerVM block.ChainVM = proposervm.New(
vmWrappedInsideProposerVM,
proposervm.Config{
ActivationTime: m.ApricotPhase4Time,
DurangoTime: version.GetDurangoTime(m.NetworkID),
MinimumPChainHeight: m.ApricotPhase4MinPChainHeight,
Upgrades: m.Upgrades,
MinBlkDelay: minBlockDelay,
NumHistoricalBlocks: numHistoricalBlocks,
StakingLeafSigner: m.StakingTLSSigner,
Expand Down Expand Up @@ -1010,7 +1006,7 @@ func (m *manager) createAvalancheChain(
VM: linearizableVM,
}
if ctx.ChainID == m.XChainID {
avalancheBootstrapperConfig.StopVertexID = version.CortinaXChainStopVertexID[ctx.NetworkID]
avalancheBootstrapperConfig.StopVertexID = m.Upgrades.CortinaXChainStopVertexID
}

avalancheBootstrapper, err := avbootstrap.New(
Expand Down Expand Up @@ -1170,8 +1166,8 @@ func (m *manager) createSnowmanChain(
numHistoricalBlocks = subnetCfg.ProposerNumHistoricalBlocks
}
m.Log.Info("creating proposervm wrapper",
zap.Time("activationTime", m.ApricotPhase4Time),
zap.Uint64("minPChainHeight", m.ApricotPhase4MinPChainHeight),
zap.Time("activationTime", m.Upgrades.ApricotPhase4Time),
zap.Uint64("minPChainHeight", m.Upgrades.ApricotPhase4MinPChainHeight),
zap.Duration("minBlockDelay", minBlockDelay),
zap.Uint64("numHistoricalBlocks", numHistoricalBlocks),
)
Expand All @@ -1191,9 +1187,7 @@ func (m *manager) createSnowmanChain(
vm = proposervm.New(
vm,
proposervm.Config{
ActivationTime: m.ApricotPhase4Time,
DurangoTime: version.GetDurangoTime(m.NetworkID),
MinimumPChainHeight: m.ApricotPhase4MinPChainHeight,
Upgrades: m.Upgrades,
MinBlkDelay: minBlockDelay,
NumHistoricalBlocks: numHistoricalBlocks,
StakingLeafSigner: m.StakingTLSSigner,
Expand Down
45 changes: 45 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 @@ -796,6 +797,44 @@ func getTxFeeConfig(v *viper.Viper, networkID uint32) genesis.TxFeeConfig {
return genesis.GetTxFeeConfig(networkID)
}

func getUpgradeConfig(v *viper.Viper, networkID uint32) (upgrade.Config, error) {
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
if !v.IsSet(UpgradeFileKey) && !v.IsSet(UpgradeFileContentKey) {
return upgrade.GetConfig(networkID), nil
}

switch networkID {
case constants.MainnetID, constants.TestnetID, constants.LocalID:
return upgrade.Config{}, fmt.Errorf("cannot configure upgrades for networkID: %s",
constants.NetworkName(networkID),
)
}

var (
upgradeBytes []byte
err error
)
switch {
case v.IsSet(UpgradeFileKey):
upgradeFileName := GetExpandedArg(v, UpgradeFileKey)
upgradeBytes, err = os.ReadFile(upgradeFileName)
if err != nil {
return upgrade.Config{}, fmt.Errorf("unable to read upgrade file: %w", err)
}
case v.IsSet(UpgradeFileContentKey):
upgradeContent := v.GetString(UpgradeFileContentKey)
upgradeBytes, err = base64.StdEncoding.DecodeString(upgradeContent)
if err != nil {
return upgrade.Config{}, fmt.Errorf("unable to decode upgrade base64 content: %w", err)
}
}

var upgradeConfig upgrade.Config
if err := json.Unmarshal(upgradeBytes, &upgradeConfig); err != nil {
return upgrade.Config{}, fmt.Errorf("unable to unmarshal upgrade bytes: %w", err)
}
return upgradeConfig, nil
}

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 @@ -1311,6 +1350,12 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
return node.Config{}, err
}

// Upgrade config
nodeConfig.UpgradeConfig, err = getUpgradeConfig(v, nodeConfig.NetworkID)
if err != nil {
return node.Config{}, err
}

// Network Config
nodeConfig.NetworkConfig, err = getNetworkConfig(
v,
Expand Down
5 changes: 5 additions & 0 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func addNodeFlags(fs *pflag.FlagSet) {
GenesisFileContentKey))
fs.String(GenesisFileContentKey, "", "Specifies base64 encoded genesis content")

// Upgrade
fs.String(UpgradeFileKey, "", fmt.Sprintf("Specifies an upgrade config file path. Ignored when running standard networks or if %s is specified",
UpgradeFileContentKey))
fs.String(UpgradeFileContentKey, "", "Specifies base64 encoded upgrade content")

// Network ID
fs.String(NetworkNameKey, constants.MainnetName, "Network ID this node will connect to")

Expand Down
2 changes: 2 additions & 0 deletions config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
VersionJSONKey = "version-json"
GenesisFileKey = "genesis-file"
GenesisFileContentKey = "genesis-file-content"
UpgradeFileKey = "upgrade-file"
UpgradeFileContentKey = "upgrade-file-content"
NetworkNameKey = "network-id"
ACPSupportKey = "acp-support"
ACPObjectKey = "acp-object"
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(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.InitiallyActiveTime,
msgCreator,
registry,
logging.NoLog{},
Expand Down Expand Up @@ -466,6 +468,7 @@ func TestTrackDoesNotDialPrivateIPs(t *testing.T) {

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

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

net, err := NewNetwork(
config,
upgrade.InitiallyActiveTime,
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(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
},
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(upgrade.InitiallyActiveTime),
},
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(upgrade.InitiallyActiveTime),
Validators: validators.NewManager(),
},
version: version.CurrentApp,
},
expectedPeer: &peer{
Config: &Config{
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
VersionCompatibility: version.GetCompatibility(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
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(upgrade.InitiallyActiveTime),
MySubnets: set.Set[ids.ID]{},
Beacons: validators.NewManager(),
Validators: validators.NewManager(),
Expand Down
Loading
Loading