mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-16 13:11:15 +00:00
Use proper bounded vector type for nominations (#10601)
* Use proper bounded vector type for nominations * add docs and tweak chill_other for cleanup purposes * Fix the build * remove TODO * add a bit more doc * even more docs gushc * Update frame/staking/src/pallet/mod.rs Co-authored-by: Zeke Mostov <z.mostov@gmail.com> * Update frame/staking/src/pallet/mod.rs Co-authored-by: Zeke Mostov <z.mostov@gmail.com> * Fix the nasty bug * also bound the Snapshot type * fix doc test * document bounded_vec * self-review * remove unused * Fix build * frame-support: repetition overload for bounded_vec Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fix * remove the need to allocate into unbounded voters etc etc * Don't expect * unbreal the build again * handle macro a bit better Co-authored-by: Zeke Mostov <z.mostov@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
//! Some helper functions/macros for this crate.
|
||||
|
||||
use super::{Config, SolutionTargetIndexOf, SolutionVoterIndexOf, VoteWeight};
|
||||
use crate::{unsigned::VoterOf, Config, SolutionTargetIndexOf, SolutionVoterIndexOf, VoteWeight};
|
||||
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
|
||||
|
||||
#[macro_export]
|
||||
@@ -34,7 +34,7 @@ macro_rules! log {
|
||||
///
|
||||
/// This can be used to efficiently build index getter closures.
|
||||
pub fn generate_voter_cache<T: Config>(
|
||||
snapshot: &Vec<(T::AccountId, VoteWeight, Vec<T::AccountId>)>,
|
||||
snapshot: &Vec<VoterOf<T>>,
|
||||
) -> BTreeMap<T::AccountId, usize> {
|
||||
let mut cache: BTreeMap<T::AccountId, usize> = BTreeMap::new();
|
||||
snapshot.iter().enumerate().for_each(|(i, (x, _, _))| {
|
||||
@@ -97,7 +97,7 @@ pub fn voter_index_fn_usize<T: Config>(
|
||||
/// Not meant to be used in production.
|
||||
#[cfg(test)]
|
||||
pub fn voter_index_fn_linear<T: Config>(
|
||||
snapshot: &Vec<(T::AccountId, VoteWeight, Vec<T::AccountId>)>,
|
||||
snapshot: &Vec<VoterOf<T>>,
|
||||
) -> impl Fn(&T::AccountId) -> Option<SolutionVoterIndexOf<T>> + '_ {
|
||||
move |who| {
|
||||
snapshot
|
||||
@@ -148,7 +148,7 @@ pub fn target_index_fn_linear<T: Config>(
|
||||
/// Create a function that can map a voter index ([`SolutionVoterIndexOf`]) to the actual voter
|
||||
/// account using a linearly indexible snapshot.
|
||||
pub fn voter_at_fn<T: Config>(
|
||||
snapshot: &Vec<(T::AccountId, VoteWeight, Vec<T::AccountId>)>,
|
||||
snapshot: &Vec<VoterOf<T>>,
|
||||
) -> impl Fn(SolutionVoterIndexOf<T>) -> Option<T::AccountId> + '_ {
|
||||
move |i| {
|
||||
<SolutionVoterIndexOf<T> as TryInto<usize>>::try_into(i)
|
||||
@@ -174,7 +174,7 @@ pub fn target_at_fn<T: Config>(
|
||||
/// This is not optimized and uses a linear search.
|
||||
#[cfg(test)]
|
||||
pub fn stake_of_fn_linear<T: Config>(
|
||||
snapshot: &Vec<(T::AccountId, VoteWeight, Vec<T::AccountId>)>,
|
||||
snapshot: &Vec<VoterOf<T>>,
|
||||
) -> impl Fn(&T::AccountId) -> VoteWeight + '_ {
|
||||
move |who| {
|
||||
snapshot
|
||||
@@ -192,7 +192,7 @@ pub fn stake_of_fn_linear<T: Config>(
|
||||
/// The cache need must be derived from the same snapshot. Zero is returned if a voter is
|
||||
/// non-existent.
|
||||
pub fn stake_of_fn<'a, T: Config>(
|
||||
snapshot: &'a Vec<(T::AccountId, VoteWeight, Vec<T::AccountId>)>,
|
||||
snapshot: &'a Vec<VoterOf<T>>,
|
||||
cache: &'a BTreeMap<T::AccountId, usize>,
|
||||
) -> impl Fn(&T::AccountId) -> VoteWeight + 'a {
|
||||
move |who| {
|
||||
|
||||
Reference in New Issue
Block a user