bounding staking: BoundedElectionProvider trait (#12362)

* add a bounded election provider trait

* extract common trait election provider base

* fmt

* only bound the outer support vector

* fix tests

* docs

* fix rust docs

* fmt

* fix rustdocs

* docs

* improve docs

* small doc change
This commit is contained in:
Ankan
2022-09-28 22:52:16 +02:00
committed by GitHub
parent ea43466879
commit 6137c8707b
7 changed files with 99 additions and 55 deletions
+3 -2
View File
@@ -80,7 +80,7 @@ macro_rules! log {
pub mod pallet {
use super::*;
use crate::types::*;
use frame_election_provider_support::ElectionProvider;
use frame_election_provider_support::ElectionProviderBase;
use frame_support::{
pallet_prelude::*,
traits::{Defensive, ReservableCurrency},
@@ -330,7 +330,8 @@ pub mod pallet {
}
}
if <T as pallet_staking::Config>::ElectionProvider::ongoing() {
if <<T as pallet_staking::Config>::ElectionProvider as ElectionProviderBase>::ongoing()
{
// NOTE: we assume `ongoing` does not consume any weight.
// there is an ongoing election -- we better not do anything. Imagine someone is not
// exposed anywhere in the last era, and the snapshot for the election is already
+3 -1
View File
@@ -104,7 +104,7 @@ parameter_types! {
}
pub struct MockElection;
impl frame_election_provider_support::ElectionProvider for MockElection {
impl frame_election_provider_support::ElectionProviderBase for MockElection {
type AccountId = AccountId;
type BlockNumber = BlockNumber;
type DataProvider = Staking;
@@ -113,7 +113,9 @@ impl frame_election_provider_support::ElectionProvider for MockElection {
fn ongoing() -> bool {
Ongoing::get()
}
}
impl frame_election_provider_support::ElectionProvider for MockElection {
fn elect() -> Result<frame_election_provider_support::Supports<AccountId>, Self::Error> {
Err(())
}