mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +00:00
Add a bounded fallback on failed elections (#10988)
* Allow `pallet-election-provider` to accept smaller solutions, issue #9478 * Fixing a typo * Adding some more tests Removing a seemingly outdated comment * making it a URL * Updating test name as per suggestion Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Updating documentation to be more explicit And to follow the general guidelines Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fixing formatting * `Fallback` now of type `InstantElectionProvider` Some cleanups * Allow `pallet-election-provider` to accept smaller solutions, issue #9478 * Fixing a typo * Adding some more tests Removing a seemingly outdated comment * making it a URL * Updating test name as per suggestion Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Updating documentation to be more explicit And to follow the general guidelines Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fixing formatting * `Fallback` now of type `InstantElectionProvider` Some cleanups * Merging types into one type with generics * Removing `ConstUSize` and use `ConstU32` * cleaning up the code * deprecating `OnChainSequentialPhragmen` Renaming it to `UnboundedSequentialPhragmen` which should only be used at genesis and for testing. Use preferrably `BoundedOnChainSequentialPhragmen` * Amending docs * Adding some explicit imports * Implementing generic `BoundedOnchainExecution` Removing the deprecated `OnChainSequentialPhragmen` * Use the right Balancing strategy * Refactoring `onchain::Config` Creating `onchain::ExecutionConfig` * Merge master * fmt * Name cleanups after review suggestions * cosmetics * renaming `instant_elect` to `elect_with_bounds` Other corresponding changes as per @kianenigma feedback * `BoundedOnchainExecution` -> `BoundedExecution` And `UnboundedOnchainExecution` -> `UnboundedExecution` * feedback from kian * fmt + unneeded import Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: kianenigma <kian@parity.io>
This commit is contained in:
@@ -168,6 +168,7 @@
|
||||
|
||||
pub mod onchain;
|
||||
pub mod traits;
|
||||
#[cfg(feature = "std")]
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{traits::Get, BoundedVec, RuntimeDebug};
|
||||
use sp_runtime::traits::Bounded;
|
||||
@@ -368,9 +369,10 @@ pub trait ElectionProvider {
|
||||
BlockNumber = Self::BlockNumber,
|
||||
>;
|
||||
|
||||
/// Elect a new set of winners.
|
||||
/// Elect a new set of winners, without specifying any bounds on the amount of data fetched from
|
||||
/// [`Self::DataProvider`]. An implementation could nonetheless impose its own custom limits.
|
||||
///
|
||||
/// The result is returned in a target major format, namely as vector of supports.
|
||||
/// The result is returned in a target major format, namely as *vector of supports*.
|
||||
///
|
||||
/// This should be implemented as a self-weighing function. The implementor should register its
|
||||
/// appropriate weight at the end of execution with the system pallet directly.
|
||||
@@ -385,11 +387,17 @@ pub trait ElectionProvider {
|
||||
/// Consequently, allows for control over the amount of data that is being fetched from the
|
||||
/// [`ElectionProvider::DataProvider`].
|
||||
pub trait InstantElectionProvider: ElectionProvider {
|
||||
/// Elect a new set of winners, instantly, with the given given limits set on the
|
||||
/// Elect a new set of winners, but unlike [`ElectionProvider::elect`] which cannot enforce
|
||||
/// bounds, this trait method can enforce bounds on the amount of data provided by the
|
||||
/// `DataProvider`.
|
||||
fn instant_elect(
|
||||
maybe_max_voters: Option<usize>,
|
||||
maybe_max_targets: Option<usize>,
|
||||
///
|
||||
/// An implementing type, if itself bounded, should choose the minimum of the two bounds to
|
||||
/// choose the final value of `max_voters` and `max_targets`. In other words, an implementation
|
||||
/// should guarantee that `max_voter` and `max_targets` provided to this method are absolutely
|
||||
/// respected.
|
||||
fn elect_with_bounds(
|
||||
max_voters: usize,
|
||||
max_targets: usize,
|
||||
) -> Result<Supports<Self::AccountId>, Self::Error>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user