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

[AHM] Moves disabling logic into pallet-session #7581

Merged
merged 242 commits into from
Feb 18, 2025
Merged

Conversation

Ank4n
Copy link
Contributor

@Ank4n Ank4n commented Feb 14, 2025

closes #6508.

TODO

  • Migrate storage DisabledValidators both in pallet-session and pallet-staking.
  • Test that disabled validator resets at era change.
  • Add always sorted try-runtime test for DisabledValidators.
  • More test coverage for the disabling logic.

gpestana and others added 30 commits October 13, 2024 15:34
@Ank4n Ank4n requested review from tdimitrov, kianenigma, seadanda and Overkillus and removed request for acatangiu February 17, 2025 13:18
Copy link
Contributor

@tdimitrov tdimitrov left a comment

Choose a reason for hiding this comment

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

I had a quick look. Changes look sane. I'm approving to get this included in the release but we have to do a proper review before deploying it on a prod network.

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.

High level interface looks very clear and good. Approving with the assumption that the impl is equivalent to the old behavior.

Base automatically changed from ankan/paged-slashing to master February 17, 2025 23:40
@Ank4n Ank4n enabled auto-merge February 18, 2025 01:59
@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/13381688399
Failed job name: fmt

@Ank4n Ank4n added this pull request to the merge queue Feb 18, 2025
auto-merge was automatically disabled February 18, 2025 03:52

Pull Request is not mergeable

Merged via the queue into master with commit 43ea306 Feb 18, 2025
221 of 232 checks passed
@Ank4n Ank4n deleted the ankan/refactor-disabling branch February 18, 2025 04:14
Copy link
Contributor

@Overkillus Overkillus left a comment

Choose a reason for hiding this comment

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

Thanks Kian, Tsveto and Donnal for a quick review and Ankan for awesome work!

Since we got this quickly merged I wanted to do a deeper dive into comparing it with pre-refactor behaviour. I highlighted a few bits and once we clarify those it's looking perfect

Comment on lines +750 to +758
/// Note: This sets the OffenceSeverity to the lowest value.
pub fn disable_index(i: u32) -> bool {
if i >= Validators::<T>::decode_len().unwrap_or(0) as u32 {
if i >= Validators::<T>::decode_len().defensive_unwrap_or(0) as u32 {
return false
}

DisabledValidators::<T>::mutate(|disabled| {
if let Err(index) = disabled.binary_search(&i) {
disabled.insert(index, i);
if let Err(index) = disabled.binary_search_by_key(&i, |(index, _)| *index) {
disabled.insert(index, (i, OffenceSeverity(Perbill::zero())));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we defaulting to lowest severity? And what is the purpose of this logic? It is not being used for report_offence as you directly modify the DisabledValidators. Just for testing then?

What worries me is that we expose a way of disabling validators that is dangerous (default to lowest priority). At least requiring a severity would make it less prone to mistakes.

And if the argument is to expose it to other pallets then shouldn't we also have the enable_index that you removed a few lines below?

Another option is to make report_offence depend on disable_index / enable_index instead of making direct changes to disabledValidators

@@ -631,7 +653,7 @@ impl<T: Config> Pallet<T> {

/// Public function to access the disabled validators.
pub fn disabled_validators() -> Vec<u32> {
DisabledValidators::<T>::get()
DisabledValidators::<T>::get().iter().map(|(i, _)| *i).collect()
Copy link
Contributor

Choose a reason for hiding this comment

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

dont we want to expose the severities as well?

@@ -740,23 +764,6 @@ impl<T: Config> Pallet<T> {
})
}

/// Re-enable the validator of index `i`, returns `false` if the validator was already enabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

see comment on disable_index

@@ -2745,6 +2741,7 @@ impl<T: Config> Pallet<T> {
Ok(())
}

/* todo(ank4n): move to session try runtime
Copy link
Contributor

Choose a reason for hiding this comment

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

todo

Comment on lines -612 to -614

// Clear disabled validators.
<DisabledValidators<T>>::kill();
Copy link
Contributor

Choose a reason for hiding this comment

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

original impl only killed DisabledValidators on era change, so they persisted between sessions. It is quite important so I'm bringing it to light explicitly. Is this behaviour replicated in the refactor?

assert!(disabling_decision.disable.is_none() && disabling_decision.reenable.is_none());
});
}
// todo(ank4n): Ensure there is a test that for older eras, the disabling strategy does not
Copy link
Contributor

Choose a reason for hiding this comment

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

todo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I4-refactor Code needs refactoring. T2-pallets This PR/Issue is related to a particular pallet.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[AHM] refactor: Move disable logic from pallet-staking to pallet-session
7 participants