Skip to content

Commit 535884a

Browse files
committed
Remove invulnerables form staking-async
The "staking-async" pallet has inherited the list of invulnerable validators from the "staking" pallet, but these are no longer used. We can therefore remove them, together with additional clean-up. --------- Signed-off-by: Andrei Trandafir <[email protected]>
1 parent 04f79fb commit 535884a

File tree

10 files changed

+0
-180
lines changed

10 files changed

+0
-180
lines changed

cumulus/parachains/runtimes/assets/asset-hub-westend/src/staking.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ impl pallet_staking_async::Config for Runtime {
298298
type HistoryDepth = frame_support::traits::ConstU32<84>;
299299
type MaxControllersInDeprecationBatch = MaxControllersInDeprecationBatch;
300300
type EventListeners = (NominationPools, DelegatedStaking);
301-
type MaxInvulnerables = frame_support::traits::ConstU32<20>;
302301
type PlanningEraOffset =
303302
pallet_staking_async::PlanningEraOffsetOf<Runtime, RelaySessionDuration, ConstU32<5>>;
304303
type RcClientInterface = StakingRcClient;

cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_staking_async.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -420,20 +420,6 @@ impl<T: frame_system::Config> pallet_staking_async::WeightInfo for WeightInfo<T>
420420
.saturating_add(Weight::from_parts(0, 0))
421421
.saturating_add(T::DbWeight::get().writes(1))
422422
}
423-
/// Storage: `Staking::Invulnerables` (r:0 w:1)
424-
/// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`)
425-
/// The range of component `v` is `[0, 20]`.
426-
fn set_invulnerables(v: u32, ) -> Weight {
427-
// Proof Size summary in bytes:
428-
// Measured: `0`
429-
// Estimated: `0`
430-
// Minimum execution time: 2_826_000 picoseconds.
431-
Weight::from_parts(3_433_272, 0)
432-
.saturating_add(Weight::from_parts(0, 0))
433-
// Standard Error: 967
434-
.saturating_add(Weight::from_parts(17_572, 0).saturating_mul(v.into()))
435-
.saturating_add(T::DbWeight::get().writes(1))
436-
}
437423
/// Storage: `Staking::Ledger` (r:1502 w:1502)
438424
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(753), added: 3228, mode: `MaxEncodedLen`)
439425
/// Storage: `Staking::Bonded` (r:751 w:751)

substrate/frame/staking-async/runtimes/parachain/src/weights/pallet_collator_selection.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,6 @@ use core::marker::PhantomData;
5151
/// Weight functions for `pallet_collator_selection`.
5252
pub struct WeightInfo<T>(PhantomData<T>);
5353
impl<T: frame_system::Config> pallet_collator_selection::WeightInfo for WeightInfo<T> {
54-
/// Storage: `Session::NextKeys` (r:20 w:0)
55-
/// Proof: `Session::NextKeys` (`max_values`: None, `max_size`: None, mode: `Measured`)
56-
/// Storage: `CollatorSelection::Invulnerables` (r:0 w:1)
57-
/// Proof: `CollatorSelection::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`)
58-
/// The range of component `b` is `[1, 20]`.
59-
fn set_invulnerables(b: u32, ) -> Weight {
60-
// Proof Size summary in bytes:
61-
// Measured: `163 + b * (79 ±0)`
62-
// Estimated: `1154 + b * (2555 ±0)`
63-
// Minimum execution time: 14_105_000 picoseconds.
64-
Weight::from_parts(12_034_824, 0)
65-
.saturating_add(Weight::from_parts(0, 1154))
66-
// Standard Error: 7_023
67-
.saturating_add(Weight::from_parts(3_121_830, 0).saturating_mul(b.into()))
68-
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(b.into())))
69-
.saturating_add(T::DbWeight::get().writes(1))
70-
.saturating_add(Weight::from_parts(0, 2555).saturating_mul(b.into()))
71-
}
7254
/// Storage: `Session::NextKeys` (r:1 w:0)
7355
/// Proof: `Session::NextKeys` (`max_values`: None, `max_size`: None, mode: `Measured`)
7456
/// Storage: `CollatorSelection::Invulnerables` (r:1 w:1)

