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

Companion for Store voters in unsorted bags to get good stake iteration properties #3413

Merged
76 commits merged into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
aa0877a
add voter bags generation script and generated values for all runtimes
coriolinus Jul 5, 2021
7dd1981
Merge remote-tracking branch 'origin/master' into prgn-companion-for-…
coriolinus Jul 6, 2021
4c853b7
VoterBagThresholds for test-runtime
coriolinus Jul 6, 2021
9c6013e
semicolon
coriolinus Jul 6, 2021
bd11bcd
Merge remote-tracking branch 'origin/master' into prgn-companion-for-…
coriolinus Jul 7, 2021
77b4c68
Merge remote-tracking branch 'origin/master' into prgn-companion-for-…
coriolinus Jul 7, 2021
fcc1f5d
turns out the header is called file_header.txt
coriolinus Jul 7, 2021
f4d40e6
perform benchmarks to get real numbers
coriolinus Jul 7, 2021
387727b
add note about when to re-run this script
coriolinus Jul 8, 2021
2bca933
Merge remote-tracking branch 'origin/master' into prgn-companion-for-…
coriolinus Jul 9, 2021
e55463c
Merge branch 'prgn-companion-for-9081' of github.com:paritytech/polka…
coriolinus Jul 9, 2021
4ca5722
Suggestions for #3413 (Store voters in unsorted bags companion) (#3488)
emostov Jul 22, 2021
e286a10
Master.into()
kianenigma Jul 22, 2021
f271329
Try resolve Cargo.lock conflicts
emostov Jul 27, 2021
0edb586
Try merge origin master
emostov Jul 27, 2021
13917ad
Add temp VoterSnapshotPerBlock value to compile
emostov Jul 27, 2021
2e1a55f
Improve voter_bags test with nominator/validator breakdown
emostov Jul 28, 2021
7bcac15
Remove miner.log
emostov Jul 28, 2021
9dad2c2
Update README
emostov Jul 28, 2021
8c7bcf8
Module doc comments
emostov Jul 28, 2021
f231603
Try merge origin master
emostov Aug 14, 2021
86a5c75
Build working
emostov Aug 14, 2021
3499379
remote-ext-tests very WIP
emostov Aug 14, 2021
846ee14
repot and fix voterr bags remote ext test
kianenigma Aug 18, 2021
61922be
Move voter-bags cli; grab system pallet
emostov Aug 20, 2021
05bfc77
Remove system module query
emostov Aug 20, 2021
428f55b
formatting and log target
emostov Aug 20, 2021
5c12880
clean up
emostov Aug 20, 2021
bc70a17
try merge origin master
emostov Aug 24, 2021
11dee8d
Save
emostov Sep 1, 2021
4f7eb6a
Try merge origin master
emostov Sep 1, 2021
17814aa
Merge branch 'master' of https://github.com/paritytech/polkadot into …
emostov Sep 1, 2021
0922ab6
Fix issues with polkadot runtime after mergin
emostov Sep 2, 2021
a932af6
Save
emostov Sep 2, 2021
c23cf3d
Try merge origin master
emostov Sep 2, 2021
479e9b9
Some updates to runtimes to make sure things compile
emostov Sep 2, 2021
edc5d78
save
emostov Sep 2, 2021
c0af428
udpate weights
emostov Sep 2, 2021
a104802
Use UseNominatorsAndUpdateBagsList
emostov Sep 2, 2021
d22f42f
make remote-ext tests a bin
emostov Sep 2, 2021
b1383c4
Adjust remote-ext test to use pub; update some comments
emostov Sep 3, 2021
4f0f7c8
Try merge origin master
emostov Sep 3, 2021
5220470
Use list_bags_get
emostov Sep 3, 2021
15ac6c8
Try fix cargo.lock
emostov Sep 5, 2021
ef8bd05
Try merge origin master
emostov Sep 5, 2021
53a3e53
Gate kusama feat code
emostov Sep 5, 2021
1014e22
Carg.lock .. again
emostov Sep 6, 2021
1279c51
point bags-list deps to master
emostov Sep 6, 2021
ed74d4b
Merge remote-tracking branch 'origin' into prgn-companion-for-9081
emostov Sep 6, 2021
f3a209c
Update voter-bags CLI to take total issuance and min balance as args
emostov Sep 7, 2021
24abba0
try merge origin master
emostov Sep 13, 2021
7afff2a
Switch polkadot runtime to UseNominatorMap
emostov Sep 13, 2021
55486a2
Some tweaks to the remote-test
kianenigma Sep 14, 2021
3b4b02b
Delete some stuff for polkadot; comments
emostov Sep 15, 2021
256c95f
Various fixes
emostov Sep 15, 2021
b52fd92
Add comment for VoterSnapshotPerBlock
emostov Sep 15, 2021
bdd266b
Remove bags-list import from polakdot cargo
emostov Sep 15, 2021
55fb64b
use benchmarking feature for pallet-bags-list
emostov Sep 15, 2021
b44ac21
Add custom migration for westend and kusama for bags-list
emostov Sep 15, 2021
b0c5305
:facepalm
emostov Sep 15, 2021
b70adc4
Try merge origin master
emostov Sep 15, 2021
baa8e6d
Merge remote-tracking branch 'origin' into prgn-companion-for-9081
emostov Sep 15, 2021
e29e77b
Fix kusama runtime
emostov Sep 15, 2021
ace47de
Try merge origin master
emostov Sep 15, 2021
3d4997b
Small clean up
emostov Sep 15, 2021
0eccbb6
Merge remote-tracking branch 'origin' into prgn-companion-for-9081
emostov Sep 15, 2021
4482a6d
Be more alphabetical ordered
emostov Sep 16, 2021
548b6ad
Use 22_500 for VoterSnapshotPerBlock
emostov Sep 16, 2021
be1b2c7
point back to master
emostov Sep 16, 2021
c03a5b6
Merge remote-tracking branch 'origin' into prgn-companion-for-9081
emostov Sep 16, 2021
c7aaaf0
remove unused type
shawntabrizi Sep 17, 2021
daa72c1
SortedListProvider for staking runtime
emostov Sep 17, 2021
3608c46
Remove polkadot for remote-ext bags test
emostov Sep 17, 2021
e96da22
Revert "Remove polkadot for remote-ext bags test"
emostov Sep 17, 2021
f4f06b5
Remove polkadot for remote-ext bags test
emostov Sep 17, 2021
225fdbf
update Substrate
Sep 17, 2021
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,906 changes: 1,805 additions & 1,101 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ members = [
"primitives",
"runtime/common",
"runtime/common/slot_range_helper",
"runtime/common/voter-bags",
"runtime/parachains",
"runtime/polkadot",
"runtime/kusama",
Expand Down
15 changes: 15 additions & 0 deletions HEADER
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
14 changes: 14 additions & 0 deletions runtime/common/voter-bags/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "runtime-common-voter-bags"
version = "0.9.8"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "prgn-nominator-unsorted-bags", features = ["make-bags"]}
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
structopt = "0.3.21"

