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

Bound some storage items for pallet staking and clean up deprecated exposures #7483

Merged

Conversation

re-gius
Copy link
Contributor

@re-gius re-gius commented Feb 5, 2025

Building from #6445 on top of #7282

Changes

  • Bound Invulnerables, vector of validators invulnerable to slashing.
    • Add MaxInvulnerables to bound Invulnerables Vec -> BoundedVec.
    • Set to constant 20 in the pallet (must be >= 17 for backward compatibility with runtime westend).
  • Bound Disabled Validators, vector of validators that have offended in a given era and have been disabled.
    • Add MaxDisabledValidators to bound DisabledValidators Vec -> BoundedVec.
    • Set to constant 100 in the pallet (it should be <= 1/3 * MaxValidatorsCount according to the current disabling strategy).
  • Remove ErasStakers and ErasStakersClipped (see Tracker issue for cleaning up old non-paged exposure logic in staking pallet #433 ), non-paged validators exposures.

Migrating pallet staking storage to v17 to apply all changes.

TO DO (in a follow-up PR)

  • Bound ErasStakersPaged
    • this needs bounding ExposurePage.others vector
  • Bound BondedEras vector
  • Bound ClaimedRewards pages vector
  • Bound ErasRewardPoints
    • this needs bounding EraRewardPoints.individual BTreeMap
  • Bound UnappliedSlashes
  • Bound SlashingSpans
    • this needs bounding SlashingSpans.prior vector

@re-gius re-gius added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Feb 5, 2025
@re-gius re-gius self-assigned this Feb 5, 2025
@re-gius re-gius changed the title Bound storage items for pallet staking and clean up deprecated exposures Bound some storage items for pallet staking and clean up deprecated exposures Feb 5, 2025
@re-gius
Copy link
Contributor Author

re-gius commented Feb 6, 2025

/cmd prdoc --audience runtime_dev --bump patch

@re-gius re-gius added the R0-silent Changes should not be mentioned in any release notes label Feb 6, 2025
@re-gius
Copy link
Contributor Author

re-gius commented Feb 6, 2025

Deferring prdoc to #7282

@re-gius re-gius marked this pull request as ready for review February 6, 2025 14:32
@re-gius re-gius requested review from acatangiu and a team as code owners February 6, 2025 14:32
@@ -842,7 +802,11 @@ pub mod pallet {
fn build(&self) {
ValidatorCount::<T>::put(self.validator_count);
MinimumValidatorCount::<T>::put(self.minimum_validator_count);
Invulnerables::<T>::put(&self.invulnerables);
assert!(
self.invulnerables.len() as u32 <= T::MaxInvulnerables::get(),
Copy link
Contributor

Choose a reason for hiding this comment

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

self.invulnerables is already bounded, we don't need this check.

let disabled_validators_maybe = BoundedVec::try_from(old_disabled_validators);
match disabled_validators_maybe {
Ok(disabled_validators) => {
y = y.saturating_add(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

You have read the storage already no matter if the match is Ok or Err.

match disabled_validators_maybe {
Ok(disabled_validators) => {
y = y.saturating_add(1);
DisabledValidators::<T>::set(disabled_validators);
Copy link
Contributor

Choose a reason for hiding this comment

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

The main point that might be missed here is that the encoding of a Vec<_> and BoundedVec<_> is exactly the same. So no data actually needs to be migrated.

What the migration would have to do is to check if the data won't fit into BoundedVec<_>, and in this case truncate it.

If hypothetically DisabledValidators is too large, your migration will not touch it, which means the runtime will still fail to decode it upon next access.

log!(warn, "v17 failed to bound some storage items.");
}

T::DbWeight::get().reads_writes(x.into(), y.into())
Copy link
Contributor

Choose a reason for hiding this comment

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

In any case I will temp remove this migration as we will start from a fresh state and migrate the data. So any failed bounding will be detected in the migration testing.

<Pallet<T>>::deposit_event(super::Event::<T>::ValidatorDisabled {
stash: params.stash.clone(),
});
if disabled.try_insert(index, (offender_idx, new_severity)).is_ok() {
Copy link
Contributor

Choose a reason for hiding this comment

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

For this you can use .defensive, worth reading up on it.

@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/13244012343
Failed job name: fmt

@kianenigma kianenigma merged commit 0fa010d into kiz-multi-block-eletion Feb 10, 2025
66 of 155 checks passed
@kianenigma kianenigma deleted the re-gius/staking/bound-storage-items branch February 10, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants