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

Full Unbond in Staking #3811

Open
wants to merge 44 commits into
base: master
Choose a base branch
from

Conversation

dharjeezy
Copy link
Contributor

@dharjeezy dharjeezy commented Mar 24, 2024

closes #414

Polkadot address: 12GyGD3QhT4i2JJpNzvMf96sxxBLWymz4RdGCxRH5Rj5agKW

@dharjeezy dharjeezy changed the title Dami/full unbond Full Unbond in Staking Mar 24, 2024
@dharjeezy
Copy link
Contributor Author

@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?

@Ank4n
Copy link
Contributor

Ank4n commented Mar 27, 2024

@kianenigma wdyt about call::unbond doing chill implicitly if it is a full unbond (unbond value == ledger.total)?

@kianenigma
Copy link
Contributor

@kianenigma wdyt about call::unbond doing chill implicitly if it is a full unbond (unbond value == ledger.total)?

This is also fine with me, no strong opinion. I like your idea better as it improves UX without wallets needing to do much.

@dharjeezy
Copy link
Contributor Author

OK. So, should we still keep the full unbond extrinsic and also implement the implicit one that @Ank4n is suggesting?

# 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
@dharjeezy
Copy link
Contributor Author

dharjeezy commented Apr 10, 2024

@Ank4n @kianenigma
I have implicitly added the chill for unbonding

please help review again

Copy link
Contributor

@kianenigma kianenigma left a 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.

Copy link
Contributor

@Ank4n Ank4n left a 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.

Comment on lines 285 to 286
assert!(new_bonded == BalanceOf::<T>::try_from(0u128).map_err(|_| "balance expected to be a u128")
.unwrap());
Copy link
Contributor

Choose a reason for hiding this comment

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

This should work.

Suggested change
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::*;
Copy link
Contributor

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 {
Copy link
Contributor

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.

@dharjeezy dharjeezy requested a review from Ank4n August 12, 2024 04:53
@Ank4n Ank4n added the T2-pallets This PR/Issue is related to a particular pallet. label Aug 12, 2024
@Ank4n
Copy link
Contributor

Ank4n commented Aug 13, 2024

bot bench polkadot-pallet --pallet=pallet_staking --runtime=westend

@command-bot
Copy link

command-bot bot commented Aug 13, 2024

@Ank4n https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6988164 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=pallet_staking. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 10-0373acde-d692-46d8-a50e-545384f7ad2c to cancel this command or bot cancel to cancel all commands in this pull request.

@@ -274,16 +274,15 @@ benchmarks! {

let stash = scenario.origin_stash1.clone();
let controller = scenario.origin_controller1.clone();
let amount = origin_weight - scenario.dest_weight;
Copy link
Contributor

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?

Copy link
Contributor

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
@command-bot
Copy link

command-bot bot commented Aug 13, 2024

@Ank4n Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=pallet_staking has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6988164 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6988164/artifacts/download.

fn unbond() -> Weight {
// Proof Size summary in bytes:
// Measured: `2128`
Copy link
Contributor

@Ank4n Ank4n Aug 14, 2024

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
Copy link
Contributor

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.

Comment on lines 248 to 249
// unbonding total of active stake passes because Chill occurs implicitly when unbonding
// full amount
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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.

@@ -0,0 +1,10 @@
title: "Chill and Full Unbond in [pallet_staking]"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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);
Copy link
Contributor

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.

Copy link
Contributor Author

@dharjeezy dharjeezy Aug 25, 2024

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.

Copy link
Contributor Author

@dharjeezy dharjeezy Sep 14, 2024

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

@@ -4133,6 +4133,49 @@ fn test_multi_page_payout_stakers_by_page() {
});
}

#[test]
fn unbond_with_chill_works() {
//
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//

#[test]
fn unbond_with_chill_works() {
//
// * Should test
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// * Should test
// Should test:

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// however, ledger associated with its controller was killed.
// however, ledger associated with its controller was killed.

Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@Ank4n Ank4n left a 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 =
Copy link
Contributor

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());
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
total_weight = total_weight.saturating_add(T::WeightInfo::chill());
total_weight.saturating_accrue(T::WeightInfo::chill());

Comment on lines 4170 to 4175
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 }
);
})
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would be lot nicer to assert against all events (see this) or do a match (see this)

@Ank4n Ank4n requested a review from gpestana September 18, 2024 12:14
@dharjeezy dharjeezy requested a review from Ank4n October 3, 2024 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Staking force_unbond
5 participants