From b9f5a36cb7e8e04695e34b3038cbe74d3f036cd1 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 4 Aug 2022 15:02:48 +0800 Subject: [PATCH] Companion of paritytech/substrate#10036 --- frame/staking/src/impls.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/frame/staking/src/impls.rs b/frame/staking/src/impls.rs index aaaa9df896..32162a2404 100644 --- a/frame/staking/src/impls.rs +++ b/frame/staking/src/impls.rs @@ -928,6 +928,8 @@ impl Pallet { let mut nominators_taken = 0u32; // track every nominator iterated over, but not necessarily added to `all_voters` let mut nominators_seen = 0u32; + // cache the total-issuance once in this function + let weight_of = Self::weight_of_fn(); let mut nominators_iter = T::SortedListProvider::iter(); while nominators_taken < nominators_quota && nominators_seen < nominators_quota * 2 { @@ -942,6 +944,12 @@ impl Pallet { if let Some(Nominations { submitted_in, mut targets, suppressed: _ }) = >::get(&nominator) { + log!( + trace, + "fetched nominator {:?} with weight {:?}", + nominator, + weight_of(&nominator) + ); targets.retain(|stash| { slashing_spans .get(stash) @@ -949,11 +957,11 @@ impl Pallet { }); if !targets.len().is_zero() { - all_voters.push((nominator.clone(), Self::weight_of(&nominator), targets)); + all_voters.push((nominator.clone(), weight_of(&nominator), targets)); nominators_taken.saturating_inc(); } } else { - log!(error, "invalid item in `SortedListProvider`: {:?}", nominator) + log!(error, "DEFENSIVE: invalid item in `SortedListProvider`: {:?}", nominator) } }