Moving NposSolution to frame (#11031)

* Move `sp-npos-elections-solution-type`
to `frame-election-provider-support`
First stab at it, will need to amend some more stuff

* Fixing tests

* Fixing tests

* Fixing cargo.toml for std configuration

* fmt

* Committing suggested changes
renaming, and re exporting macro.

* Removing unneeded imports

* Move `NposSolution` to frame

* Removing `npos_election` dependencies
Implementing _fpes better

* some feedback for moving NPoSSolution to frame

* fmt

* more formatting

* Fixed some imports and fmt

* Fixing docs

Co-authored-by: kianenigma <kian@parity.io>
This commit is contained in:
Georges
2022-03-16 21:27:19 +00:00
committed by GitHub
parent 7a54efd1f2
commit 26a8c7e6b2
19 changed files with 312 additions and 292 deletions
@@ -28,7 +28,6 @@ use frame_support::{
use frame_system::RawOrigin;
use rand::{prelude::SliceRandom, rngs::SmallRng, SeedableRng};
use sp_arithmetic::{per_things::Percent, traits::One};
use sp_npos_elections::IndexAssignment;
use sp_runtime::InnerOf;
const SEED: u32 = 999;
@@ -461,6 +460,7 @@ frame_benchmarking::benchmarks! {
T::BenchmarkingConfig::DESIRED_TARGETS[1];
// Subtract this percentage from the actual encoded size
let f in 0 .. 95;
use frame_election_provider_support::IndexAssignment;
// Compute a random solution, then work backwards to get the lists of voters, targets, and
// assignments
@@ -231,7 +231,7 @@
use codec::{Decode, Encode};
use frame_election_provider_support::{
ElectionDataProvider, ElectionProvider, InstantElectionProvider,
ElectionDataProvider, ElectionProvider, InstantElectionProvider, NposSolution,
};
use frame_support::{
dispatch::DispatchResultWithPostInfo,
@@ -246,8 +246,7 @@ use sp_arithmetic::{
UpperOf,
};
use sp_npos_elections::{
assignment_ratio_to_staked_normalized, ElectionScore, EvaluateSupport, NposSolution, Supports,
VoteWeight,
assignment_ratio_to_staked_normalized, ElectionScore, EvaluateSupport, Supports, VoteWeight,
};
use sp_runtime::{
traits::Bounded,
@@ -18,7 +18,7 @@
use super::*;
use crate as multi_phase;
use frame_election_provider_support::{
data_provider, onchain, ElectionDataProvider, SequentialPhragmen,
data_provider, onchain, ElectionDataProvider, NposSolution, SequentialPhragmen,
};
pub use frame_support::{assert_noop, assert_ok};
use frame_support::{
@@ -38,7 +38,7 @@ use sp_core::{
};
use sp_npos_elections::{
assignment_ratio_to_staked_normalized, seq_phragmen, to_supports, ElectionResult,
EvaluateSupport, ExtendedBalance, NposSolution,
EvaluateSupport, ExtendedBalance,
};
use sp_runtime::{
testing::Header,
@@ -23,12 +23,13 @@ use crate::{
SolutionOrSnapshotSize, Weight, WeightInfo,
};
use codec::{Decode, Encode, HasCompact};
use frame_election_provider_support::NposSolution;
use frame_support::{
storage::bounded_btree_map::BoundedBTreeMap,
traits::{defensive_prelude::*, Currency, Get, OnUnbalanced, ReservableCurrency},
};
use sp_arithmetic::traits::SaturatedConversion;
use sp_npos_elections::{ElectionScore, NposSolution};
use sp_npos_elections::ElectionScore;
use sp_runtime::{
traits::{Saturating, Zero},
RuntimeDebug,
@@ -23,12 +23,11 @@ use crate::{
WeightInfo,
};
use codec::Encode;
use frame_election_provider_support::{NposSolver, PerThing128};
use frame_election_provider_support::{NposSolution, NposSolver, PerThing128};
use frame_support::{dispatch::DispatchResult, ensure, traits::Get};
use frame_system::offchain::SubmitTransaction;
use sp_npos_elections::{
assignment_ratio_to_staked_normalized, assignment_staked_to_ratio_normalized, ElectionResult,
NposSolution,
};
use sp_runtime::{
offchain::storage::{MutateStorageError, StorageValueRef},
@@ -52,9 +51,9 @@ pub type VoterOf<T> = frame_election_provider_support::VoterOf<<T as Config>::Da
pub type Assignment<T> =
sp_npos_elections::Assignment<<T as frame_system::Config>::AccountId, SolutionAccuracyOf<T>>;
/// The [`IndexAssignment`][sp_npos_elections::IndexAssignment] type specialized for a particular
/// runtime `T`.
pub type IndexAssignmentOf<T> = sp_npos_elections::IndexAssignmentOf<SolutionOf<T>>;
/// The [`IndexAssignment`][frame_election_provider_support::IndexAssignment] type specialized for a
/// particular runtime `T`.
pub type IndexAssignmentOf<T> = frame_election_provider_support::IndexAssignmentOf<SolutionOf<T>>;
/// Error type of the pallet's [`crate::Config::Solver`].
pub type SolverErrorOf<T> = <<T as Config>::Solver as NposSolver>::Error;
@@ -742,10 +741,11 @@ mod tests {
};
use codec::Decode;
use frame_benchmarking::Zero;
use frame_election_provider_support::IndexAssignment;
use frame_support::{
assert_noop, assert_ok, bounded_vec, dispatch::Dispatchable, traits::OffchainWorker,
};
use sp_npos_elections::{ElectionScore, IndexAssignment};
use sp_npos_elections::ElectionScore;
use sp_runtime::{
offchain::storage_lock::{BlockAndTime, StorageLock},
traits::ValidateUnsigned,