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

Replace staking reserves with locks #1604

Merged
merged 70 commits into from Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
c51db00
Replace (most) reserves with locks
notlesh Jun 14, 2022
fcc4be3
fmt
notlesh Jun 20, 2022
72ee227
Merge branch 'master' into notlesh-staking-locks
notlesh Jun 20, 2022
7730daf
Convert last remaining reserve -> balance
notlesh Jun 20, 2022
e9b5338
Adds simple test for locks in staking (WIP)
Jun 21, 2022
ebe64c8
Encapsulation of (most) delegator locking logic
notlesh Jun 21, 2022
9f8aa56
Convert collator reserve -> lock
notlesh Jun 21, 2022
b4b0b8b
Remove SplitCandidateStateToDecreasePoV
notlesh Jun 21, 2022
3903575
fmt
notlesh Jun 21, 2022
e715709
editorconfig
notlesh Jun 21, 2022
dcc5e53
wtf
notlesh Jun 21, 2022
a91b021
:construction:
notlesh Jun 21, 2022
a07d17f
Don't use free_balance with locks
notlesh Jun 21, 2022
28f5a63
Very basic migration
notlesh Jun 21, 2022
343cb09
Hook up migration
notlesh Jun 21, 2022
bc752d1
Fix try-runtime
notlesh Jun 22, 2022
bd0343f
Add logging to migration
notlesh Jun 22, 2022
04ce29d
Typo
notlesh Jun 22, 2022
e504851
Update tests to reflect reserve -> lock
notlesh Jun 22, 2022
f78fc98
Better parameter name
notlesh Jun 24, 2022
54cb304
fmt
notlesh Jun 24, 2022
3f30c12
fmt (not just in parachain-staking)
notlesh Jun 24, 2022
62b7c4a
Merge branch 'master' into notlesh-staking-locks
notlesh Jun 24, 2022
6b65085
Throw error when additional_required_balance > total
notlesh Jun 24, 2022
8dca170
Staking Locks: JIT migration (#1625)
notlesh Jun 27, 2022
69dbe7d
Rename staking lock ids
notlesh Jun 27, 2022
ceebb6e
Remove staking locks on_runtime_upgrade migration
notlesh Jun 27, 2022
1d311cb
Restore `reserved_balance()` checks
notlesh Jun 27, 2022
efe687b
fmt
notlesh Jun 27, 2022
fb542bf
use wrapper for incrementing balances
nbaztec Jun 28, 2022
74de13e
remove comments
nbaztec Jun 28, 2022
b3a75b0
remove comments
nbaztec Jun 28, 2022
0c79838
Add hotfix migrations and lots of related tests
Jun 28, 2022
075cac5
fmt
Jun 28, 2022
7274b51
Explicitly ignore error
notlesh Jun 28, 2022
f54837e
Fix lock names in ts tests
notlesh Jun 28, 2022
80649ca
Merge original branch and fix tests
notlesh Jun 29, 2022
e591bca
Create regression test for bumping delegator
notlesh Jun 29, 2022
cc58d06
Hacky fix for migrating about-to-be-bumped delegator
notlesh Jun 29, 2022
b96f143
fmt
notlesh Jun 29, 2022
5c4113e
Merge branch 'notlesh-staking-locks' into notlesh-nish-notlesh-stakin…
notlesh Jun 29, 2022
637a41a
Merge branch 'master' into notlesh-staking-locks
notlesh Jun 29, 2022
0ac493e
fmt
notlesh Jun 29, 2022
280ccb5
Add some TODO notes
notlesh Jun 29, 2022
e005705
Implement crude weight fn
notlesh Jun 29, 2022
40f9208
Add ts test for hotfix extrinsic fees
notlesh Jun 30, 2022
387ec0f
fmt
notlesh Jun 30, 2022
88a909f
Poke at locks/reserves when revoking last delegation
notlesh Jun 30, 2022
b3beea4
Remove TODO, we have test cases for this
notlesh Jun 30, 2022
746243a
fmt
notlesh Jun 30, 2022
46b2b64
Test that bumping because of top delegator insertion leaves no reserve
notlesh Jun 30, 2022
3ed614d
Remove duplicate locks modification
notlesh Jun 30, 2022
2915982
WIP: test that we can both vote while staked in ts test
notlesh Jun 30, 2022
ebbe653
Notlesh staking locks debug (#1651)
Jul 3, 2022
ea3732b
Merge branch 'master' into notlesh-staking-locks
Jul 3, 2022
6f1398b
Adds more testing
Jul 4, 2022
3a80a78
Increase timeout for big staking tests
Jul 4, 2022
8b5e9bb
Improve timeouts
Jul 4, 2022
7633690
More timeout
Jul 4, 2022
ad0d7fd
Update tests/tests/test-staking/test-staking-locks.ts
notlesh Jul 5, 2022
afce2d3
Update pallets/parachain-staking/src/types.rs
notlesh Jul 5, 2022
0227fda
Update pallets/parachain-staking/src/types.rs
notlesh Jul 5, 2022
d2baeda
Use generic error instead of irrelevant one
notlesh Jul 5, 2022
6c10b2c
Remove extra toString()
notlesh Jul 5, 2022
53ad8a4
Update pallets/parachain-staking/src/types.rs
notlesh Jul 5, 2022
5d6f934
Update pallets/parachain-staking/src/types.rs
notlesh Jul 5, 2022
004ceaf
Use LockIdentifier type alias
notlesh Jul 5, 2022
ded490e
Use usable_balance to include locks in test
notlesh Jul 5, 2022
c98547f
fmt
notlesh Jul 5, 2022
10abaee
Revent default_with_total
notlesh Jul 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions pallets/author-mapping/src/migrations.rs
Expand Up @@ -60,6 +60,8 @@ impl<T: Config> OnRuntimeUpgrade for AddAccountIdToNimbusLookup<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
use frame_support::traits::OnRuntimeUpgradeHelpersExt;
use sp_std::vec::Vec;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this needed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was needed for try-runtime I believe, although that doesn't currently build (I think we need moonbeam-foundation/nimbus#62)


let mut nimbus_set: Vec<NimbusId> = Vec::new();
for (nimbus_id, info) in <MappingWithDeposit<T>>::iter() {
if !nimbus_set.contains(&nimbus_id) {
Expand Down
50 changes: 33 additions & 17 deletions pallets/parachain-staking/src/delegation_requests.rs
Expand Up @@ -22,7 +22,7 @@ use crate::pallet::{
};
use crate::Delegator;
use frame_support::ensure;
use frame_support::traits::{Get, ReservableCurrency};
use frame_support::traits::Get;
use frame_support::{dispatch::DispatchResultWithPostInfo, RuntimeDebug};
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -140,7 +140,7 @@ impl<T: Config> Pallet<T> {
);

// Net Total is total after pending orders are executed
let net_total = state.total.saturating_sub(state.less_total);
let net_total = state.total().saturating_sub(state.less_total);
// Net Total is always >= MinDelegatorStk
let max_subtracted_amount = net_total.saturating_sub(T::MinDelegatorStk::get().into());
ensure!(
Expand Down Expand Up @@ -232,7 +232,10 @@ impl<T: Config> Pallet<T> {
true
} else {
ensure!(
state.total.saturating_sub(T::MinDelegatorStk::get().into()) >= amount,
state
.total()
.saturating_sub(T::MinDelegatorStk::get().into())
>= amount,
<Error<T>>::DelegatorBondBelowMin
);
false
Expand All @@ -243,7 +246,7 @@ impl<T: Config> Pallet<T> {
state.less_total = state.less_total.saturating_sub(amount);

// remove delegation from delegator state
state.rm_delegation(&collator);
state.rm_delegation::<T>(&collator);

// remove delegation from collator state delegations
Self::delegator_leaves_candidate(collator.clone(), delegator.clone(), amount)?;
Expand Down Expand Up @@ -276,19 +279,25 @@ impl<T: Config> Pallet<T> {
return if bond.amount > amount {
let amount_before: BalanceOf<T> = bond.amount.into();
bond.amount = bond.amount.saturating_sub(amount);
state.total = state.total.saturating_sub(amount);
let new_total: BalanceOf<T> = state.total.into();
ensure!(
new_total >= T::MinDelegation::get(),
<Error<T>>::DelegationBelowMin
);
ensure!(
new_total >= T::MinDelegatorStk::get(),
<Error<T>>::DelegatorBondBelowMin
);
let mut collator_info = <CandidateInfo<T>>::get(&collator)
.ok_or(<Error<T>>::CandidateDNE)?;
T::Currency::unreserve(&delegator, amount);

state.total_sub_if::<T, _>(amount, |total| {
let new_total: BalanceOf<T> = total.into();
ensure!(
new_total >= T::MinDelegation::get(),
<Error<T>>::DelegationBelowMin
);
ensure!(
new_total >= T::MinDelegatorStk::get(),
<Error<T>>::DelegatorBondBelowMin
);

Self::jit_ensure_delegator_reserve_migrated(&delegator)?;
notlesh marked this conversation as resolved.
Show resolved Hide resolved

Ok(())
})?;

// need to go into decrease_delegation
let in_top = collator_info.decrease_delegation::<T>(
&collator,
Expand Down Expand Up @@ -428,7 +437,7 @@ impl<T: Config> Pallet<T> {
delegator: T::AccountId,
delegation_count: u32,
) -> DispatchResultWithPostInfo {
let state = <DelegatorState<T>>::get(&delegator).ok_or(<Error<T>>::DelegatorDNE)?;
let mut state = <DelegatorState<T>>::get(&delegator).ok_or(<Error<T>>::DelegatorDNE)?;
ensure!(
delegation_count >= (state.delegations.0.len() as u32),
Error::<T>::TooLowDelegationCountToLeaveDelegators
Expand Down Expand Up @@ -475,6 +484,13 @@ impl<T: Config> Pallet<T> {
updated_scheduled_requests.push((collator, scheduled_requests));
}

// TODO: reveiew -- we're about to leave, so this is mostly extra work (extra writes)
Self::jit_ensure_delegator_reserve_migrated(&delegator)?;

notlesh marked this conversation as resolved.
Show resolved Hide resolved
// set state.total so that state.adjust_bond_lock will remove lock
let unstaked_amount = state.total();
state.total_sub::<T>(unstaked_amount)?;

updated_scheduled_requests
.into_iter()
.for_each(|(collator, scheduled_requests)| {
Expand All @@ -483,7 +499,7 @@ impl<T: Config> Pallet<T> {

Self::deposit_event(Event::DelegatorLeft {
delegator: delegator.clone(),
unstaked_amount: state.total,
unstaked_amount,
});
<DelegatorState<T>>::remove(&delegator);

Expand Down