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

Bound elections-phragmen pallet #12549

Draft
wants to merge 48 commits into
base: master
Choose a base branch
from
Draft

Conversation

Szegoo
Copy link
Contributor

@Szegoo Szegoo commented Oct 23, 2022

Helps with: paritytech/polkadot-sdk#323

This PR replaces all the Vec types that are stored inside storage with BoundedVec so that we have an upper limit of items in all of the storage values. Also adapts the extrinsics to match these changes.

A new migration is introduced which will bound all the existing values inside the storage items and upgrade the elections pallet version to V6. The following storage will get updated when applying the storage migration:

  • Voting
  • Members
  • RunnersUp
  • Candidates

polkadot companion: paritytech/polkadot#6396

Polkadot address: 126X27SbhrV19mBFawys3ovkyBS87SGfYwtwa8J2FjHrtbmA

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.

I think we already have a bound for MaxVoters that is a constant in the file. You should remove that, use the new config in the transaction where we set the voters.

You should also document that reducing MaxVoters in a runtime upgrade might need a migration.

Otherwise, looks good in general and should be feasible.

@Szegoo
Copy link
Contributor Author

Szegoo commented Oct 24, 2022

NOTE: this is still a draft PR, so it may be too early to review :)

@Szegoo Szegoo marked this pull request as ready for review October 25, 2022 15:07
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 has a few fundamental flaws, but certainly in the right direction! 🙇

@kianenigma
Copy link
Contributor

kianenigma commented Oct 29, 2022

NOTE: this is still a draft PR, so it may be too early to review :)

Indeed, I am just doing a quick review to make sure you are in the right path. Ping me when you think this is final.

@kianenigma kianenigma added the A3-in_progress Pull request is in progress. No review needed at this stage. label Oct 29, 2022
@kianenigma kianenigma changed the title Bound Phragmen Bound elections-phragmen pallet Oct 29, 2022
@Szegoo
Copy link
Contributor Author

Szegoo commented Nov 1, 2022

@gpestana The PR is ready for review :)

@command-bot
Copy link

command-bot bot commented Feb 24, 2023

Here's a link to docs

@kianenigma
Copy link
Contributor

@gpestana @kianenigma Could you please review this?

This should be reviewed after #13453.

Copy link
Contributor

@gpestana gpestana left a comment

Choose a reason for hiding this comment

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

A few additional comments:

  • Could you add more info about what the PR does, the breaking changes and its migrations in the PR description? This helps reviewers and users and to keep track of changes pre and post-release.
  • It would be helpful if the branch build without errors/warnings when asking for a review, or state why it doesn't build if you need help/comments.
  • As @kianenigma mentioned, we should wait for Abstracts elections-phragmen pallet to use NposSolver (v2) #13453 to be merged and then rebase and apply these changes, since there are substancial changes on the election pallet (e.g. name change, etc). The comments above and my PR comments can be addressed before merging PR#13453 though.

frame/elections-phragmen/src/lib.rs Show resolved Hide resolved
.collect::<Vec<_>>(),
.collect::<Vec<_>>()
.try_into()
.expect("number members will never exceed T::DesiredMembers. qed."),
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer us to be defensive here, especially because this code runs on on_initialize. Changes in the logic/bounds may change the assumptions and number members will never exceed T::DesiredMembers. qed. may not hold true anymore.

I'd suggest to fail and return earlier here if the collect fails instead of using the expect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code is being executed inside a closure so I cannot return the weight from here, at least not without re-organizing the code. I took the approach of taking the first T::DesiredMembers members so that we can be sure there will never be more members.

Is this ok?

.try_into()
.expect(
"number runners up will never exceed T::DesiredRunnersUp. qed.",
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

@Szegoo
Copy link
Contributor Author

Szegoo commented Feb 27, 2023

  • Could you add more info about what the PR does, the breaking changes and its migrations in the PR description? This helps reviewers and users and to keep track of changes pre and post-release.

I have added a description now.

  • It would be helpful if the branch build without errors/warnings when asking for a review, or state why it doesn't build if you need help/comments.

The PR was passing the CI checks when I requested the review. After the comment from @kianenigma I merged master into this branch and the CI is not passing anymore, I will need to do some changes but I planned to do that once #13453 is merged. I will probably make this a draft PR for now.

@Szegoo Szegoo marked this pull request as draft February 27, 2023 17:23
@stale
Copy link

stale bot commented Apr 4, 2023

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A3-stale label Apr 4, 2023
@stale stale bot removed the A3-stale label Apr 5, 2023
@gpestana
Copy link
Contributor

@Szegoo quick update on this PR, I think it would be useful to have #13453 merged first -- happening soon -- and then we can come back to this one, do another round of reviews and try to close it.

@stale
Copy link

stale bot commented May 25, 2023

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A3-stale label May 25, 2023
@stale stale bot removed the A3-stale label May 25, 2023
@stale
Copy link

stale bot commented Jun 24, 2023

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A3-stale label Jun 24, 2023
@Szegoo
Copy link
Contributor Author

Szegoo commented Jun 24, 2023

Waiting for: #13453

@stale stale bot removed the A3-stale label Jun 24, 2023
@stale
Copy link

stale bot commented Jul 24, 2023

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A3-stale label Jul 24, 2023
@stale stale bot removed the A3-stale label Jul 24, 2023
@paritytech-cicd-pr
Copy link

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

@stale
Copy link

stale bot commented Aug 23, 2023

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added A3-stale and removed A3-stale labels Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A3-in_progress Pull request is in progress. No review needed at this stage.
Projects
Status: ✂️ In progress.
Development

Successfully merging this pull request may close these issues.

5 participants