Skip to content

Commit 065e64d

Browse files
committed
Revert "[Staking] Bounded Slashing: Paginated Offence Processing & Slash Application (#7424)"
This reverts commit dda2cb5.
1 parent d1c91d9 commit 065e64d

File tree

24 files changed

+1102
-1164
lines changed

24 files changed

+1102
-1164
lines changed

polkadot/runtime/test-runtime/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ impl pallet_session::Config for Runtime {
323323
}
324324

325325
impl pallet_session::historical::Config for Runtime {
326-
type FullIdentification = ();
327-
type FullIdentificationOf = pallet_staking::NullIdentity;
326+
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
327+
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
328328
}
329329

330330
pallet_staking_reward_curve::build! {

polkadot/runtime/westend/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,6 @@ pub mod migrations {
18741874
parachains_shared::migration::MigrateToV1<Runtime>,
18751875
parachains_scheduler::migration::MigrateV2ToV3<Runtime>,
18761876
pallet_staking::migrations::v16::MigrateV15ToV16<Runtime>,
1877-
pallet_staking::migrations::v17::MigrateV16ToV17<Runtime>,
18781877
pallet_session::migrations::v1::MigrateV0ToV1<
18791878
Runtime,
18801879
pallet_staking::migrations::v17::MigrateDisabledToSession<Runtime>,

polkadot/runtime/westend/src/weights/pallet_staking.rs

-28
Original file line numberDiff line numberDiff line change
@@ -847,34 +847,6 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
847847
.saturating_add(T::DbWeight::get().reads(6))
848848
.saturating_add(T::DbWeight::get().writes(2))
849849
}
850-
/// Storage: `Staking::ActiveEra` (r:1 w:0)
851-
/// Proof: `Staking::ActiveEra` (`max_values`: Some(1), `max_size`: Some(13), added: 508, mode: `MaxEncodedLen`)
852-
/// Storage: `Staking::UnappliedSlashes` (r:1 w:1)
853-
/// Proof: `Staking::UnappliedSlashes` (`max_values`: None, `max_size`: Some(3231), added: 5706, mode: `MaxEncodedLen`)
854-
/// Storage: `Staking::Bonded` (r:65 w:0)
855-
/// Proof: `Staking::Bonded` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`)
856-
/// Storage: `Staking::Ledger` (r:65 w:65)
857-
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
858-
/// Storage: `NominationPools::ReversePoolIdLookup` (r:65 w:0)
859-
/// Proof: `NominationPools::ReversePoolIdLookup` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`)
860-
/// Storage: `DelegatedStaking::Agents` (r:65 w:65)
861-
/// Proof: `DelegatedStaking::Agents` (`max_values`: None, `max_size`: Some(120), added: 2595, mode: `MaxEncodedLen`)
862-
/// Storage: `System::Account` (r:65 w:65)
863-
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
864-
/// Storage: `Staking::VirtualStakers` (r:65 w:0)
865-
/// Proof: `Staking::VirtualStakers` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`)
866-
/// Storage: `Balances::Holds` (r:65 w:65)
867-
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(103), added: 2578, mode: `MaxEncodedLen`)
868-
fn apply_slash() -> Weight {
869-
// Proof Size summary in bytes:
870-
// Measured: `29228`
871-
// Estimated: `232780`
872-
// Minimum execution time: 3_571_461_000 picoseconds.
873-
Weight::from_parts(3_638_696_000, 0)
874-
.saturating_add(Weight::from_parts(0, 232780))
875-
.saturating_add(T::DbWeight::get().reads(457))
876-
.saturating_add(T::DbWeight::get().writes(261))
877-
}
878850
/// Storage: `Staking::CurrentEra` (r:1 w:0)
879851
/// Proof: `Staking::CurrentEra` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
880852
/// Storage: `Staking::ErasStartSessionIndex` (r:1 w:0)

prdoc/pr_7424.prdoc

-37
This file was deleted.

substrate/bin/node/runtime/src/lib.rs

