Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

session, staking: introduce static limit on the number of validators #11967

Closed
wants to merge 17 commits into from

Conversation

Doordashcon
Copy link
Contributor

@Doordashcon Doordashcon commented Aug 2, 2022

Attempts to resolve #9724

polkadot companion: paritytech/polkadot#5905
cumulus companion: paritytech/cumulus#1558

@Doordashcon Doordashcon changed the title initial session, staking: introduce static limit on the number of validators Aug 2, 2022
@Doordashcon
Copy link
Contributor Author

@andresilva is this the general direction you envisioned?

@kianenigma kianenigma added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes labels Aug 11, 2022
@@ -647,7 +653,9 @@ impl<T: Config> Pallet<T> {
let session_keys = <QueuedKeys<T>>::get();
let validators =
session_keys.iter().map(|(validator, _)| validator.clone()).collect::<Vec<_>>();
Validators::<T>::put(&validators);

let validator2: BoundedVec<T::ValidatorId, T::ValidatorSet> = validators.clone().try_into().expect("Too many current validators");
Copy link
Contributor

Choose a reason for hiding this comment

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

You certainly cannot and should not panic here -- need to handle it defensively, either use WeakBoundedVec, or truncate to fit (better).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved?

Copy link
Contributor

Choose a reason for hiding this comment

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

not yet -- you cannot panic in any runtime code path such as on_initialize or a transaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mapping to a custom error would be ideal?

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.

Good start, but needs some more work, looking forward!

@Doordashcon Doordashcon marked this pull request as ready for review August 14, 2022 20:32
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - cargo-check-benches
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1743895

@Doordashcon Doordashcon requested a review from acatangiu as a code owner August 14, 2022 21:17
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - cargo-check-benches
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1743975

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - cargo-check-benches
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1744048

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - cargo-check-benches
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1744086

Validators::<T>::put(&validators);

let bounded_validator_set: WeakBoundedVec<T::ValidatorId, T::MaxValidators> =
validators.clone().try_into().expect("Max validators reached");
Copy link
Contributor

Choose a reason for hiding this comment

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

this panic is still not valid.

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.

Still creating some panicing code that is not allowed.

The correct way to to do this is actually to bound the interfaces linking staking and session pallet as well, something that is not done yet but is toyed with as a part of #11499 and alike.

For example, the session pallet should be able to ENSURE that its SessionManager does not return more than x validators.

This is all likely to be part of a greater effort to bound and fix all the staking related pallets. We can continue trying it out here, but I can't guarantee that it will be easy 😅

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

session, staking: introduce static limit on the number of validators
3 participants