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

Validator disabling in session enhancements #7663

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

Conversation

Overkillus
Copy link
Contributor

@Overkillus Overkillus commented Feb 21, 2025

On top of 7581.

Adds the missing testing cases and adresses some overdue review feedback post merge.

  • Clean up disabling interface
  • Review disabling severity defaults in the refactor
  • Verify and test disabling duration (should be era long)
  • Add always sorted try-runtime test for DisabledValidators.
  • expose severities
  • better debuggin/tracing
  • Make migration more robust
  • Ensure we dont disable for past era slashes (+test)
  • Move disabling strategy tests from staking to session (left some there as it also tests the offence pipeline)
  • more?

@Overkillus Overkillus self-assigned this Feb 21, 2025
@Overkillus Overkillus added T8-polkadot This PR/Issue is related to/affects the Polkadot network. T10-tests This PR/Issue is related to tests. labels Feb 21, 2025
@Overkillus Overkillus changed the title Mkz session disabling plus Validator disabling in session enhancements Feb 21, 2025
@tdimitrov
Copy link
Contributor

Looks good so far.

@Overkillus Overkillus marked this pull request as ready for review February 25, 2025 19:45
@Overkillus Overkillus requested a review from a team as a code owner February 25, 2025 19:45
@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/13529783966
Failed job name: fmt

@Overkillus Overkillus requested a review from ordian February 27, 2025 13:04
Copy link
Member

@ordian ordian left a comment

Choose a reason for hiding this comment

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

small nits, looks good overall

log::trace!(
target: "runtime::session",
log!(
trace,
Copy link
Member

Choose a reason for hiding this comment

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

here and elsewhere: would be gud to bring the target: LOG_TARGET back, otherwise, setting trace level logs will be painful

Comment on lines +267 to +272
impl Default for OffenceSeverity {
fn default() -> Self {
Self(Perbill::from_percent(100))
}
}

Copy link
Member

Choose a reason for hiding this comment

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

i'm not sure this is intuitive implementation. i would suggest instead create an inherent method named fn most_severe() -> Self to be more explicit

Copy link
Contributor Author

@Overkillus Overkillus Feb 27, 2025

Choose a reason for hiding this comment

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

This is quite intentional but I can change it if you guys think so. The intention was to make sure that if severity is unknown or unclear you default to max. AKA if severity is unknown I'd rather have the offender never re-enabled (max severity) than them at 0% and re-enable them too easily.

Not having this default made it so Ankan mistakenly also assumed that lowest severity is a sensible default when it isn't.

Still thinking I should change it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was about to suggest to have a function max_severity() but @ordian was faster.

What you say makes sense but I still think it's not readable enough. You can add a max_severity()/most_severe() initialiser and call it in default)() if you insist on default behaviour.

That way it will be clear that a) 100% is the highest severity and b) your default value concern: when in doubt - slash them hard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to be clear this is NOT slashing anyone :D it's purely for purposes of disabling but I like the compromise Tsveto proposes 👍

@@ -81,7 +83,7 @@ pub mod v17 {

#[frame_support::storage_alias]
pub type DisabledValidators<T: Config> =
StorageValue<Pallet<T>, BoundedVec<(u32, OffenceSeverity), ConstU32<100>>, ValueQuery>;
StorageValue<Pallet<T>, BoundedVec<(u32, OffenceSeverity), ConstU32<300>>, ValueQuery>;
Copy link
Member

Choose a reason for hiding this comment

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

should this be 333 instead? assuming f out of 3f + 1 (1000 eventually)

DisabledValidators::<T>::mutate(|disabled| {
if let Ok(index) = disabled.binary_search_by_key(&i, |(index, _)| *index) {
log!(trace, "reenabling validator {:?}", i);
Self::deposit_event(Event::ValidatorReenabled { validator: Validators::<T>::get()[index as usize].clone() });
Copy link
Member

Choose a reason for hiding this comment

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

not introduced here, but direct indexing makes me uneasy if index is somehow out of range for Validators (e.g. due to a bug) - this will make the runtime panic!

Comment on lines +267 to +272
impl Default for OffenceSeverity {
fn default() -> Self {
Self(Perbill::from_percent(100))
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I was about to suggest to have a function max_severity() but @ordian was faster.

What you say makes sense but I still think it's not readable enough. You can add a max_severity()/most_severe() initialiser and call it in default)() if you insist on default behaviour.

That way it will be clear that a) 100% is the highest severity and b) your default value concern: when in doubt - slash them hard.

@@ -49,14 +49,14 @@ impl<T: Config> MigrateDisabledValidators for InitOffenceSeverity<T> {
fn peek_disabled() -> Vec<(u32, OffenceSeverity)> {
DisabledValidators::<T>::get()
.iter()
.map(|v| (*v, OffenceSeverity(Perbill::zero())))
.map(|v| (*v, OffenceSeverity::default()))
Copy link
Contributor

Choose a reason for hiding this comment

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

For example here default() doesn't mean much to the readed in comparison with most_severe().

@@ -81,7 +83,7 @@ pub mod v17 {

#[frame_support::storage_alias]
pub type DisabledValidators<T: Config> =
StorageValue<Pallet<T>, BoundedVec<(u32, OffenceSeverity), ConstU32<100>>, ValueQuery>;
StorageValue<Pallet<T>, BoundedVec<(u32, OffenceSeverity), ConstU32<300>>, ValueQuery>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't we wanted to merge v16 and v17?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T8-polkadot This PR/Issue is related to/affects the Polkadot network. T10-tests This PR/Issue is related to tests.
Projects
Status: No status
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants