Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Suggestions for #9081 (Store voters in unsorted bags) #9328

Merged
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/node/runtime/voter-bags/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct Opt {
}

fn main() -> Result<(), std::io::Error> {
let Opt {n_bags, output, runtime } = Opt::from_args();
let Opt { n_bags, output, runtime } = Opt::from_args();
let mut ext = sp_io::TestExternalities::new_empty();
ext.execute_with(|| runtime.generate_thresholds()(n_bags, &output))
}
10 changes: 7 additions & 3 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,15 @@ benchmarks! {
// Clean up any existing state.
clear_validators_and_nominators::<T>();

let threshold = T::VoterBagThresholds::get();
kianenigma marked this conversation as resolved.
Show resolved Hide resolved

// stash controls the node account
let (stash, controller) = make_validator(USER_SEED, 100)?;
let bag0_thresh = threshold[0];
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
let (stash, controller) = make_validator(USER_SEED, bag0_thresh as u32)?;

// create another validator with 3x the stake
let (other_stash, _) = make_validator(USER_SEED + 1, 300)?;
// create another validator with more stake
let bag2_thresh = threshold[2];
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
let (other_stash, _) = make_validator(USER_SEED + 1, bag2_thresh as u32)?;

// update the stash account's value/weight
//
Expand Down
5 changes: 3 additions & 2 deletions frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,16 @@
#![recursion_limit = "128"]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(any(test, feature = "make-bags"))]
pub mod mock;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
#[cfg(any(feature = "runtime-benchmarks", test))]
pub mod testing_utils;
#[cfg(any(feature = "runtime-benchmarks", test))]
pub mod benchmarking;


pub mod inflation;
pub mod slashing;
pub mod voter_bags;
Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn is_disabled(controller: AccountId) -> bool {
}

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
pub(crate) type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
pub enum Test where
Expand Down
70 changes: 2 additions & 68 deletions frame/staking/src/mock/voter_bags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,71 +31,5 @@ pub const EXISTENTIAL_WEIGHT: u64 = 1;
pub const CONSTANT_RATIO: f64 = 2.0000000000000000;

/// Upper thresholds delimiting the bag list.
pub const THRESHOLDS: [u64; 65] = [5, 15, 25, 50, 100, 1000, 2000, 3000]
pub const THRESHOLDS: [u64; 65] = [
1,
2,
4,
8,
16,
32,
64,
128,
256,
512,
1_024,
2_048,
4_096,
8_192,
16_384,
32_768,
65_536,
131_072,
262_144,
524_288,
1_048_576,
2_097_152,
4_194_304,
8_388_608,
16_777_216,
33_554_432,
67_108_864,
134_217_728,
268_435_456,
536_870_912,
1_073_741_824,
2_147_483_648,
4_294_967_296,
8_589_934_592,
17_179_869_184,
34_359_738_368,
68_719_476_736,
137_438_953_472,
274_877_906_944,
549_755_813_888,
1_099_511_627_776,
2_199_023_255_552,
4_398_046_511_104,
8_796_093_022_208,
17_592_186_044_416,
35_184_372_088_832,
70_368_744_177_664,
140_737_488_355_328,
281_474_976_710_656,
562_949_953_421_312,
1_125_899_906_842_624,
2_251_799_813_685_248,
4_503_599_627_370_496,
9_007_199_254_740_992,
18_014_398_509_481_984,
36_028_797_018_963_968,
72_057_594_037_927_936,
144_115_188_075_855_872,
288_230_376_151_711_744,
576_460_752_303_423_488,
1_152_921_504_606_846_976,
2_305_843_009_213_693_952,
4_611_686_018_427_387_904,
9_223_372_036_854_775_808,
18_446_744_073_709_551_615,
];
// pub const THRESHOLDS: [u64; 65] = [5, 15, 25, 50, 100, 1000, 2000, 3000]; // TODO: switch to this
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
pub const THRESHOLDS: [u64; 9] = [10, 20, 30, 40, 50, 60, 1_000, 2_000, 10_000];
6 changes: 3 additions & 3 deletions frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn basic_setup_works() {
// for these stash ids, see
// https://github.com/paritytech/substrate/
// blob/631d4cdbcad438248c2597213918d8207d85bf6e/frame/staking/src/mock.rs#L435-L441
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
for genesis_stash_account_id in [11, 21, 31, 101] {
for genesis_stash_account_id in &[11, 21, 31, 101] {
let node = crate::voter_bags::Node::<Test>::from_id(&genesis_stash_account_id)
.expect(&format!("node was created for account {}", genesis_stash_account_id));
assert!(!node.is_misplaced(&weight_of));
Expand Down Expand Up @@ -3901,8 +3901,8 @@ fn test_rebag() {
ExtBuilder::default().build_and_execute(|| {
// We want to have two validators: one, `stash`, is the one we will rebag.
// The other, `other_stash`, exists only so that the destination bag is not empty.
let stash = make_validator(0, 100).unwrap();
let other_stash = make_validator(1, 300).unwrap();
let stash = make_validator(0, 2000).unwrap();
let other_stash = make_validator(1, 9000).unwrap();

// verify preconditions
let weight_of = Staking::weight_of_fn();
Expand Down
Loading