Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ impl pallet_staking_async::Config for Runtime {
type HistoryDepth = frame_support::traits::ConstU32<84>;
type MaxControllersInDeprecationBatch = MaxControllersInDeprecationBatch;
type EventListeners = (NominationPools, DelegatedStaking);
type MaxInvulnerables = frame_support::traits::ConstU32<20>;
type PlanningEraOffset =
pallet_staking_async::PlanningEraOffsetOf<Runtime, RelaySessionDuration, ConstU32<5>>;
type RcClientInterface = StakingRcClient;
Expand Down

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions prdoc/pr_10359.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: Remove invulnerables form staking-async
doc:
- audience: Runtime Dev
description: |-
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. This includes removing the 'set_invulnerables(...)' call together with the 'Invulnerables<T: Config>' storage type.
crates:
- name: asset-hub-westend-runtime
bump: major
- name: pallet-staking-async
bump: major
1 change: 0 additions & 1 deletion substrate/frame/staking-async/ahm-test/src/ah/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ impl pallet_staking_async::Config for Runtime {

type MaxValidatorSet = MaxValidators;
type MaxExposurePageSize = MaxExposurePageSize;
type MaxInvulnerables = MaxValidators;
type MaxUnlockingChunks = ConstU32<16>;
type NominationsQuota = pallet_staking_async::FixedNominationsQuota<16>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ impl pallet_staking_async::Config for Runtime {
type MaxControllersInDeprecationBatch = MaxControllersInDeprecationBatch;
type EventListeners = (NominationPools, DelegatedStaking);
type WeightInfo = pallet_staking_async::weights::SubstrateWeight<Runtime>;
type MaxInvulnerables = frame_support::traits::ConstU32<20>;
type MaxEraDuration = MaxEraDuration;
type MaxPruningItems = MaxPruningItems;
type PlanningEraOffset =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ pub trait WeightInfo {
fn force_no_eras() -> Weight;
fn force_new_era() -> Weight;
fn force_new_era_always() -> Weight;
fn set_invulnerables(v: u32, ) -> Weight;
fn deprecate_controller_batch(u: u32, ) -> Weight;
fn force_unstake() -> Weight;
fn cancel_deferred_slash(s: u32, ) -> Weight;
Expand Down Expand Up @@ -449,17 +448,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
Weight::from_parts(11_000_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `Staking::Invulnerables` (r:0 w:1)
/// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`)
/// The range of component `v` is `[0, 20]`.
fn set_invulnerables(_v: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 4_000_000 picoseconds.
Weight::from_parts(6_000_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `Staking::Ledger` (r:1502 w:1502)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(753), added: 3228, mode: `MaxEncodedLen`)
/// Storage: `Staking::Bonded` (r:751 w:751)
Expand Down Expand Up @@ -822,8 +810,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Proof: `Staking::ActiveEra` (`max_values`: Some(1), `max_size`: Some(13), added: 508, mode: `MaxEncodedLen`)
/// Storage: `Staking::BondedEras` (r:1 w:0)
/// Proof: `Staking::BondedEras` (`max_values`: Some(1), `max_size`: Some(25), added: 520, mode: `MaxEncodedLen`)
/// Storage: `Staking::Invulnerables` (r:1 w:0)
/// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasStakersOverview` (r:500 w:0)
/// Proof: `Staking::ErasStakersOverview` (`max_values`: None, `max_size`: Some(92), added: 2567, mode: `MaxEncodedLen`)
/// Storage: `Staking::ValidatorSlashInEra` (r:500 w:500)
Expand Down Expand Up @@ -1342,17 +1328,6 @@ impl WeightInfo for () {
Weight::from_parts(11_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `Staking::Invulnerables` (r:0 w:1)
/// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`)
/// The range of component `v` is `[0, 20]`.
fn set_invulnerables(_v: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 4_000_000 picoseconds.
Weight::from_parts(6_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `Staking::Ledger` (r:1502 w:1502)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(753), added: 3228, mode: `MaxEncodedLen`)
/// Storage: `Staking::Bonded` (r:751 w:751)
Expand Down Expand Up @@ -1715,8 +1690,6 @@ impl WeightInfo for () {
/// Proof: `Staking::ActiveEra` (`max_values`: Some(1), `max_size`: Some(13), added: 508, mode: `MaxEncodedLen`)
/// Storage: `Staking::BondedEras` (r:1 w:0)
/// Proof: `Staking::BondedEras` (`max_values`: Some(1), `max_size`: Some(25), added: 520, mode: `MaxEncodedLen`)
/// Storage: `Staking::Invulnerables` (r:1 w:0)
/// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasStakersOverview` (r:500 w:0)
/// Proof: `Staking::ErasStakersOverview` (`max_values`: None, `max_size`: Some(92), added: 2567, mode: `MaxEncodedLen`)
/// Storage: `Staking::ValidatorSlashInEra` (r:500 w:500)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ impl<T: frame_system::Config> pallet_offences::WeightInfo for WeightInfo<T> {
/// Proof: `Staking::ActiveEra` (`max_values`: Some(1), `max_size`: Some(13), added: 508, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasStartSessionIndex` (r:1 w:0)
/// Proof: `Staking::ErasStartSessionIndex` (`max_values`: None, `max_size`: Some(16), added: 2491, mode: `MaxEncodedLen`)
/// Storage: `Staking::Invulnerables` (r:1 w:0)
/// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasStakersOverview` (r:1 w:0)
/// Proof: `Staking::ErasStakersOverview` (`max_values`: None, `max_size`: Some(92), added: 2567, mode: `MaxEncodedLen`)
/// Storage: `Session::DisabledValidators` (r:1 w:1)
Expand Down Expand Up @@ -94,8 +92,6 @@ impl<T: frame_system::Config> pallet_offences::WeightInfo for WeightInfo<T> {
/// Proof: `Staking::ActiveEra` (`max_values`: Some(1), `max_size`: Some(13), added: 508, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasStartSessionIndex` (r:1 w:0)
/// Proof: `Staking::ErasStartSessionIndex` (`max_values`: None, `max_size`: Some(16), added: 2491, mode: `MaxEncodedLen`)
/// Storage: `Staking::Invulnerables` (r:1 w:0)
/// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasStakersOverview` (r:1 w:0)
/// Proof: `Staking::ErasStakersOverview` (`max_values`: None, `max_size`: Some(92), added: 2567, mode: `MaxEncodedLen`)
/// Storage: `Session::DisabledValidators` (r:1 w:1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::disputes::slashing::W
/// Proof: `Staking::ActiveEra` (`max_values`: Some(1), `max_size`: Some(13), added: 508, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasStartSessionIndex` (r:1 w:0)
/// Proof: `Staking::ErasStartSessionIndex` (`max_values`: None, `max_size`: Some(16), added: 2491, mode: `MaxEncodedLen`)
/// Storage: `Staking::Invulnerables` (r:1 w:0)
/// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasStakersOverview` (r:1 w:0)
/// Proof: `Staking::ErasStakersOverview` (`max_values`: None, `max_size`: Some(92), added: 2567, mode: `MaxEncodedLen`)
/// Storage: `Session::DisabledValidators` (r:1 w:1)
Expand Down
14 changes: 0 additions & 14 deletions substrate/frame/staking-async/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,20 +594,6 @@ mod benchmarks {
assert_eq!(ForceEra::<T>::get(), Forcing::ForceAlways);
}

#[benchmark]
// Worst case scenario, the list of invulnerables is very long.
fn set_invulnerables(v: Linear<0, { T::MaxInvulnerables::get() }>) {
let mut invulnerables = Vec::new();
for i in 0..v {
invulnerables.push(account("invulnerable", i, SEED));
}

#[extrinsic_call]
_(RawOrigin::Root, invulnerables);

assert_eq!(Invulnerables::<T>::get().len(), v as usize);
}

#[benchmark]
fn deprecate_controller_batch(
// We pass a dynamic number of controllers to the benchmark, up to
Expand Down
9 changes: 0 additions & 9 deletions substrate/frame/staking-async/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ impl crate::pallet::pallet::Config for Test {
type BondingDuration = BondingDuration;
type MaxControllersInDeprecationBatch = MaxControllersInDeprecationBatch;
type EventListeners = EventListenerMock;
type MaxInvulnerables = ConstU32<20>;
type MaxEraDuration = MaxEraDuration;
type MaxPruningItems = MaxPruningItems;
type PlanningEraOffset = PlanningEraOffset;
Expand Down Expand Up @@ -477,7 +476,6 @@ parameter_types! {
pub struct ExtBuilder {
nominate: bool,
validator_count: u32,
invulnerables: BoundedVec<AccountId, <Test as Config>::MaxInvulnerables>,
has_stakers: bool,
pub min_nominator_bond: Balance,
min_validator_bond: Balance,
Expand All @@ -494,7 +492,6 @@ impl Default for ExtBuilder {
nominate: true,
validator_count: 2,
balance_factor: 1,
invulnerables: BoundedVec::new(),
has_stakers: true,
min_nominator_bond: ExistentialDeposit::get(),
min_validator_bond: ExistentialDeposit::get(),
Expand Down Expand Up @@ -548,11 +545,6 @@ impl ExtBuilder {
SlashDeferDuration::set(eras);
self
}
pub(crate) fn invulnerables(mut self, invulnerables: Vec<AccountId>) -> Self {
self.invulnerables = BoundedVec::try_from(invulnerables)
.expect("Too many invulnerable validators: upper limit is MaxInvulnerables");
self
}
pub(crate) fn session_per_era(self, length: SessionIndex) -> Self {
SessionsPerEra::set(length);
self
Expand Down Expand Up @@ -687,7 +679,6 @@ impl ExtBuilder {
let _ = pallet_staking_async::GenesisConfig::<Test> {
stakers: maybe_stakers,
validator_count: self.validator_count,
invulnerables: self.invulnerables,
active_era: (0, 0, INIT_TIMESTAMP),
slash_reward_fraction: Perbill::from_percent(10),
min_nominator_bond: self.min_nominator_bond,
Expand Down
7 changes: 0 additions & 7 deletions substrate/frame/staking-async/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,16 +1193,9 @@ impl<T: Config> rc_client::AHStakingInterface for Pallet<T> {
active_era.index.saturating_sub(T::SlashDeferDuration::get().saturating_sub(1))
};

let invulnerables = Invulnerables::<T>::get();

for o in offences {
let slash_fraction = o.slash_fraction;
let validator: <T as frame_system::Config>::AccountId = o.offender.into();
// Skip if the validator is invulnerable.
if invulnerables.contains(&validator) {
log!(debug, "🦹 on_offence: {:?} is invulnerable; ignoring offence", validator);
continue
}

// ignore offence if too old to report.
if offence_era < oldest_reportable_offence_era {
Expand Down
35 changes: 0 additions & 35 deletions substrate/frame/staking-async/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,6 @@ pub mod pallet {
#[pallet::no_default_bounds]
type EventListeners: sp_staking::OnStakingUpdate<Self::AccountId, BalanceOf<Self>>;

/// Maximum number of invulnerable validators.
#[pallet::constant]
type MaxInvulnerables: Get<u32>;

/// Maximum allowed era duration in milliseconds.
///
/// This provides a defensive upper bound to cap the effective era duration, preventing
Expand Down Expand Up @@ -406,7 +402,6 @@ pub mod pallet {
type MaxUnlockingChunks = ConstU32<32>;
type MaxValidatorSet = ConstU32<100>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type MaxInvulnerables = ConstU32<20>;
type MaxEraDuration = ();
type MaxPruningItems = MaxPruningItems;
type EventListeners = ();
Expand All @@ -419,13 +414,6 @@ pub mod pallet {
#[pallet::storage]
pub type ValidatorCount<T> = StorageValue<_, u32, ValueQuery>;

/// Any validators that may never be slashed or forcibly kicked. It's a Vec since they're
/// easy to initialize and the performance hit is minimal (we expect no more than four
/// invulnerables) and restricted to testnets.
#[pallet::storage]
pub type Invulnerables<T: Config> =
StorageValue<_, BoundedVec<T::AccountId, T::MaxInvulnerables>, ValueQuery>;

/// Map from all locked "stash" accounts to the controller account.
///
/// TWOX-NOTE: SAFE since `AccountId` is a secure hash.
Expand Down Expand Up @@ -855,7 +843,6 @@ pub mod pallet {
#[derive(frame_support::DefaultNoBound, frame_support::DebugNoBound)]
pub struct GenesisConfig<T: Config> {
pub validator_count: u32,
pub invulnerables: BoundedVec<T::AccountId, T::MaxInvulnerables>,
pub force_era: Forcing,
pub slash_reward_fraction: Perbill,
pub canceled_payout: BalanceOf<T>,
Expand Down Expand Up @@ -908,12 +895,6 @@ pub mod pallet {
);
ValidatorCount::<T>::put(self.validator_count);

assert!(
self.invulnerables.len() as u32 <= T::MaxInvulnerables::get(),
"Too many invulnerable validators at genesis."
);
<Invulnerables<T>>::put(&self.invulnerables);

ForceEra::<T>::put(self.force_era);
CanceledSlashPayout::<T>::put(self.canceled_payout);
SlashRewardFraction::<T>::put(self.slash_reward_fraction);
Expand Down Expand Up @@ -1967,22 +1948,6 @@ pub mod pallet {
Ok(())
}

/// Set the validators who cannot be slashed (if any).
///
/// The dispatch origin must be Root.
#[pallet::call_index(14)]
#[pallet::weight(T::WeightInfo::set_invulnerables(invulnerables.len() as u32))]
pub fn set_invulnerables(
origin: OriginFor<T>,
invulnerables: Vec<T::AccountId>,
) -> DispatchResult {
ensure_root(origin)?;
let invulnerables =
BoundedVec::try_from(invulnerables).map_err(|_| Error::<T>::BoundNotMet)?;
<Invulnerables<T>>::put(invulnerables);
Ok(())
}

/// Force a current staker to become completely unstaked, immediately.
///
/// The dispatch origin must be Root.
Expand Down
36 changes: 0 additions & 36 deletions substrate/frame/staking-async/src/tests/slashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,42 +512,6 @@ fn retroactive_deferred_slashes_one_before() {
})
}

#[test]
fn invulnerables_are_not_slashed() {
// For invulnerable validators no slashing is performed.
ExtBuilder::default()
.invulnerables(vec![11])
.nominate(false)
.build_and_execute(|| {
assert_eq!(asset::stakeable_balance::<T>(&11), 1000);
assert_eq!(asset::stakeable_balance::<T>(&21), 1000);

let initial_balance = Staking::slashable_balance_of(&21);

// slash both
add_slash(11);
add_slash(21);
Session::roll_next();
assert_eq!(
staking_events_since_last_call(),
vec![
Event::OffenceReported {
offence_era: 1,
validator: 21,
fraction: Perbill::from_percent(10)
},
Event::SlashComputed { offence_era: 1, slash_era: 1, offender: 21, page: 0 },
Event::Slashed { staker: 21, amount: 100 }
]
);

// The validator 11 hasn't been slashed, but 21 has been.
assert_eq!(asset::stakeable_balance::<T>(&11), 1000);
// 1000 - (0.1 * initial_balance)
assert_eq!(asset::stakeable_balance::<T>(&21), 1000 - (initial_balance / 10));
});
}

#[test]
fn dont_slash_if_fraction_is_zero() {
// Don't slash if the fraction is zero.
Expand Down
27 changes: 0 additions & 27 deletions substrate/frame/staking-async/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading