mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +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:
@@ -242,7 +242,7 @@ use frame_support::{
|
||||
use frame_system::{ensure_none, offchain::SendTransactionTypes};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_arithmetic::{
|
||||
traits::{CheckedAdd, Saturating, Zero},
|
||||
traits::{Bounded, CheckedAdd, Saturating, Zero},
|
||||
UpperOf,
|
||||
};
|
||||
use sp_npos_elections::{
|
||||
@@ -323,10 +323,7 @@ impl<T: Config> ElectionProvider for NoFallback<T> {
|
||||
}
|
||||
|
||||
impl<T: Config> InstantElectionProvider for NoFallback<T> {
|
||||
fn instant_elect(
|
||||
_: Option<usize>,
|
||||
_: Option<usize>,
|
||||
) -> Result<Supports<T::AccountId>, Self::Error> {
|
||||
fn elect_with_bounds(_: usize, _: usize) -> Result<Supports<T::AccountId>, Self::Error> {
|
||||
Err("NoFallback.")
|
||||
}
|
||||
}
|
||||
@@ -683,7 +680,7 @@ pub mod pallet {
|
||||
+ TypeInfo;
|
||||
|
||||
/// Configuration for the fallback.
|
||||
type Fallback: ElectionProvider<
|
||||
type Fallback: InstantElectionProvider<
|
||||
AccountId = Self::AccountId,
|
||||
BlockNumber = Self::BlockNumber,
|
||||
DataProvider = Self::DataProvider,
|
||||
@@ -692,7 +689,7 @@ pub mod pallet {
|
||||
/// Configuration of the governance-only fallback.
|
||||
///
|
||||
/// As a side-note, it is recommend for test-nets to use `type ElectionProvider =
|
||||
/// OnChainSeqPhragmen<_>` if the test-net is not expected to have thousands of nominators.
|
||||
/// BoundedExecution<_>` if the test-net is not expected to have thousands of nominators.
|
||||
type GovernanceFallback: InstantElectionProvider<
|
||||
AccountId = Self::AccountId,
|
||||
BlockNumber = Self::BlockNumber,
|
||||
@@ -1040,13 +1037,14 @@ pub mod pallet {
|
||||
let maybe_max_voters = maybe_max_voters.map(|x| x as usize);
|
||||
let maybe_max_targets = maybe_max_targets.map(|x| x as usize);
|
||||
|
||||
let supports =
|
||||
T::GovernanceFallback::instant_elect(maybe_max_voters, maybe_max_targets).map_err(
|
||||
|e| {
|
||||
log!(error, "GovernanceFallback failed: {:?}", e);
|
||||
Error::<T>::FallbackFailed
|
||||
},
|
||||
)?;
|
||||
let supports = T::GovernanceFallback::elect_with_bounds(
|
||||
maybe_max_voters.unwrap_or(Bounded::max_value()),
|
||||
maybe_max_targets.unwrap_or(Bounded::max_value()),
|
||||
)
|
||||
.map_err(|e| {
|
||||
log!(error, "GovernanceFallback failed: {:?}", e);
|
||||
Error::<T>::FallbackFailed
|
||||
})?;
|
||||
|
||||
let solution = ReadySolution {
|
||||
supports,
|
||||
|
||||
Reference in New Issue
Block a user