Skip to content

Commit

Permalink
Add D upgrade boilerplate (ava-labs#2049)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Sep 21, 2023
1 parent a797b91 commit f0374d9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
1 change: 1 addition & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ func (n *Node) initVMs() error {
ApricotPhase5Time: version.GetApricotPhase5Time(n.Config.NetworkID),
BanffTime: version.GetBanffTime(n.Config.NetworkID),
CortinaTime: version.GetCortinaTime(n.Config.NetworkID),
DTime: version.GetDTime(n.Config.NetworkID),
UseCurrentHeight: n.Config.UseCurrentHeight,
},
}),
Expand Down
33 changes: 21 additions & 12 deletions version/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ var (
// by avalanchego, but is useful for downstream libraries.
RPCChainVMProtocolCompatibility map[uint][]*Semantic

DefaultUpgradeTime = time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC)

ApricotPhase3Times = map[uint32]time.Time{
constants.MainnetID: time.Date(2021, time.August, 24, 14, 0, 0, 0, time.UTC),
constants.FujiID: time.Date(2021, time.August, 16, 19, 0, 0, 0, time.UTC),
}
ApricotPhase3DefaultTime = time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC)

ApricotPhase4Times = map[uint32]time.Time{
constants.MainnetID: time.Date(2021, time.September, 22, 21, 0, 0, 0, time.UTC),
constants.FujiID: time.Date(2021, time.September, 16, 21, 0, 0, 0, time.UTC),
}
ApricotPhase4DefaultTime = time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC)
ApricotPhase4MinPChainHeight = map[uint32]uint64{
constants.MainnetID: 793005,
constants.FujiID: 47437,
Expand All @@ -81,25 +81,27 @@ var (
constants.MainnetID: time.Date(2021, time.December, 2, 18, 0, 0, 0, time.UTC),
constants.FujiID: time.Date(2021, time.November, 24, 15, 0, 0, 0, time.UTC),
}
ApricotPhase5DefaultTime = time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC)

ApricotPhase6Times = map[uint32]time.Time{
constants.MainnetID: time.Date(2022, time.September, 6, 20, 0, 0, 0, time.UTC),
constants.FujiID: time.Date(2022, time.September, 6, 20, 0, 0, 0, time.UTC),
}
ApricotPhase6DefaultTime = time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC)

BanffTimes = map[uint32]time.Time{
constants.MainnetID: time.Date(2022, time.October, 18, 16, 0, 0, 0, time.UTC),
constants.FujiID: time.Date(2022, time.October, 3, 14, 0, 0, 0, time.UTC),
}
BanffDefaultTime = time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC)

CortinaTimes = map[uint32]time.Time{
constants.MainnetID: time.Date(2023, time.April, 25, 15, 0, 0, 0, time.UTC),
constants.FujiID: time.Date(2023, time.April, 6, 15, 0, 0, 0, time.UTC),
}
CortinaDefaultTime = time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC)

// TODO: update this before release
DTimes = map[uint32]time.Time{
constants.MainnetID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
constants.FujiID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
}
)

func init() {
Expand Down Expand Up @@ -127,14 +129,14 @@ func GetApricotPhase3Time(networkID uint32) time.Time {
if upgradeTime, exists := ApricotPhase3Times[networkID]; exists {
return upgradeTime
}
return ApricotPhase3DefaultTime
return DefaultUpgradeTime
}

func GetApricotPhase4Time(networkID uint32) time.Time {
if upgradeTime, exists := ApricotPhase4Times[networkID]; exists {
return upgradeTime
}
return ApricotPhase4DefaultTime
return DefaultUpgradeTime
}

func GetApricotPhase4MinPChainHeight(networkID uint32) uint64 {
Expand All @@ -148,28 +150,35 @@ func GetApricotPhase5Time(networkID uint32) time.Time {
if upgradeTime, exists := ApricotPhase5Times[networkID]; exists {
return upgradeTime
}
return ApricotPhase5DefaultTime
return DefaultUpgradeTime
}

func GetApricotPhase6Time(networkID uint32) time.Time {
if upgradeTime, exists := ApricotPhase6Times[networkID]; exists {
return upgradeTime
}
return ApricotPhase6DefaultTime
return DefaultUpgradeTime
}

func GetBanffTime(networkID uint32) time.Time {
if upgradeTime, exists := BanffTimes[networkID]; exists {
return upgradeTime
}
return BanffDefaultTime
return DefaultUpgradeTime
}

func GetCortinaTime(networkID uint32) time.Time {
if upgradeTime, exists := CortinaTimes[networkID]; exists {
return upgradeTime
}
return CortinaDefaultTime
return DefaultUpgradeTime
}

func GetDTime(networkID uint32) time.Time {
if upgradeTime, exists := DTimes[networkID]; exists {
return upgradeTime
}
return DefaultUpgradeTime
}

func GetCompatibility(networkID uint32) Compatibility {
Expand Down
2 changes: 1 addition & 1 deletion vms/avm/states/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func TestInitializeChainState(t *testing.T) {
require.NoError(err)

stopVertexID := ids.GenerateTestID()
genesisTimestamp := version.CortinaDefaultTime
genesisTimestamp := version.DefaultUpgradeTime
require.NoError(s.InitializeChainState(stopVertexID, genesisTimestamp))

lastAcceptedID := s.GetLastAccepted()
Expand Down
8 changes: 8 additions & 0 deletions vms/platformvm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ type Config struct {
// Time of the Cortina network upgrade
CortinaTime time.Time

// Time of the D network upgrade
DTime time.Time

// UseCurrentHeight forces [GetMinimumHeight] to return the current height
// of the P-Chain instead of the oldest block in the [recentlyAccepted]
// window.
Expand All @@ -130,6 +133,11 @@ func (c *Config) IsCortinaActivated(timestamp time.Time) bool {
return !timestamp.Before(c.CortinaTime)
}

// TODO: Rename
func (c *Config) IsDActivated(timestamp time.Time) bool {
return !timestamp.Before(c.DTime)
}

func (c *Config) GetCreateBlockchainTxFee(timestamp time.Time) uint64 {
if c.IsApricotPhase3Activated(timestamp) {
return c.CreateBlockchainTxFee
Expand Down

0 comments on commit f0374d9

Please sign in to comment.