Skip to content

Add F Upgrade Scaffolding. Post-Etna Cleanup #3672

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

Merged
merged 5 commits into from
Jan 24, 2025
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
3 changes: 2 additions & 1 deletion api/info/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,8 @@ curl -X POST --data '{
"cortinaTime": "2020-12-05T05:00:00Z",
"cortinaXChainStopVertexID": "11111111111111111111111111111111LpoYY",
"durangoTime": "2020-12-05T05:00:00Z",
"etnaTime": "2024-10-09T20:00:00Z"
"etnaTime": "2024-10-09T20:00:00Z",
"fUpgradeTime": "9999-12-01T05:00:00Z"
},
"id": 1
}
Expand Down
889 changes: 451 additions & 438 deletions proto/pb/vm/vm.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions proto/vm/vm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ message NetworkUpgrades {
bytes cortina_x_chain_stop_vertex_id = 12;
google.protobuf.Timestamp durango_time = 13;
google.protobuf.Timestamp etna_time = 14;
google.protobuf.Timestamp f_upgrade_time = 15;
}

message InitializeResponse {
Expand Down
9 changes: 9 additions & 0 deletions upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
CortinaXChainStopVertexID: ids.FromStringOrPanic("jrGWDh5Po9FMj54depyunNixpia5PN4aAYxfmNzU8n752Rjga"),
DurangoTime: time.Date(2024, time.March, 6, 16, 0, 0, 0, time.UTC),
EtnaTime: time.Date(2024, time.December, 16, 17, 0, 0, 0, time.UTC),
FUpgradeTime: UnscheduledActivationTime,
}
Fuji = Config{
ApricotPhase1Time: time.Date(2021, time.March, 26, 14, 0, 0, 0, time.UTC),
Expand All @@ -55,6 +56,7 @@ var (
CortinaXChainStopVertexID: ids.FromStringOrPanic("2D1cmbiG36BqQMRyHt4kFhWarmatA1ighSpND3FeFgz3vFVtCZ"),
DurangoTime: time.Date(2024, time.February, 13, 16, 0, 0, 0, time.UTC),
EtnaTime: time.Date(2024, time.November, 25, 16, 0, 0, 0, time.UTC),
FUpgradeTime: UnscheduledActivationTime,
}
Default = Config{
ApricotPhase1Time: InitiallyActiveTime,
Expand All @@ -71,6 +73,7 @@ var (
CortinaXChainStopVertexID: ids.Empty,
DurangoTime: InitiallyActiveTime,
EtnaTime: InitiallyActiveTime,
FUpgradeTime: UnscheduledActivationTime,
}

ErrInvalidUpgradeTimes = errors.New("invalid upgrade configuration")
Expand All @@ -91,6 +94,7 @@ type Config struct {
CortinaXChainStopVertexID ids.ID `json:"cortinaXChainStopVertexID"`
DurangoTime time.Time `json:"durangoTime"`
EtnaTime time.Time `json:"etnaTime"`
FUpgradeTime time.Time `json:"fUpgradeTime"`
}

func (c *Config) Validate() error {
Expand All @@ -107,6 +111,7 @@ func (c *Config) Validate() error {
c.CortinaTime,
c.DurangoTime,
c.EtnaTime,
c.FUpgradeTime,
}
for i := 0; i < len(upgrades)-1; i++ {
if upgrades[i].After(upgrades[i+1]) {
Expand Down Expand Up @@ -170,6 +175,10 @@ func (c *Config) IsEtnaActivated(t time.Time) bool {
return !t.Before(c.EtnaTime)
}

func (c *Config) IsFUpgradeActivated(t time.Time) bool {
return !t.Before(c.FUpgradeTime)
}

func GetConfig(networkID uint32) Config {
switch networkID {
case constants.MainnetID:
Expand Down
3 changes: 3 additions & 0 deletions upgrade/upgradetest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func GetConfigWithUpgradeTime(fork Fork, upgradeTime time.Time) upgrade.Config {
// to the provided upgradeTime.
func SetTimesTo(c *upgrade.Config, fork Fork, upgradeTime time.Time) {
switch fork {
case FUpgrade:
c.FUpgradeTime = upgradeTime
fallthrough
case Etna:
c.EtnaTime = upgradeTime
fallthrough
Expand Down
3 changes: 3 additions & 0 deletions upgrade/upgradetest/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
Cortina
Durango
Etna
FUpgrade

Latest = Etna
)
Expand All @@ -26,6 +27,8 @@ type Fork int

func (f Fork) String() string {
switch f {
case FUpgrade:
return "FUpgrade"
case Etna:
return "Etna"
case Durango:
Expand Down
15 changes: 0 additions & 15 deletions vms/platformvm/state/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 2 additions & 17 deletions vms/platformvm/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ var (
InactivePrefix = []byte("inactive")
SingletonPrefix = []byte("singleton")

EtnaHeightKey = []byte("etna height")
TimestampKey = []byte("timestamp")
FeeStateKey = []byte("fee state")
L1ValidatorExcessKey = []byte("l1Validator excess")
Expand Down Expand Up @@ -157,9 +156,6 @@ type State interface {
uptime.State
avax.UTXOReader

// TODO: Remove after Etna is activated
GetEtnaHeight() (uint64, error)

GetLastAccepted() ids.ID
SetLastAccepted(blkID ids.ID)

Expand Down Expand Up @@ -319,7 +315,6 @@ type stateBlk struct {
* '-. singletons
* |-- initializedKey -> nil
* |-- blocksReindexedKey -> nil
* |-- etnaHeightKey -> height
* |-- timestampKey -> timestamp
* |-- feeStateKey -> feeState
* |-- l1ValidatorExcessKey -> l1ValidatorExcess
Expand Down Expand Up @@ -1326,10 +1321,6 @@ func (s *state) GetStartTime(nodeID ids.NodeID) (time.Time, error) {
return staker.StartTime, nil
}

func (s *state) GetEtnaHeight() (uint64, error) {
return database.GetUInt64(s.singletonDB, EtnaHeightKey)
}

// GetTimestamp allows for concurrent reads.
func (s *state) GetTimestamp() time.Time {
return s.timestamp
Expand Down Expand Up @@ -2127,7 +2118,7 @@ func (s *state) write(updateValidators bool, height uint64) error {
s.writeTransformedSubnets(),
s.writeSubnetSupplies(),
s.writeChains(),
s.writeMetadata(height),
s.writeMetadata(),
)
}

Expand Down Expand Up @@ -3041,13 +3032,7 @@ func (s *state) writeChains() error {
return nil
}

func (s *state) writeMetadata(height uint64) error {
if !s.upgrades.IsEtnaActivated(s.persistedTimestamp) && s.upgrades.IsEtnaActivated(s.timestamp) {
if err := database.PutUInt64(s.singletonDB, EtnaHeightKey, height); err != nil {
return fmt.Errorf("failed to write etna height: %w", err)
}
}

func (s *state) writeMetadata() error {
if !s.persistedTimestamp.Equal(s.timestamp) {
if err := database.PutTimestamp(s.singletonDB, TimestampKey, s.timestamp); err != nil {
return fmt.Errorf("failed to write timestamp: %w", err)
Expand Down
68 changes: 0 additions & 68 deletions vms/platformvm/state/state_interface_test.go

This file was deleted.

90 changes: 1 addition & 89 deletions vms/platformvm/validators/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/ava-labs/avalanchego/cache"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/constants"
Expand Down Expand Up @@ -59,9 +58,6 @@ type Manager interface {
type State interface {
GetTx(txID ids.ID) (*txs.Tx, status.Status, error)

// TODO: Remove after Etna is activated
GetEtnaHeight() (uint64, error)

GetLastAccepted() ids.ID
GetStatelessBlock(blockID ids.ID) (block.Block, error)

Expand Down Expand Up @@ -213,23 +209,10 @@ func (m *manager) GetValidatorSet(
return maps.Clone(validatorSet), nil
}

etnaHeight, err := m.state.GetEtnaHeight()
if err != nil && err != database.ErrNotFound {
return nil, err
}

// get the start time to track metrics
startTime := m.clk.Time()

var (
validatorSet map[ids.NodeID]*validators.GetValidatorOutput
currentHeight uint64
)
if subnetID == constants.PrimaryNetworkID || (err == nil && targetHeight >= etnaHeight) {
validatorSet, currentHeight, err = m.makeValidatorSet(ctx, targetHeight, subnetID)
} else {
validatorSet, currentHeight, err = m.makeSubnetValidatorSet(ctx, targetHeight, subnetID)
}
validatorSet, currentHeight, err := m.makeValidatorSet(ctx, targetHeight, subnetID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -317,77 +300,6 @@ func (m *manager) getCurrentValidatorSet(
return subnetMap, currentHeight, err
}

// TODO: Once Etna has been activated, remove this function and use
// makeValidatorSet for all validator set lookups.
func (m *manager) makeSubnetValidatorSet(
ctx context.Context,
targetHeight uint64,
subnetID ids.ID,
) (map[ids.NodeID]*validators.GetValidatorOutput, uint64, error) {
subnetValidatorSet, primaryValidatorSet, currentHeight, err := m.getCurrentValidatorSets(ctx, subnetID)
if err != nil {
return nil, 0, err
}
if currentHeight < targetHeight {
return nil, 0, fmt.Errorf("%w with SubnetID = %s: current P-chain height (%d) < requested P-Chain height (%d)",
errUnfinalizedHeight,
subnetID,
currentHeight,
targetHeight,
)
}

// Rebuild subnet validators at [targetHeight]
//
// Note: Since we are attempting to generate the validator set at
// [targetHeight], we want to apply the diffs from
// (targetHeight, currentHeight]. Because the state interface is implemented
// to be inclusive, we apply diffs in [targetHeight + 1, currentHeight].
lastDiffHeight := targetHeight + 1
err = m.state.ApplyValidatorWeightDiffs(
ctx,
subnetValidatorSet,
currentHeight,
lastDiffHeight,
subnetID,
)
if err != nil {
return nil, 0, err
}

// Update the subnet validator set to include the public keys at
// [currentHeight]. When we apply the public key diffs, we will convert
// these keys to represent the public keys at [targetHeight]. If the subnet
// validator is not currently a primary network validator, it doesn't have a
// key at [currentHeight].
for nodeID, vdr := range subnetValidatorSet {
if primaryVdr, ok := primaryValidatorSet[nodeID]; ok {
vdr.PublicKey = primaryVdr.PublicKey
} else {
vdr.PublicKey = nil
}
}

err = m.state.ApplyValidatorPublicKeyDiffs(
ctx,
subnetValidatorSet,
currentHeight,
lastDiffHeight,
constants.PrimaryNetworkID,
)
return subnetValidatorSet, currentHeight, err
}

func (m *manager) getCurrentValidatorSets(
ctx context.Context,
subnetID ids.ID,
) (map[ids.NodeID]*validators.GetValidatorOutput, map[ids.NodeID]*validators.GetValidatorOutput, uint64, error) {
subnetMap := m.cfg.Validators.GetMap(subnetID)
primaryMap := m.cfg.Validators.GetMap(constants.PrimaryNetworkID)
currentHeight, err := m.getCurrentHeight(ctx)
return subnetMap, primaryMap, currentHeight, err
}

func (m *manager) GetSubnetID(_ context.Context, chainID ids.ID) (ids.ID, error) {
if chainID == constants.PlatformChainID {
return constants.PrimaryNetworkID, nil
Expand Down
1 change: 1 addition & 0 deletions vms/rpcchainvm/vm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (vm *VMClient) Initialize(
CortinaXChainStopVertexId: chainCtx.NetworkUpgrades.CortinaXChainStopVertexID[:],
DurangoTime: grpcutils.TimestampFromTime(chainCtx.NetworkUpgrades.DurangoTime),
EtnaTime: grpcutils.TimestampFromTime(chainCtx.NetworkUpgrades.EtnaTime),
FUpgradeTime: grpcutils.TimestampFromTime(chainCtx.NetworkUpgrades.FUpgradeTime),
}

resp, err := vm.client.Initialize(ctx, &vmpb.InitializeRequest{
Expand Down
5 changes: 5 additions & 0 deletions vms/rpcchainvm/vm_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ func convertNetworkUpgrades(pbUpgrades *vmpb.NetworkUpgrades) (upgrade.Config, e
if err != nil {
return upgrade.Config{}, err
}
fupgrade, err := grpcutils.TimestampAsTime(pbUpgrades.FUpgradeTime)
if err != nil {
return upgrade.Config{}, err
}

cortinaXChainStopVertexID, err := ids.ToID(pbUpgrades.CortinaXChainStopVertexId)
if err != nil {
Expand All @@ -888,5 +892,6 @@ func convertNetworkUpgrades(pbUpgrades *vmpb.NetworkUpgrades) (upgrade.Config, e
CortinaXChainStopVertexID: cortinaXChainStopVertexID,
DurangoTime: durango,
EtnaTime: etna,
FUpgradeTime: fupgrade,
}, nil
}
Loading