westend-runtime = { path = "../../westend" }
kusama-runtime = { path = "../../kusama" }
polkadot-runtime = { path = "../../polkadot" }
72 changes: 72 additions & 0 deletions runtime/common/voter-bags/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.


//! Make the set of voting bag thresholds to be used in `voter_bags.rs`.
kianenigma marked this conversation as resolved.
Show resolved Hide resolved

use pallet_staking::voter_bags::make_bags::generate_thresholds_module;
use std::path::{Path, PathBuf};
use structopt::{StructOpt, clap::arg_enum};
use westend_runtime::Runtime as WestendRuntime;
use kusama_runtime::Runtime as KusamaRuntime;
use polkadot_runtime::Runtime as PolkadotRuntime;

arg_enum!{
#[derive(Debug)]
enum Runtime {
Westend,
Kusama,
Polkadot,
}
}

impl Runtime {
fn generate_thresholds(&self) -> Box<dyn FnOnce(usize, &Path) -> Result<(), std::io::Error>> {
match self {
Runtime::Westend => Box::new(generate_thresholds_module::<WestendRuntime>),
Runtime::Kusama => Box::new(generate_thresholds_module::<KusamaRuntime>),
Runtime::Polkadot => Box::new(generate_thresholds_module::<PolkadotRuntime>),
}
}
}

