Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
616dc1a
first draft of partial unbonding for pools
kianenigma Apr 10, 2022
c045e06
remove option
kianenigma Apr 10, 2022
b333d21
Upstream.into()
kianenigma Apr 12, 2022
ad7f37c
Add some more tests and fix issues
kianenigma Apr 13, 2022
764ae6f
Fix all tests
kianenigma Apr 13, 2022
28844a2
simplify some tests
kianenigma Apr 13, 2022
9a2af20
Update frame/nomination-pools/src/mock.rs
kianenigma Apr 13, 2022
de80c7b
remove clone
kianenigma Apr 14, 2022
580e45d
Merge branch 'kiz-pools-partial-unbonding' of github.com:paritytech/s…
kianenigma Apr 14, 2022
d0f0121
rename to delegator_unbonding_eras
kianenigma Apr 14, 2022
03dafcb
Update frame/nomination-pools/src/tests.rs
kianenigma Apr 14, 2022
257f48b
Update frame/nomination-pools/src/tests.rs
kianenigma Apr 14, 2022
4e04c79
Update frame/nomination-pools/src/tests.rs
kianenigma Apr 14, 2022
26197e3
remove pub
kianenigma Apr 14, 2022
774c28d
Merge branch 'kiz-pools-partial-unbonding' of github.com:paritytech/s…
kianenigma Apr 14, 2022
a469433
Update frame/nomination-pools/src/lib.rs
kianenigma Apr 14, 2022
a1d5e3a
Update frame/nomination-pools/src/lib.rs
kianenigma Apr 14, 2022
b1ee72e
undo
kianenigma Apr 14, 2022
d9ae892
Merge branch 'kiz-pools-partial-unbonding' of github.com:paritytech/s…
kianenigma Apr 14, 2022
ef96a11
Update frame/nomination-pools/src/lib.rs
kianenigma Apr 14, 2022
17296fa
Update frame/nomination-pools/src/lib.rs
kianenigma Apr 14, 2022
5c04916
leftovers
kianenigma Apr 14, 2022
02ff7b6
Merge branch 'kiz-pools-partial-unbonding' of github.com:paritytech/s…
kianenigma Apr 14, 2022
2b52a25
fix invariant
kianenigma Apr 14, 2022
339c7a1
Fix all tests
kianenigma Apr 14, 2022
ac2b5d6
upstream into
kianenigma Apr 15, 2022
b2b5470
Fix the depositor assumption
kianenigma Apr 15, 2022
70f9f8f
round of self-review
kianenigma Apr 15, 2022
4d389f5
little bit more cleanup
kianenigma Apr 15, 2022
31c522d
Update frame/nomination-pools/src/mock.rs
emostov Apr 15, 2022
d7fabb2
Apply suggestions from code review
emostov Apr 16, 2022
40c21f5
Update frame/nomination-pools/src/lib.rs
kianenigma Apr 18, 2022
cb56178
Fix interpretation of MinCreateBond
kianenigma Apr 19, 2022
11a5e91
Merge branch 'kiz-pools-partial-unbonding' of github.com:paritytech/s…
kianenigma Apr 19, 2022
011e8bc
controvesial refactor
kianenigma Apr 19, 2022
49409d7
rename
kianenigma Apr 19, 2022
9e801fc
Merge branch 'zeke-staking-pools' of github.com:paritytech/substrate …
kianenigma Apr 19, 2022
8e8aa5a
make everything build
kianenigma Apr 19, 2022
8985a84
add TODO about killing the reward account
kianenigma Apr 19, 2022
20846ce
Update frame/nomination-pools/src/lib.rs
kianenigma Apr 19, 2022
1e4f7fa
Update frame/nomination-pools/src/lib.rs
emostov Apr 19, 2022
4ef56ae
Upstream.into()
kianenigma Apr 20, 2022
8657efc
last self-review
kianenigma Apr 20, 2022
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
Prev Previous commit
Next Next commit
Upstream.into()
  • Loading branch information
kianenigma committed Apr 20, 2022
commit 4ef56ae4566c070dacac3290041668cd87c5d57c
5 changes: 3 additions & 2 deletions frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1953,14 +1953,15 @@ impl<T: Config> Pallet<T> {
current_points: BalanceOf<T>,
points: BalanceOf<T>,
) -> BalanceOf<T> {
let u256 = |x| T::BalanceToU256::convert(x);
let balance = |x| T::U256ToBalance::convert(x);
if current_balance.is_zero() || current_points.is_zero() || points.is_zero() {
// There is nothing to unbond
return Zero::zero()
}

// Equivalent of (current_balance / current_points) * points
current_balance
.saturating_mul(points)
balance(u256(current_balance).saturating_mul(u256(points)))
// We check for zero above
.div(current_points)
}
Expand Down
25 changes: 24 additions & 1 deletion frame/nomination-pools/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1828,9 +1828,9 @@ mod unbond {
})
}

// depositor can unbond inly up to `MinCreateBond`.
#[test]
fn depositor_permissioned_partial_unbond() {
Copy link
Contributor

Choose a reason for hiding this comment

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

A nice bonus would be to have a quick test that is just the default pool with 10, then slash the pools active balance to 5, then have 10 try to unbond 4 which normally should now fail (but in the previous version of this PR would work)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice one, will do 4ef56ae

// Scenarios where non-admin accounts can unbond others
ExtBuilder::default()
.ed(1)
.add_delegators(vec![(100, 100)])
Expand All @@ -1852,6 +1852,29 @@ mod unbond {
);
});
}

// same as above, but the pool is slashed and therefore the depositor cannot partially unbond.
#[test]
fn depositor_permissioned_partial_unbond_slashed() {
ExtBuilder::default()
.ed(1)
.add_delegators(vec![(100, 100)])
.build_and_execute(|| {
// given
assert_eq!(MinCreateBond::<Runtime>::get(), 2);
assert_eq!(Delegators::<Runtime>::get(10).unwrap().active_points(), 10);
assert_eq!(Delegators::<Runtime>::get(10).unwrap().unbonding_points(), 0);

// slash the default pool
StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 5);

// cannot unbond even 7, because the value of shares is now less.
assert_noop!(
Pools::unbond(Origin::signed(10), 10, 7),
Error::<Runtime>::NotOnlyDelegator
);
});
}
}

mod pool_withdraw_unbonded {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.