Skip to content

Commit b36416d

Browse files
Drop Pending Stakers 1 - introduced ScheduledStaker txs (#2323)
Co-authored-by: Stephen Buttolph <stephen@avalabs.org>
1 parent 7df1f3a commit b36416d

14 files changed

+187
-49
lines changed

vms/platformvm/state/staker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (s *Staker) Less(than *Staker) bool {
8383
return bytes.Compare(s.TxID[:], than.TxID[:]) == -1
8484
}
8585

86-
func NewCurrentStaker(txID ids.ID, staker txs.Staker, potentialReward uint64) (*Staker, error) {
86+
func NewCurrentStaker(txID ids.ID, staker txs.ScheduledStaker, potentialReward uint64) (*Staker, error) {
8787
publicKey, _, err := staker.PublicKey()
8888
if err != nil {
8989
return nil, err
@@ -103,7 +103,7 @@ func NewCurrentStaker(txID ids.ID, staker txs.Staker, potentialReward uint64) (*
103103
}, nil
104104
}
105105

106-
func NewPendingStaker(txID ids.ID, staker txs.Staker) (*Staker, error) {
106+
func NewPendingStaker(txID ids.ID, staker txs.ScheduledStaker) (*Staker, error) {
107107
publicKey, _, err := staker.PublicKey()
108108
if err != nil {
109109
return nil, err

vms/platformvm/state/staker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func TestNewCurrentStaker(t *testing.T) {
148148
potentialReward := uint64(54321)
149149
currentPriority := txs.SubnetPermissionedValidatorCurrentPriority
150150

151-
stakerTx := txs.NewMockStaker(ctrl)
151+
stakerTx := txs.NewMockScheduledStaker(ctrl)
152152
stakerTx.EXPECT().NodeID().Return(nodeID)
153153
stakerTx.EXPECT().PublicKey().Return(publicKey, true, nil)
154154
stakerTx.EXPECT().SubnetID().Return(subnetID)
@@ -192,7 +192,7 @@ func TestNewPendingStaker(t *testing.T) {
192192
endTime := time.Now()
193193
pendingPriority := txs.SubnetPermissionedValidatorPendingPriority
194194

195-
stakerTx := txs.NewMockStaker(ctrl)
195+
stakerTx := txs.NewMockScheduledStaker(ctrl)
196196
stakerTx.EXPECT().NodeID().Return(nodeID)
197197
stakerTx.EXPECT().PublicKey().Return(publicKey, true, nil)
198198
stakerTx.EXPECT().SubnetID().Return(subnetID)

vms/platformvm/state/state.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,9 +1320,13 @@ func (s *state) syncGenesis(genesisBlk block.Block, genesis *genesis.Genesis) er
13201320

13211321
// Persist primary network validator set at genesis
13221322
for _, vdrTx := range genesis.Validators {
1323-
validatorTx, ok := vdrTx.Unsigned.(txs.ValidatorTx)
1323+
// We expect genesis validator txs to be either AddValidatorTx or
1324+
// AddPermissionlessValidatorTx.
1325+
//
1326+
// TODO: Enforce stricter type check
1327+
validatorTx, ok := vdrTx.Unsigned.(txs.ScheduledStaker)
13241328
if !ok {
1325-
return fmt.Errorf("expected tx type txs.ValidatorTx but got %T", vdrTx.Unsigned)
1329+
return fmt.Errorf("expected a scheduled staker but got %T", vdrTx.Unsigned)
13261330
}
13271331

13281332
stakeAmount := validatorTx.Weight()
@@ -1451,7 +1455,7 @@ func (s *state) loadCurrentValidators() error {
14511455
return fmt.Errorf("failed loading validator transaction txID %s, %w", txID, err)
14521456
}
14531457

1454-
stakerTx, ok := tx.Unsigned.(txs.Staker)
1458+
stakerTx, ok := tx.Unsigned.(txs.ScheduledStaker)
14551459
if !ok {
14561460
return fmt.Errorf("expected tx type txs.Staker but got %T", tx.Unsigned)
14571461
}
@@ -1492,7 +1496,7 @@ func (s *state) loadCurrentValidators() error {
14921496
return err
14931497
}
14941498

1495-
stakerTx, ok := tx.Unsigned.(txs.Staker)
1499+
stakerTx, ok := tx.Unsigned.(txs.ScheduledStaker)
14961500
if !ok {
14971501
return fmt.Errorf("expected tx type txs.Staker but got %T", tx.Unsigned)
14981502
}
@@ -1539,7 +1543,7 @@ func (s *state) loadCurrentValidators() error {
15391543
return err
15401544
}
15411545

1542-
stakerTx, ok := tx.Unsigned.(txs.Staker)
1546+
stakerTx, ok := tx.Unsigned.(txs.ScheduledStaker)
15431547
if !ok {
15441548
return fmt.Errorf("expected tx type txs.Staker but got %T", tx.Unsigned)
15451549
}
@@ -1596,7 +1600,7 @@ func (s *state) loadPendingValidators() error {
15961600
return err
15971601
}
15981602

1599-
stakerTx, ok := tx.Unsigned.(txs.Staker)
1603+
stakerTx, ok := tx.Unsigned.(txs.ScheduledStaker)
16001604
if !ok {
16011605
return fmt.Errorf("expected tx type txs.Staker but got %T", tx.Unsigned)
16021606
}
@@ -1631,7 +1635,7 @@ func (s *state) loadPendingValidators() error {
16311635
return err
16321636
}
16331637

1634-
stakerTx, ok := tx.Unsigned.(txs.Staker)
1638+
stakerTx, ok := tx.Unsigned.(txs.ScheduledStaker)
16351639
if !ok {
16361640
return fmt.Errorf("expected tx type txs.Staker but got %T", tx.Unsigned)
16371641
}

vms/platformvm/txs/add_delegator_tx.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
)
2020

2121
var (
22-
_ DelegatorTx = (*AddDelegatorTx)(nil)
22+
_ DelegatorTx = (*AddDelegatorTx)(nil)
23+
_ ScheduledStaker = (*AddDelegatorTx)(nil)
2324

2425
errDelegatorWeightMismatch = errors.New("delegator weight is not equal to total stake weight")
2526
errStakeMustBeAVAX = errors.New("stake must be AVAX")

vms/platformvm/txs/add_permissionless_delegator_tx.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import (
1717
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
1818
)
1919

20-
var _ DelegatorTx = (*AddPermissionlessDelegatorTx)(nil)
20+
var (
21+
_ DelegatorTx = (*AddPermissionlessDelegatorTx)(nil)
22+
_ ScheduledStaker = (*AddPermissionlessDelegatorTx)(nil)
23+
)
2124

2225
// AddPermissionlessDelegatorTx is an unsigned addPermissionlessDelegatorTx
2326
type AddPermissionlessDelegatorTx struct {

vms/platformvm/txs/add_permissionless_validator_tx.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
)
2222

2323
var (
24-
_ ValidatorTx = (*AddPermissionlessValidatorTx)(nil)
24+
_ ValidatorTx = (*AddPermissionlessValidatorTx)(nil)
25+
_ ScheduledStaker = (*AddPermissionlessDelegatorTx)(nil)
2526

2627
errEmptyNodeID = errors.New("validator nodeID cannot be empty")
2728
errNoStake = errors.New("no stake")

vms/platformvm/txs/add_subnet_validator_tx.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import (
1414
)
1515

1616
var (
17-
_ StakerTx = (*AddSubnetValidatorTx)(nil)
17+
_ StakerTx = (*AddSubnetValidatorTx)(nil)
18+
_ ScheduledStaker = (*AddSubnetValidatorTx)(nil)
1819

1920
errAddPrimaryNetworkValidator = errors.New("can't add primary network validator with AddSubnetValidatorTx")
2021
)

vms/platformvm/txs/add_validator_tx.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
)
2020

2121
var (
22-
_ ValidatorTx = (*AddValidatorTx)(nil)
22+
_ ValidatorTx = (*AddValidatorTx)(nil)
23+
_ ScheduledStaker = (*AddValidatorTx)(nil)
2324

2425
errTooManyShares = fmt.Errorf("a staker can only require at most %d shares from delegators", reward.PercentDenominator)
2526
)

vms/platformvm/txs/executor/standard_tx_executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ func (e *StandardTxExecutor) BaseTx(tx *txs.BaseTx) error {
534534
}
535535

536536
// Creates the staker as defined in [stakerTx] and adds it to [e.State].
537-
func (e *StandardTxExecutor) putStaker(stakerTx txs.Staker) error {
537+
func (e *StandardTxExecutor) putStaker(stakerTx txs.ScheduledStaker) error {
538538
txID := e.Tx.ID()
539539
staker, err := state.NewPendingStaker(txID, stakerTx)
540540
if err != nil {

vms/platformvm/txs/mempool/mempool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func (m *mempool) DropExpiredStakerTxs(minStartTime time.Time) []ids.ID {
280280
txIter := m.unissuedTxs.NewIterator()
281281
for txIter.Next() {
282282
tx := txIter.Value()
283-
stakerTx, ok := tx.Unsigned.(txs.Staker)
283+
stakerTx, ok := tx.Unsigned.(txs.ScheduledStaker)
284284
if !ok {
285285
continue
286286
}

0 commit comments

Comments
 (0)