staking: Proportional ledger slashing (#10982)

* staking: Proportional ledger slashing

* Some comment cleanup

* Update frame/staking/src/pallet/mod.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Fix benchmarks

* FMT

* Try fill in all staking configs

* round of feedback and imp from kian

* demonstrate per_thing usage

* Update some tests

* FMT

* Test that era offset works correctly

* Update mocks

* Remove unnescary docs

* Remove unlock_era

* Update frame/staking/src/lib.rs

* Adjust tests to account for only remove when < ED

* Remove stale TODOs

* Remove dupe test

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: kianenigma <kian@parity.io>
This commit is contained in:
Zeke Mostov
2022-04-21 15:53:54 -07:00
committed by GitHub
parent 7416c8c5de
commit e0bf4f36bf
13 changed files with 399 additions and 74 deletions
+14 -3
View File
@@ -598,6 +598,7 @@ pub fn do_slash<T: Config>(
value: BalanceOf<T>,
reward_payout: &mut BalanceOf<T>,
slashed_imbalance: &mut NegativeImbalanceOf<T>,
slash_era: EraIndex,
) {
let controller = match <Pallet<T>>::bonded(stash) {
None => return, // defensive: should always exist.
@@ -609,7 +610,7 @@ pub fn do_slash<T: Config>(
None => return, // nothing to do.
};
let value = ledger.slash(value, T::Currency::minimum_balance());
let value = ledger.slash(value, T::Currency::minimum_balance(), slash_era);
if !value.is_zero() {
let (imbalance, missing) = T::Currency::slash(stash, value);
@@ -628,7 +629,10 @@ pub fn do_slash<T: Config>(
}
/// Apply a previously-unapplied slash.
pub(crate) fn apply_slash<T: Config>(unapplied_slash: UnappliedSlash<T::AccountId, BalanceOf<T>>) {
pub(crate) fn apply_slash<T: Config>(
unapplied_slash: UnappliedSlash<T::AccountId, BalanceOf<T>>,
slash_era: EraIndex,
) {
let mut slashed_imbalance = NegativeImbalanceOf::<T>::zero();
let mut reward_payout = unapplied_slash.payout;
@@ -637,10 +641,17 @@ pub(crate) fn apply_slash<T: Config>(unapplied_slash: UnappliedSlash<T::AccountI
unapplied_slash.own,
&mut reward_payout,
&mut slashed_imbalance,
slash_era,
);
for &(ref nominator, nominator_slash) in &unapplied_slash.others {
do_slash::<T>(&nominator, nominator_slash, &mut reward_payout, &mut slashed_imbalance);
do_slash::<T>(
&nominator,
nominator_slash,
&mut reward_payout,
&mut slashed_imbalance,
slash_era,
);
}
pay_reporters::<T>(reward_payout, slashed_imbalance, &unapplied_slash.reporters);