Enable bags-list pallet in polkadot (#4080)

* Enable bags-list pallet in polkadot

* add files

* Remove trailing semicolon

* more fixes

* Update runtime/polkadot/src/lib.rs

* add features

* remove par

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Kian Paimani
2021-10-25 11:18:17 +01:00
committed by GitHub
parent 182667830f
commit f9bd3c576f
13 changed files with 382 additions and 21 deletions
@@ -23,6 +23,7 @@ mod voter_bags;
#[derive(StructOpt)]
enum Runtime {
Kusama,
Polkadot,
}
impl std::str::FromStr for Runtime {
@@ -30,6 +31,7 @@ impl std::str::FromStr for Runtime {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"kusama" => Ok(Runtime::Kusama),
"polkadot" => Ok(Runtime::Polkadot),
_ => Err("wrong Runtime: can be 'polkadot' or 'kusama'."),
}
}
@@ -37,9 +39,9 @@ impl std::str::FromStr for Runtime {
#[derive(StructOpt)]
struct Cli {
#[structopt(long, default_value = "wss://rpc.kusama.io")]
#[structopt(long, default_value = "wss://rpc.polkadot.io")]
uri: String,
#[structopt(long, short, default_value = "kusama")]
#[structopt(long, short, default_value = "polkadot")]
runtime: Runtime,
}
@@ -55,5 +57,13 @@ async fn main() {
)
.await;
},
Runtime::Polkadot => {
use polkadot_runtime::{constants::currency::UNITS, Block, Runtime};
voter_bags::test_voter_bags_migration::<Runtime, Block>(
UNITS as u64,
options.uri.clone(),
)
.await;
},
}
}
@@ -54,6 +54,15 @@ pub(crate) async fn test_voter_bags_migration<
// set the ss58 prefix so addresses printed below are human friendly.
sp_core::crypto::set_default_ss58_version(Runtime::SS58Prefix::get().try_into().unwrap());
// clear anything that may have existed before.
if <Runtime as pallet_staking::Config>::SortedListProvider::count() != 0 {
log::warn!(
target: LOG_TARGET,
"some data already seem to exist in the bags-list pallet.."
);
}
<Runtime as pallet_staking::Config>::SortedListProvider::clear(None);
// get the nominator & validator count prior to migrating; these should be invariant.
let pre_migrate_nominator_count = <Nominators<Runtime>>::iter().count() as u32;
log::info!(target: LOG_TARGET, "Nominator count: {}", pre_migrate_nominator_count);
@@ -99,7 +108,7 @@ pub(crate) async fn test_voter_bags_migration<
(*vote_weight_thresh).try_into().map_err(|_| "should not fail").unwrap();
if vote_weight_as_balance <= min_nominator_bond {
for id in bag.std_iter().map(|node| node.std_id().clone()) {
log::trace!(
log::error!(
target: LOG_TARGET,
"{} Account found below min bond: {:?}.",
pretty_thresh,