-
Notifications
You must be signed in to change notification settings - Fork 660
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
Full Unbond in Staking #3811
base: master
Are you sure you want to change the base?
Full Unbond in Staking #3811
Conversation
@Ank4n according to @kianenigma we want to fully unbond everything after chilling. Therefore, the extrinsic don't need to take any value, also there will be no need to add a check for minimum active bond which you suggested earlier here. #3629 (comment) Also, if we want to do a chill also when we expect a value, we can definitely do that in the unbond extrinsic. should i go ahead and include that? |
@kianenigma wdyt about |
This is also fine with me, no strong opinion. I like your idea better as it improves UX without wallets needing to do much. |
OK. So, should we still keep the full unbond extrinsic and also implement the implicit one that @Ank4n is suggesting? |
f6032b7
to
df5c186
Compare
# Conflicts: # polkadot/runtime/westend/src/weights/pallet_staking.rs # substrate/frame/staking/src/benchmarking.rs # substrate/frame/staking/src/pallet/impls.rs # substrate/frame/staking/src/pallet/mod.rs # substrate/frame/staking/src/weights.rs
# Conflicts: # Cargo.lock
@Ank4n @kianenigma please help review again |
…re unbonding all amount
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.
Looks good, needs more tests (for unbond fully calling chill) and better prdoc and bench etc.
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.
@dharjeezy Sorry for the delay in reviews. Had been on vacation.
Suggested some nits + there are CI errors. Could you please fix it and ping me. I will try to get this merged promptly.
assert!(new_bonded == BalanceOf::<T>::try_from(0u128).map_err(|_| "balance expected to be a u128") | ||
.unwrap()); |
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 should work.
assert!(new_bonded == BalanceOf::<T>::try_from(0u128).map_err(|_| "balance expected to be a u128") | |
.unwrap()); | |
assert!(new_bonded == Zero::zero()); |
@@ -36,6 +36,7 @@ use frame_support::{ | |||
traits::{Defensive, LockableCurrency}, | |||
}; | |||
use sp_staking::{StakingAccount, StakingInterface}; | |||
use sp_std::prelude::*; |
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.
Do we need this?
|
||
Self::deposit_event(Event::<T>::Unbonded { stash, amount: value }); | ||
if value == ledger.total { |
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.
Because of this, you may want to check value >= ledger.total
instead.
Alternatively, you can move the ceiling logic let mut value = value.min(ledger.active)
to this function.
bot bench polkadot-pallet --pallet=pallet_staking --runtime=westend |
@Ank4n https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6988164 was started for your command Comment |
@@ -274,16 +274,15 @@ benchmarks! { | |||
|
|||
let stash = scenario.origin_stash1.clone(); | |||
let controller = scenario.origin_controller1.clone(); | |||
let amount = origin_weight - scenario.dest_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.
Would this impact the worst case weight calculation for updating bags list?
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.
wrt https://github.com/paritytech/polkadot-sdk/pull/3811/files?diff=split&w=0#r1717563991, an alternate way would be to keep this existing benchmark and add the chill weight to it for worst case weight of unbond
.
…=westend --target_dir=polkadot --pallet=pallet_staking
@Ank4n Command |
fn unbond() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `2128` |
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.
Seems the unbond benchmark is not correct. You would expect weight to increase with the extra chill in the worst case but both proof size and execution time decreases.
if the value to be unbonded is the total of what is bonded | ||
|
||
crates: | ||
- name: pallet-staking |
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.
needs the bump
field here, I'd suggest minor
.
// unbonding total of active stake passes because Chill occurs implicitly when unbonding | ||
// full amount |
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.
// unbonding total of active stake passes because Chill occurs implicitly when unbonding | |
// full amount | |
// unbonding total of active stake passes because chill occurs implicitly when unbonding | |
// full amount. |
prdoc/pr_3811.prdoc
Outdated
@@ -0,0 +1,10 @@ | |||
title: "Chill and Full Unbond in [pallet_staking]" |
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.
title: "Chill and Full Unbond in [pallet_staking]" | |
title: "Implicit chill when full unbounding in [pallet_staking]" |
|
||
Self::deposit_event(Event::<T>::Unbonded { stash, amount: value }); | ||
if value >= ledger.total { | ||
Self::chill_stash(&ledger.stash); |
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.
The weight returned by this call should also be used in the PostInfo
, i.e. as part of the actual_weight
calculation.
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.
There is no weight returned by that call, that function does not return anything.
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.
i understand you now, i have updated this. @gpestana
substrate/frame/staking/src/tests.rs
Outdated
@@ -4133,6 +4133,49 @@ fn test_multi_page_payout_stakers_by_page() { | |||
}); | |||
} | |||
|
|||
#[test] | |||
fn unbond_with_chill_works() { | |||
// |
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.
// |
substrate/frame/staking/src/tests.rs
Outdated
#[test] | ||
fn unbond_with_chill_works() { | ||
// | ||
// * Should test |
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.
// * Should test | |
// Should test: |
substrate/frame/staking/src/tests.rs
Outdated
@@ -7995,7 +8038,7 @@ mod ledger_recovery { | |||
assert_eq!(Balances::balance_locked(crate::STAKING_ID, &333), lock_333_before); // OK | |||
assert_eq!(Bonded::<Test>::get(&333), Some(444)); // OK | |||
assert!(Payee::<Test>::get(&333).is_some()); // OK | |||
// however, ledger associated with its controller was killed. | |||
// however, ledger associated with its controller was killed. |
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.
// however, ledger associated with its controller was killed. | |
// however, ledger associated with its controller was killed. |
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.
for some reason the fmt is not working here (noticed that elsewhere). Better to add a break line and it should be fine.
@@ -1161,6 +1162,91 @@ impl<T: Config> Pallet<T> { | |||
) -> Exposure<T::AccountId, BalanceOf<T>> { | |||
EraInfo::<T>::get_full_exposure(era, account) | |||
} | |||
|
|||
/// Whether `who` is a virtual staker whose funds are managed by another pallet. | |||
pub(crate) fn is_virtual_staker(who: &T::AccountId) -> bool { |
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 fn seems unrelated to the logic to be implemented?
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.
did not touch that actually
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.
Looking good. I am happy to approve once you fix the default pallet::weight
for fn unbond
. Few other suggestions but those are just nits.
@@ -1094,86 +1094,21 @@ pub mod pallet { | |||
#[pallet::compact] value: BalanceOf<T>, | |||
) -> DispatchResultWithPostInfo { | |||
let controller = ensure_signed(origin)?; | |||
let unlocking = |
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.
github doesn't allow me to add comment on the non changed line 1090
so adding here.
Add chill weight to the call so in worst case it always adds chill weight.
#[pallet::call_index(2)]
#[pallet::weight(
T::WeightInfo::withdraw_unbonded_kill(SPECULATIVE_NUM_SPANS).saturating_add(T::WeightInfo::unbond())
.saturating_add(T::WeightInfo::Chill()))
]
Additional info: Before any transaction this fund is reserved, and any difference in the PostInfo is refunded. So this should always contain the worst case weight.
Self::deposit_event(Event::<T>::Unbonded { stash, amount: value }); | ||
if value >= ledger.total { | ||
Self::chill_stash(&ledger.stash); | ||
total_weight = total_weight.saturating_add(T::WeightInfo::chill()); |
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.
nit
total_weight = total_weight.saturating_add(T::WeightInfo::chill()); | |
total_weight.saturating_accrue(T::WeightInfo::chill()); |
substrate/frame/staking/src/tests.rs
Outdated
assert_eq!(*staking_events().last().unwrap(), Event::Unbonded { stash: 11, amount: 1000 }); | ||
assert_eq!( | ||
*staking_events().get(staking_events().len() - 2).unwrap(), | ||
Event::Chilled { stash: 11 } | ||
); | ||
}) |
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.
closes #414
Polkadot address: 12GyGD3QhT4i2JJpNzvMf96sxxBLWymz4RdGCxRH5Rj5agKW