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

Implement wrapping of EPM types #1633

Merged
merged 24 commits into from
Jan 22, 2024
Merged

Conversation

wirednkod
Copy link
Contributor

This PR wraps the Snapshot, SnapshotMetadata and DesiredTargets storage items in the EPM pallet in order to keep them in sync throughout the election lifetime and in order to be killed together.

Prior to this PR, these storage items were mutated in different places in the pallet;

In addition 2 helper fns are introduced for chekcing if all the wrapped storage items exist or not;

Fixes #413 ;

@wirednkod wirednkod added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Sep 19, 2023
@wirednkod wirednkod marked this pull request as ready for review September 19, 2023 11:30
@wirednkod wirednkod requested review from a team September 19, 2023 11:30
@wirednkod wirednkod requested a review from a team as a code owner September 19, 2023 11:30
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.

There are unrelated changes in the diff @wirednkod.

@wirednkod
Copy link
Contributor Author

There are unrelated changes in the diff @wirednkod.

Can you elaborate? The ones in polkadot/xcm/xcm-builder/src/universal_exports.rs are cargo +nightly fmt changes

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.

The PR is going in the right direction but it needs some improvements, thanks for putting this together.

substrate/frame/election-provider-multi-phase/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/election-provider-multi-phase/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/election-provider-multi-phase/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/election-provider-multi-phase/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/election-provider-multi-phase/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/election-provider-multi-phase/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/election-provider-multi-phase/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/election-provider-multi-phase/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/election-provider-multi-phase/src/lib.rs Outdated Show resolved Hide resolved
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 comment nits, if the tests pass it looks great to me.

One more suggestion, could you please a few words on the Snapshot, etc storage types definitions and say that we should use the SnapshotWrapper to mutate these types? thanks! (e.g. /// Note: This storage type must only be mutates thorough[SnapshotWrapper].

substrate/frame/election-provider-multi-phase/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/election-provider-multi-phase/src/lib.rs Outdated Show resolved Hide resolved
@gpestana gpestana requested a review from Ank4n October 11, 2023 14:29
…paritytech/polkadot-sdk into nik-wrap-epm-types-with-snapshotwrapper
Comment on lines 1381 to 1388
pub fn is_consistent() -> bool {
(<Snapshot<T>>::exists() &&
<SnapshotMetadata<T>>::exists() &&
<DesiredTargets<T>>::exists()) ||
(!<Snapshot<T>>::exists() &&
!<SnapshotMetadata<T>>::exists() &&
!<DesiredTargets<T>>::exists())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe can do something like this for improved readability

Suggested change
pub fn is_consistent() -> bool {
(<Snapshot<T>>::exists() &&
<SnapshotMetadata<T>>::exists() &&
<DesiredTargets<T>>::exists()) ||
(!<Snapshot<T>>::exists() &&
!<SnapshotMetadata<T>>::exists() &&
!<DesiredTargets<T>>::exists())
}
pub fn is_consistent() -> bool {
let snapshots = [
<Snapshot<T>>::exists(),
<SnapshotMetadata<T>>::exists(),
<DesiredTargets<T>>::exists(),
];
// All should either exist or not exist
snapshots.iter().all(|&exists| exists) || snapshots.iter().all(|&exists| !exists)
}

Copy link
Contributor

@kianenigma kianenigma Nov 6, 2023

Choose a reason for hiding this comment

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

snapshots.iter().skip(1).all(|v| snapshots[0] == v) has the same effect.

@paritytech-review-bot paritytech-review-bot bot requested a review from a team November 6, 2023 08:54
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.

Can go in assuming buffer is a slice and everything else works fine

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable 1/3
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/4239410

@bkchr bkchr added the R0-silent Changes should not be mentioned in any release notes label Jan 22, 2024
@bkchr bkchr enabled auto-merge January 22, 2024 12:14
@bkchr bkchr added this pull request to the merge queue Jan 22, 2024
Merged via the queue into master with commit 3029280 Jan 22, 2024
124 of 127 checks passed
@bkchr bkchr deleted the nik-wrap-epm-types-with-snapshotwrapper branch January 22, 2024 15:11
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
This PR wraps the `Snapshot`, `SnapshotMetadata` and `DesiredTargets`
storage items in the [EPM
pallet](https://paritytech.github.io/substrate/master/pallet_election_provider_multi_phase/index.html)
in order to keep them in sync throughout the election lifetime and in
order to be killed together.

Prior to this PR, these storage items were mutated in different places
in the pallet;

In addition 2 helper `fns` are introduced for chekcing if all the
wrapped storage items exist or not;

Fixes paritytech#413 ;

---------

Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
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: Audited
Development

Successfully merging this pull request may close these issues.

Wrap EPM Snapshot, SnapshotMetadata and DesiredTargets to ensure invariants
10 participants