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

Drop Pending Stakers 1 - introduced ScheduledStaker txs #2323

Merged
merged 41 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6079eb0
introduced pre durango staker tx
abi87 Nov 16, 2023
c6736b6
nit
abi87 Nov 16, 2023
944f309
Merge branch 'dev' into post_durango_staker_txs_0
abi87 Nov 17, 2023
0106d75
Merge branch 'dev' into post_durango_staker_txs_0
abi87 Nov 18, 2023
9a9897c
nit
abi87 Nov 18, 2023
d17f2a2
nits
abi87 Nov 18, 2023
4c4c011
nits to reduce future diffs
abi87 Nov 19, 2023
905e55e
nit
abi87 Nov 19, 2023
89094cd
improved e2e test
abi87 Nov 19, 2023
5dd8dd8
Merge branch 'post_durango_nits_0' into post_durango_staker_txs_0
abi87 Nov 19, 2023
698af90
Merge branch 'dev' into post_durango_nits_0
abi87 Nov 21, 2023
0c631c6
Merge branch 'post_durango_nits_0' into post_durango_staker_txs_0
abi87 Nov 21, 2023
c3e3670
nits
abi87 Nov 21, 2023
9606b77
Merge branch 'dev' into post_durango_nits_0
abi87 Nov 22, 2023
ce87dea
nits
abi87 Nov 22, 2023
fd33fde
Merge branch 'post_durango_nits_0' into post_durango_staker_txs_0
abi87 Nov 22, 2023
6ea5add
Merge branch 'dev' into post_durango_nits_0
abi87 Nov 23, 2023
b820cae
Merge branch 'post_durango_nits_0' into post_durango_staker_txs_0
abi87 Nov 23, 2023
8260546
Merge branch 'dev' into post_durango_nits_0
abi87 Nov 27, 2023
73d5c2f
nit
abi87 Nov 27, 2023
84321ef
Merge branch 'dev' into post_durango_nits_0
abi87 Nov 28, 2023
c353c33
nits
abi87 Nov 28, 2023
d296e52
Merge branch 'post_durango_nits_0' into post_durango_staker_txs_0
abi87 Nov 28, 2023
9bd9d60
Merge branch 'dev' into post_durango_nits_0
abi87 Nov 28, 2023
a99a5f7
Merge branch 'dev' into post_durango_nits_0
abi87 Nov 29, 2023
c07e2c8
Merge branch 'post_durango_nits_0' into post_durango_staker_txs_0
abi87 Nov 29, 2023
5bb301b
Merge branch 'dev' into post_durango_nits_0
abi87 Nov 29, 2023
e6463b7
Merge branch 'dev' into post_durango_nits_0
abi87 Nov 30, 2023
43839ee
Merge branch 'post_durango_nits_0' into post_durango_staker_txs_0
abi87 Nov 30, 2023
15d7871
Merge branch 'dev' into post_durango_nits_0
abi87 Dec 1, 2023
5e10688
nits
abi87 Dec 1, 2023
0e40da4
Merge branch 'post_durango_nits_0' into post_durango_staker_txs_0
abi87 Dec 1, 2023
a5b3875
Merge branch 'dev' into post_durango_nits_0
abi87 Dec 3, 2023
a7daf81
Merge branch 'post_durango_nits_0' into post_durango_staker_txs_0
abi87 Dec 3, 2023
fb85fe1
Merge branch 'dev' into post_durango_staker_txs_0
abi87 Dec 4, 2023
bfc29a1
Merge branch 'dev' into post_durango_staker_txs_0
abi87 Dec 5, 2023
9b97b59
fix
abi87 Dec 5, 2023
0684a8a
nits
StephenButtolph Dec 5, 2023
d914f34
Merge branch 'dev' into post_durango_staker_txs_0
abi87 Dec 6, 2023
89ce3c2
fix error
abi87 Dec 6, 2023
fa9269c
simplify comment
StephenButtolph Dec 6, 2023
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
4 changes: 2 additions & 2 deletions vms/platformvm/state/staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *Staker) Less(than *Staker) bool {
return bytes.Compare(s.TxID[:], than.TxID[:]) == -1
}

