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

Add stake priority helpers #1375

Merged
merged 5 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 2 additions & 4 deletions vms/platformvm/txs/executor/staker_tx_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ func removeSubnetValidatorValidation(
)
}

if vdr.Priority != txs.SubnetPermissionedValidatorCurrentPriority &&
vdr.Priority != txs.SubnetPermissionedValidatorPendingPriority {
if !vdr.Priority.IsPermissionedValidator() {
return nil, false, errRemovePermissionlessValidator
}

Expand Down Expand Up @@ -696,8 +695,7 @@ func verifyAddPermissionlessDelegatorTx(
// AddSubnetValidatorTx. AddSubnetValidatorTx is the only
// permissioned validator, so we verify this delegator is
// pointing to a permissionless validator.
if validator.Priority == txs.SubnetPermissionedValidatorCurrentPriority ||
validator.Priority == txs.SubnetPermissionedValidatorPendingPriority {
if validator.Priority.IsPermissionedValidator() {
return errDelegateToPermissionedValidator
}

Expand Down
44 changes: 44 additions & 0 deletions vms/platformvm/txs/priorities.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,47 @@ var PendingToCurrentPriorities = []Priority{
}

type Priority byte

func (p Priority) IsCurrent() bool {
return p.IsCurrentValidator() || p.IsCurrentDelegator()
}

func (p Priority) IsPending() bool {
return p.IsPendingValidator() || p.IsPendingDelegator()
}

func (p Priority) IsValidator() bool {
return p.IsCurrentValidator() || p.IsPendingValidator()
}

func (p Priority) IsPermissionedValidator() bool {
return p == SubnetPermissionedValidatorCurrentPriority ||
p == SubnetPermissionedValidatorPendingPriority
}

func (p Priority) IsDelegator() bool {
return p.IsCurrentDelegator() || p.IsPendingDelegator()
}

func (p Priority) IsCurrentValidator() bool {
return p == PrimaryNetworkValidatorCurrentPriority ||
p == SubnetPermissionedValidatorCurrentPriority ||
p == SubnetPermissionlessValidatorCurrentPriority
}

func (p Priority) IsCurrentDelegator() bool {
return p == PrimaryNetworkDelegatorCurrentPriority ||
p == SubnetPermissionlessDelegatorCurrentPriority
}

func (p Priority) IsPendingValidator() bool {
return p == PrimaryNetworkValidatorPendingPriority ||
p == SubnetPermissionedValidatorPendingPriority ||
p == SubnetPermissionlessValidatorPendingPriority
}

func (p Priority) IsPendingDelegator() bool {
return p == PrimaryNetworkDelegatorBanffPendingPriority ||
p == PrimaryNetworkDelegatorApricotPendingPriority ||
p == SubnetPermissionlessDelegatorPendingPriority
}