substrate/frame/staking-async/runtimes/parachain/src/weights/pallet_staking_async.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ pub trait WeightInfo {
7373
fn force_no_eras() -> Weight;
7474
fn force_new_era() -> Weight;
7575
fn force_new_era_always() -> Weight;
76-
fn set_invulnerables(v: u32, ) -> Weight;
7776
fn deprecate_controller_batch(u: u32, ) -> Weight;
7877
fn force_unstake() -> Weight;
7978
fn cancel_deferred_slash(s: u32, ) -> Weight;
@@ -449,17 +448,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
449448
Weight::from_parts(11_000_000, 0)
450449
.saturating_add(T::DbWeight::get().writes(1_u64))
451450
}
452-
/// Storage: `Staking::Invulnerables` (r:0 w:1)
453-
/// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`)
454-
/// The range of component `v` is `[0, 20]`.
455-
fn set_invulnerables(_v: u32, ) -> Weight {
456-
// Proof Size summary in bytes:
457-
// Measured: `0`
458-
// Estimated: `0`
459-
// Minimum execution time: 4_000_000 picoseconds.
460-
Weight::from_parts(6_000_000, 0)
461-
.saturating_add(T::DbWeight::get().writes(1_u64))
462-
}
463451
/// Storage: `Staking::Ledger` (r:1502 w:1502)
464452
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(753), added: 3228, mode: `MaxEncodedLen`)
465453
/// Storage: `Staking::Bonded` (r:751 w:751)
@@ -1342,17 +1330,6 @@ impl WeightInfo for () {
13421330
Weight::from_parts(11_000_000, 0)
13431331
.saturating_add(RocksDbWeight::get().writes(1_u64))
13441332
}
1345-
/// Storage: `Staking::Invulnerables` (r:0 w:1)
1346-
/// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`)
1347-
/// The range of component `v` is `[0, 20]`.
1348-
fn set_invulnerables(_v: u32, ) -> Weight {
1349-
// Proof Size summary in bytes:
1350-
// Measured: `0`
1351-
// Estimated: `0`
1352-
// Minimum execution time: 4_000_000 picoseconds.
1353-
Weight::from_parts(6_000_000, 0)
1354-
.saturating_add(RocksDbWeight::get().writes(1_u64))
1355-
}
13561333
/// Storage: `Staking::Ledger` (r:1502 w:1502)
13571334
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(753), added: 3228, mode: `MaxEncodedLen`)
13581335
/// Storage: `Staking::Bonded` (r:751 w:751)

substrate/frame/staking-async/src/benchmarking.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -594,20 +594,6 @@ mod benchmarks {
594594
assert_eq!(ForceEra::<T>::get(), Forcing::ForceAlways);
595595
}
596596

