-
Notifications
You must be signed in to change notification settings - Fork 20
Allow configuring winner count in dry-run #539
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2dc18e0
first pass: allow configuring winner count in dry-run
jsdw d012959
cargo fmt
jsdw 3542df0
Merge branch 'main' into jsdw-simulate-winner-count
jsdw d272a88
fix merge
jsdw fb88c5d
move feasibility checking until after we've obtained and logged a sol…
jsdw b4c8f77
replace metadata with modern, stripped down version with just EPM pal…
jsdw c5c6287
no feasibliity check if force_winner_count set
jsdw bf4599b
revert; put original metadata from main back; stripping updates to v1…
jsdw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ use crate::{ | |
| use codec::{Decode, Encode}; | ||
| use frame_election_provider_support::{NposSolution, PhragMMS, SequentialPhragmen}; | ||
| use frame_support::weights::Weight; | ||
| use pallet_election_provider_multi_phase::{RawSolution, SolutionOf, SolutionOrSnapshotSize}; | ||
| use pallet_election_provider_multi_phase::{RawSolution, SolutionOrSnapshotSize}; | ||
| use scale_info::{PortableRegistry, TypeInfo}; | ||
| use scale_value::scale::{decode_as_type, TypeId}; | ||
| use sp_core::Bytes; | ||
|
|
@@ -175,7 +175,8 @@ pub async fn fetch_snapshot_and_mine_solution<T>( | |
| hash: Option<Hash>, | ||
| solver: Solver, | ||
| round: u32, | ||
| ) -> Result<(SolutionOf<T>, ElectionScore, SolutionOrSnapshotSize), Error> | ||
| forced_desired_targets: Option<u32>, | ||
| ) -> Result<MinedSolution<T>, Error> | ||
| where | ||
| T: MinerConfig<AccountId = AccountId, MaxVotesPerVoter = static_types::MaxVotesPerVoter> | ||
| + Send | ||
|
|
@@ -184,13 +185,17 @@ where | |
| T::Solution: Send, | ||
| { | ||
| let snapshot = snapshot_at(hash, &api).await?; | ||
| let desired_targets = api | ||
| .storage() | ||
| .at(hash) | ||
| .await? | ||
| .fetch(&runtime::storage().election_provider_multi_phase().desired_targets()) | ||
| .await? | ||
| .expect("Snapshot is non-empty; `desired_target` should exist; qed"); | ||
|
|
||
| let desired_targets = match forced_desired_targets { | ||
| Some(x) => x, | ||
| None => api | ||
| .storage() | ||
| .at(hash) | ||
| .await? | ||
| .fetch(&runtime::storage().election_provider_multi_phase().desired_targets()) | ||
| .await? | ||
| .expect("Snapshot is non-empty; `desired_target` should exist; qed"), | ||
| }; | ||
|
|
||
| let minimum_untrusted_score = api | ||
| .storage() | ||
|
|
@@ -221,27 +226,70 @@ where | |
| .await; | ||
|
|
||
| match blocking_task { | ||
| Ok(Ok((solution, score, solution_or_snapshot))) => { | ||
| match Miner::<T>::feasibility_check( | ||
| RawSolution { solution: solution.clone(), score, round }, | ||
| pallet_election_provider_multi_phase::ElectionCompute::Signed, | ||
| desired_targets, | ||
| snapshot, | ||
| round, | ||
| minimum_untrusted_score, | ||
| ) { | ||
| Ok(_) => Ok((solution, score, solution_or_snapshot)), | ||
| Err(e) => { | ||
| log::error!(target: LOG_TARGET, "Solution feasibility error {:?}", e); | ||
| Err(Error::Feasibility(format!("{:?}", e))) | ||
| }, | ||
| } | ||
| }, | ||
| Ok(Ok((solution, score, solution_or_snapshot_size))) => Ok(MinedSolution { | ||
| round, | ||
| desired_targets, | ||
| snapshot, | ||
| minimum_untrusted_score, | ||
| solution, | ||
| score, | ||
| solution_or_snapshot_size, | ||
| }), | ||
| Ok(Err(err)) => Err(Error::Other(format!("{:?}", err))), | ||
| Err(err) => Err(err.into()), | ||
| } | ||
| } | ||
|
|
||
| /// The result of calling [`fetch_snapshot_and_mine_solution`]. | ||
| pub struct MinedSolution<T: MinerConfig> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice 👍 much cleaner than what I did earlier |
||
| round: u32, | ||
| desired_targets: u32, | ||
| snapshot: RoundSnapshot, | ||
| minimum_untrusted_score: Option<ElectionScore>, | ||
| solution: T::Solution, | ||
| score: ElectionScore, | ||
| solution_or_snapshot_size: SolutionOrSnapshotSize, | ||
| } | ||
|
|
||
| impl<T> MinedSolution<T> | ||
| where | ||
| T: MinerConfig<AccountId = AccountId, MaxVotesPerVoter = static_types::MaxVotesPerVoter> | ||
| + Send | ||
| + Sync | ||
| + 'static, | ||
| T::Solution: Send, | ||
| { | ||
| pub fn solution(&self) -> T::Solution { | ||
| self.solution.clone() | ||
| } | ||
|
|
||
| pub fn score(&self) -> ElectionScore { | ||
| self.score | ||
| } | ||
|
|
||
| pub fn size(&self) -> SolutionOrSnapshotSize { | ||
| self.solution_or_snapshot_size | ||
| } | ||
|
|
||
| /// Check that this solution is feasible | ||
| pub fn feasibility_check(&self) -> Result<(), Error> { | ||
| match Miner::<T>::feasibility_check( | ||
| RawSolution { solution: self.solution.clone(), score: self.score, round: self.round }, | ||
| pallet_election_provider_multi_phase::ElectionCompute::Signed, | ||
| self.desired_targets, | ||
| self.snapshot.clone(), | ||
| self.round, | ||
| self.minimum_untrusted_score, | ||
| ) { | ||
| Ok(_) => Ok(()), | ||
| Err(e) => { | ||
| log::error!(target: LOG_TARGET, "Solution feasibility error {:?}", e); | ||
| Err(Error::Feasibility(format!("{:?}", e))) | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn make_type<T: scale_info::TypeInfo + 'static>() -> (TypeId, PortableRegistry) { | ||
| let m = scale_info::MetaType::new::<T>(); | ||
| let mut types = scale_info::Registry::new(); | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.