pub struct FairElection<T: Config>(PhantomData<T>);Expand description
A FairElection represents an election model that preserves the structure and fairness of backing by retaining each supporter’s individual contribution weight.
Unlike FlatElection, this model does not flatten backing.
Instead, every supporter - including the author themselves - is treated
as an individual backer with a distinct weight.
Self-collateral is therefore considered self-backing, contributing to the author’s support while still remaining structurally independent from other backers.
Both:
- self-backing (author’s own collateral), and
- external backing (direct backers, unmanaged indexes, or managed pools) are preserved as separate weighted relationships rather than being aggregated into a single scalar.
Each backing weight is mapped individually to the author they support, and the election outcome is computed from these unaggregated backer-author relationships.
§Characteristics
- Treats self-collateral as self-backing (not flattened).
- Preserves individual backer weights without aggregation.
- Maintains structural fairness across all supporters.
- Reflects both commitment (self-backing) and community support.
- Emphasizes proportional and decentralized representation.
§Election Flow
- Gather all backers for each author, including self-backing.
- Map each backer’s weight individually to their chosen author.
- Provide these mappings to the
Config::FairElectionModelplugin. - Compute outcomes that reflect proportional and distributed support.
§Typical Use-Case
- Selecting representatives, validators, or leaders where fair proportional influence from all supporters - including the author’s own stake - should be preserved without flattening.
§Summary
FairElection preserves the backing structure:
every supporter (self or external) is represented individually, and each
weight contributes proportionally without being merged into a single value.
The model prioritizes fair representation and structural integrity of support.
Tuple Fields§
§0: PhantomData<T>Trait Implementations§
Source§impl<T: Config> ElectionManager<<T as Config>::AccountId> for FairElection<T>
Implementation of the ElectionManager trait for FairElection.
impl<T: Config> ElectionManager<<T as Config>::AccountId> for FairElection<T>
Implementation of the ElectionManager trait for FairElection.
This binds the FairElection system to a concrete election computation
using backing-based metrics, leveraging runtime-configured plugin models and contexts.
- Election weights are computed from
BackingElectionWeightvalues forAuthor. - Input type to the election plugin is
ElectViaBacking(candidates with their backing contributions). - Output type is
ElectedAuthors(a collection of elected candidates).
Source§type ElectionWeight = (Funder<T>, <<T as Config>::CommitmentAdapter as InspectAsset<<T as Config>::AccountId>>::Asset)
type ElectionWeight = (Funder<T>, <<T as Config>::CommitmentAdapter as InspectAsset<<T as Config>::AccountId>>::Asset)
Election weight type: corresponds to a singular backing contribution to an author.
Source§type ElectionWeightOf = Vec<<FairElection<T> as ElectionManager<<T as Config>::AccountId>>::ElectionWeight>
type ElectionWeightOf = Vec<<FairElection<T> as ElectionManager<<T as Config>::AccountId>>::ElectionWeight>
Collection type holding all weights (backing contributions) of an author.
Each author may have multiple backers; this vector represents all backing weights.
Source§type Params = Vec<(<T as Config>::AccountId, Vec<(Funder<T>, <<T as Config>::CommitmentAdapter as InspectAsset<<T as Config>::AccountId>>::Asset)>)>
type Params = Vec<(<T as Config>::AccountId, Vec<(Funder<T>, <<T as Config>::CommitmentAdapter as InspectAsset<<T as Config>::AccountId>>::Asset)>)>
Input type for election computation: authors paired with their backing weights.
Source§type ElectionContext = <T as Config>::FairElectionContext
type ElectionContext = <T as Config>::FairElectionContext
Plugin context providing runtime configuration for the election model.
Source§type ElectionModel = <T as Config>::FairElectionModel
type ElectionModel = <T as Config>::FairElectionModel
Plugin model implementing the election algorithm.
Source§fn reveal() -> Option<Self::Elected>
fn reveal() -> Option<Self::Elected>
Retrieve the currently elected candidates.
Fetches the authors elected in the most recent election round,
using RecentElectedOn to determine the latest block where
results were stored.
§Returns
Ok(Elected)- A collection of elected authors.Noneotherwise.
Source§fn remove(who: &Author<T>)
fn remove(who: &Author<T>)
Optimistically remove a candidate from the most recent elected pool.
Directly updates storage by deleting the (block, author) entry
from Elected for the latest election block.
Does not retroactively remove authors from historical elections.
Source§fn is_candidate(who: &Author<T>) -> DispatchResult
fn is_candidate(who: &Author<T>) -> DispatchResult
Search if the given candidate is an elected in the recent election.
DispatchError otherwise
Source§fn store(elects: &Self::Elected) -> DispatchResult
fn store(elects: &Self::Elected) -> DispatchResult
Persist the election results into storage.
Stores the newly elected authors under the current block number,
updating Elected and RecentElectedOn.
§Behavior
- Ensures the number of elected candidates meets the minimum requirement.
- Optionally truncates to the maximum limit if
ForceMaxElectedis enabled. - Each elected author is stored under
(current_block, author).
§Errors
- Returns a [
DispatchError] if fails.
Source§fn can_prepare(from: &Self::Params) -> DispatchResult
fn can_prepare(from: &Self::Params) -> DispatchResult
Check if the election can be prepared with the given authors as candidates.
Ensures that the provided candidate set meets the configured minimum
(MinElected) before initiating election computation.
Source§fn on_prepare_success(elects: &Self::Elected)
fn on_prepare_success(elects: &Self::Elected)
Hook invoked after a successful election process.
Source§fn on_prepare_fail(error: DispatchError)
fn on_prepare_fail(error: DispatchError)
Hook invoked when an election process fails.
Source§impl<T: Config> InspectWeight<<T as Config>::AccountId, Vec<(Funder<T>, <<T as Config>::CommitmentAdapter as InspectAsset<<T as Config>::AccountId>>::Asset)>> for FairElection<T>
Implementation of the InspectWeight trait for FairElection.
impl<T: Config> InspectWeight<<T as Config>::AccountId, Vec<(Funder<T>, <<T as Config>::CommitmentAdapter as InspectAsset<<T as Config>::AccountId>>::Asset)>> for FairElection<T>
Implementation of the InspectWeight trait for FairElection.
This provides a way to inspect the backing weights of an Author
in terms of their individual contributions from backers, leveraging the stored
backing information in the pallet.
§Author Weight
- Returns the weight of an author as a
Vec<BackingElectionWeight>. Each element represents the backing contribution of an individual backer i.e., an external funder. - Wrapping the contributions in a vector satisfies the generic input requirements
of
ElectionManagerfor bothFairElectionandFlatElection.
Source§fn weight_of(
who: &Author<T>,
) -> Result<Vec<BackingElectionWeight<T>>, DispatchError>
fn weight_of( who: &Author<T>, ) -> Result<Vec<BackingElectionWeight<T>>, DispatchError>
Returns the backing weights of an author wrapped in a vector.
§Behavior
- Fetches the list of backers for the author using
FundRoles::backers_of. - Returns the backers’ contributions as a vector.
§Errors
- Returns a [
DispatchError] if fails.
Auto Trait Implementations§
impl<T> Freeze for FairElection<T>
impl<T> RefUnwindSafe for FairElection<T>where
T: RefUnwindSafe,
impl<T> Send for FairElection<T>where
T: Send,
impl<T> Sync for FairElection<T>where
T: Sync,
impl<T> Unpin for FairElection<T>where
T: Unpin,
impl<T> UnwindSafe for FairElection<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
§fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T, U, Tag> IntoTag<U, Tag> for Twhere
U: FromTag<T, Tag>,
Tag: DiscriminantTag,
impl<T, U, Tag> IntoTag<U, Tag> for Twhere
U: FromTag<T, Tag>,
Tag: DiscriminantTag,
§impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
fn into_tuple(self) -> Dest
§impl<T> IsType<T> for T
impl<T> IsType<T> for T
§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
Source§impl<T, Time> Logging<Time> for Twhere
Time: Time,
impl<T, Time> Logging<Time> for Twhere
Time: Time,
Source§const FALLBACK_TARGET: &'static str = "routine"
const FALLBACK_TARGET: &'static str = "routine"
Default logging target if none is provided.
Most routines, especially offchain workers or background tasks, use this target for simplicity.
It allows a consistent place to look for routine logs without requiring every call to specify a target.
Note: This target is only a conveninence and may be somewhat vague. To ensure errors can still be traced accurately, the logged messages should include additional metadata (e.g., module name, error index, or contextual info) so that the source of the error can be identified even if the target is generic.
Source§type Logger = DispatchError
type Logger = DispatchError
The type taken and returned for logging.
We simply return the same [DispatchError] that was logged,
so logging does not change control flow or error propagation.
DispatchError is used because in Substrate it encompasses all
runtime errors - including module errors, token errors, arithmetic
issues, and transactional boundaries - making it the universal
substrate-side error representation.
Source§type Level = LogLevel
type Level = LogLevel
The log level type.
We use the LogLevel enum to standardize severity levels
(Info, Warn, Error, Debug) across all routine logs.
Source§fn log(
level: <T as Logging<Time>>::Level,
err: &<T as Logging<Time>>::Logger,
timestamp: Time,
target: Option<&str>,
fmt: Option<fn(Time, &<T as Logging<Time>>::Level, &str, &str) -> String>,
) -> <T as Logging<Time>>::Logger
fn log( level: <T as Logging<Time>>::Level, err: &<T as Logging<Time>>::Logger, timestamp: Time, target: Option<&str>, fmt: Option<fn(Time, &<T as Logging<Time>>::Level, &str, &str) -> String>, ) -> <T as Logging<Time>>::Logger
Source§fn info(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
fn info(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
Source§fn warn(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
fn warn(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T. Read more§impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
type Error = <U as TryFromKey<T>>::Error
fn try_into_key(self) -> Result<U, <U as TryFromKey<T>>::Error>
§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T.