597-
#[benchmark]
598-
// Worst case scenario, the list of invulnerables is very long.
599-
fn set_invulnerables(v: Linear<0, { T::MaxInvulnerables::get() }>) {
600-
let mut invulnerables = Vec::new();
601-
for i in 0..v {
602-
invulnerables.push(account("invulnerable", i, SEED));
603-
}
604-
605-
#[extrinsic_call]
606-
_(RawOrigin::Root, invulnerables);
607-
608-
assert_eq!(Invulnerables::<T>::get().len(), v as usize);
609-
}
610-
611597
#[benchmark]
612598
fn deprecate_controller_batch(
613599
// We pass a dynamic number of controllers to the benchmark, up to

substrate/frame/staking-async/src/mock.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ impl crate::pallet::pallet::Config for Test {
438438
type BondingDuration = BondingDuration;
439439
type MaxControllersInDeprecationBatch = MaxControllersInDeprecationBatch;
440440
type EventListeners = EventListenerMock;
441-
type MaxInvulnerables = ConstU32<20>;
442441
type MaxEraDuration = MaxEraDuration;
443442
type MaxPruningItems = MaxPruningItems;
444443
type PlanningEraOffset = PlanningEraOffset;
@@ -477,7 +476,6 @@ parameter_types! {
477476
pub struct ExtBuilder {
478477
nominate: bool,
479478
validator_count: u32,
480-
invulnerables: BoundedVec<AccountId, <Test as Config>::MaxInvulnerables>,
481479
has_stakers: bool,
482480
pub min_nominator_bond: Balance,
483481
min_validator_bond: Balance,
@@ -494,7 +492,6 @@ impl Default for ExtBuilder {
494492
nominate: true,
495493
validator_count: 2,
496494
balance_factor: 1,
497-
invulnerables: BoundedVec::new(),
498495
has_stakers: true,
499496
min_nominator_bond: ExistentialDeposit::get(),
500497
min_validator_bond: ExistentialDeposit::get(),
@@ -548,11 +545,6 @@ impl ExtBuilder {
548545
SlashDeferDuration::set(eras);
549546
self
550547
}
551-
pub(crate) fn invulnerables(mut self, invulnerables: Vec<AccountId>) -> Self {
552-
self.invulnerables = BoundedVec::try_from(invulnerables)
553-
.expect("Too many invulnerable validators: upper limit is MaxInvulnerables");
554-
self
555-
}
556548
pub(crate) fn session_per_era(self, length: SessionIndex) -> Self {
557549
SessionsPerEra::set(length);
558550
self
@@ -687,7 +679,6 @@ impl ExtBuilder {
687679
let _ = pallet_staking_async::GenesisConfig::<Test> {
688680
stakers: maybe_stakers,
689681
validator_count: self.validator_count,
690-
invulnerables: self.invulnerables,
691682
active_era: (0, 0, INIT_TIMESTAMP),
692683
slash_reward_fraction: Perbill::from_percent(10),
693684
min_nominator_bond: self.min_nominator_bond,

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,16 +1193,9 @@ impl<T: Config> rc_client::AHStakingInterface for Pallet<T> {
11931193
active_era.index.saturating_sub(T::SlashDeferDuration::get().saturating_sub(1))
11941194
};
11951195

1196-
let invulnerables = Invulnerables::<T>::get();
1197-
11981196
for o in offences {
11991197
let slash_fraction = o.slash_fraction;
12001198
let validator: <T as frame_system::Config>::AccountId = o.offender.into();
1201-
// Skip if the validator is invulnerable.
1202-
if invulnerables.contains(&validator) {
1203-
log!(debug, "🦹 on_offence: {:?} is invulnerable; ignoring offence", validator);
1204-
continue
1205-
}
12061199

12071200
// ignore offence if too old to report.
12081201
if offence_era < oldest_reportable_offence_era {

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,6 @@ pub mod pallet {
323323
#[pallet::no_default_bounds]
324324
type EventListeners: sp_staking::OnStakingUpdate<Self::AccountId, BalanceOf<Self>>;
325325

326-
/// Maximum number of invulnerable validators.
327-
#[pallet::constant]
328-
type MaxInvulnerables: Get<u32>;
329-
330326
/// Maximum allowed era duration in milliseconds.
331327
///
332328
/// This provides a defensive upper bound to cap the effective era duration, preventing
@@ -406,7 +402,6 @@ pub mod pallet {
406402
type MaxUnlockingChunks = ConstU32<32>;
407403
type MaxValidatorSet = ConstU32<100>;
408404
type MaxControllersInDeprecationBatch = ConstU32<100>;
409-
type MaxInvulnerables = ConstU32<20>;
410405
type MaxEraDuration = ();
411406
type MaxPruningItems = MaxPruningItems;
412407
type EventListeners = ();
@@ -419,13 +414,6 @@ pub mod pallet {
419414
#[pallet::storage]
420415
pub type ValidatorCount<T> = StorageValue<_, u32, ValueQuery>;
421416

422-
/// Any validators that may never be slashed or forcibly kicked. It's a Vec since they're
423-
/// easy to initialize and the performance hit is minimal (we expect no more than four
424-
/// invulnerables) and restricted to testnets.
425-
#[pallet::storage]
426-
pub type Invulnerables<T: Config> =
427-
StorageValue<_, BoundedVec<T::AccountId, T::MaxInvulnerables>, ValueQuery>;
428-
429417
/// Map from all locked "stash" accounts to the controller account.
430418
///
431419
/// TWOX-NOTE: SAFE since `AccountId` is a secure hash.
@@ -855,7 +843,6 @@ pub mod pallet {
855843
#[derive(frame_support::DefaultNoBound, frame_support::DebugNoBound)]
856844
pub struct GenesisConfig<T: Config> {
857845
pub validator_count: u32,
858-
pub invulnerables: BoundedVec<T::AccountId, T::MaxInvulnerables>,
859846
pub force_era: Forcing,
860847
pub slash_reward_fraction: Perbill,
861848
pub canceled_payout: BalanceOf<T>,
@@ -908,12 +895,6 @@ pub mod pallet {
908895
);
909896
ValidatorCount::<T>::put(self.validator_count);
910897

911-
assert!(
912-
self.invulnerables.len() as u32 <= T::MaxInvulnerables::get(),
913-
"Too many invulnerable validators at genesis."
914-
);
915-
<Invulnerables<T>>::put(&self.invulnerables);
916-
917898
ForceEra::<T>::put(self.force_era);
918899
CanceledSlashPayout::<T>::put(self.canceled_payout);
919900
SlashRewardFraction::<T>::put(self.slash_reward_fraction);
@@ -1967,22 +1948,6 @@ pub mod pallet {
19671948
Ok(())
19681949
}
19691950

1970-
/// Set the validators who cannot be slashed (if any).
1971-
///
1972-
/// The dispatch origin must be Root.
1973-
#[pallet::call_index(14)]
1974-
#[pallet::weight(T::WeightInfo::set_invulnerables(invulnerables.len() as u32))]
1975-
pub fn set_invulnerables(
1976-
origin: OriginFor<T>,
1977-
invulnerables: Vec<T::AccountId>,
1978-
) -> DispatchResult {
1979-
ensure_root(origin)?;
1980-
let invulnerables =
1981-
BoundedVec::try_from(invulnerables).map_err(|_| Error::<T>::BoundNotMet)?;
1982-
<Invulnerables<T>>::put(invulnerables);
1983-
Ok(())
1984-
}
1985-
19861951
/// Force a current staker to become completely unstaked, immediately.
19871952
///
19881953
/// The dispatch origin must be Root.

substrate/frame/staking-async/src/tests/slashing.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -512,42 +512,6 @@ fn retroactive_deferred_slashes_one_before() {
512512
})
513513
}
514514

515-
#[test]
516-
fn invulnerables_are_not_slashed() {
517-
// For invulnerable validators no slashing is performed.
518-
ExtBuilder::default()
519-
.invulnerables(vec![11])
520-
.nominate(false)
521-
.build_and_execute(|| {
522-
assert_eq!(asset::stakeable_balance::<T>(&11), 1000);
523-
assert_eq!(asset::stakeable_balance::<T>(&21), 1000);
524-
525-
let initial_balance = Staking::slashable_balance_of(&21);
526-
527-
// slash both
528-
add_slash(11);
529-
add_slash(21);
530-
Session::roll_next();
531-
assert_eq!(
532-
staking_events_since_last_call(),
533-
vec![
534-
Event::OffenceReported {
535-
offence_era: 1,
536-
validator: 21,
537-
fraction: Perbill::from_percent(10)
538-
},
539-
Event::SlashComputed { offence_era: 1, slash_era: 1, offender: 21, page: 0 },
540-
Event::Slashed { staker: 21, amount: 100 }
541-
]
542-
);
543-
544-
// The validator 11 hasn't been slashed, but 21 has been.
545-
assert_eq!(asset::stakeable_balance::<T>(&11), 1000);
546-
// 1000 - (0.1 * initial_balance)
547-
assert_eq!(asset::stakeable_balance::<T>(&21), 1000 - (initial_balance / 10));
548-
});
549-
}
550-
551515
#[test]
552516
fn dont_slash_if_fraction_is_zero() {
553517
// Don't slash if the fraction is zero.

substrate/frame/staking-async/src/weights.rs

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

0 commit comments

Comments
 (0)