mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 05:51:02 +00:00
move generics of election trait to associated types (#10475)
* move generics of election trait to associated types * fix doctest
This commit is contained in:
@@ -289,7 +289,7 @@ frame_benchmarking::benchmarks! {
|
||||
assert!(<Snapshot<T>>::get().is_some());
|
||||
assert!(<SnapshotMetadata<T>>::get().is_some());
|
||||
}: {
|
||||
assert_ok!(<MultiPhase<T> as ElectionProvider<T::AccountId, T::BlockNumber>>::elect());
|
||||
assert_ok!(<MultiPhase<T> as ElectionProvider>::elect());
|
||||
} verify {
|
||||
assert!(<MultiPhase<T>>::queued_solution().is_none());
|
||||
assert!(<DesiredTargets<T>>::get().is_none());
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
//! To generate an emergency solution, one must only provide one argument: [`Supports`]. This is
|
||||
//! essentially a collection of elected winners for the election, and voters who support them. The
|
||||
//! supports can be generated by any means. In the simplest case, it could be manual. For example,
|
||||
//! in the case of massive network failure or misbehaviour, [`Config::ForceOrigin`] might decide to
|
||||
//! in the case of massive network failure or misbehavior, [`Config::ForceOrigin`] might decide to
|
||||
//! select only a small number of emergency winners (which would greatly restrict the next validator
|
||||
//! set, if this pallet is used with `pallet-staking`). If the failure is for other technical
|
||||
//! reasons, then a simple and safe way to generate supports is using the staking-miner binary
|
||||
@@ -286,10 +286,7 @@ pub type SolutionTargetIndexOf<T> = <SolutionOf<T> as NposSolution>::TargetIndex
|
||||
/// The accuracy of the election, when submitted from offchain. Derived from [`SolutionOf`].
|
||||
pub type SolutionAccuracyOf<T> = <SolutionOf<T> as NposSolution>::Accuracy;
|
||||
/// The fallback election type.
|
||||
pub type FallbackErrorOf<T> = <<T as crate::Config>::Fallback as ElectionProvider<
|
||||
<T as frame_system::Config>::AccountId,
|
||||
<T as frame_system::Config>::BlockNumber,
|
||||
>>::Error;
|
||||
pub type FallbackErrorOf<T> = <<T as crate::Config>::Fallback as ElectionProvider>::Error;
|
||||
|
||||
/// Configuration for the benchmarks of the pallet.
|
||||
pub trait BenchmarkingConfig {
|
||||
@@ -312,7 +309,9 @@ pub trait BenchmarkingConfig {
|
||||
/// A fallback implementation that transitions the pallet to the emergency phase.
|
||||
pub struct NoFallback<T>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
impl<T: Config> ElectionProvider<T::AccountId, T::BlockNumber> for NoFallback<T> {
|
||||
impl<T: Config> ElectionProvider for NoFallback<T> {
|
||||
type AccountId = T::AccountId;
|
||||
type BlockNumber = T::BlockNumber;
|
||||
type DataProvider = T::DataProvider;
|
||||
type Error = &'static str;
|
||||
|
||||
@@ -654,7 +653,10 @@ pub mod pallet {
|
||||
type MinerMaxLength: Get<u32>;
|
||||
|
||||
/// Something that will provide the election data.
|
||||
type DataProvider: ElectionDataProvider<Self::AccountId, Self::BlockNumber>;
|
||||
type DataProvider: ElectionDataProvider<
|
||||
AccountId = Self::AccountId,
|
||||
BlockNumber = Self::BlockNumber,
|
||||
>;
|
||||
|
||||
/// The solution type.
|
||||
type Solution: codec::Codec
|
||||
@@ -669,8 +671,8 @@ pub mod pallet {
|
||||
|
||||
/// Configuration for the fallback
|
||||
type Fallback: ElectionProvider<
|
||||
Self::AccountId,
|
||||
Self::BlockNumber,
|
||||
AccountId = Self::AccountId,
|
||||
BlockNumber = Self::BlockNumber,
|
||||
DataProvider = Self::DataProvider,
|
||||
>;
|
||||
|
||||
@@ -818,7 +820,7 @@ pub mod pallet {
|
||||
// NOTE that this pallet does not really need to enforce this in runtime. The
|
||||
// solution cannot represent any voters more than `LIMIT` anyhow.
|
||||
assert_eq!(
|
||||
<T::DataProvider as ElectionDataProvider<T::AccountId, T::BlockNumber>>::MAXIMUM_VOTES_PER_VOTER,
|
||||
<T::DataProvider as ElectionDataProvider>::MAXIMUM_VOTES_PER_VOTER,
|
||||
<SolutionOf<T> as NposSolution>::LIMIT as u32,
|
||||
);
|
||||
}
|
||||
@@ -1492,7 +1494,9 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> ElectionProvider<T::AccountId, T::BlockNumber> for Pallet<T> {
|
||||
impl<T: Config> ElectionProvider for Pallet<T> {
|
||||
type AccountId = T::AccountId;
|
||||
type BlockNumber = T::BlockNumber;
|
||||
type Error = ElectionError<T>;
|
||||
type DataProvider = T::DataProvider;
|
||||
|
||||
|
||||
@@ -285,7 +285,9 @@ impl onchain::Config for Runtime {
|
||||
}
|
||||
|
||||
pub struct MockFallback;
|
||||
impl ElectionProvider<AccountId, u64> for MockFallback {
|
||||
impl ElectionProvider for MockFallback {
|
||||
type AccountId = AccountId;
|
||||
type BlockNumber = u64;
|
||||
type Error = &'static str;
|
||||
type DataProvider = StakingMock;
|
||||
|
||||
@@ -438,7 +440,9 @@ pub type Extrinsic = sp_runtime::testing::TestXt<Call, ()>;
|
||||
pub struct ExtBuilder {}
|
||||
|
||||
pub struct StakingMock;
|
||||
impl ElectionDataProvider<AccountId, u64> for StakingMock {
|
||||
impl ElectionDataProvider for StakingMock {
|
||||
type AccountId = AccountId;
|
||||
type BlockNumber = u64;
|
||||
const MAXIMUM_VOTES_PER_VOTER: u32 = <TestNposSolution as NposSolution>::LIMIT as u32;
|
||||
fn targets(maybe_max_len: Option<usize>) -> data_provider::Result<Vec<AccountId>> {
|
||||
let targets = Targets::get();
|
||||
|
||||
Reference in New Issue
Block a user