-
Notifications
You must be signed in to change notification settings - Fork 789
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
Conversation
There was a problem hiding this 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.
Can you elaborate? The ones in |
…wrap-epm-types-with-snapshotwrapper
…paritytech/polkadot-sdk into nik-wrap-epm-types-with-snapshotwrapper
There was a problem hiding this 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.
There was a problem hiding this 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].
…s must only be mutated throught the SnapshotWrapper
…paritytech/polkadot-sdk into nik-wrap-epm-types-with-snapshotwrapper
pub fn is_consistent() -> bool { | ||
(<Snapshot<T>>::exists() && | ||
<SnapshotMetadata<T>>::exists() && | ||
<DesiredTargets<T>>::exists()) || | ||
(!<Snapshot<T>>::exists() && | ||
!<SnapshotMetadata<T>>::exists() && | ||
!<DesiredTargets<T>>::exists()) | ||
} |
There was a problem hiding this comment.
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
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) | |
} |
There was a problem hiding this comment.
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.
There was a problem hiding this 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/polkadot-sdk into nik-wrap-epm-types-with-snapshotwrapper
The CI pipeline was cancelled due to failure one of the required jobs. |
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>
This PR wraps the
Snapshot
,SnapshotMetadata
andDesiredTargets
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 ;