Skip to content

Commit 10b86a0

Browse files
committed
remove test & fix formatting
- as suggested removed test that does not give more purpose - fixed formatting & docs to be more relevant now
1 parent c8c6ccf commit 10b86a0

File tree

8 files changed

+23
-75
lines changed

8 files changed

+23
-75
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prdoc/pr_10880.prdoc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
title: Remove failing assertion related to VoterList count mismatch
22
doc:
3-
- audience: Runtime Dev
4-
description: PR resolves the error that occurs when VoterList count does not align
5-
with sum of Nominators & Validators in bags-list & tests to ensure PendingRebag fills when bags list is locked. This misalignment happens while
6-
bags-list is locked & nominations/validations are received.
3+
- audience: Runtime Dev
4+
description:
5+
Updated bags-list so that on_insert queues items into PendingRebag instead of failing,
6+
and removed the invariant that required VoterList's count to equal the combined number
7+
of Nominators and Validators. This is safe while bags-list is locked. After unlocking,
8+
on_idle drains PendingRebag, and the counts converge back to consistency over time.
79
crates:
8-
- name: pallet-staking-async
9-
bump: patch
10-
- name: pallet-bags-list
11-
bump: patch
10+
- name: pallet-staking-async
11+
bump: patch
12+
- name: pallet-bags-list
13+
bump: patch

substrate/frame/staking-async/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ pallet-dap = { optional = true, workspace = true }
4040
anyhow = { workspace = true }
4141
env_logger = { workspace = true }
4242
frame-benchmarking = { workspace = true, default-features = true }
43-
frame-support = { features = ["experimental"], workspace = true, default-features = true }
43+
frame-support = { features = [
44+
"experimental",
45+
], workspace = true, default-features = true }
4446
pallet-bags-list = { workspace = true, default-features = true }
4547
pallet-balances = { workspace = true, default-features = true }
4648
pallet-dap = { workspace = true, default-features = true }

substrate/frame/staking-async/ahm-test/Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ codec = { features = ["derive"], workspace = true, default-features = true }
2020
frame = { workspace = true, default-features = true }
2121
frame-support = { workspace = true, default-features = true }
2222
log = { workspace = true }
23-
scale-info = { features = ["derive"], workspace = true, default-features = true }
23+
scale-info = { features = [
24+
"derive",
25+
], workspace = true, default-features = true }
2426
sp-core = { workspace = true, default-features = true }
2527
sp-session = { workspace = true, default-features = true }
2628
sp-staking = { workspace = true, default-features = true }
@@ -35,7 +37,6 @@ pallet-proxy = { workspace = true, default-features = true }
3537

3638
# pallets that we need in AH
3739
frame-election-provider-support = { workspace = true, default-features = true }
38-
pallet-bags-list = { workspace = true, default-features = true }
3940
pallet-dap = { workspace = true, default-features = true }
4041
pallet-election-provider-multi-block = { workspace = true, default-features = true }
4142
pallet-staking-async = { workspace = true, default-features = true }
@@ -52,9 +53,7 @@ pallet-root-offences = { workspace = true, default-features = true }
5253
pallet-staking = { workspace = true, default-features = true }
5354