#[derive(Debug, StructOpt)]
struct Opt {
/// How many bags to generate.
#[structopt(
long,
default_value = "200",
)]
n_bags: usize,

/// Which runtime to generate.
#[structopt(
long,
case_insensitive = true,
default_value = "Polkadot",
possible_values = &Runtime::variants(),
)]
runtime: Runtime,

/// Where to write the output.
output: PathBuf,
}

fn main() -> Result<(), std::io::Error> {
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))
}
8 changes: 8 additions & 0 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ use constants::{time::*, currency::*, fee::*};
// Weights used in the runtime.
mod weights;

// Voter bag threshold definitions.
mod voter_bags;

#[cfg(test)]
mod tests;

Expand Down Expand Up @@ -500,6 +503,10 @@ type SlashCancelOrigin = EnsureOneOf<
pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>
>;

parameter_types! {
pub const VoterBagThresholds: &'static [u64] = &voter_bags::THRESHOLDS;
}

impl pallet_staking::Config for Runtime {
const MAX_NOMINATIONS: u32 = <NposCompactSolution24 as sp_npos_elections::CompactSolution>::LIMIT as u32;
type Currency = Balances;
Expand All @@ -524,6 +531,7 @@ impl pallet_staking::Config for Runtime {
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
type VoterBagThresholds = VoterBagThresholds;
}

parameter_types! {
Expand Down
234 changes: 234 additions & 0 deletions runtime/kusama/src/voter_bags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
// Copyright 2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Autogenerated voter bag thresholds.
//!
//! Generated on 2021-07-05T14:34:44.453491278+00:00
//! for the kusama runtime.

/// Existential weight for this runtime.
#[cfg(any(test, feature = "std"))]
#[allow(unused)]
pub const EXISTENTIAL_WEIGHT: u64 = 33_333_333;

/// Constant ratio between bags for this runtime.
#[cfg(any(test, feature = "std"))]
#[allow(unused)]
pub const CONSTANT_RATIO: f64 = 1.1455399939091000;

/// Upper thresholds delimiting the bag list.
pub const THRESHOLDS: [u64; 200] = [
33_333_333,
38_184_666,
43_742_062,
50_108_281,
57_401_040,
65_755_187,
75_325_197,
86_288_026,
98_846_385,
113_232_487,
129_712_342,
148_590_675,
170_216_561,
194_989_878,
223_368_704,
255_877_784,
293_118_235,
335_778_661,
384_647_885,
440_629_536,
504_758_756,
578_221_342,
662_375_673,
758_777_824,
869_210_344,
995_715_212,
1_140_631_598,
1_306_639_114,
1_496_807_363,
1_714_652_697,
1_964_203_240,
2_250_073_368,
2_577_549_032,
2_952_685_502,
3_382_419_332,
3_874_696_621,
4_438_619_944,
5_084_616_664,
5_824_631_742,
6_672_348_610,
7_643_442_186,
8_755_868_715,
10_030_197_794,
11_489_992_720,
13_162_246_190,
15_077_879_420,
17_272_313_899,
19_786_126_359,
22_665_799_069,
25_964_579_327,
29_743_464_044,
34_072_327_620,
39_031_213_974,
44_711_816_618,
51_219_174_136,
58_673_612_428,
67_212_969_623,
76_995_144_813,
88_201_017_720,
101_037_793_302,
115_742_833_124,
132_588_044_352,
151_884_907_519,
173_990_236_034,
199_312_773_927,
228_320_753_830,
261_550_554_952,
299_616_621_127,
343_222_822_341,
393_175_469_814,
450_398_225_296,
515_949_180_262,
591_040_420_815,
677_060_440_060,
775_599_812_382,
888_480_604_352,
1_017_790_066_098,
1_165_919_226_119,
1_335_607_103_187,
1_529_991_352_850,
1_752_666_285_025,
2_007_749_325_472,
2_299_957_150_072,
2_634_692_899_685,
3_018_146_088_258,
3_457_407_051_560,
3_960_598_052_785,
4_537_023_469_264,
5_197_341_837_346,
5_953_762_936_697,
6_820_273_558_240,
7_812_896_130_365,
8_949_984_985_591,
10_252_565_745_880,
11_744_724_102_088,
13_454_051_176_370,
15_412_153_702_632,
17_655_238_458_639,
20_224_781_756_373,
23_168_296_370_008,
26_540_210_082_583,
30_402_872_096_348,
34_827_705_916_070,
39_896_530_022_963,
45_703_070_759_499,
52_354_695_399_464,
59_974_397_449_015,
68_703_070_888_447,
78_702_115_407_088,
90_156_420_804_069,
103_277_785_738_759,
118_308_834_046_123,
135_527_501_032_588,
155_252_172_707_386,
177_847_572_977_594,
203_731_507_665_501,
233_382_590_050_230,
267_349_090_784_630,
306_259_075_829_029,
350_832_019_859_793,
401_892_109_893_305,
460_383_485_119_292,
527_387_694_739_404,
604_143_696_619_511,
692_070_766_545_736,
792_794_741_693_469,
908_178_083_570_703,
1_040_354_316_321_961,
1_191_767_477_182_765,
1_365_217_308_553_008,
1_563_911_027_324_411,
1_791_522_628_715_580,
2_052_260_821_186_860,
2_350_946_848_602_280,
2_693_103_638_628_474,
3_085_057_925_791_037,
3_534_057_237_519_885,
4_048_403_906_342_940,
4_637_608_586_213_668,
5_312_566_111_603_995,
6_085_756_951_128_531,
6_971_477_980_728_040,
7_986_106_843_580_624,
9_148_404_784_952_770,
10_479_863_561_632_778,
12_005_102_840_561_012,
13_752_325_434_854_380,
15_753_838_794_879_048,
18_046_652_397_130_688,
20_673_162_077_088_732,
23_681_933_959_870_064,
27_128_602_484_145_260,
31_076_899_124_450_156,
35_599_830_833_736_348,
40_781_029_996_443_328,
46_716_300_853_732_512,
53_515_390_995_440_424,
61_304_020_674_959_928,
70_226_207_470_596_936,
80_446_929_278_126_800,
92_155_174_875_271_168,
105_567_438_465_310_176,
120_931_722_816_550_704,
138_532_125_018_688_464,
158_694_089_650_123_072,
181_790_426_491_212_160,
208_248_204_055_475_872,
238_556_646_405_290_848,
273_276_179_270_092_192,
313_048_792_736_563_520,
358_609_912_124_694_080,
410_801_996_551_064_960,
470_590_116_626_953_088,
539_079_799_334_522_496,
617_537_470_046_187_776,
707_413_869_675_350_912,
810_370_879_959_114_368,
928_312_252_892_475_904,
1_063_418_812_524_189_696,
1_218_188_780_021_782_528,
1_395_483_967_646_286_592,
1_598_582_695_797_773_824,
1_831_240_411_607_374_592,
2_097_759_129_958_809_600,
2_403_066_980_955_773_440,
2_752_809_334_727_236_096,
3_153_453_188_536_351_744,
3_612_406_746_388_564_480,
4_138_156_402_255_148_032,
4_740_423_659_834_265_600,
5_430_344_890_413_097_984,
6_220_677_252_688_132_096,
7_126_034_582_154_840_064,
8_163_157_611_837_691_904,
9_351_223_520_943_572_992,
10_712_200_535_224_332_288,
12_271_254_135_873_939_456,
14_057_212_388_066_050_048,
16_103_098_993_404_108_800,
18_446_744_073_709_551_615,
];
8 changes: 8 additions & 0 deletions runtime/kusama/src/weights/pallet_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,12 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn rebag() -> Weight {
// TODO!
0
}
fn regenerate(_: u32, _: u32) -> Weight {
// TODO!
0
}
}
Loading