+37-17
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ impl_opaque_keys! {
680680

681681
#[cfg(feature = "staking-playground")]
682682
pub mod staking_playground {
683+
use pallet_staking::Exposure;
684+
683685
use super::*;
684686

685687
/// An adapter to make the chain work with --dev only, even though it is running a large staking
@@ -714,43 +716,61 @@ pub mod staking_playground {
714716
}
715717
}
716718

717-
impl pallet_session::historical::SessionManager<AccountId, ()> for AliceAsOnlyValidator {
719+
impl pallet_session::historical::SessionManager<AccountId, Exposure<AccountId, Balance>>
720+
for AliceAsOnlyValidator
721+
{
718722
fn end_session(end_index: sp_staking::SessionIndex) {
719-
<Staking as pallet_session::historical::SessionManager<AccountId, ()>>::end_session(
720-
end_index,
721-
)
723+
<Staking as pallet_session::historical::SessionManager<
724+
AccountId,
725+
Exposure<AccountId, Balance>,
726+
>>::end_session(end_index)
722727
}
723728

724-
fn new_session(new_index: sp_staking::SessionIndex) -> Option<Vec<(AccountId, ())>> {
725-
<Staking as pallet_session::historical::SessionManager<AccountId, ()>>::new_session(
726-
new_index,
727-
)
729+
fn new_session(
730+
new_index: sp_staking::SessionIndex,
731+
) -> Option<Vec<(AccountId, Exposure<AccountId, Balance>)>> {
732+
<Staking as pallet_session::historical::SessionManager<
733+
AccountId,
734+
Exposure<AccountId, Balance>,
735+
>>::new_session(new_index)
728736
.map(|_ignored| {
729737
// construct a fake exposure for alice.
730-
vec![(sp_keyring::Sr25519Keyring::AliceStash.to_account_id().into(), ())]
738+
vec![(
739+
sp_keyring::Sr25519Keyring::AliceStash.to_account_id().into(),
740+
pallet_staking::Exposure {
741+
total: 1_000_000_000,
742+
own: 1_000_000_000,
743+
others: vec![],
744+
},
745+
)]
731746
})
732747
}
733748

734749
fn new_session_genesis(
735750
new_index: sp_staking::SessionIndex,
736-
) -> Option<Vec<(AccountId, ())>> {
751+
) -> Option<Vec<(AccountId, Exposure<AccountId, Balance>)>> {
737752
<Staking as pallet_session::historical::SessionManager<
738753
AccountId,
739-
(),
754+
Exposure<AccountId, Balance>,
740755
>>::new_session_genesis(new_index)
741756
.map(|_ignored| {
742757
// construct a fake exposure for alice.
743758
vec![(
744759
sp_keyring::Sr25519Keyring::AliceStash.to_account_id().into(),
745-
(),
760+
pallet_staking::Exposure {
761+
total: 1_000_000_000,
762+
own: 1_000_000_000,
763+
others: vec![],
764+
},
746765
)]
747766
})
748767
}
749768

750769
fn start_session(start_index: sp_staking::SessionIndex) {
751-
<Staking as pallet_session::historical::SessionManager<AccountId, ()>>::start_session(
752-
start_index,
753-
)
770+
<Staking as pallet_session::historical::SessionManager<
771+
AccountId,
772+
Exposure<AccountId, Balance>,
773+
>>::start_session(start_index)
754774
}
755775
}
756776
}
@@ -776,8 +796,8 @@ impl pallet_session::Config for Runtime {
776796
}
777797

778798
impl pallet_session::historical::Config for Runtime {
779-
type FullIdentification = ();
780-
type FullIdentificationOf = pallet_staking::NullIdentity;
799+
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
800+
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
781801
}
782802

783803
pallet_staking_reward_curve::build! {

substrate/frame/babe/src/mock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ impl pallet_session::Config for Test {
105105
}
106106

107107
impl pallet_session::historical::Config for Test {
108-
type FullIdentification = ();
109-
type FullIdentificationOf = pallet_staking::NullIdentity;
108+
type FullIdentification = pallet_staking::Exposure<u64, u128>;
109+
type FullIdentificationOf = pallet_staking::ExposureOf<Self>;
110110
}
111111

112112
impl pallet_authorship::Config for Test {

substrate/frame/beefy/src/mock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ impl pallet_session::Config for Test {
189189
}
190190

191191
impl pallet_session::historical::Config for Test {
192-
type FullIdentification = ();
193-
type FullIdentificationOf = pallet_staking::NullIdentity;
192+
type FullIdentification = pallet_staking::Exposure<u64, u128>;
193+
type FullIdentificationOf = pallet_staking::ExposureOf<Self>;
194194
}
195195

196196
impl pallet_authorship::Config for Test {

substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ impl pallet_session::Config for Runtime {
147147
type WeightInfo = ();
148148
}
149149
impl pallet_session::historical::Config for Runtime {
150-
type FullIdentification = ();
151-
type FullIdentificationOf = pallet_staking::NullIdentity;
150+
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
151+
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
152152
}
153153

154154
frame_election_provider_support::generate_solution_type!(
@@ -909,7 +909,10 @@ pub(crate) fn on_offence_now(
909909
// Add offence to validator, slash it.
910910
pub(crate) fn add_slash(who: &AccountId) {
911911
on_offence_now(
912-
&[OffenceDetails { offender: (*who, ()), reporters: vec![] }],
912+
&[OffenceDetails {
913+
offender: (*who, Staking::eras_stakers(active_era(), who)),
914+
reporters: vec![],
915+
}],
913916
&[Perbill::from_percent(10)],
914917
);
915918
}

substrate/frame/grandpa/src/mock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ impl pallet_session::Config for Test {
109109
}
110110

111111
impl pallet_session::historical::Config for Test {
112-
type FullIdentification = ();
113-
type FullIdentificationOf = pallet_staking::NullIdentity;
112+
type FullIdentification = pallet_staking::Exposure<u64, u128>;
113+
type FullIdentificationOf = pallet_staking::ExposureOf<Self>;
114114
}
115115

116116
impl pallet_authorship::Config for Test {

substrate/frame/offences/benchmarking/src/inner.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,6 @@ fn make_offenders<T: Config>(
170170
Ok(id_tuples)
171171
}
172172

173-
#[cfg(test)]
174-
fn run_staking_next_block<T: Config>() {
175-
use frame_support::traits::Hooks;
176-
System::<T>::set_block_number(System::<T>::block_number().saturating_add(1u32.into()));
177-
Staking::<T>::on_initialize(System::<T>::block_number());
178-
}
179-
180173
#[cfg(test)]
181174
fn assert_all_slashes_applied<T>(offender_count: usize)
182175
where
@@ -189,10 +182,10 @@ where
189182
// make sure that all slashes have been applied
190183
// deposit to reporter + reporter account endowed.
191184
assert_eq!(System::<T>::read_events_for_pallet::<pallet_balances::Event<T>>().len(), 2);
192-
// (n nominators + one validator) * slashed + Slash Reported + Slash Computed
185+
// (n nominators + one validator) * slashed + Slash Reported
193186
assert_eq!(
194187
System::<T>::read_events_for_pallet::<pallet_staking::Event<T>>().len(),
195-
1 * (offender_count + 1) as usize + 2
188+
1 * (offender_count + 1) as usize + 1
196189
);
197190
// offence
198191
assert_eq!(System::<T>::read_events_for_pallet::<pallet_offences::Event>().len(), 1);
@@ -239,8 +232,6 @@ mod benchmarks {
239232

240233
#[cfg(test)]
241234
{
242-
// slashes applied at the next block.
243-
run_staking_next_block::<T>();
244235
assert_all_slashes_applied::<T>(n as usize);
245236
}
246237

@@ -275,8 +266,6 @@ mod benchmarks {
275266
}
276267
#[cfg(test)]
277268
{
278-
// slashes applied at the next block.
279-
run_staking_next_block::<T>();
280269
assert_all_slashes_applied::<T>(n as usize);
281270
}
282271

substrate/frame/offences/benchmarking/src/mock.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use sp_runtime::{
3333
};
3434

3535
type AccountId = u64;
36+
type Balance = u64;
3637

3738
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
3839
impl frame_system::Config for Test {
@@ -53,8 +54,8 @@ impl pallet_timestamp::Config for Test {
5354
type WeightInfo = ();
5455
}
5556
impl pallet_session::historical::Config for Test {
56-
type FullIdentification = ();
57-
type FullIdentificationOf = pallet_staking::NullIdentity;
57+
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
58+
type FullIdentificationOf = pallet_staking::ExposureOf<Test>;
5859
}
5960

6061
sp_runtime::impl_opaque_keys! {

substrate/frame/root-offences/src/lib.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern crate alloc;
3131

3232
use alloc::vec::Vec;
3333
use pallet_session::historical::IdentificationTuple;
34-
use pallet_staking::Pallet as Staking;
34+
use pallet_staking::{BalanceOf, Exposure, ExposureOf, Pallet as Staking};
3535
use sp_runtime::Perbill;
3636
use sp_staking::offence::OnOffenceHandler;
3737

@@ -49,8 +49,11 @@ pub mod pallet {
4949
+ pallet_staking::Config
5050
+ pallet_session::Config<ValidatorId = <Self as frame_system::Config>::AccountId>
5151
+ pallet_session::historical::Config<
52-
FullIdentification = (),
53-
FullIdentificationOf = pallet_staking::NullIdentity,
52+
FullIdentification = Exposure<
53+
<Self as frame_system::Config>::AccountId,
54+
BalanceOf<Self>,
55+
>,
56+
FullIdentificationOf = ExposureOf<Self>,
5457
>
5558
{
5659
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
@@ -103,11 +106,15 @@ pub mod pallet {
103106
fn get_offence_details(
104107
offenders: Vec<(T::AccountId, Perbill)>,
105108
) -> Result<Vec<OffenceDetails<T>>, DispatchError> {
109+
let now = pallet_staking::ActiveEra::<T>::get()
110+
.map(|e| e.index)
111+
.ok_or(Error::<T>::FailedToGetActiveEra)?;
112+
106113
Ok(offenders
107114
.clone()
108115
.into_iter()
109116
.map(|(o, _)| OffenceDetails::<T> {
110-
offender: (o.clone(), ()),
117+
offender: (o.clone(), Staking::<T>::eras_stakers(now, &o)),
111118
reporters: Default::default(),
112119
})
113120
.collect())
@@ -117,7 +124,7 @@ pub mod pallet {
117124
fn submit_offence(offenders: &[OffenceDetails<T>], slash_fraction: &[Perbill]) {
118125
let session_index = <pallet_session::Pallet<T> as frame_support::traits::ValidatorSet<T::AccountId>>::session_index();
119126

120-
<Staking<T> as OnOffenceHandler<
127+
<pallet_staking::Pallet<T> as OnOffenceHandler<
121128
T::AccountId,
122129
IdentificationTuple<T>,
123130
Weight,

substrate/frame/root-offences/src/mock.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use frame_support::{
2828
traits::{ConstU32, ConstU64, OneSessionHandler},
2929
BoundedVec,
3030
};
31-
use pallet_staking::{BalanceOf, StakerStatus};
31+
use pallet_staking::StakerStatus;
3232
use sp_core::ConstBool;
3333
use sp_runtime::{curve::PiecewiseLinear, testing::UintAuthorityId, traits::Zero, BuildStorage};
3434
use sp_staking::{EraIndex, SessionIndex};
@@ -148,8 +148,8 @@ impl pallet_staking::Config for Test {
148148
}
149149

150150
impl pallet_session::historical::Config for Test {
151-
type FullIdentification = ();
152-
type FullIdentificationOf = pallet_staking::NullIdentity;
151+
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
152+
type FullIdentificationOf = pallet_staking::ExposureOf<Test>;
153153
}
154154

155155
sp_runtime::impl_opaque_keys! {
@@ -298,11 +298,6 @@ pub(crate) fn run_to_block(n: BlockNumber) {
298298
);
299299
}
300300

301-
/// Progress by n block.
302-
pub(crate) fn advance_blocks(n: u64) {
303-
run_to_block(System::block_number() + n);
304-
}
305-
306301
pub(crate) fn active_era() -> EraIndex {
307302
pallet_staking::ActiveEra::<Test>::get().unwrap().index
308303
}

0 commit comments

Comments
 (0)