Store validator self-vote in bags-list, and allow them to be trimmed for election (#10821)

* Implement the new validator-in-bags-list scenario + migration

* Apply suggestions from code review

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* some review comments

* guard the migration

* some review comments

* Fix tests 🤦‍♂️

* Fix build

* fix weight_of_fn

* reformat line width

* make const

* use weight of fn cached

* SortedListProvider -> VoterList

* Fix all build and docs

* check post migration

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>
This commit is contained in:
Kian Paimani
2022-03-23 14:17:26 +00:00
committed by GitHub
parent e0cef34921
commit 661d0ea5bb
17 changed files with 317 additions and 216 deletions
@@ -48,7 +48,7 @@ pub fn display_and_check_bags<Runtime: RuntimeT>(currency_unit: u64, currency_na
let min_nominator_bond = <pallet_staking::MinNominatorBond<Runtime>>::get();
log::info!(target: LOG_TARGET, "min nominator bond is {:?}", min_nominator_bond);
let voter_list_count = <Runtime as pallet_staking::Config>::SortedListProvider::count();
let voter_list_count = <Runtime as pallet_staking::Config>::VoterList::count();
// go through every bag to track the total number of voters within bags and log some info about
// how voters are distributed within the bags.
@@ -17,7 +17,6 @@
//! Test to check the migration of the voter bag.
use crate::{RuntimeT, LOG_TARGET};
use frame_election_provider_support::SortedListProvider;
use frame_support::traits::PalletInfoAccess;
use pallet_staking::Nominators;
use remote_externalities::{Builder, Mode, OnlineConfig};
@@ -45,16 +44,16 @@ pub async fn execute<Runtime: RuntimeT, Block: BlockT + DeserializeOwned>(
let pre_migrate_nominator_count = <Nominators<Runtime>>::iter().count() as u32;
log::info!(target: LOG_TARGET, "Nominator count: {}", pre_migrate_nominator_count);
// run the actual migration,
let moved = <Runtime as pallet_staking::Config>::SortedListProvider::unsafe_regenerate(
use frame_election_provider_support::SortedListProvider;
// run the actual migration
let moved = <Runtime as pallet_staking::Config>::VoterList::unsafe_regenerate(
pallet_staking::Nominators::<Runtime>::iter().map(|(n, _)| n),
pallet_staking::Pallet::<Runtime>::weight_of_fn(),
);
log::info!(target: LOG_TARGET, "Moved {} nominators", moved);
let voter_list_len =
<Runtime as pallet_staking::Config>::SortedListProvider::iter().count() as u32;
let voter_list_count = <Runtime as pallet_staking::Config>::SortedListProvider::count();
let voter_list_len = <Runtime as pallet_staking::Config>::VoterList::iter().count() as u32;
let voter_list_count = <Runtime as pallet_staking::Config>::VoterList::count();
// and confirm it is equal to the length of the `VoterList`.
assert_eq!(pre_migrate_nominator_count, voter_list_len);
assert_eq!(pre_migrate_nominator_count, voter_list_count);
@@ -16,6 +16,7 @@
//! Test to execute the snapshot using the voter bag.
use frame_election_provider_support::SortedListProvider;
use frame_support::traits::PalletInfoAccess;
use remote_externalities::{Builder, Mode, OnlineConfig};
use sp_runtime::{traits::Block as BlockT, DeserializeOwned};
@@ -48,11 +49,11 @@ pub async fn execute<Runtime: crate::RuntimeT, Block: BlockT + DeserializeOwned>
.unwrap();
ext.execute_with(|| {
use frame_election_provider_support::{ElectionDataProvider, SortedListProvider};
use frame_election_provider_support::ElectionDataProvider;
log::info!(
target: crate::LOG_TARGET,
"{} nodes in bags list.",
<Runtime as pallet_staking::Config>::SortedListProvider::count(),
<Runtime as pallet_staking::Config>::VoterList::count(),
);
let voters =