Skip to content

Commit

Permalink
updated PR to acp proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Nov 15, 2023
1 parent 19a8318 commit 0deb60a
Show file tree
Hide file tree
Showing 17 changed files with 202 additions and 212 deletions.
7 changes: 3 additions & 4 deletions vms/platformvm/state/staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s *Staker) Less(than *Staker) bool {

func NewCurrentStaker(
txID ids.ID,
staker txs.PostDurangoStaker,
staker txs.Staker,
startTime time.Time,
potentialReward uint64,
) (*Staker, error) {
Expand All @@ -94,8 +94,7 @@ func NewCurrentStaker(
return nil, err
}

stakingDuration := staker.Duration()
endTime := startTime.Add(stakingDuration)
endTime := staker.EndTime()
return &Staker{
TxID: txID,
NodeID: staker.NodeID(),
Expand All @@ -110,7 +109,7 @@ func NewCurrentStaker(
}, nil
}

func NewPendingStaker(txID ids.ID, staker txs.Staker) (*Staker, error) {
func NewPendingStaker(txID ids.ID, staker txs.PreDurangoStaker) (*Staker, error) {
publicKey, _, err := staker.PublicKey()
if err != nil {
return nil, err
Expand Down
7 changes: 3 additions & 4 deletions vms/platformvm/state/staker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,12 @@ func TestNewCurrentStaker(t *testing.T) {
subnetID := ids.GenerateTestID()
weight := uint64(12345)
startTime := time.Now()
duration := time.Hour
endTime := startTime.Add(duration)
endTime := startTime.Add(time.Hour)
potentialReward := uint64(54321)
currentPriority := txs.SubnetPermissionedValidatorCurrentPriority

stakerTx := txs.NewMockPostDurangoStaker(ctrl)
stakerTx.EXPECT().Duration().Return(duration)
stakerTx := txs.NewMockStaker(ctrl)
stakerTx.EXPECT().EndTime().Return(endTime)
stakerTx.EXPECT().NodeID().Return(nodeID)
stakerTx.EXPECT().PublicKey().Return(publicKey, true, nil)
stakerTx.EXPECT().SubnetID().Return(subnetID)
Expand Down
22 changes: 11 additions & 11 deletions vms/platformvm/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1460,15 +1460,14 @@ func (s *state) loadCurrentValidators() error {
// Note: we don't provide [LastUpdated] here because we expect it to
// always be present on disk.
}
err = parseValidatorMetadata(metadataBytes, metadata)
if err != nil {
if err := parseValidatorMetadata(metadataBytes, metadata); err != nil {
return err
}

staker, err := NewCurrentStaker(
txID,
stakerTx.(txs.PostDurangoStaker),
stakerTx.StartTime(),
stakerTx,
stakerTx.(txs.PreDurangoStaker).StartTime(),
metadata.PotentialReward)
if err != nil {
return err
Expand Down Expand Up @@ -1501,20 +1500,21 @@ func (s *state) loadCurrentValidators() error {
}

metadataBytes := subnetValidatorIt.Value()
startTime := stakerTx.(txs.PreDurangoStaker).StartTime()
metadata := &validatorMetadata{
txID: txID,
// use the start time as the fallback value
// in case it's not stored in the database
LastUpdated: uint64(stakerTx.StartTime().Unix()),
LastUpdated: uint64(startTime.Unix()),
}
if err := parseValidatorMetadata(metadataBytes, metadata); err != nil {
return err
}

staker, err := NewCurrentStaker(
txID,
stakerTx.(txs.PostDurangoStaker),
stakerTx.StartTime(),
stakerTx,
startTime,
metadata.PotentialReward,
)
if err != nil {
Expand Down Expand Up @@ -1561,8 +1561,8 @@ func (s *state) loadCurrentValidators() error {

staker, err := NewCurrentStaker(
txID,
stakerTx.(txs.PostDurangoStaker),
stakerTx.StartTime(),
stakerTx,
stakerTx.(txs.PreDurangoStaker).StartTime(),
metadata.PotentialReward,
)
if err != nil {
Expand Down Expand Up @@ -1608,7 +1608,7 @@ func (s *state) loadPendingValidators() error {
return err
}

stakerTx, ok := tx.Unsigned.(txs.Staker)
stakerTx, ok := tx.Unsigned.(txs.PreDurangoStaker)
if !ok {
return fmt.Errorf("expected tx type txs.Staker but got %T", tx.Unsigned)
}
Expand Down Expand Up @@ -1643,7 +1643,7 @@ func (s *state) loadPendingValidators() error {
return err
}

stakerTx, ok := tx.Unsigned.(txs.Staker)
stakerTx, ok := tx.Unsigned.(txs.PreDurangoStaker)
if !ok {
return fmt.Errorf("expected tx type txs.Staker but got %T", tx.Unsigned)
}
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/txs/add_delegator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
)

var (
_ DelegatorTx = (*AddDelegatorTx)(nil)
_ PostDurangoStaker = (*AddDelegatorTx)(nil)
_ DelegatorTx = (*AddDelegatorTx)(nil)
_ PreDurangoStaker = (*AddDelegatorTx)(nil)

errDelegatorWeightMismatch = errors.New("delegator weight is not equal to total stake weight")
errStakeMustBeAVAX = errors.New("stake must be AVAX")
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/txs/add_permissionless_delegator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
)

var (
_ DelegatorTx = (*AddPermissionlessDelegatorTx)(nil)
_ PostDurangoStaker = (*AddPermissionlessDelegatorTx)(nil)
_ DelegatorTx = (*AddPermissionlessDelegatorTx)(nil)
_ PreDurangoStaker = (*AddPermissionlessDelegatorTx)(nil)
)

// AddPermissionlessDelegatorTx is an unsigned addPermissionlessDelegatorTx
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/txs/add_permissionless_validator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
)

var (
_ ValidatorTx = (*AddPermissionlessValidatorTx)(nil)
_ PostDurangoStaker = (*AddPermissionlessDelegatorTx)(nil)
_ ValidatorTx = (*AddPermissionlessValidatorTx)(nil)
_ PreDurangoStaker = (*AddPermissionlessDelegatorTx)(nil)

errEmptyNodeID = errors.New("validator nodeID cannot be empty")
errNoStake = errors.New("no stake")
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/txs/add_subnet_validator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
)

var (
_ StakerTx = (*AddSubnetValidatorTx)(nil)
_ PostDurangoStaker = (*AddSubnetValidatorTx)(nil)
_ StakerTx = (*AddSubnetValidatorTx)(nil)
_ PreDurangoStaker = (*AddSubnetValidatorTx)(nil)

errAddPrimaryNetworkValidator = errors.New("can't add primary network validator with AddSubnetValidatorTx")
)
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/txs/add_validator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
)

var (
_ ValidatorTx = (*AddValidatorTx)(nil)
_ PostDurangoStaker = (*AddValidatorTx)(nil)
_ ValidatorTx = (*AddValidatorTx)(nil)
_ PreDurangoStaker = (*AddValidatorTx)(nil)

errTooManyShares = fmt.Errorf("a staker can only require at most %d shares from delegators", reward.PercentDenominator)
)
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/txs/executor/standard_tx_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func (e *StandardTxExecutor) BaseTx(tx *txs.BaseTx) error {
}

// addStakerFromStakerTx creates the staker and adds it to state.
func (e *StandardTxExecutor) addStakerFromStakerTx(stakerTx txs.Staker) error {
func (e *StandardTxExecutor) addStakerFromStakerTx(stakerTx txs.PreDurangoStaker) error {
// Pre Durango fork, stakers are added as pending first, then promoted
// to current when chainTime reaches their start time.
// Post Durango fork, stakers are immediately marked as current.
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/txs/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func DropExpiredStakerTxs(mempool Mempool, minStartTime time.Time) []ids.ID {

for mempool.HasStakerTx() {
tx := mempool.PeekStakerTx()
startTime := tx.Unsigned.(txs.Staker).StartTime()
startTime := tx.Unsigned.(txs.PreDurangoStaker).StartTime()
if !startTime.Before(minStartTime) {
// The next proposal tx in the mempool starts sufficiently far in
// the future.
Expand Down
126 changes: 0 additions & 126 deletions vms/platformvm/txs/mock_post_durango_staker.go

This file was deleted.

Loading

0 comments on commit 0deb60a

Please sign in to comment.