-
Notifications
You must be signed in to change notification settings - Fork 47
feat: remove multiple delegations #391
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
Conversation
wischli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments which should simplify your review.
|
|
||
| /// Minimum stake required for any account to be able to delegate. | ||
| #[pallet::constant] | ||
| type MinDelegation: Get<BalanceOf<Self>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter was always redundant because of MinDelegatorStake.
| OptionQuery, | ||
| >; | ||
| pub(crate) type DelegatorState<T: Config> = | ||
| StorageMap<_, Twox64Concat, T::AccountId, Delegator<T::AccountId, BalanceOf<T>>, OptionQuery>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migration will be part of #384
| /// | ||
| /// The dispatch origin must be Root. | ||
| /// | ||
| /// # <weight> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed all of these because they are super outdated.
| let delegator_state = Delegator::try_new(collator.clone(), amount) | ||
| .map_err(|_| Error::<T>::MaxCollatorsPerDelegatorExceeded)?; | ||
|
|
||
| let delegator_state = Delegator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had to try before, because a DelegatorState included an ordered set of delegations. Now it's just { amount: BalanceOf<T>, owner: Option<AccountId> }.
| Self::do_update_delegator(delegation, state)? | ||
| } else { | ||
| state.total = state.total.saturating_add(amount); | ||
| (state, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to care about the kicked delegator anymore because they cannot have other delegations anymore.
| /// - Kills: DelegatorState if the delegator has not delegated to | ||
| /// another collator | ||
| /// # </weight> | ||
| fn delegator_revokes_collator(acc: T::AccountId, collator: T::AccountId) -> Result<u32, DispatchError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required anymore because of delegator_leaves_collator.
| /// remaining | ||
| /// * Or `None`, signalling the delegator state should be cleared once | ||
| /// the transaction cannot fail anymore. | ||
| fn prep_kick_delegator( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required anymore because the replaced delegator cannot have further delegations.
|
|
||
| /// Either clear the storage of a kicked delegator or update its | ||
| /// delegation state if it still contains other delegations. | ||
| fn update_kicked_delegator_storage(delegator: Option<ReplacedDelegator<T>>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When kicking a delegator, we kill their DelegatorState storage.
| } | ||
|
|
||
| impl<AccountId, Balance, MaxCollatorsPerDelegator> Delegator<AccountId, Balance, MaxCollatorsPerDelegator> | ||
| pub type Delegator<AccountId, Balance> = Stake<Option<AccountId>, Balance>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to wrap the collator accountid into an option to differentiate between default (empty) delegator states. Unfortunately (or luckily!), AccountId does and should not implement Default anymore.
ntn-x2
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't check the unit tests, but otherwise the changes make sense to me.
Co-authored-by: Antonio <[email protected]>
|
On a note: I am done with #384 (based on the state of this branch) but havent pushed it to the branch yet (instead |
weichweich
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* wip: poc * refactor: extrinsics and inherents * refactor: remove storage redundancy * tests: fix existing ones for staking * tests: 80% * feat: rm delegate_another_candidate and more * docs: remove deprecated weight * Apply suggestions from code review Co-authored-by: Antonio <[email protected]> * tests: 100% * fix: benchmarks * feat: remove multiple delegations (#391) * tests: 80% * feat: rm delegate_another_candidate and more * docs: remove deprecated weight * Apply suggestions from code review Co-authored-by: Antonio <[email protected]> Co-authored-by: Antonio <[email protected]> * Apply suggestions from code review Co-authored-by: Antonio <[email protected]> * fix: suggestions from @ntn-x2 review * fmt * fix: typos * fix: docker file * feat: add staking rewards runtime api * docs: add new extrinsics to staking header * feat: add staking rates api * tests: add api * fix: unify staking runtime api * refactor: stricter claiming * fix: easy suggestions from code review * tests: comp api claim with claiming * stlye: fmt * tests: add safety check to API rewards * style: fmt * feat: write delegator state migration * refactor: Delegator interface functions * refactor: rm Option for Delegator.owner * style: apply turbofish to staking * fix: replace RewardCount with two counters * refactor: rm col input for del stake adjustment * Update pallets/parachain-staking/src/lib.rs Co-authored-by: Albrecht <[email protected]> Co-authored-by: Antonio <[email protected]> Co-authored-by: Albrecht <[email protected]>
* wip: poc * refactor: extrinsics and inherents * refactor: remove storage redundancy * tests: fix existing ones for staking * tests: 80% * feat: rm delegate_another_candidate and more * docs: remove deprecated weight * Apply suggestions from code review Co-authored-by: Antonio <[email protected]> * tests: 100% * fix: benchmarks * feat: remove multiple delegations (#391) * tests: 80% * feat: rm delegate_another_candidate and more * docs: remove deprecated weight * Apply suggestions from code review Co-authored-by: Antonio <[email protected]> Co-authored-by: Antonio <[email protected]> * Apply suggestions from code review Co-authored-by: Antonio <[email protected]> * fix: suggestions from @ntn-x2 review * fmt * fix: typos * fix: docker file * feat: add staking rewards runtime api * docs: add new extrinsics to staking header * feat: add staking rates api * tests: add api * fix: unify staking runtime api * refactor: stricter claiming * fix: easy suggestions from code review * refactor: separate runtime api from custom rpc * tests: comp api claim with claiming * refactor: move runtime api calls to mod * stlye: fmt * refactor: split api into separate crates * refactor: simplify staking api name * refactor: normalize public creds runtime api * refactor: machete cleanup * tests: add safety check to API rewards * style: fmt * feat: write delegator state migration * refactor: remove unneeded no_std flags * refactor: Delegator interface functions * refactor: rm Option for Delegator.owner * style: apply turbofish to staking * fix: replace RewardCount with two counters * refactor: rm col input for del stake adjustment * style: fmt Co-authored-by: Antonio <[email protected]>
No Ticket - part of #384
This PR removes unused code from the staking pallet, mainly the unusable
delegate_another_candidateextrinsic,revoke_delegationextrinsic and two useless staking parameters.While working on #384 I just stumbled the problem in the current redesign introduced by allowing for more than one delegation per delegator (which we do in the unit test environment). As discussed, we don't seem to plan supporting multiple delegations from the same account in the future.
What was removed?
delegate_another_candidateextrinsicrevoke_delegationextrinsic (not needed because ofleave_delegators)weightof functions in the Staking PalletDelegatorstruct (it's justStake)ReplacedDelegatorstruct, not needed anymoreNomStakeBelowMinerror (redundant because ofDelegationBelowMin)prep_kick_delegatorfunction --> was only required because of potentially still existent delegations of kicked delegatorOpen tasks
DelegatorStateStorage Map --> feat: staking payout refactor #384.Checklist:
array[3]useget(3), ...)