-
Notifications
You must be signed in to change notification settings - Fork 20
Implements emergency solution command #557
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f0a3ed0
Implements emergency solution command
gpestana 48dde12
Update src/commands/emergency_solution.rs
gpestana 3243971
Adds encoded call data to set emergency result cmd
gpestana 40d795d
replaces sp_core_crypto for sp_runtime::AccountId
gpestana b17f822
Print encoded hex call
gpestana 3dcf3ba
Update src/epm.rs
niklasad1 c1a3f69
Update src/epm.rs
niklasad1 c84c561
Update src/epm.rs
niklasad1 b58f19c
cargo fmt
niklasad1 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
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 |
|---|---|---|
|
|
@@ -15,3 +15,7 @@ Cargo.lock | |
|
|
||
| # all the key files | ||
| *.key | ||
|
|
||
| # output files from cmds | ||
| encoded.call | ||
| solution.supports.bin | ||
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, SolutionOrSnapshotSize}; | ||
| use pallet_election_provider_multi_phase::{RawSolution, ReadySolution, SolutionOrSnapshotSize}; | ||
| use scale_info::{PortableRegistry, TypeInfo}; | ||
| use scale_value::scale::{decode_as_type, TypeId}; | ||
| use sp_core::Bytes; | ||
|
|
@@ -67,7 +67,8 @@ pub(crate) async fn update_metadata_constants(api: &SubxtClient) -> Result<(), E | |
| const SIGNED_MAX_WEIGHT: EpmConstant = EpmConstant::new("SignedMaxWeight"); | ||
| const MAX_LENGTH: EpmConstant = EpmConstant::new("MinerMaxLength"); | ||
| const MAX_VOTES_PER_VOTER: EpmConstant = EpmConstant::new("MinerMaxVotesPerVoter"); | ||
| const MAX_WINNERS: EpmConstant = EpmConstant::new("MinerMaxWinners"); | ||
| // NOTE: `MaxWinners` is used instead of `MinerMaxWinners` to work with older metadata. | ||
| const MAX_WINNERS: EpmConstant = EpmConstant::new("MaxWinners"); | ||
|
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. Ok, this was set to work with older metadata right? Smart move as this is just duplicated in the
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. Maybe add a comment for that :)
niklasad1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| fn log_metadata(metadata: EpmConstant, val: impl std::fmt::Display) { | ||
| log::trace!(target: LOG_TARGET, "updating metadata constant `{metadata}`: {val}",); | ||
|
|
@@ -112,6 +113,16 @@ fn read_constant<'a, T: serde::Deserialize<'a>>( | |
| }) | ||
| } | ||
|
|
||
| /// Helper to construct a set emergency solution transaction. | ||
| pub(crate) fn set_emergency_result<A: Encode + TypeInfo + 'static>( | ||
| supports: frame_election_provider_support::Supports<A>, | ||
| ) -> Result<DynamicTxPayload<'static>, Error> { | ||
| let scale_result = to_scale_value(supports) | ||
| .map_err(|e| Error::DynamicTransaction(format!("Failed to encode `Supports`: {:?}", e)))?; | ||
|
|
||
| Ok(subxt::dynamic::tx(EPM_PALLET_NAME, "set_emergency_election_result", vec![scale_result])) | ||
| } | ||
|
|
||
| /// Helper to construct a signed solution transaction. | ||
| pub fn signed_solution<S: NposSolution + Encode + TypeInfo + 'static>( | ||
| solution: RawSolution<S>, | ||
|
|
@@ -169,6 +180,7 @@ pub async fn snapshot_at(at: Option<Hash>, api: &SubxtClient) -> Result<RoundSna | |
| } | ||
|
|
||
| /// Helper to fetch snapshot data via RPC | ||
|
|
||
| /// and compute an NPos solution via [`pallet_election_provider_multi_phase`]. | ||
| pub async fn fetch_snapshot_and_mine_solution<T>( | ||
| api: &SubxtClient, | ||
|
|
@@ -272,7 +284,9 @@ where | |
| } | ||
|
|
||
| /// Check that this solution is feasible | ||
| pub fn feasibility_check(&self) -> Result<(), Error> { | ||
| /// | ||
| /// Returns a [`pallet_election_provider_multi_phase::ReadySolution`] if the check passes. | ||
| pub fn feasibility_check(&self) -> Result<ReadySolution<AccountId, T::MaxWinners>, Error> { | ||
| match Miner::<T>::feasibility_check( | ||
| RawSolution { solution: self.solution.clone(), score: self.score, round: self.round }, | ||
| pallet_election_provider_multi_phase::ElectionCompute::Signed, | ||
|
|
@@ -281,7 +295,7 @@ where | |
| self.round, | ||
| self.minimum_untrusted_score, | ||
| ) { | ||
| Ok(_) => Ok(()), | ||
| Ok(ready_solution) => Ok(ready_solution), | ||
| Err(e) => { | ||
| log::error!(target: LOG_TARGET, "Solution feasibility error {:?}", e); | ||
| Err(Error::Feasibility(format!("{:?}", e))) | ||
|
|
||
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
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.