mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 02:07:56 +00:00
Bound Election and Staking by MaxActiveValidators (#12436)
* bounding election provider with kian * multi phase implement bounded election provider * election provider blanket implementation * staking compiles * fix test for election provider support * fmt * fixing epmp tests, does not compile yet * fix epmp tests * fix staking tests * fmt * fix runtime tests * fmt * remove outdated wip tags * add enum error * sort and truncate supports * comment * error when unsupported number of election winners * compiling wip after kian's suggestions * fix TODOs * remove,fix tags * ensure validator count does not exceed maxwinners * clean up * some more clean up and todos * handle too many winners * rename parameter for mock * todo * add sort and truncate rule if there are too many winners * fmt * fail, not swallow emergency result bound not met * remove too many winners resolution as it can be guaranteed to be bounded * fix benchmark * give MaxWinners more contextual name * make ready solution generic over T * kian feedback * fix stuff * Kian's way of solvign this * comment fix * fix compile * remove use of BoundedExecution * fmt * comment out failing integrity test * cap validator count increment to max winners * dont panic * add test for bad data provider * Update frame/staking/src/pallet/impls.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * fix namespace conflict and add test for onchain max winners less than desired targets * defensive unwrap * early convert to bounded vec * fix syntax * fmt * fix doc * fix rustdoc * fmt * fix maxwinner count for benchmarking * add instant election for noelection * fmt * fix compile * pr feedbacks * always error at validator count exceeding max winners * add useful error message * pr comments * import fix * add checked_desired_targets * fmt * fmt * fix rust doc Co-authored-by: parity-processbot <> Co-authored-by: kianenigma <kian@parity.io> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -462,7 +462,7 @@ impl<T: Config> Pallet<T> {
|
||||
///
|
||||
/// Infallible
|
||||
pub fn finalize_signed_phase_accept_solution(
|
||||
ready_solution: ReadySolution<T::AccountId>,
|
||||
ready_solution: ReadySolution<T>,
|
||||
who: &T::AccountId,
|
||||
deposit: BalanceOf<T>,
|
||||
call_fee: BalanceOf<T>,
|
||||
@@ -537,7 +537,7 @@ impl<T: Config> Pallet<T> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{mock::*, ElectionCompute, Error, Event, Perbill, Phase};
|
||||
use crate::{mock::*, ElectionCompute, ElectionError, Error, Event, Perbill, Phase};
|
||||
use frame_support::{assert_noop, assert_ok, assert_storage_noop};
|
||||
|
||||
#[test]
|
||||
@@ -557,6 +557,50 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_provider_should_respect_target_limits() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
// given a reduced expectation of maximum electable targets
|
||||
MaxElectableTargets::set(2);
|
||||
// and a data provider that does not respect limits
|
||||
DataProviderAllowBadData::set(true);
|
||||
|
||||
assert_noop!(
|
||||
MultiPhase::create_snapshot(),
|
||||
ElectionError::DataProvider("Snapshot too big for submission."),
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_provider_should_respect_voter_limits() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
// given a reduced expectation of maximum electing voters
|
||||
MaxElectingVoters::set(2);
|
||||
// and a data provider that does not respect limits
|
||||
DataProviderAllowBadData::set(true);
|
||||
|
||||
assert_noop!(
|
||||
MultiPhase::create_snapshot(),
|
||||
ElectionError::DataProvider("Snapshot too big for submission."),
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn desired_targets_greater_than_max_winners() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
// given desired_targets bigger than MaxWinners
|
||||
DesiredTargets::set(4);
|
||||
MaxWinners::set(3);
|
||||
|
||||
let (_, _, actual_desired_targets) = MultiPhase::create_snapshot_external().unwrap();
|
||||
|
||||
// snapshot is created with min of desired_targets and MaxWinners
|
||||
assert_eq!(actual_desired_targets, 3);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_pay_deposit() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
|
||||
Reference in New Issue
Block a user