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
+3 -6
View File
@@ -213,10 +213,7 @@ impl<T: Config> Pallet<T> {
/// Update the ledger for a controller.
///
/// This will also update the stash lock.
pub(crate) fn update_ledger(
controller: &T::AccountId,
ledger: &StakingLedger<T::AccountId, BalanceOf<T>>,
) {
pub(crate) fn update_ledger(controller: &T::AccountId, ledger: &StakingLedger<T>) {
T::Currency::set_lock(STAKING_ID, &ledger.stash, ledger.total, WithdrawReasons::all());
<Ledger<T>>::insert(controller, ledger);
}
@@ -606,7 +603,7 @@ impl<T: Config> Pallet<T> {
for era in (*earliest)..keep_from {
let era_slashes = <Self as Store>::UnappliedSlashes::take(&era);
for slash in era_slashes {
slashing::apply_slash::<T>(slash);
slashing::apply_slash::<T>(slash, era);
}
}
@@ -1248,7 +1245,7 @@ where
unapplied.reporters = details.reporters.clone();
if slash_defer_duration == 0 {
// Apply right away.
slashing::apply_slash::<T>(unapplied);
slashing::apply_slash::<T>(unapplied, slash_era);
{
let slash_cost = (6, 5);
let reward_cost = (2, 2);
+21 -4
View File
@@ -75,8 +75,22 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config + SendTransactionTypes<Call<Self>> {
/// The staking balance.
type Currency: LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>;
type Currency: LockableCurrency<
Self::AccountId,
Moment = Self::BlockNumber,
Balance = Self::CurrencyBalance,
>;
/// Just the `Currency::Balance` type; we have this item to allow us to constrain it to
/// `From<u64>`.
type CurrencyBalance: sp_runtime::traits::AtLeast32BitUnsigned
+ codec::FullCodec
+ Copy
+ MaybeSerializeDeserialize
+ sp_std::fmt::Debug
+ Default
+ From<u64>
+ TypeInfo
+ MaxEncodedLen;
/// Time used for computing era duration.
///
/// It is guaranteed to start being called from the first `on_finalize`. Thus value at
@@ -177,6 +191,10 @@ pub mod pallet {
#[pallet::constant]
type MaxUnlockingChunks: Get<u32>;
/// A hook called when any staker is slashed. Mostly likely this can be a no-op unless
/// other pallets exist that are affected by slashing per-staker.
type OnStakerSlash: sp_staking::OnStakerSlash<Self::AccountId, BalanceOf<Self>>;
/// Some parameters of the benchmarking.
type BenchmarkingConfig: BenchmarkingConfig;
@@ -239,8 +257,7 @@ pub mod pallet {
/// Map from all (unlocked) "controller" accounts to the info regarding the staking.
#[pallet::storage]
#[pallet::getter(fn ledger)]
pub type Ledger<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger<T::AccountId, BalanceOf<T>>>;
pub type Ledger<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger<T>>;
/// Where the reward payment should be made. Keyed by stash.
#[pallet::storage]