From 28479cfaa22c166952dc74e06f0b21977657a338 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 26 Aug 2021 17:32:35 -0400 Subject: [PATCH 1/2] extract pub compute top candidates from private select top candidates --- pallets/parachain-staking/src/lib.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index cb85f824ac..68f95e5f54 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -1865,23 +1865,27 @@ pub mod pallet { exit_queue.nominator_schedule = remaining_exits; >::put(exit_queue); } - /// Best as in most cumulatively supported in terms of stake - /// Returns [collator_count, nomination_count, total staked] - fn select_top_candidates(next: RoundIndex) -> (u32, u32, BalanceOf) { - let (mut collator_count, mut nomination_count, mut total) = - (0u32, 0u32, BalanceOf::::zero()); + pub fn compute_top_candidates() -> Vec { let mut candidates = >::get().0; // order candidates by stake (least to greatest so requires `rev()`) candidates.sort_unstable_by(|a, b| a.amount.partial_cmp(&b.amount).unwrap()); let top_n = >::get() as usize; // choose the top TotalSelected qualified candidates, ordered by stake - let mut collators = candidates + candidates .into_iter() .rev() .take(top_n) .filter(|x| x.amount >= T::MinCollatorStk::get()) .map(|x| x.owner) - .collect::>(); + .collect::>() + } + /// Best as in most cumulatively supported in terms of stake + /// Returns [collator_count, nomination_count, total staked] + fn select_top_candidates(next: RoundIndex) -> (u32, u32, BalanceOf) { + let (mut collator_count, mut nomination_count, mut total) = + (0u32, 0u32, BalanceOf::::zero()); + // choose the top TotalSelected qualified candidates, ordered by stake + let mut collators = Self::compute_top_candidates(); // snapshot exposure for round for weighting reward distribution for account in collators.iter() { let state = >::get(&account) From 5275564cc18894c9b89aadbbfe4b05b2b7866a3b Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 26 Aug 2021 18:08:00 -0400 Subject: [PATCH 2/2] doc comment --- pallets/parachain-staking/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index 68f95e5f54..94f6aa1027 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -1865,6 +1865,8 @@ pub mod pallet { exit_queue.nominator_schedule = remaining_exits; >::put(exit_queue); } + /// Compute the top `TotalSelected` candidates in the CandidatePool and return + /// a vec of their AccountIds (in the order of selection) pub fn compute_top_candidates() -> Vec { let mut candidates = >::get().0; // order candidates by stake (least to greatest so requires `rev()`)