mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
Make bags-list generic over node value and instantiable (#10997)
* make instantiable * update * cargo fmt * Clean up * bags-list: Make it generic over node value * Respond to some feedback * Apply suggestions from code review Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Add back default impl for weight update worst case * Update to Score in more places' * Use VoteWeight, not u64 to reduce test diff * FMT * FullCodec implies Codec * formatting * Fixup bags list remote test Co-authored-by: doordashcon <jesse.chejieh@gmail.com> Co-authored-by: Doordashcon <90750465+Doordashcon@users.noreply.github.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
//! Utilities for remote-testing pallet-bags-list.
|
||||
|
||||
use frame_election_provider_support::ScoreProvider;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// A common log target to use.
|
||||
@@ -55,8 +56,12 @@ pub fn display_and_check_bags<Runtime: RuntimeT>(currency_unit: u64, currency_na
|
||||
let mut rebaggable = 0;
|
||||
let mut active_bags = 0;
|
||||
for vote_weight_thresh in <Runtime as pallet_bags_list::Config>::BagThresholds::get() {
|
||||
let vote_weight_thresh_u64: u64 = (*vote_weight_thresh)
|
||||
.try_into()
|
||||
.map_err(|_| "runtime must configure score to at most u64 to use this test")
|
||||
.unwrap();
|
||||
// threshold in terms of UNITS (e.g. KSM, DOT etc)
|
||||
let vote_weight_thresh_as_unit = *vote_weight_thresh as f64 / currency_unit as f64;
|
||||
let vote_weight_thresh_as_unit = vote_weight_thresh_u64 as f64 / currency_unit as f64;
|
||||
let pretty_thresh = format!("Threshold: {}. {}", vote_weight_thresh_as_unit, currency_name);
|
||||
|
||||
let bag = match pallet_bags_list::Pallet::<Runtime>::list_bags_get(*vote_weight_thresh) {
|
||||
@@ -70,9 +75,13 @@ pub fn display_and_check_bags<Runtime: RuntimeT>(currency_unit: u64, currency_na
|
||||
active_bags += 1;
|
||||
|
||||
for id in bag.std_iter().map(|node| node.std_id().clone()) {
|
||||
let vote_weight = pallet_staking::Pallet::<Runtime>::weight_of(&id);
|
||||
let vote_weight = <Runtime as pallet_bags_list::Config>::ScoreProvider::score(&id);
|
||||
let vote_weight_thresh_u64: u64 = (*vote_weight_thresh)
|
||||
.try_into()
|
||||
.map_err(|_| "runtime must configure score to at most u64 to use this test")
|
||||
.unwrap();
|
||||
let vote_weight_as_balance: pallet_staking::BalanceOf<Runtime> =
|
||||
vote_weight.try_into().map_err(|_| "can't convert").unwrap();
|
||||
vote_weight_thresh_u64.try_into().map_err(|_| "can't convert").unwrap();
|
||||
|
||||
if vote_weight_as_balance < min_nominator_bond {
|
||||
log::trace!(
|
||||
@@ -87,13 +96,17 @@ pub fn display_and_check_bags<Runtime: RuntimeT>(currency_unit: u64, currency_na
|
||||
pallet_bags_list::Node::<Runtime>::get(&id).expect("node in bag must exist.");
|
||||
if node.is_misplaced(vote_weight) {
|
||||
rebaggable += 1;
|
||||
let notional_bag = pallet_bags_list::notional_bag_for::<Runtime, _>(vote_weight);
|
||||
let notional_bag_as_u64: u64 = notional_bag
|
||||
.try_into()
|
||||
.map_err(|_| "runtime must configure score to at most u64 to use this test")
|
||||
.unwrap();
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"Account {:?} can be rebagged from {:?} to {:?}",
|
||||
id,
|
||||
vote_weight_thresh_as_unit,
|
||||
pallet_bags_list::notional_bag_for::<Runtime>(vote_weight) as f64 /
|
||||
currency_unit as f64
|
||||
notional_bag_as_u64 as f64 / currency_unit as f64
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user