func NewCurrentStaker(txID ids.ID, staker txs.Staker, potentialReward uint64) (*Staker, error) {
func NewCurrentStaker(txID ids.ID, staker txs.ScheduledStaker, potentialReward uint64) (*Staker, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in next PR we'll change the signature of this function to use txs.Staker instead of txs.ScheduledStaker.

publicKey, _, err := staker.PublicKey()
if err != nil {
return nil, err
Expand All @@ -103,7 +103,7 @@ func NewCurrentStaker(txID ids.ID, staker txs.Staker, potentialReward uint64) (*
}, nil
}

func NewPendingStaker(txID ids.ID, staker txs.Staker) (*Staker, error) {
func NewPendingStaker(txID ids.ID, staker txs.ScheduledStaker) (*Staker, error) {
publicKey, _, err := staker.PublicKey()
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/state/staker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestNewCurrentStaker(t *testing.T) {
potentialReward := uint64(54321)
currentPriority := txs.SubnetPermissionedValidatorCurrentPriority

stakerTx := txs.NewMockStaker(ctrl)
stakerTx := txs.NewMockScheduledStaker(ctrl)
stakerTx.EXPECT().NodeID().Return(nodeID)
stakerTx.EXPECT().PublicKey().Return(publicKey, true, nil)
stakerTx.EXPECT().SubnetID().Return(subnetID)
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestNewPendingStaker(t *testing.T) {
endTime := time.Now()
pendingPriority := txs.SubnetPermissionedValidatorPendingPriority

stakerTx := txs.NewMockStaker(ctrl)
stakerTx := txs.NewMockScheduledStaker(ctrl)
stakerTx.EXPECT().NodeID().Return(nodeID)
stakerTx.EXPECT().PublicKey().Return(publicKey, true, nil)
stakerTx.EXPECT().SubnetID().Return(subnetID)
Expand Down
12 changes: 6 additions & 6 deletions vms/platformvm/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ func (s *state) syncGenesis(genesisBlk block.Block, genesis *genesis.Genesis) er

// Persist primary network validator set at genesis
for _, vdrTx := range genesis.Validators {
validatorTx, ok := vdrTx.Unsigned.(txs.ValidatorTx)
validatorTx, ok := vdrTx.Unsigned.(txs.ScheduledStaker)
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return fmt.Errorf("expected tx type txs.ValidatorTx but got %T", vdrTx.Unsigned)
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down Expand Up @@ -1451,7 +1451,7 @@ func (s *state) loadCurrentValidators() error {
return fmt.Errorf("failed loading validator transaction txID %s, %w", txID, err)
}

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

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

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

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

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

var (
_ DelegatorTx = (*AddDelegatorTx)(nil)
_ DelegatorTx = (*AddDelegatorTx)(nil)
_ ScheduledStaker = (*AddDelegatorTx)(nil)
Comment on lines +22 to +23
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no change to existing tx format


errDelegatorWeightMismatch = errors.New("delegator weight is not equal to total stake weight")
errStakeMustBeAVAX = errors.New("stake must be AVAX")
Expand Down
5 changes: 4 additions & 1 deletion vms/platformvm/txs/add_permissionless_delegator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import (
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

var _ DelegatorTx = (*AddPermissionlessDelegatorTx)(nil)
var (
_ DelegatorTx = (*AddPermissionlessDelegatorTx)(nil)
_ ScheduledStaker = (*AddPermissionlessDelegatorTx)(nil)
)

// AddPermissionlessDelegatorTx is an unsigned addPermissionlessDelegatorTx
type AddPermissionlessDelegatorTx struct {
Expand Down
3 changes: 2 additions & 1 deletion vms/platformvm/txs/add_permissionless_validator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
)

var (
_ ValidatorTx = (*AddPermissionlessValidatorTx)(nil)
_ ValidatorTx = (*AddPermissionlessValidatorTx)(nil)
_ ScheduledStaker = (*AddPermissionlessDelegatorTx)(nil)

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

var (
_ StakerTx = (*AddSubnetValidatorTx)(nil)
_ StakerTx = (*AddSubnetValidatorTx)(nil)
_ ScheduledStaker = (*AddSubnetValidatorTx)(nil)

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

var (
_ ValidatorTx = (*AddValidatorTx)(nil)
_ ValidatorTx = (*AddValidatorTx)(nil)
_ ScheduledStaker = (*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 @@ -534,7 +534,7 @@ func (e *StandardTxExecutor) BaseTx(tx *txs.BaseTx) error {
}

// Creates the staker as defined in [stakerTx] and adds it to [e.State].
func (e *StandardTxExecutor) putStaker(stakerTx txs.Staker) error {
func (e *StandardTxExecutor) putStaker(stakerTx txs.ScheduledStaker) error {
txID := e.Tx.ID()
staker, err := state.NewPendingStaker(txID, stakerTx)
if err != nil {
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 @@ -280,7 +280,7 @@ func (m *mempool) DropExpiredStakerTxs(minStartTime time.Time) []ids.ID {
txIter := m.unissuedTxs.NewIterator()
for txIter.Next() {
tx := txIter.Value()
stakerTx, ok := tx.Unsigned.(txs.Staker)
stakerTx, ok := tx.Unsigned.(txs.ScheduledStaker)
if !ok {
continue
}
Expand Down
151 changes: 151 additions & 0 deletions vms/platformvm/txs/mock_scheduled_staker.go

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

28 changes: 0 additions & 28 deletions vms/platformvm/txs/mock_staker.go

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

8 changes: 6 additions & 2 deletions vms/platformvm/txs/staker_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ type Staker interface {
// PublicKey returns the BLS public key registered by this transaction. If
// there was no key registered by this transaction, it will return false.
PublicKey() (*bls.PublicKey, bool, error)
StartTime() time.Time
EndTime() time.Time
Weight() uint64
PendingPriority() Priority
CurrentPriority() Priority
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably could be renamed Priority() instead of current priority. But I'd wait for that to keep PR scope small

}

type ScheduledStaker interface {
Staker
StartTime() time.Time
PendingPriority() Priority
}
Comment on lines +56 to +60
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change of the PR, the rest is just unlocking compilation + small nits

2 changes: 1 addition & 1 deletion vms/platformvm/validator_set_property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ func addPrimaryValidatorWithoutBLSKey(vm *VM, data *validatorInputData) (*state.
}

func internalAddValidator(vm *VM, signedTx *txs.Tx) (*state.Staker, error) {
stakerTx := signedTx.Unsigned.(txs.StakerTx)
if err := vm.Network.IssueTx(context.Background(), signedTx); err != nil {
return nil, fmt.Errorf("could not add tx to mempool: %w", err)
}
Expand All @@ -393,6 +392,7 @@ func internalAddValidator(vm *VM, signedTx *txs.Tx) (*state.Staker, error) {
}

// move time ahead, promoting the validator to current
stakerTx := signedTx.Unsigned.(txs.ScheduledStaker)
currentTime := stakerTx.StartTime()
vm.clock.Set(currentTime)
vm.state.SetTimestamp(currentTime)
Expand Down
Loading