This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Conversation
coriolinus
approved these changes
Apr 12, 2021
Contributor
coriolinus
left a comment
There was a problem hiding this comment.
Looks good, pending CI.
We could code
impl DataProvider for multi_phase::Palletin 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 | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
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 | |
| } |
Contributor
Author
|
I won't work on this PR immediately now, so putting it inprogress temporarily. |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 Fallbackis merely anotherElectionProviderthat might be anything.Also, we ensure that a fallback method uses the snapshot that is created in the
multi-phasepallet. In the past, theDataProviderofFallbackwasStaking, 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 implementElectionDataProviderformulti_phase::Pallet<T>, meaning thatmulti_phasecan 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_phasehas no snapshot to give to the fallback, and the fallback cannot do anything.We could code
impl DataProvider for multi_phase::Palletin such a way that first tries to return the data from its own snapshot, and if failure, fallback to its ownT::DataProvider(staking).