-
Notifications
You must be signed in to change notification settings - Fork 709
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.
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.
bot fmt |
@Ank4n https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7537093 was started for your command Comment |
cc: @gpestana |
@Ank4n Command |
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 left a few nits and suggestions which when included should wrap up this PR, thanks!
@@ -1087,93 +1087,28 @@ pub mod pallet { | |||
/// See also [`Call::withdraw_unbonded`]. | |||
#[pallet::call_index(2)] | |||
#[pallet::weight( | |||
T::WeightInfo::withdraw_unbonded_kill(SPECULATIVE_NUM_SPANS).saturating_add(T::WeightInfo::unbond())) | |||
T::WeightInfo::withdraw_unbonded_kill(SPECULATIVE_NUM_SPANS).saturating_add(T::WeightInfo::unbond()).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.
T::WeightInfo::withdraw_unbonded_kill(SPECULATIVE_NUM_SPANS).saturating_add(T::WeightInfo::unbond()).saturating_add(T::WeightInfo::chill())) | |
T::WeightInfo::withdraw_unbonded_kill(SPECULATIVE_NUM_SPANS) | |
.saturating_add(T::WeightInfo::unbond()) | |
.saturating_add(T::WeightInfo::chill())) |
Or something along these lines. Have you ran rustfmt against the current code? At least the clippy CI job seems to be failing.
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 actually ran cargo +nightly fmt before pushing.
if value >= ledger.total { | ||
Self::chill_stash(&ledger.stash); | ||
total_weight.saturating_accrue(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.
if value >= ledger.total { | |
Self::chill_stash(&ledger.stash); | |
total_weight.saturating_accrue(T::WeightInfo::chill()); | |
let mut total_weight = if value >= ledger.total { | |
Self::chill_stash(&ledger.stash); | |
T::WeightInfo::chill() | |
} else { | |
Zero::zero() | |
}; |
nit but how about this? then we can remove let mut total_weight
instantiation from line 1100 (but do not forget to saturate_accrue the weight of unbound at the end (line 1111).
substrate/frame/staking/src/tests.rs
Outdated
#[test] | ||
fn unbond_with_chill_works() { | ||
// Should test: | ||
// * Given an account being bonded [and chosen as a validator](not mandatory) |
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.
// * Given an account being bonded [and chosen as a validator](not mandatory) | |
// * Given a abounded account, |
@@ -1087,93 +1087,28 @@ pub mod pallet { | |||
/// See also [`Call::withdraw_unbonded`]. | |||
#[pallet::call_index(2)] | |||
#[pallet::weight( | |||
T::WeightInfo::withdraw_unbonded_kill(SPECULATIVE_NUM_SPANS).saturating_add(T::WeightInfo::unbond())) | |||
T::WeightInfo::withdraw_unbonded_kill(SPECULATIVE_NUM_SPANS).saturating_add(T::WeightInfo::unbond()).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.
Could you also update the rustdoc of this callable and mention that the stash may be chilled if the ledger total amount falls to 0 after unbonding?
substrate/frame/staking/src/tests.rs
Outdated
let res = Staking::unbond(RuntimeOrigin::signed(11), 1000); | ||
assert!(res.is_ok()); |
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.
let res = Staking::unbond(RuntimeOrigin::signed(11), 1000); | |
assert!(res.is_ok()); | |
assert_ok!(Staking::unbond(RuntimeOrigin::signed(11), 1000)); |
This is cleaner and common practice in frame.
Event::Unbonded { stash: 11, amount: 1000 } | ||
] | ||
)); | ||
}) |
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.
One last check is to ensure that the stash is actually chilled instead of only relying on the events above. e.g.
assert!(Nominators::<Test>::get(11).is_none());
assert!(Validators::<Test>::get(11).is_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.
i have done this
prdoc/pr_3811.prdoc
Outdated
Modifies the `unbond` extrinsic by forcefully chilling and unbonding the full value | ||
if the value to be unbonded is the total of what is bonded |
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.
Modifies the `unbond` extrinsic by forcefully chilling and unbonding the full value | |
if the value to be unbonded is the total of what is bonded | |
Modifies the `unbond` extrinsic to forcefully chill stash when unbonding | |
if the value to be unbonded is the total of what is bonded. |
# Conflicts: # substrate/frame/staking/src/pallet/mod.rs
@gpestana can you please help with review so this can be closed out? |
closes #414
Polkadot address: 12GyGD3QhT4i2JJpNzvMf96sxxBLWymz4RdGCxRH5Rj5agKW