|
69 | 69 | //! Upon the end of the signed phase, the solutions are examined from best to worse (i.e. `pop()`ed |
70 | 70 | //! until drained). Each solution undergoes an expensive `Pallet::feasibility_check`, which ensures |
71 | 71 | //! the score claimed by this score was correct, and it is valid based on the election data (i.e. |
72 | | -//! votes and candidates). At each step, if the current best solution passes the feasibility check, |
| 72 | +//! votes and targets). At each step, if the current best solution passes the feasibility check, |
73 | 73 | //! it is considered to be the best one. The sender of the origin is rewarded, and the rest of the |
74 | 74 | //! queued solutions get their deposit back and are discarded, without being checked. |
75 | 75 | //! |
@@ -249,7 +249,6 @@ use sp_npos_elections::{ |
249 | 249 | assignment_ratio_to_staked_normalized, ElectionScore, EvaluateSupport, Supports, VoteWeight, |
250 | 250 | }; |
251 | 251 | use sp_runtime::{ |
252 | | - traits::Bounded, |
253 | 252 | transaction_validity::{ |
254 | 253 | InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, |
255 | 254 | TransactionValidityError, ValidTransaction, |
@@ -643,14 +642,15 @@ pub mod pallet { |
643 | 642 | #[pallet::constant] |
644 | 643 | type SignedDepositWeight: Get<BalanceOf<Self>>; |
645 | 644 |
|
646 | | - /// The maximum number of voters to put in the snapshot. At the moment, snapshots are only |
647 | | - /// over a single block, but once multi-block elections are introduced they will take place |
648 | | - /// over multiple blocks. |
649 | | - /// |
650 | | - /// Also, note the data type: If the voters are represented by a `u32` in `type |
651 | | - /// CompactSolution`, the same `u32` is used here to ensure bounds are respected. |
| 645 | + /// The maximum number of electing voters to put in the snapshot. At the moment, snapshots |
| 646 | + /// are only over a single block, but once multi-block elections are introduced they will |
| 647 | + /// take place over multiple blocks. |
| 648 | + #[pallet::constant] |
| 649 | + type MaxElectingVoters: Get<SolutionVoterIndexOf<Self>>; |
| 650 | + |
| 651 | + /// The maximum number of electable targets to put in the snapshot. |
652 | 652 | #[pallet::constant] |
653 | | - type VoterSnapshotPerBlock: Get<SolutionVoterIndexOf<Self>>; |
| 653 | + type MaxElectableTargets: Get<SolutionTargetIndexOf<Self>>; |
654 | 654 |
|
655 | 655 | /// Handler for the slashed deposits. |
656 | 656 | type SlashHandler: OnUnbalanced<NegativeImbalanceOf<Self>>; |
@@ -817,7 +817,7 @@ pub mod pallet { |
817 | 817 | fn integrity_test() { |
818 | 818 | use sp_std::mem::size_of; |
819 | 819 | // The index type of both voters and targets need to be smaller than that of usize (very |
820 | | - // unlikely to be the case, but anyhow). |
| 820 | + // unlikely to be the case, but anyhow).. |
821 | 821 | assert!(size_of::<SolutionVoterIndexOf<T>>() <= size_of::<usize>()); |
822 | 822 | assert!(size_of::<SolutionTargetIndexOf<T>>() <= size_of::<usize>()); |
823 | 823 |
|
@@ -1338,14 +1338,13 @@ impl<T: Config> Pallet<T> { |
1338 | 1338 | /// Extracted for easier weight calculation. |
1339 | 1339 | fn create_snapshot_external( |
1340 | 1340 | ) -> Result<(Vec<T::AccountId>, Vec<VoterOf<T>>, u32), ElectionError<T>> { |
1341 | | - let target_limit = <SolutionTargetIndexOf<T>>::max_value().saturated_into::<usize>(); |
1342 | | - // for now we have just a single block snapshot. |
1343 | | - let voter_limit = T::VoterSnapshotPerBlock::get().saturated_into::<usize>(); |
1344 | | - |
1345 | | - let targets = |
1346 | | - T::DataProvider::targets(Some(target_limit)).map_err(ElectionError::DataProvider)?; |
1347 | | - let voters = |
1348 | | - T::DataProvider::voters(Some(voter_limit)).map_err(ElectionError::DataProvider)?; |
| 1341 | + let target_limit = T::MaxElectableTargets::get().saturated_into::<usize>(); |
| 1342 | + let voter_limit = T::MaxElectingVoters::get().saturated_into::<usize>(); |
| 1343 | + |
| 1344 | + let targets = T::DataProvider::electable_targets(Some(target_limit)) |
| 1345 | + .map_err(ElectionError::DataProvider)?; |
| 1346 | + let voters = T::DataProvider::electing_voters(Some(voter_limit)) |
| 1347 | + .map_err(ElectionError::DataProvider)?; |
1349 | 1348 | let mut desired_targets = |
1350 | 1349 | T::DataProvider::desired_targets().map_err(ElectionError::DataProvider)?; |
1351 | 1350 |
|
@@ -2090,7 +2089,7 @@ mod tests { |
2090 | 2089 | // we have 8 voters in total. |
2091 | 2090 | assert_eq!(crate::mock::Voters::get().len(), 8); |
2092 | 2091 | // but we want to take 2. |
2093 | | - crate::mock::VoterSnapshotPerBlock::set(2); |
| 2092 | + crate::mock::MaxElectingVoters::set(2); |
2094 | 2093 |
|
2095 | 2094 | // Signed phase opens just fine. |
2096 | 2095 | roll_to(15); |
|
0 commit comments