From 1747485b8079f404b1512045bcb8c48da0a9a750 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Tue, 14 May 2024 10:01:33 +0200 Subject: [PATCH] repackaged upgrades times into upgrade package --- node/node.go | 17 ++-- vms/platformvm/block/builder/builder_test.go | 2 +- vms/platformvm/block/builder/helpers_test.go | 27 +++--- vms/platformvm/block/executor/helpers_test.go | 27 +++--- vms/platformvm/block/executor/verifier.go | 6 +- .../block/executor/verifier_test.go | 67 +++++++++++---- vms/platformvm/config/config.go | 48 ++--------- vms/platformvm/state/state.go | 2 +- .../txs/executor/advance_time_test.go | 6 +- .../txs/executor/create_chain_test.go | 2 +- .../txs/executor/create_subnet_test.go | 2 +- vms/platformvm/txs/executor/export_test.go | 2 +- vms/platformvm/txs/executor/helpers_test.go | 27 +++--- vms/platformvm/txs/executor/import_test.go | 4 +- .../txs/executor/proposal_tx_executor.go | 18 ++-- .../txs/executor/proposal_tx_executor_test.go | 2 +- .../txs/executor/staker_tx_verification.go | 16 ++-- .../txs/executor/standard_tx_executor.go | 14 +-- .../txs/executor/standard_tx_executor_test.go | 33 +++---- vms/platformvm/upgrade/config.go | 50 +++++++++++ vms/platformvm/validator_set_property_test.go | 13 +-- vms/platformvm/vm_regression_test.go | 13 +-- vms/platformvm/vm_test.go | 85 +++++++++++-------- 23 files changed, 282 insertions(+), 201 deletions(-) create mode 100644 vms/platformvm/upgrade/config.go diff --git a/node/node.go b/node/node.go index 58e903404470..d225667ccf13 100644 --- a/node/node.go +++ b/node/node.go @@ -75,6 +75,7 @@ import ( "github.com/ava-labs/avalanchego/vms/avm" "github.com/ava-labs/avalanchego/vms/platformvm" "github.com/ava-labs/avalanchego/vms/platformvm/signer" + "github.com/ava-labs/avalanchego/vms/platformvm/upgrade" "github.com/ava-labs/avalanchego/vms/registry" "github.com/ava-labs/avalanchego/vms/rpcchainvm/runtime" @@ -1149,13 +1150,15 @@ func (n *Node) initVMs() error { MinStakeDuration: n.Config.MinStakeDuration, MaxStakeDuration: n.Config.MaxStakeDuration, RewardConfig: n.Config.RewardConfig, - ApricotPhase3Time: version.GetApricotPhase3Time(n.Config.NetworkID), - ApricotPhase5Time: version.GetApricotPhase5Time(n.Config.NetworkID), - BanffTime: version.GetBanffTime(n.Config.NetworkID), - CortinaTime: version.GetCortinaTime(n.Config.NetworkID), - DurangoTime: version.GetDurangoTime(n.Config.NetworkID), - EUpgradeTime: eUpgradeTime, - UseCurrentHeight: n.Config.UseCurrentHeight, + UpgradeConfig: upgrade.Config{ + ApricotPhase3Time: version.GetApricotPhase3Time(n.Config.NetworkID), + ApricotPhase5Time: version.GetApricotPhase5Time(n.Config.NetworkID), + BanffTime: version.GetBanffTime(n.Config.NetworkID), + CortinaTime: version.GetCortinaTime(n.Config.NetworkID), + DurangoTime: version.GetDurangoTime(n.Config.NetworkID), + EUpgradeTime: eUpgradeTime, + }, + UseCurrentHeight: n.Config.UseCurrentHeight, }, }), n.VMManager.RegisterFactory(context.TODO(), constants.AVMID, &avm.Factory{ diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index 64abd8a46857..4088ccaee7a1 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -301,7 +301,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { // Post-Durango, [StartTime] is no longer validated. Staking durations are // based on the current chain timestamp and must be validated. - env.config.DurangoTime = time.Time{} + env.config.UpgradeConfig.DurangoTime = time.Time{} var ( now = env.backend.Clk.Time() diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 958ef92ae5c2..e9310ac05b4f 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -45,6 +45,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool" "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" + "github.com/ava-labs/avalanchego/vms/platformvm/upgrade" "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -321,32 +322,34 @@ func defaultConfig(t *testing.T, f fork) *config.Config { MintingPeriod: 365 * 24 * time.Hour, SupplyCap: 720 * units.MegaAvax, }, - ApricotPhase3Time: mockable.MaxTime, - ApricotPhase5Time: mockable.MaxTime, - BanffTime: mockable.MaxTime, - CortinaTime: mockable.MaxTime, - DurangoTime: mockable.MaxTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + ApricotPhase3Time: mockable.MaxTime, + ApricotPhase5Time: mockable.MaxTime, + BanffTime: mockable.MaxTime, + CortinaTime: mockable.MaxTime, + DurangoTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, + }, } switch f { case eUpgrade: - c.EUpgradeTime = time.Time{} // neglecting fork ordering this for package tests + c.UpgradeConfig.EUpgradeTime = time.Time{} // neglecting fork ordering this for package tests fallthrough case durango: - c.DurangoTime = time.Time{} // neglecting fork ordering for this package's tests + c.UpgradeConfig.DurangoTime = time.Time{} // neglecting fork ordering for this package's tests fallthrough case cortina: - c.CortinaTime = time.Time{} // neglecting fork ordering for this package's tests + c.UpgradeConfig.CortinaTime = time.Time{} // neglecting fork ordering for this package's tests fallthrough case banff: - c.BanffTime = time.Time{} // neglecting fork ordering for this package's tests + c.UpgradeConfig.BanffTime = time.Time{} // neglecting fork ordering for this package's tests fallthrough case apricotPhase5: - c.ApricotPhase5Time = defaultValidateEndTime + c.UpgradeConfig.ApricotPhase5Time = defaultValidateEndTime fallthrough case apricotPhase3: - c.ApricotPhase3Time = defaultValidateEndTime + c.UpgradeConfig.ApricotPhase3Time = defaultValidateEndTime default: require.FailNow(t, "unhandled fork", f) } diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 0849146afcf6..c1295f862a6c 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -46,6 +46,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" "github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool" "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" + "github.com/ava-labs/avalanchego/vms/platformvm/upgrade" "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -343,32 +344,34 @@ func defaultConfig(t *testing.T, f fork) *config.Config { MintingPeriod: 365 * 24 * time.Hour, SupplyCap: 720 * units.MegaAvax, }, - ApricotPhase3Time: mockable.MaxTime, - ApricotPhase5Time: mockable.MaxTime, - BanffTime: mockable.MaxTime, - CortinaTime: mockable.MaxTime, - DurangoTime: mockable.MaxTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + ApricotPhase3Time: mockable.MaxTime, + ApricotPhase5Time: mockable.MaxTime, + BanffTime: mockable.MaxTime, + CortinaTime: mockable.MaxTime, + DurangoTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, + }, } switch f { case eUpgrade: - c.EUpgradeTime = time.Time{} // neglecting fork ordering this for package tests + c.UpgradeConfig.EUpgradeTime = time.Time{} // neglecting fork ordering this for package tests fallthrough case durango: - c.DurangoTime = time.Time{} // neglecting fork ordering for this package's tests + c.UpgradeConfig.DurangoTime = time.Time{} // neglecting fork ordering for this package's tests fallthrough case cortina: - c.CortinaTime = time.Time{} // neglecting fork ordering for this package's tests + c.UpgradeConfig.CortinaTime = time.Time{} // neglecting fork ordering for this package's tests fallthrough case banff: - c.BanffTime = time.Time{} // neglecting fork ordering for this package's tests + c.UpgradeConfig.BanffTime = time.Time{} // neglecting fork ordering for this package's tests fallthrough case apricotPhase5: - c.ApricotPhase5Time = defaultValidateEndTime + c.UpgradeConfig.ApricotPhase5Time = defaultValidateEndTime fallthrough case apricotPhase3: - c.ApricotPhase3Time = defaultValidateEndTime + c.UpgradeConfig.ApricotPhase3Time = defaultValidateEndTime default: require.FailNow(t, "unhandled fork", f) } diff --git a/vms/platformvm/block/executor/verifier.go b/vms/platformvm/block/executor/verifier.go index 926a7acf4fa0..c56abc45e3c1 100644 --- a/vms/platformvm/block/executor/verifier.go +++ b/vms/platformvm/block/executor/verifier.go @@ -179,11 +179,11 @@ func (v *verifier) ApricotAtomicBlock(b *block.ApricotAtomicBlock) error { parentID := b.Parent() currentTimestamp := v.getTimestamp(parentID) cfg := v.txExecutorBackend.Config - if cfg.IsApricotPhase5Activated(currentTimestamp) { + if cfg.UpgradeConfig.IsApricotPhase5Activated(currentTimestamp) { return fmt.Errorf( "the chain timestamp (%d) is after the apricot phase 5 time (%d), hence atomic transactions should go through the standard block", currentTimestamp.Unix(), - cfg.ApricotPhase5Time.Unix(), + cfg.UpgradeConfig.ApricotPhase5Time.Unix(), ) } @@ -290,7 +290,7 @@ func (v *verifier) apricotCommonBlock(b block.Block) error { // during the verification of the ProposalBlock. parentID := b.Parent() timestamp := v.getTimestamp(parentID) - if v.txExecutorBackend.Config.IsBanffActivated(timestamp) { + if v.txExecutorBackend.Config.UpgradeConfig.IsBanffActivated(timestamp) { return fmt.Errorf("%w: timestamp = %s", errApricotBlockIssuedAfterFork, timestamp) } return v.commonBlock(b) diff --git a/vms/platformvm/block/executor/verifier_test.go b/vms/platformvm/block/executor/verifier_test.go index ba24fb2f1298..34d8a0d7432e 100644 --- a/vms/platformvm/block/executor/verifier_test.go +++ b/vms/platformvm/block/executor/verifier_test.go @@ -26,6 +26,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" "github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool" + "github.com/ava-labs/avalanchego/vms/platformvm/upgrade" ) func TestVerifierVisitProposalBlock(t *testing.T) { @@ -58,7 +59,9 @@ func TestVerifierVisitProposalBlock(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: mockable.MaxTime, // banff is not activated + UpgradeConfig: upgrade.Config{ + BanffTime: mockable.MaxTime, // banff is not activated + }, }, Clk: &mockable.Clock{}, }, @@ -142,8 +145,10 @@ func TestVerifierVisitAtomicBlock(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - ApricotPhase5Time: time.Now().Add(time.Hour), - BanffTime: mockable.MaxTime, // banff is not activated + UpgradeConfig: upgrade.Config{ + ApricotPhase5Time: time.Now().Add(time.Hour), + BanffTime: mockable.MaxTime, // banff is not activated + }, }, Clk: &mockable.Clock{}, }, @@ -229,8 +234,10 @@ func TestVerifierVisitStandardBlock(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - ApricotPhase5Time: time.Now().Add(time.Hour), - BanffTime: mockable.MaxTime, // banff is not activated + UpgradeConfig: upgrade.Config{ + ApricotPhase5Time: time.Now().Add(time.Hour), + BanffTime: mockable.MaxTime, // banff is not activated + }, }, Clk: &mockable.Clock{}, }, @@ -334,7 +341,9 @@ func TestVerifierVisitCommitBlock(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: mockable.MaxTime, // banff is not activated + UpgradeConfig: upgrade.Config{ + BanffTime: mockable.MaxTime, // banff is not activated + }, }, Clk: &mockable.Clock{}, }, @@ -405,7 +414,9 @@ func TestVerifierVisitAbortBlock(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: mockable.MaxTime, // banff is not activated + UpgradeConfig: upgrade.Config{ + BanffTime: mockable.MaxTime, // banff is not activated + }, }, Clk: &mockable.Clock{}, }, @@ -464,7 +475,9 @@ func TestVerifyUnverifiedParent(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: mockable.MaxTime, // banff is not activated + UpgradeConfig: upgrade.Config{ + BanffTime: mockable.MaxTime, // banff is not activated + }, }, Clk: &mockable.Clock{}, }, @@ -536,7 +549,9 @@ func TestBanffAbortBlockTimestampChecks(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: time.Time{}, // banff is activated + UpgradeConfig: upgrade.Config{ + BanffTime: time.Time{}, // banff is activated + }, }, Clk: &mockable.Clock{}, }, @@ -632,7 +647,9 @@ func TestBanffCommitBlockTimestampChecks(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: time.Time{}, // banff is activated + UpgradeConfig: upgrade.Config{ + BanffTime: time.Time{}, // banff is activated + }, }, Clk: &mockable.Clock{}, }, @@ -711,8 +728,10 @@ func TestVerifierVisitStandardBlockWithDuplicateInputs(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - ApricotPhase5Time: time.Now().Add(time.Hour), - BanffTime: mockable.MaxTime, // banff is not activated + UpgradeConfig: upgrade.Config{ + ApricotPhase5Time: time.Now().Add(time.Hour), + BanffTime: mockable.MaxTime, // banff is not activated + }, }, Clk: &mockable.Clock{}, }, @@ -800,7 +819,9 @@ func TestVerifierVisitApricotStandardBlockWithProposalBlockParent(t *testing.T) verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: mockable.MaxTime, // banff is not activated + UpgradeConfig: upgrade.Config{ + BanffTime: mockable.MaxTime, // banff is not activated + }, }, Clk: &mockable.Clock{}, }, @@ -857,7 +878,9 @@ func TestVerifierVisitBanffStandardBlockWithProposalBlockParent(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: time.Time{}, // banff is activated + UpgradeConfig: upgrade.Config{ + BanffTime: time.Time{}, // banff is activated + }, }, Clk: &mockable.Clock{}, }, @@ -894,7 +917,9 @@ func TestVerifierVisitApricotCommitBlockUnexpectedParentState(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: mockable.MaxTime, // banff is not activated + UpgradeConfig: upgrade.Config{ + BanffTime: mockable.MaxTime, // banff is not activated + }, }, Clk: &mockable.Clock{}, }, @@ -937,7 +962,9 @@ func TestVerifierVisitBanffCommitBlockUnexpectedParentState(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: time.Time{}, // banff is activated + UpgradeConfig: upgrade.Config{ + BanffTime: time.Time{}, // banff is activated + }, }, Clk: &mockable.Clock{}, }, @@ -981,7 +1008,9 @@ func TestVerifierVisitApricotAbortBlockUnexpectedParentState(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: mockable.MaxTime, // banff is not activated + UpgradeConfig: upgrade.Config{ + BanffTime: mockable.MaxTime, // banff is not activated + }, }, Clk: &mockable.Clock{}, }, @@ -1024,7 +1053,9 @@ func TestVerifierVisitBanffAbortBlockUnexpectedParentState(t *testing.T) { verifier := &verifier{ txExecutorBackend: &executor.Backend{ Config: &config.Config{ - BanffTime: time.Time{}, // banff is activated + UpgradeConfig: upgrade.Config{ + BanffTime: time.Time{}, // banff is activated + }, }, Clk: &mockable.Clock{}, }, diff --git a/vms/platformvm/config/config.go b/vms/platformvm/config/config.go index 0c5fcf15a475..8b8a0c717aed 100644 --- a/vms/platformvm/config/config.go +++ b/vms/platformvm/config/config.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/txs" + "github.com/ava-labs/avalanchego/vms/platformvm/upgrade" ) // Struct collecting all foundational parameters of PlatformVM @@ -92,23 +93,8 @@ type Config struct { // Config for the minting function RewardConfig reward.Config - // Time of the AP3 network upgrade - ApricotPhase3Time time.Time - - // Time of the AP5 network upgrade - ApricotPhase5Time time.Time - - // Time of the Banff network upgrade - BanffTime time.Time - - // Time of the Cortina network upgrade - CortinaTime time.Time - - // Time of the Durango network upgrade - DurangoTime time.Time - - // Time of the E network upgrade - EUpgradeTime time.Time + // All network upgrade timestamps + UpgradeConfig upgrade.Config // UseCurrentHeight forces [GetMinimumHeight] to return the current height // of the P-Chain instead of the oldest block in the [recentlyAccepted] @@ -120,39 +106,15 @@ type Config struct { UseCurrentHeight bool } -func (c *Config) IsApricotPhase3Activated(timestamp time.Time) bool { - return !timestamp.Before(c.ApricotPhase3Time) -} - -func (c *Config) IsApricotPhase5Activated(timestamp time.Time) bool { - return !timestamp.Before(c.ApricotPhase5Time) -} - -func (c *Config) IsBanffActivated(timestamp time.Time) bool { - return !timestamp.Before(c.BanffTime) -} - -func (c *Config) IsCortinaActivated(timestamp time.Time) bool { - return !timestamp.Before(c.CortinaTime) -} - -func (c *Config) IsDurangoActivated(timestamp time.Time) bool { - return !timestamp.Before(c.DurangoTime) -} - -func (c *Config) IsEActivated(timestamp time.Time) bool { - return !timestamp.Before(c.EUpgradeTime) -} - func (c *Config) GetCreateBlockchainTxFee(timestamp time.Time) uint64 { - if c.IsApricotPhase3Activated(timestamp) { + if c.UpgradeConfig.IsApricotPhase3Activated(timestamp) { return c.CreateBlockchainTxFee } return c.CreateAssetTxFee } func (c *Config) GetCreateSubnetTxFee(timestamp time.Time) uint64 { - if c.IsApricotPhase3Activated(timestamp) { + if c.UpgradeConfig.IsApricotPhase3Activated(timestamp) { return c.CreateSubnetTxFee } return c.CreateAssetTxFee diff --git a/vms/platformvm/state/state.go b/vms/platformvm/state/state.go index ccfd6d824159..7f06f02e86d6 100644 --- a/vms/platformvm/state/state.go +++ b/vms/platformvm/state/state.go @@ -1628,7 +1628,7 @@ func (s *state) initValidatorSets() error { func (s *state) write(updateValidators bool, height uint64) error { codecVersion := CodecVersion1 - if !s.cfg.IsDurangoActivated(s.GetTimestamp()) { + if !s.cfg.UpgradeConfig.IsDurangoActivated(s.GetTimestamp()) { codecVersion = CodecVersion0 } diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index ea36af13e939..755cbb3b2beb 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -852,9 +852,9 @@ func TestAdvanceTimeTxAfterBanff(t *testing.T) { defer env.ctx.Lock.Unlock() env.clk.Set(defaultGenesisTime) // VM's clock reads the genesis time upgradeTime := env.clk.Time().Add(SyncBound) - env.config.BanffTime = upgradeTime - env.config.CortinaTime = upgradeTime - env.config.DurangoTime = upgradeTime + env.config.UpgradeConfig.BanffTime = upgradeTime + env.config.UpgradeConfig.CortinaTime = upgradeTime + env.config.UpgradeConfig.DurangoTime = upgradeTime // Proposed advancing timestamp to the banff timestamp tx, err := newAdvanceTimeTx(t, upgradeTime) diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index 5b714909b942..288a294e493b 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -185,7 +185,7 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { require := require.New(t) env := newEnvironment(t, banff) - env.config.ApricotPhase3Time = ap3Time + env.config.UpgradeConfig.ApricotPhase3Time = ap3Time addrs := set.NewSet[ids.ShortID](len(preFundedKeys)) for _, key := range preFundedKeys { diff --git a/vms/platformvm/txs/executor/create_subnet_test.go b/vms/platformvm/txs/executor/create_subnet_test.go index f4358e1d8bce..77b37773107b 100644 --- a/vms/platformvm/txs/executor/create_subnet_test.go +++ b/vms/platformvm/txs/executor/create_subnet_test.go @@ -50,7 +50,7 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { require := require.New(t) env := newEnvironment(t, apricotPhase3) - env.config.ApricotPhase3Time = ap3Time + env.config.UpgradeConfig.ApricotPhase3Time = ap3Time env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index d45a52b486d5..7959791187db 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -41,7 +41,7 @@ func TestNewExportTx(t *testing.T) { description: "P->C export", destinationChainID: env.ctx.CChainID, sourceKeys: []*secp256k1.PrivateKey{sourceKey}, - timestamp: env.config.ApricotPhase5Time, + timestamp: env.config.UpgradeConfig.ApricotPhase5Time, }, } diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 387b5d2a831d..994250dd5940 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -42,6 +42,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" + "github.com/ava-labs/avalanchego/vms/platformvm/upgrade" "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" @@ -292,32 +293,34 @@ func defaultConfig(t *testing.T, f fork) *config.Config { MintingPeriod: 365 * 24 * time.Hour, SupplyCap: 720 * units.MegaAvax, }, - ApricotPhase3Time: mockable.MaxTime, - ApricotPhase5Time: mockable.MaxTime, - BanffTime: mockable.MaxTime, - CortinaTime: mockable.MaxTime, - DurangoTime: mockable.MaxTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + ApricotPhase3Time: mockable.MaxTime, + ApricotPhase5Time: mockable.MaxTime, + BanffTime: mockable.MaxTime, + CortinaTime: mockable.MaxTime, + DurangoTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, + }, } switch f { case eUpgrade: - c.EUpgradeTime = defaultValidateStartTime.Add(-2 * time.Second) + c.UpgradeConfig.EUpgradeTime = defaultValidateStartTime.Add(-2 * time.Second) fallthrough case durango: - c.DurangoTime = defaultValidateStartTime.Add(-2 * time.Second) + c.UpgradeConfig.DurangoTime = defaultValidateStartTime.Add(-2 * time.Second) fallthrough case cortina: - c.CortinaTime = defaultValidateStartTime.Add(-2 * time.Second) + c.UpgradeConfig.CortinaTime = defaultValidateStartTime.Add(-2 * time.Second) fallthrough case banff: - c.BanffTime = defaultValidateStartTime.Add(-2 * time.Second) + c.UpgradeConfig.BanffTime = defaultValidateStartTime.Add(-2 * time.Second) fallthrough case apricotPhase5: - c.ApricotPhase5Time = defaultValidateEndTime + c.UpgradeConfig.ApricotPhase5Time = defaultValidateEndTime fallthrough case apricotPhase3: - c.ApricotPhase3Time = defaultValidateEndTime + c.UpgradeConfig.ApricotPhase3Time = defaultValidateEndTime default: require.FailNow(t, "unhandled fork", f) } diff --git a/vms/platformvm/txs/executor/import_test.go b/vms/platformvm/txs/executor/import_test.go index 4ae35d80ae03..c05607526841 100644 --- a/vms/platformvm/txs/executor/import_test.go +++ b/vms/platformvm/txs/executor/import_test.go @@ -84,7 +84,7 @@ func TestNewImportTx(t *testing.T) { }, ), sourceKeys: []*secp256k1.PrivateKey{sourceKey}, - timestamp: env.config.ApricotPhase5Time, + timestamp: env.config.UpgradeConfig.ApricotPhase5Time, expectedErr: nil, }, { @@ -101,7 +101,7 @@ func TestNewImportTx(t *testing.T) { }, ), sourceKeys: []*secp256k1.PrivateKey{sourceKey}, - timestamp: env.config.ApricotPhase5Time, + timestamp: env.config.UpgradeConfig.ApricotPhase5Time, expectedErr: nil, }, } diff --git a/vms/platformvm/txs/executor/proposal_tx_executor.go b/vms/platformvm/txs/executor/proposal_tx_executor.go index 0f082cb8b296..294e01486a17 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor.go @@ -103,12 +103,12 @@ func (e *ProposalTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error { // activation. Following the activation, AddValidatorTxs must be issued into // StandardBlocks. currentTimestamp := e.OnCommitState.GetTimestamp() - if e.Config.IsBanffActivated(currentTimestamp) { + if e.Config.UpgradeConfig.IsBanffActivated(currentTimestamp) { return fmt.Errorf( "%w: timestamp (%s) >= Banff fork time (%s)", ErrProposedAddStakerTxAfterBanff, currentTimestamp, - e.Config.BanffTime, + e.Config.UpgradeConfig.BanffTime, ) } @@ -150,12 +150,12 @@ func (e *ProposalTxExecutor) AddSubnetValidatorTx(tx *txs.AddSubnetValidatorTx) // activation. Following the activation, AddSubnetValidatorTxs must be // issued into StandardBlocks. currentTimestamp := e.OnCommitState.GetTimestamp() - if e.Config.IsBanffActivated(currentTimestamp) { + if e.Config.UpgradeConfig.IsBanffActivated(currentTimestamp) { return fmt.Errorf( "%w: timestamp (%s) >= Banff fork time (%s)", ErrProposedAddStakerTxAfterBanff, currentTimestamp, - e.Config.BanffTime, + e.Config.UpgradeConfig.BanffTime, ) } @@ -196,12 +196,12 @@ func (e *ProposalTxExecutor) AddDelegatorTx(tx *txs.AddDelegatorTx) error { // activation. Following the activation, AddDelegatorTxs must be issued into // StandardBlocks. currentTimestamp := e.OnCommitState.GetTimestamp() - if e.Config.IsBanffActivated(currentTimestamp) { + if e.Config.UpgradeConfig.IsBanffActivated(currentTimestamp) { return fmt.Errorf( "%w: timestamp (%s) >= Banff fork time (%s)", ErrProposedAddStakerTxAfterBanff, currentTimestamp, - e.Config.BanffTime, + e.Config.UpgradeConfig.BanffTime, ) } @@ -248,12 +248,12 @@ func (e *ProposalTxExecutor) AdvanceTimeTx(tx *txs.AdvanceTimeTx) error { // Validate [newChainTime] newChainTime := tx.Timestamp() - if e.Config.IsBanffActivated(newChainTime) { + if e.Config.UpgradeConfig.IsBanffActivated(newChainTime) { return fmt.Errorf( "%w: proposed timestamp (%s) >= Banff fork time (%s)", ErrAdvanceTimeTxIssuedAfterBanff, newChainTime, - e.Config.BanffTime, + e.Config.UpgradeConfig.BanffTime, ) } @@ -558,7 +558,7 @@ func (e *ProposalTxExecutor) rewardDelegatorTx(uDelegatorTx txs.DelegatorTx, del } // Reward the delegatee here - if e.Config.IsCortinaActivated(validator.StartTime) { + if e.Config.UpgradeConfig.IsCortinaActivated(validator.StartTime) { previousDelegateeReward, err := e.OnCommitState.GetDelegateeReward( validator.SubnetID, validator.NodeID, diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 6fe0f7831235..87caaca7d7c1 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -235,7 +235,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { t.Run(tt.description, func(t *testing.T) { require := require.New(t) env := newEnvironment(t, apricotPhase5) - env.config.ApricotPhase3Time = tt.AP3Time + env.config.UpgradeConfig.ApricotPhase3Time = tt.AP3Time tx, err := env.txBuilder.NewAddDelegatorTx( &txs.Validator{ diff --git a/vms/platformvm/txs/executor/staker_tx_verification.go b/vms/platformvm/txs/executor/staker_tx_verification.go index 893a8a1c3405..befd736a674b 100644 --- a/vms/platformvm/txs/executor/staker_tx_verification.go +++ b/vms/platformvm/txs/executor/staker_tx_verification.go @@ -97,7 +97,7 @@ func verifyAddValidatorTx( error, ) { currentTimestamp := chainState.GetTimestamp() - if backend.Config.IsDurangoActivated(currentTimestamp) { + if backend.Config.UpgradeConfig.IsDurangoActivated(currentTimestamp) { return nil, ErrAddValidatorTxPostDurango } @@ -194,7 +194,7 @@ func verifyAddSubnetValidatorTx( var ( currentTimestamp = chainState.GetTimestamp() - isDurangoActive = backend.Config.IsDurangoActivated(currentTimestamp) + isDurangoActive = backend.Config.UpgradeConfig.IsDurangoActivated(currentTimestamp) ) if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { return err @@ -288,7 +288,7 @@ func verifyRemoveSubnetValidatorTx( var ( currentTimestamp = chainState.GetTimestamp() - isDurangoActive = backend.Config.IsDurangoActivated(currentTimestamp) + isDurangoActive = backend.Config.UpgradeConfig.IsDurangoActivated(currentTimestamp) ) if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { return nil, false, err @@ -355,7 +355,7 @@ func verifyAddDelegatorTx( error, ) { currentTimestamp := chainState.GetTimestamp() - if backend.Config.IsDurangoActivated(currentTimestamp) { + if backend.Config.UpgradeConfig.IsDurangoActivated(currentTimestamp) { return nil, ErrAddDelegatorTxPostDurango } @@ -413,7 +413,7 @@ func verifyAddDelegatorTx( return nil, ErrStakeOverflow } - if backend.Config.IsApricotPhase3Activated(currentTimestamp) { + if backend.Config.UpgradeConfig.IsApricotPhase3Activated(currentTimestamp) { maximumWeight = min(maximumWeight, backend.Config.MaxValidatorStake) } @@ -472,7 +472,7 @@ func verifyAddPermissionlessValidatorTx( var ( currentTimestamp = chainState.GetTimestamp() - isDurangoActive = backend.Config.IsDurangoActivated(currentTimestamp) + isDurangoActive = backend.Config.UpgradeConfig.IsDurangoActivated(currentTimestamp) ) if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { return err @@ -594,7 +594,7 @@ func verifyAddPermissionlessDelegatorTx( var ( currentTimestamp = chainState.GetTimestamp() - isDurangoActive = backend.Config.IsDurangoActivated(currentTimestamp) + isDurangoActive = backend.Config.UpgradeConfig.IsDurangoActivated(currentTimestamp) ) if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { return err @@ -737,7 +737,7 @@ func verifyTransferSubnetOwnershipTx( sTx *txs.Tx, tx *txs.TransferSubnetOwnershipTx, ) error { - if !backend.Config.IsDurangoActivated(chainState.GetTimestamp()) { + if !backend.Config.UpgradeConfig.IsDurangoActivated(chainState.GetTimestamp()) { return ErrDurangoUpgradeNotActive } diff --git a/vms/platformvm/txs/executor/standard_tx_executor.go b/vms/platformvm/txs/executor/standard_tx_executor.go index aa3ea9a2aafe..4ee5ced73173 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor.go +++ b/vms/platformvm/txs/executor/standard_tx_executor.go @@ -56,7 +56,7 @@ func (e *StandardTxExecutor) CreateChainTx(tx *txs.CreateChainTx) error { var ( currentTimestamp = e.State.GetTimestamp() - isDurangoActive = e.Config.IsDurangoActivated(currentTimestamp) + isDurangoActive = e.Config.UpgradeConfig.IsDurangoActivated(currentTimestamp) ) if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { return err @@ -107,7 +107,7 @@ func (e *StandardTxExecutor) CreateSubnetTx(tx *txs.CreateSubnetTx) error { var ( currentTimestamp = e.State.GetTimestamp() - isDurangoActive = e.Config.IsDurangoActivated(currentTimestamp) + isDurangoActive = e.Config.UpgradeConfig.IsDurangoActivated(currentTimestamp) ) if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { return err @@ -147,7 +147,7 @@ func (e *StandardTxExecutor) ImportTx(tx *txs.ImportTx) error { var ( currentTimestamp = e.State.GetTimestamp() - isDurangoActive = e.Config.IsDurangoActivated(currentTimestamp) + isDurangoActive = e.Config.UpgradeConfig.IsDurangoActivated(currentTimestamp) ) if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { return err @@ -233,7 +233,7 @@ func (e *StandardTxExecutor) ExportTx(tx *txs.ExportTx) error { var ( currentTimestamp = e.State.GetTimestamp() - isDurangoActive = e.Config.IsDurangoActivated(currentTimestamp) + isDurangoActive = e.Config.UpgradeConfig.IsDurangoActivated(currentTimestamp) ) if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { return err @@ -418,7 +418,7 @@ func (e *StandardTxExecutor) TransformSubnetTx(tx *txs.TransformSubnetTx) error var ( currentTimestamp = e.State.GetTimestamp() - isDurangoActive = e.Config.IsDurangoActivated(currentTimestamp) + isDurangoActive = e.Config.UpgradeConfig.IsDurangoActivated(currentTimestamp) ) if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { return err @@ -541,7 +541,7 @@ func (e *StandardTxExecutor) TransferSubnetOwnershipTx(tx *txs.TransferSubnetOwn } func (e *StandardTxExecutor) BaseTx(tx *txs.BaseTx) error { - if !e.Backend.Config.IsDurangoActivated(e.State.GetTimestamp()) { + if !e.Backend.Config.UpgradeConfig.IsDurangoActivated(e.State.GetTimestamp()) { return ErrDurangoUpgradeNotActive } @@ -585,7 +585,7 @@ func (e *StandardTxExecutor) putStaker(stakerTx txs.Staker) error { err error ) - if !e.Config.IsDurangoActivated(chainTime) { + if !e.Config.UpgradeConfig.IsDurangoActivated(chainTime) { // Pre-Durango, stakers set a future [StartTime] and are added to the // pending staker set. They are promoted to the current staker set once // the chain time reaches [StartTime]. diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index d582e592d52a..28fb5a2404fb 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -31,6 +31,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" + "github.com/ava-labs/avalanchego/vms/platformvm/upgrade" "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" @@ -70,7 +71,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { } for _, test := range tests { // Case: Empty validator node ID after banff - env.config.BanffTime = test.banffTime + env.config.UpgradeConfig.BanffTime = test.banffTime tx, err := env.txBuilder.NewAddValidatorTx( // create the tx &txs.Validator{ @@ -315,7 +316,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { t.Run(tt.description, func(t *testing.T) { require := require.New(t) env := newEnvironment(t, apricotPhase5) - env.config.ApricotPhase3Time = tt.AP3Time + env.config.UpgradeConfig.ApricotPhase3Time = tt.AP3Time tx, err := env.txBuilder.NewAddDelegatorTx( &txs.Validator{ @@ -339,7 +340,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) - env.config.BanffTime = onAcceptState.GetTimestamp() + env.config.UpgradeConfig.BanffTime = onAcceptState.GetTimestamp() executor := StandardTxExecutor{ Backend: &env.backend, @@ -2080,32 +2081,34 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { func defaultTestConfig(t *testing.T, f fork, tm time.Time) *config.Config { c := &config.Config{ - ApricotPhase3Time: mockable.MaxTime, - ApricotPhase5Time: mockable.MaxTime, - BanffTime: mockable.MaxTime, - CortinaTime: mockable.MaxTime, - DurangoTime: mockable.MaxTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + ApricotPhase3Time: mockable.MaxTime, + ApricotPhase5Time: mockable.MaxTime, + BanffTime: mockable.MaxTime, + CortinaTime: mockable.MaxTime, + DurangoTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, + }, } switch f { case eUpgrade: - c.EUpgradeTime = tm + c.UpgradeConfig.EUpgradeTime = tm fallthrough case durango: - c.DurangoTime = tm + c.UpgradeConfig.DurangoTime = tm fallthrough case cortina: - c.CortinaTime = tm + c.UpgradeConfig.CortinaTime = tm fallthrough case banff: - c.BanffTime = tm + c.UpgradeConfig.BanffTime = tm fallthrough case apricotPhase5: - c.ApricotPhase5Time = tm + c.UpgradeConfig.ApricotPhase5Time = tm fallthrough case apricotPhase3: - c.ApricotPhase3Time = tm + c.UpgradeConfig.ApricotPhase3Time = tm default: require.FailNow(t, "unhandled fork", f) } diff --git a/vms/platformvm/upgrade/config.go b/vms/platformvm/upgrade/config.go new file mode 100644 index 000000000000..1d92736a2ee3 --- /dev/null +++ b/vms/platformvm/upgrade/config.go @@ -0,0 +1,50 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package upgrade + +import "time" + +type Config struct { + // Time of the AP3 network upgrade + ApricotPhase3Time time.Time + + // Time of the AP5 network upgrade + ApricotPhase5Time time.Time + + // Time of the Banff network upgrade + BanffTime time.Time + + // Time of the Cortina network upgrade + CortinaTime time.Time + + // Time of the Durango network upgrade + DurangoTime time.Time + + // Time of the E network upgrade + EUpgradeTime time.Time +} + +func (c *Config) IsApricotPhase3Activated(timestamp time.Time) bool { + return !timestamp.Before(c.ApricotPhase3Time) +} + +func (c *Config) IsApricotPhase5Activated(timestamp time.Time) bool { + return !timestamp.Before(c.ApricotPhase5Time) +} + +func (c *Config) IsBanffActivated(timestamp time.Time) bool { + return !timestamp.Before(c.BanffTime) +} + +func (c *Config) IsCortinaActivated(timestamp time.Time) bool { + return !timestamp.Before(c.CortinaTime) +} + +func (c *Config) IsDurangoActivated(timestamp time.Time) bool { + return !timestamp.Before(c.DurangoTime) +} + +func (c *Config) IsEActivated(timestamp time.Time) bool { + return !timestamp.Before(c.EUpgradeTime) +} diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 9effc6fbeeb2..4c1e3ef9fe2c 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -44,6 +44,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" + "github.com/ava-labs/avalanchego/vms/platformvm/upgrade" "github.com/ava-labs/avalanchego/vms/secp256k1fx" blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor" @@ -661,11 +662,13 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { MinStakeDuration: defaultMinStakingDuration, MaxStakeDuration: defaultMaxStakingDuration, RewardConfig: defaultRewardConfig, - ApricotPhase3Time: forkTime, - ApricotPhase5Time: forkTime, - BanffTime: forkTime, - CortinaTime: forkTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + ApricotPhase3Time: forkTime, + ApricotPhase5Time: forkTime, + BanffTime: forkTime, + CortinaTime: forkTime, + EUpgradeTime: mockable.MaxTime, + }, }} vm.clock.Set(forkTime.Add(time.Second)) diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 0218e115521d..6813919614b8 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -45,6 +45,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" + "github.com/ava-labs/avalanchego/vms/platformvm/upgrade" "github.com/ava-labs/avalanchego/vms/secp256k1fx" blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor" @@ -251,7 +252,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { require := require.New(t) vm, txBuilder, _, _ := defaultVM(t, apricotPhase3) - vm.ApricotPhase3Time = test.ap3Time + vm.UpgradeConfig.ApricotPhase3Time = test.ap3Time vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -442,10 +443,12 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { MinStakeDuration: defaultMinStakingDuration, MaxStakeDuration: defaultMaxStakingDuration, RewardConfig: defaultRewardConfig, - BanffTime: latestForkTime, - CortinaTime: mockable.MaxTime, - DurangoTime: mockable.MaxTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + BanffTime: latestForkTime, + CortinaTime: mockable.MaxTime, + DurangoTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, + }, }} ctx := snowtest.Context(t, snowtest.PChainID) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index f5be2e5684a4..6f1177ed17f1 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -58,6 +58,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" + "github.com/ava-labs/avalanchego/vms/platformvm/upgrade" "github.com/ava-labs/avalanchego/vms/secp256k1fx" p2ppb "github.com/ava-labs/avalanchego/proto/pb/p2p" @@ -254,12 +255,14 @@ func defaultVM(t *testing.T, f fork) (*VM, *txstest.Builder, database.Database, MinStakeDuration: defaultMinStakingDuration, MaxStakeDuration: defaultMaxStakingDuration, RewardConfig: defaultRewardConfig, - ApricotPhase3Time: apricotPhase3Time, - ApricotPhase5Time: apricotPhase5Time, - BanffTime: banffTime, - CortinaTime: cortinaTime, - DurangoTime: durangoTime, - EUpgradeTime: eUpgradeTime, + UpgradeConfig: upgrade.Config{ + ApricotPhase3Time: apricotPhase3Time, + ApricotPhase5Time: apricotPhase5Time, + BanffTime: banffTime, + CortinaTime: cortinaTime, + DurangoTime: durangoTime, + EUpgradeTime: eUpgradeTime, + }, }} db := memdb.New() @@ -1178,10 +1181,12 @@ func TestRestartFullyAccepted(t *testing.T) { MinStakeDuration: defaultMinStakingDuration, MaxStakeDuration: defaultMaxStakingDuration, RewardConfig: defaultRewardConfig, - BanffTime: latestForkTime, - CortinaTime: latestForkTime, - DurangoTime: latestForkTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + BanffTime: latestForkTime, + CortinaTime: latestForkTime, + DurangoTime: latestForkTime, + EUpgradeTime: mockable.MaxTime, + }, }} firstCtx := snowtest.Context(t, snowtest.PChainID) @@ -1266,10 +1271,12 @@ func TestRestartFullyAccepted(t *testing.T) { MinStakeDuration: defaultMinStakingDuration, MaxStakeDuration: defaultMaxStakingDuration, RewardConfig: defaultRewardConfig, - BanffTime: latestForkTime, - CortinaTime: latestForkTime, - DurangoTime: latestForkTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + BanffTime: latestForkTime, + CortinaTime: latestForkTime, + DurangoTime: latestForkTime, + EUpgradeTime: mockable.MaxTime, + }, }} secondCtx := snowtest.Context(t, snowtest.PChainID) @@ -1315,10 +1322,12 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { MinStakeDuration: defaultMinStakingDuration, MaxStakeDuration: defaultMaxStakingDuration, RewardConfig: defaultRewardConfig, - BanffTime: latestForkTime, - CortinaTime: latestForkTime, - DurangoTime: latestForkTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + BanffTime: latestForkTime, + CortinaTime: latestForkTime, + DurangoTime: latestForkTime, + EUpgradeTime: mockable.MaxTime, + }, }} initialClkTime := latestForkTime.Add(time.Second) @@ -1662,10 +1671,12 @@ func TestUnverifiedParent(t *testing.T) { MinStakeDuration: defaultMinStakingDuration, MaxStakeDuration: defaultMaxStakingDuration, RewardConfig: defaultRewardConfig, - BanffTime: latestForkTime, - CortinaTime: latestForkTime, - DurangoTime: latestForkTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + BanffTime: latestForkTime, + CortinaTime: latestForkTime, + DurangoTime: latestForkTime, + EUpgradeTime: mockable.MaxTime, + }, }} initialClkTime := latestForkTime.Add(time.Second) @@ -1823,10 +1834,12 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { RewardConfig: defaultRewardConfig, Validators: validators.NewManager(), UptimeLockedCalculator: uptime.NewLockedCalculator(), - BanffTime: latestForkTime, - CortinaTime: latestForkTime, - DurangoTime: latestForkTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + BanffTime: latestForkTime, + CortinaTime: latestForkTime, + DurangoTime: latestForkTime, + EUpgradeTime: mockable.MaxTime, + }, }} firstCtx := snowtest.Context(t, snowtest.PChainID) @@ -1872,10 +1885,12 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { UptimePercentage: secondUptimePercentage / 100., Validators: validators.NewManager(), UptimeLockedCalculator: uptime.NewLockedCalculator(), - BanffTime: latestForkTime, - CortinaTime: latestForkTime, - DurangoTime: latestForkTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + BanffTime: latestForkTime, + CortinaTime: latestForkTime, + DurangoTime: latestForkTime, + EUpgradeTime: mockable.MaxTime, + }, }} secondCtx := snowtest.Context(t, snowtest.PChainID) @@ -1972,10 +1987,12 @@ func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { RewardConfig: defaultRewardConfig, Validators: validators.NewManager(), UptimeLockedCalculator: uptime.NewLockedCalculator(), - BanffTime: latestForkTime, - CortinaTime: latestForkTime, - DurangoTime: latestForkTime, - EUpgradeTime: mockable.MaxTime, + UpgradeConfig: upgrade.Config{ + BanffTime: latestForkTime, + CortinaTime: latestForkTime, + DurangoTime: latestForkTime, + EUpgradeTime: mockable.MaxTime, + }, }} ctx := snowtest.Context(t, snowtest.PChainID)