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

Repackaged upgrades times into upgrade package #3019

Merged
merged 1 commit into from
May 14, 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
17 changes: 10 additions & 7 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/block/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
27 changes: 15 additions & 12 deletions vms/platformvm/block/builder/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}
Expand Down
27 changes: 15 additions & 12 deletions vms/platformvm/block/executor/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions vms/platformvm/block/executor/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}

Expand Down Expand Up @@ -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)
Expand Down
67 changes: 49 additions & 18 deletions vms/platformvm/block/executor/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down Expand Up @@ -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{},
},
Expand Down
Loading
Loading