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

Store validator approval-stakes in TargetList, use for ranking validators. #11013

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
500bc9d
Implement the new validator-in-bags-list scenario + migration
kianenigma Feb 8, 2022
ddcc81b
Apply suggestions from code review
kianenigma Feb 15, 2022
41540f2
some review comments
kianenigma Feb 15, 2022
8ba2563
Merge branch 'kiz-validators-in-bags' of github.com:paritytech/substr…
kianenigma Feb 15, 2022
c293a0c
Merge branch 'master' of github.com:paritytech/substrate into kiz-val…
kianenigma Feb 16, 2022
398cf70
guard the migration
kianenigma Feb 16, 2022
66fc7d2
some review comments
kianenigma Feb 16, 2022
75989de
Fix tests 🤦‍♂️
kianenigma Feb 16, 2022
db2a7b8
Fix build
kianenigma Feb 16, 2022
53561cb
Merge branch 'kiz-validators-in-bags' of github.com:paritytech/substr…
kianenigma Feb 28, 2022
18fb2f4
lay the groundwork to store validators in a bags-list instance
kianenigma Feb 28, 2022
ae8165f
add migration struct
kianenigma Feb 28, 2022
3e0a25d
make node-runtime build fine
kianenigma Feb 28, 2022
8f74872
Merge branch 'master' of github.com:paritytech/substrate into kiz-val…
kianenigma Feb 28, 2022
ac6473b
Merge branch 'master' of github.com:paritytech/substrate into kiz-rev…
kianenigma Feb 28, 2022
5c48b57
make instantiable
Doordashcon Mar 1, 2022
90d09f2
update
Doordashcon Mar 4, 2022
7d6cb8d
cargo fmt
Doordashcon Mar 4, 2022
0304977
Merge branch 'paritytech:master' into ddc-BPL-T1
Doordashcon Mar 4, 2022
dc7bd89
Most things work now
kianenigma Mar 8, 2022
7a55fad
Master.into()
kianenigma Mar 8, 2022
44d1281
Upstream.into()
kianenigma Mar 8, 2022
b3f93c5
most things wokr now
kianenigma Mar 9, 2022
1ac8c34
Master.into()
kianenigma Mar 9, 2022
8cdd144
Everything merged, tests need a lot of fixing
kianenigma Mar 10, 2022
700141e
All tests work now
kianenigma Mar 10, 2022
93d79a4
dead-end with restricted nominations
kianenigma Mar 11, 2022
2f295b7
dead-end with restricted nominations
kianenigma Mar 11, 2022
29071fc
most tests work again
kianenigma Mar 11, 2022
34b1d8a
use balance as the type for TargetList
kianenigma Mar 11, 2022
8a431dd
a little bit of self-review
kianenigma Mar 11, 2022
0ce73d5
Merge branch 'master' of github.com:paritytech/substrate into kiz-val…
kianenigma Mar 11, 2022
f892d04
fix weight_of_fn
kianenigma Mar 11, 2022
5640da7
reformat line width
kianenigma Mar 11, 2022
3aefa00
make const
kianenigma Mar 11, 2022
0923d5b
use weight of fn cached
kianenigma Mar 11, 2022
2ea0769
SortedListProvider -> VoterList
kianenigma Mar 11, 2022
4c9ef4b
Fix all build and docs
kianenigma Mar 11, 2022
b311d03
check post migration
kianenigma Mar 11, 2022
a4bbda1
better doc
kianenigma Mar 11, 2022
4c275a6
Upstream.into()
kianenigma Mar 11, 2022
19bd4cd
mostly stable and working stuff
kianenigma Mar 11, 2022
bfe5d2a
Master.into()
kianenigma Mar 25, 2022
43cec35
some fixes to make node-runtime work
kianenigma Mar 25, 2022
0d395bb
Master.into()
kianenigma Apr 13, 2022
0c8a891
Update frame/bags-list/src/list/mod.rs
kianenigma Apr 19, 2022
dbae8a5
small fixes + add an important TODO about a potential leftover bug
kianenigma May 1, 2022
96948e0
Merge branch 'kiz-revamp-sorted-list-providers-2-approval-stake' of g…
kianenigma May 1, 2022
7837d07
Master.into()
kianenigma May 1, 2022
cc7ee91
Fix a few things in the bags-list pallet
kianenigma May 1, 2022
a10ff10
cleanup a few things
kianenigma May 3, 2022
488362c
Merge branch 'master' into kiz-revamp-sorted-list-providers-2-approva…
shawntabrizi May 3, 2022
10a7ced
Update frame/staking/src/pallet/impls.rs
shawntabrizi May 3, 2022
20bc48e
Update frame/bags-list/src/list/tests.rs
shawntabrizi May 3, 2022
4e7821d
Fix everything build related
kianenigma May 3, 2022
b3ac3c4
Merge branch 'kiz-revamp-sorted-list-providers-2-approval-stake' of g…
kianenigma May 3, 2022
3381b4c
Update frame/staking/src/pallet/mod.rs
kianenigma May 3, 2022
b3aeb44
some feedback
kianenigma May 3, 2022
3258cc4
Merge branch 'kiz-revamp-sorted-list-providers-2-approval-stake' of g…
kianenigma May 3, 2022
d60d2ab
some review feedback
kianenigma May 3, 2022
8e54545
fix compile
shawntabrizi May 3, 2022
f93563f
Merge branch 'master' into kiz-revamp-sorted-list-providers-2-approva…
shawntabrizi May 4, 2022
518ffb3
fix warning
shawntabrizi May 4, 2022
8457800
Merge branch 'master' into kiz-revamp-sorted-list-providers-2-approva…
shawntabrizi Jul 26, 2022
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
27 changes: 22 additions & 5 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ impl pallet_staking::Config for Runtime {
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = onchain::UnboundedExecution<OnChainSeqPhragmen>;
type VoterList = BagsList;
type VoterList = VoterBagsList;
type TargetList = TargetBagsList;
type MaxUnlockingChunks = ConstU32<32>;
type OnStakerSlash = NominationPools;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
Expand Down Expand Up @@ -717,14 +718,29 @@ impl pallet_election_provider_multi_phase::Config for Runtime {

parameter_types! {
pub const BagThresholds: &'static [u64] = &voter_bags::THRESHOLDS;
pub BagThresholdsBalance: &'static [Balance] = &voter_bags::THRESHOLDS_BALANCE;
}

impl pallet_bags_list::Config for Runtime {
type VoterBagsListInstance = pallet_bags_list::Instance1;
impl pallet_bags_list::Config<VoterBagsListInstance> for Runtime {
type Event = Event;
type ScoreProvider = Staking;
type WeightInfo = pallet_bags_list::weights::SubstrateWeight<Runtime>;
type BagThresholds = BagThresholds;
/// The voter bags-list is loosely kept up to date, and the real source of truth for the score
/// of each node is the staking pallet.
type ScoreProvider = Staking;
type Score = VoteWeight;
type WeightInfo = pallet_bags_list::weights::SubstrateWeight<Runtime>;
}

type TargetBagsListInstance = pallet_bags_list::Instance2;
impl pallet_bags_list::Config<TargetBagsListInstance> for Runtime {
type Event = Event;
// The bags-list itself will be the source of truth about the approval stakes. This implies that
// staking should keep the approval stakes up to date at all times.
type ScoreProvider = TargetBagsList;
type BagThresholds = BagThresholdsBalance;
type Score = Balance;
type WeightInfo = pallet_bags_list::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -1624,7 +1640,8 @@ construct_runtime!(
Gilt: pallet_gilt,
Uniques: pallet_uniques,
TransactionStorage: pallet_transaction_storage,
BagsList: pallet_bags_list,
VoterBagsList: pallet_bags_list::<Instance1>,
TargetBagsList: pallet_bags_list::<Instance2>,
StateTrieMigration: pallet_state_trie_migration,
ChildBounties: pallet_child_bounties,
Referenda: pallet_referenda,
Expand Down
203 changes: 203 additions & 0 deletions bin/node/runtime/src/voter_bags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,206 @@ pub const THRESHOLDS: [u64; 200] = [
17_356_326_621_502_140_416,
18_446_744_073_709_551_615,
];

pub const THRESHOLDS_BALANCE: [crate::Balance; 200] = [
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
100_000_000_000_000,
106_282_535_907_434,
112_959_774_389_150,
120_056_512_776_105,
127_599_106_300_477,
Comment on lines +237 to +242
Copy link
Member

@shawntabrizi shawntabrizi May 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was auto-generated, and now you have copy pasted some reused code here. you should generate a new file or make this in a new file or whatever, but not modify an auto-generated file.

135_615_565_971_369,
144_135_662_599_590,
153_191_037_357_827,
162_815_319_286_803,
173_044_250_183_800,
183_915_817_337_347,
195_470_394_601_017,
207_750_892_330_229,
220_802_916_738_890,
234_674_939_267_673,
249_418_476_592_914,
265_088_281_944_639,
281_742_548_444_211,
299_443_125_216_738,
318_255_747_080_822,
338_250_278_668_647,
359_500_973_883_001,
382_086_751_654_776,
406_091_489_025_036,
431_604_332_640_068,
458_720_029_816_222,
487_539_280_404_019,
518_169_110_758_247,
550_723_271_202_866,
585_322_658_466_782,
622_095_764_659_305,
661_179_154_452_653,
702_717_972_243_610,
746_866_481_177_808,
793_788_636_038_393,
843_658_692_126_636,
896_661_852_395_681,
952_994_955_240_703,
1_012_867_205_499_736,
1_076_500_951_379_881,
1_144_132_510_194_192,
1_216_013_045_975_769,
1_292_409_502_228_280,
1_373_605_593_276_862,
1_459_902_857_901_004,
1_551_621_779_162_291,
1_649_102_974_585_730,
1_752_708_461_114_642,
1_862_822_999_536_805,
1_979_855_523_374_646,
2_104_240_657_545_975,
2_236_440_332_435_128,
2_376_945_499_368_703,
2_526_277_953_866_680,
2_684_992_273_439_945,
2_853_677_877_130_641,
3_032_961_214_443_876,
3_223_508_091_799_862,
3_426_026_145_146_232,
3_641_267_467_913_124,
3_870_031_404_070_482,
4_113_167_516_660_186,
4_371_578_742_827_277,
4_646_224_747_067_156,
4_938_125_485_141_739,
5_248_364_991_899_922,
5_578_095_407_069_235,
5_928_541_253_969_291,
6_301_003_987_036_955,
6_696_866_825_051_405,
7_117_599_888_008_300,
7_564_765_656_719_910,
8_040_024_775_416_580,
8_545_142_218_898_723,
9_081_993_847_142_344,
9_652_573_371_700_016,
10_258_999_759_768_490,
10_903_525_103_419_522,
11_588_542_983_217_942,
12_316_597_357_287_042,
13_090_392_008_832_678,
13_912_800_587_211_472,
14_786_877_279_832_732,
15_715_868_154_526_436,
16_703_223_214_499_558,
17_752_609_210_649_358,
18_867_923_258_814_856,
20_053_307_312_537_008,
21_313_163_545_075_252,
22_652_170_697_804_756,
24_075_301_455_707_600,
25_587_840_914_485_432,
27_195_406_207_875_088,
28_903_967_368_057_400,
30_719_869_496_628_636,
32_649_856_328_471_220,
34_701_095_276_033_064,
36_881_204_047_022_752,
39_198_278_934_370_992,
41_660_924_883_519_016,
44_278_287_448_695_240,
47_060_086_756_856_400,
50_016_653_605_425_536,
53_158_967_827_883_320,
56_498_699_069_691_424,
60_048_250_125_977_912,
63_820_803_001_928_304,
67_830_367_866_937_216,
72_091_835_084_322_176,
76_621_030_509_822_880,
81_434_774_264_248_528,
86_550_943_198_537_824,
91_988_537_283_208_848,
97_767_750_168_749_840,
103_910_044_178_992_000,
110_438_230_015_967_792,
117_376_551_472_255_616,
124_750_775_465_407_920,
132_588_287_728_824_640,
140_918_194_514_440_064,
149_771_430_684_917_568,
159_180_874_596_775_264,
169_181_470_201_085_280,
179_810_356_815_193_344,
191_107_007_047_393_216,
203_113_373_386_768_288,
215_874_044_002_592_672,
229_436_408_331_885_600,
243_850_833_070_063_392,
259_170_849_218_267_264,
275_453_350_882_006_752,
292_758_806_559_399_232,
311_151_483_703_668_992,
330_699_687_393_865_920,
351_476_014_000_157_824,
373_557_620_785_735_808,
397_026_512_446_556_096,
421_969_845_653_044_224,
448_480_252_724_740_928,
476_656_185_639_923_904,
506_602_281_657_757_760,
538_429_751_910_786_752,
572_256_794_410_890_176,
608_209_033_002_485_632,
646_419_983_893_124_352,
687_031_551_494_039_552,
730_194_555_412_054_016,
776_069_290_549_944_960,
824_826_122_395_314_176,
876_646_119_708_695_936,
931_721_726_960_522_368,
990_257_479_014_182_144,
1_052_470_760_709_299_712,
1_118_592_614_166_106_112,
1_188_868_596_808_997_376,
1_263_559_693_295_730_432,
1_342_943_284_738_898_688,
1_427_314_178_819_094_784,
1_516_985_704_615_302_400,
1_612_290_876_218_400_768,
1_713_583_629_449_105_408,
1_821_240_136_273_157_632,
1_935_660_201_795_120_128,
2_057_268_749_018_809_600,
2_186_517_396_888_336_384,
2_323_886_137_470_138_880,
2_469_885_118_504_583_168,
2_625_056_537_947_004_416,
2_789_976_657_533_970_944,
2_965_257_942_852_572_160,
3_151_551_337_860_326_400,
3_349_548_682_302_620_672,
3_559_985_281_005_267_968,
3_783_642_634_583_792_128,
4_021_351_341_710_503_936,
4_273_994_183_717_548_544,
4_542_509_402_991_247_872,
4_827_894_187_332_742_144,
5_131_208_373_224_844_288,
5_453_578_381_757_959_168,
5_796_201_401_831_965_696,
6_160_349_836_169_256_960,
6_547_376_026_650_146_816,
6_958_717_276_519_173_120,
7_395_901_188_113_309_696,
7_860_551_335_934_872_576,
8_354_393_296_137_270_272,
8_879_261_054_815_360_000,
9_437_103_818_898_946_048,
10_029_993_254_943_105_024,
10_660_131_182_698_121_216,
11_329_857_752_030_707_712,
12_041_660_133_563_240_448,
12_798_181_755_305_525_248,
13_602_232_119_581_272_064,
14_456_797_236_706_498_560,
15_365_050_714_167_523_328,
16_330_365_542_480_556_032,
17_356_326_621_502_140_416,
18_446_744_073_709_551_615,
];
1 change: 1 addition & 0 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ impl pallet_staking::Config for Test {
type ElectionProvider = onchain::UnboundedExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = Self::ElectionProvider;
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Self>;
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type MaxUnlockingChunks = ConstU32<32>;
type OnStakerSlash = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
Expand Down
1 change: 1 addition & 0 deletions frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ impl pallet_staking::Config for Test {
type ElectionProvider = onchain::UnboundedExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = Self::ElectionProvider;
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Self>;
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type MaxUnlockingChunks = ConstU32<32>;
type OnStakerSlash = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
Expand Down
11 changes: 5 additions & 6 deletions frame/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
//! ## Overview
//!
//! This pallet contains functionality for multi-signature dispatch, a (potentially) stateful
//! operation, allowing multiple signed
//! origins (accounts) to coordinate and dispatch a call from a well-known origin, derivable
//! deterministically from the set of account IDs and the threshold number of accounts from the
//! set that must approve it. In the case that the threshold is just one then this is a stateless
//! operation. This is useful for multisig wallets where cryptographic threshold signatures are
//! not available or desired.
//! operation, allowing multiple signed origins (accounts) to coordinate and dispatch a call from a
//! well-known origin, derivable deterministically from the set of account IDs and the threshold
//! number of accounts from the set that must approve it. In the case that the threshold is just one
//! then this is a stateless operation. This is useful for multisig wallets where cryptographic
//! threshold signatures are not available or desired.
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
//!
//! ## Interface
//!
Expand Down
1 change: 1 addition & 0 deletions frame/nomination-pools/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl pallet_staking::Config for Runtime {
frame_election_provider_support::NoElection<(AccountId, BlockNumber, Staking)>;
type GenesisElectionProvider = Self::ElectionProvider;
type VoterList = pallet_bags_list::Pallet<Self>;
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type MaxUnlockingChunks = ConstU32<32>;
type OnStakerSlash = Pools;
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
Expand Down
1 change: 1 addition & 0 deletions frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ impl pallet_staking::Config for Test {
type ElectionProvider = onchain::UnboundedExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = Self::ElectionProvider;
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Self>;
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type MaxUnlockingChunks = ConstU32<32>;
type OnStakerSlash = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
Expand Down
1 change: 1 addition & 0 deletions frame/session/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl pallet_staking::Config for Test {
type GenesisElectionProvider = Self::ElectionProvider;
type MaxUnlockingChunks = ConstU32<32>;
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Self>;
type TargetList = pallet_staking::UseValidatorsMap<Self>;
type OnStakerSlash = ();
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ benchmarks! {
v, n, T::MaxNominations::get() as usize, false, None
)?;
}: {
let targets = <Staking<T>>::get_npos_targets();
let targets = <Staking<T>>::get_npos_targets(None);
assert_eq!(targets.len() as u32, v);
}

Expand Down
13 changes: 12 additions & 1 deletion frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,16 @@ pub struct Nominations<T: Config> {
pub suppressed: bool,
}

/// An unbounded version of `Nominations`, use for some really wacky hacks.
#[derive(PartialEqNoBound, EqNoBound, Clone, Encode, Decode, RuntimeDebugNoBound, TypeInfo)]
#[codec(mel_bound())]
#[scale_info(skip_type_params(T))]
struct UnboundedNominations<T: Config> {
pub targets: Vec<T::AccountId>,
pub submitted_in: EraIndex,
pub suppressed: bool,
}

/// The amount of exposure (to slashing) than an individual nominator has.
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct IndividualExposure<AccountId, Balance: HasCompact> {
Expand Down Expand Up @@ -878,11 +888,12 @@ enum Releases {
V8_0_0, // populate `VoterList`.
V9_0_0, // inject validators into `VoterList` as well.
V10_0_0, // remove `EarliestUnappliedSlash`.
V11_0_0, // inject validator's approval stake into `TargetList`.
}

impl Default for Releases {
fn default() -> Self {
Releases::V8_0_0
Releases::V11_0_0
}
}

Expand Down
Loading