5455
[features]
55-
std = [
56-
"log/std",
57-
]
56+
std = ["log/std"]
5857
try-runtime = [
5958
"pallet-balances/try-runtime",
6059
"pallet-proxy/try-runtime",
@@ -70,7 +69,6 @@ try-runtime = [
7069
"frame-support/try-runtime",
7170
"frame/try-runtime",
7271
"pallet-authorship/try-runtime",
73-
"pallet-bags-list/try-runtime",
7472
"pallet-election-provider-multi-block/try-runtime",
7573
"pallet-offences/try-runtime",
7674
"pallet-root-offences/try-runtime",

substrate/frame/staking-async/ahm-test/src/ah/mock.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::shared;
1919
use frame::testing_prelude::*;
2020
use frame_election_provider_support::{
2121
bounds::{ElectionBounds, ElectionBoundsBuilder},
22-
SequentialPhragmen, VoteWeight,
22+
SequentialPhragmen,
2323
};
2424
use frame_support::{
2525
sp_runtime::testing::TestXt,
@@ -54,8 +54,6 @@ construct_runtime! {
5454
MultiBlockVerifier: multi_block::verifier,
5555
MultiBlockSigned: multi_block::signed,
5656
MultiBlockUnsigned: multi_block::unsigned,
57-
58-
VoterBagsList: pallet_bags_list::<Instance1>,
5957
Dap: pallet_dap,
6058
}
6159
}
@@ -85,7 +83,6 @@ pub fn roll_next() {
8583
let mut meter = NextPollWeight::take()
8684
.map(WeightMeter::with_limit)
8785
.unwrap_or_else(System::remaining_block_weight);
88-
VoterBagsList::on_idle(next, meter.limit());
8986
Staking::on_poll(next, &mut meter);
9087
MultiBlock::on_poll(next, &mut meter);
9188
}
@@ -280,24 +277,6 @@ pub type Hash = <Runtime as frame_system::Config>::Hash;
280277
pub type BlockNumber = BlockNumberFor<Runtime>;
281278
pub type BlockWeights = <Runtime as frame_system::Config>::BlockWeights;
282279

283-
pub(crate) const THRESHOLDS: [VoteWeight; 9] = [10, 20, 30, 40, 50, 60, 1_000, 2_000, 10_000];
284-
285-
parameter_types! {
286-
pub static BagThresholds: &'static [VoteWeight] = &THRESHOLDS;
287-
pub static MaxAutoRebagPerBlock: u32 = 10;
288-
}
289-
290-
pub type VoterBagsListInstance = pallet_bags_list::Instance1;
291-
impl pallet_bags_list::Config<VoterBagsListInstance> for Runtime {
292-
type RuntimeEvent = RuntimeEvent;
293-
type WeightInfo = ();
294-
// Staking is the source of truth for voter bags list, since they are not kept up to date.
295-
type ScoreProvider = Staking;
296-
type BagThresholds = BagThresholds;
297-
type MaxAutoRebagPerBlock = MaxAutoRebagPerBlock;
298-
type Score = VoteWeight;
299-
}
300-
301280
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
302281
impl frame_system::Config for Runtime {
303282
type Block = MockBlock<Self>;
@@ -491,7 +470,7 @@ impl pallet_staking_async::Config for Runtime {
491470
type MaxUnlockingChunks = ConstU32<16>;
492471
type NominationsQuota = pallet_staking_async::FixedNominationsQuota<16>;
493472

494-
type VoterList = VoterBagsList;
473+
type VoterList = pallet_staking_async::UseNominatorsAndValidatorsMap<Self>;
495474
type TargetList = pallet_staking_async::UseValidatorsMap<Self>;
496475

497476
type RcClientInterface = RcClient;

substrate/frame/staking-async/ahm-test/src/ah/test.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use crate::{ah::mock::*, rc, shared};
1919
use frame::prelude::Perbill;
20-
use frame_election_provider_support::{SortedListProvider, Weight};
20+
use frame_election_provider_support::Weight;
2121
use frame_support::{assert_ok, hypothetically};
2222

2323
use pallet_election_provider_multi_block::{
@@ -1084,36 +1084,6 @@ fn era_lifecycle_test() {
10841084
});
10851085
}
10861086

1087-
#[test]
1088-
fn vote_nominate_while_bagslist_is_locked() {
1089-
ExtBuilder::default().build().execute_with(|| {
1090-
VoterBagsList::lock();
1091-
1092-
assert_ok!(Staking::nominate(RuntimeOrigin::signed(2), vec![3]));
1093-
assert!(pallet_bags_list::PendingRebag::<T, VoterBagsListInstance>::contains_key(&2));
1094-
roll_next();
1095-
1096-
assert!(pallet_bags_list::PendingRebag::<T, VoterBagsListInstance>::contains_key(&2));
1097-
VoterBagsList::unlock();
1098-
1099-
roll_next();
1100-
assert!(!pallet_bags_list::PendingRebag::<T, VoterBagsListInstance>::contains_key(&2));
1101-
1102-
VoterBagsList::lock();
1103-
1104-
assert_ok!(Staking::validate(
1105-
RuntimeOrigin::signed(2),
1106-
pallet_staking_async::ValidatorPrefs::default()
1107-
));
1108-
assert!(pallet_bags_list::PendingRebag::<T, VoterBagsListInstance>::contains_key(&2));
1109-
1110-
VoterBagsList::unlock();
1111-
roll_next();
1112-
1113-
assert!(!pallet_bags_list::PendingRebag::<T, VoterBagsListInstance>::contains_key(&2));
1114-
assert_ok!(pallet_bags_list::List::<T, VoterBagsListInstance>::get_score(&2));
1115-
})
1116-
}
11171087
mod poll_operations {
11181088
use super::*;
11191089
use pallet_election_provider_multi_block::verifier::{Status, Verifier};

substrate/frame/staking-async/src/pallet/impls.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,13 +1897,12 @@ impl<T: Config> Pallet<T> {
18971897
}
18981898

18991899
/// Invariants:
1900-
/// * Number of voters in `VoterList` match that of the number of Nominators and Validators in
1901-
/// the system (validator is both voter and target).
19021900
/// * Number of targets in `TargetList` matches the number of validators in the system.
19031901
/// * Current validator count is bounded by the election provider's max winners.
19041902
fn check_count() -> Result<(), TryRuntimeError> {
19051903
// When the bags list is locked, nominators and validators may be temporarily
1906-
// missing from the voter set. `PendingRebag` will later reconcile the mismatch.
1904+
// missing from the voter set. If `PendingRebag` is enabled, it will later
1905+
// reconcile the mismatch.
19071906
crate::log!(
19081907
debug,
19091908
"VoterList count: {}, Nominators count: {}, Validators count: {}",

substrate/frame/staking-async/src/pallet/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,8 +1043,7 @@ pub mod pallet {
10431043
assert_eq!(
10441044
T::VoterList::count(),
10451045
Nominators::<T>::count() + Validators::<T>::count(),
1046-
"not all genesis stakers were inserted into sorted list provider, something is
1047-
wrong."
1046+
"not all genesis stakers were inserted into sorted list provider, something is wrong."
10481047
);
10491048

10501049
// now generate the dev stakers, after all else is setup

0 commit comments

Comments
 (0)