This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kianenigma
added
A0-please_review
Pull request needs code review.
B0-silent
Changes should not be mentioned in any release notes
C3-medium
PR touches the given topic and has a medium impact on builders.
labels
Apr 8, 2021
coriolinus
approved these changes
Apr 12, 2021
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.
Looks good, pending CI.
We could code
impl DataProvider for multi_phase::Pallet
in such a way that first tries to return the data from its own snapshot, and if failure, fallback to its ownT::DataProvider
(staking).
Future PR?
Comment on lines
+1080
to
+1086
fn maybe_trim<T>(items: Vec<T>, maybe_size: Option<usize>) -> Vec<T> { | ||
if let Some(size) = maybe_size { | ||
items.into_iter().take(size).collect::<Vec<T>>() | ||
} else { | ||
items | ||
} | ||
} |
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.
I find the size
name a bit confusing. The implementation can also avoid allocating a new vector:
Suggested change
fn maybe_trim<T>(items: Vec<T>, maybe_size: Option<usize>) -> Vec<T> { | |
if let Some(size) = maybe_size { | |
items.into_iter().take(size).collect::<Vec<T>>() | |
} else { | |
items | |
} | |
} | |
fn maybe_trim<T>(mut items: Vec<T>, maybe_qty: Option<usize>) -> Vec<T> { | |
items.truncate(maybe_qty.unwrap_or_else(|| items.len())); | |
items | |
} |
kianenigma
added
A3-in_progress
Pull request is in progress. No review needed at this stage.
and removed
A0-please_review
Pull request needs code review.
labels
Apr 13, 2021
I won't work on this PR immediately now, so putting it inprogress temporarily. |
gnunicorn
added
the
A5-stale
Pull request did not receive any updates in a long time. No review needed at this stage. Close it.
label
May 19, 2021
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.
A5-stale
Pull request did not receive any updates in a long time. No review needed at this stage. Close it.
B0-silent
Changes should not be mentioned in any release notes
C3-medium
PR touches the given topic and has a medium impact on builders.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to https://github.com/paritytech/srlabs_findings/issues/79 and https://github.com/paritytech/srlabs_findings/issues/65.
The fundamental change here is that instead of assuming a hardcoded:
We leave this open: The
type Fallback
is merely anotherElectionProvider
that might be anything.Also, we ensure that a fallback method uses the snapshot that is created in the
multi-phase
pallet. In the past, theDataProvider
ofFallback
wasStaking
, meaning that we would need to re-query all validators and nominators from chain-state one by one to trigger the on-chain election. Now, we implementElectionDataProvider
formulti_phase::Pallet<T>
, meaning thatmulti_phase
can itself be the data provider of the fallback.This is beneficial if: The snapshot is created in
multi_phase
, but election fails. In this case, we use the snapshot and this is much more optimized in terms of storage operations.This is tricky if: Everything gets fails in
multi_phase
, and no snapshot exists there. An example of this is if the snapshot creation fails. In these cases,multi_phase
has no snapshot to give to the fallback, and the fallback cannot do anything.We could code
impl DataProvider for multi_phase::Pallet
in such a way that first tries to return the data from its own snapshot, and if failure, fallback to its ownT::DataProvider
(staking).