|
50 | 50 | //! Based on research at <https://research.web3.foundation/en/latest/polkadot/slashing/npos.html>
|
51 | 51 |
|
52 | 52 | use crate::{
|
53 |
| - asset, log, BalanceOf, Config, EraInfo, Error, NegativeImbalanceOf, NominatorSlashInEra, |
54 |
| - OffenceQueue, OffenceQueueEras, PagedExposure, Pallet, Perbill, ProcessingOffence, |
55 |
| - SlashRewardFraction, SpanSlash, UnappliedSlash, UnappliedSlashes, ValidatorSlashInEra, |
| 53 | + asset, log, BalanceOf, Config, EraInfo, Error, Exposure, NegativeImbalanceOf, |
| 54 | + NominatorSlashInEra, PagedExposure, Pallet, Perbill, SlashRewardFraction, SpanSlash, |
| 55 | + UnappliedSlash, UnappliedSlashes, ValidatorSlashInEra, |
56 | 56 | };
|
57 | 57 | use alloc::vec::Vec;
|
58 | 58 | use codec::{Decode, Encode, MaxEncodedLen};
|
@@ -284,8 +284,6 @@ pub(crate) fn compute_slash<T: Config>(
|
284 | 284 | }
|
285 | 285 | }
|
286 | 286 |
|
287 |
| - add_offending_validator::<T>(¶ms); |
288 |
| - |
289 | 287 | let mut nominators_slashed = Vec::new();
|
290 | 288 | reward_payout += slash_nominators::<T>(params.clone(), prior_slash_p, &mut nominators_slashed);
|
291 | 289 |
|
@@ -316,109 +314,6 @@ fn kick_out_if_recent<T: Config>(params: SlashParams<T>) {
|
316 | 314 | // Check https://github.com/paritytech/polkadot-sdk/issues/2650 for details
|
317 | 315 | spans.end_span(params.now);
|
318 | 316 | }
|
319 |
| - |
320 |
| - add_offending_validator::<T>(¶ms); |
321 |
| -} |
322 |
| - |
323 |
| -/// Inform the [`DisablingStrategy`] implementation about the new offender and disable the list of |
324 |
| -/// validators provided by [`decision`]. |
325 |
| -pub(crate) fn add_offending_validator<T: Config>( |
326 |
| - stash: &T::AccountId, |
327 |
| - slash: Perbill, |
328 |
| - offence_era: EraIndex, |
329 |
| -) { |
330 |
| - DisabledValidators::<T>::mutate(|disabled| { |
331 |
| - let new_severity = OffenceSeverity(slash); |
332 |
| - let decision = T::DisablingStrategy::decision(stash, new_severity, offence_era, &disabled); |
333 |
| - |
334 |
| - if let Some(offender_idx) = decision.disable { |
335 |
| - // Check if the offender is already disabled |
336 |
| - match disabled.binary_search_by_key(&offender_idx, |(index, _)| *index) { |
337 |
| - // Offender is already disabled, update severity if the new one is higher |
338 |
| - Ok(index) => { |
339 |
| - let (_, old_severity) = &mut disabled[index]; |
340 |
| - if new_severity > *old_severity { |
341 |
| - *old_severity = new_severity; |
342 |
| - } |
343 |
| - }, |
344 |
| - Err(index) => { |
345 |
| - // Offender is not disabled, add to `DisabledValidators` and disable it |
346 |
| - if disabled.try_insert(index, (offender_idx, new_severity)).defensive().is_ok() |
347 |
| - { |
348 |
| - // Propagate disablement to session level |
349 |
| - T::SessionInterface::disable_validator(offender_idx); |
350 |
| - // Emit event that a validator got disabled |
351 |
| - <Pallet<T>>::deposit_event(super::Event::<T>::ValidatorDisabled { |
352 |
| - stash: stash.clone(), |
353 |
| - }); |
354 |
| - } |
355 |
| - }, |
356 |
| - } |
357 |
| - } |
358 |
| - |
359 |
| - if let Some(reenable_idx) = decision.reenable { |
360 |
| - // Remove the validator from `DisabledValidators` and re-enable it. |
361 |
| - if let Ok(index) = disabled.binary_search_by_key(&reenable_idx, |(index, _)| *index) { |
362 |
| - disabled.remove(index); |
363 |
| - // Propagate re-enablement to session level |
364 |
| - T::SessionInterface::enable_validator(reenable_idx); |
365 |
| - // Emit event that a validator got re-enabled |
366 |
| - let reenabled_stash = |
367 |
| - T::SessionInterface::validators()[reenable_idx as usize].clone(); |
368 |
| - <Pallet<T>>::deposit_event(super::Event::<T>::ValidatorReenabled { |
369 |
| - stash: reenabled_stash, |
370 |
| - }); |
371 |
| - } |
372 |
| - } |
373 |
| - }); |
374 |
| - |
375 |
| - // `DisabledValidators` should be kept sorted |
376 |
| - debug_assert!(DisabledValidators::<T>::get().windows(2).all(|pair| pair[0] < pair[1])); |
377 |
| -} |
378 |
| - |
379 |
| -/// Compute the slash for a validator. Returns the amount slashed and the reward payout. |
380 |
| -fn slash_validator<T: Config>(params: SlashParams<T>) -> (BalanceOf<T>, BalanceOf<T>) { |
381 |
| - let own_slash = params.slash * params.exposure.exposure_metadata.own; |
382 |
| - log!( |
383 |
| - warn, |
384 |
| - "🦹 slashing validator {:?} of stake: {:?} with {:?}% for {:?} in era {:?}", |
385 |
| - params.stash, |
386 |
| - params.exposure.exposure_metadata.own, |
387 |
| - params.slash, |
388 |
| - own_slash, |
389 |
| - params.slash_era, |
390 |
| - ); |
391 |
| - |
392 |
| - if own_slash == Zero::zero() { |
393 |
| - // kick out the validator even if they won't be slashed, |
394 |
| - // as long as the misbehavior is from their most recent slashing span. |
395 |
| - kick_out_if_recent::<T>(params); |
396 |
| - return (Zero::zero(), Zero::zero()) |
397 |
| - } |
398 |
| - |
399 |
| - // apply slash to validator. |
400 |
| - let mut reward_payout = Zero::zero(); |
401 |
| - let mut val_slashed = Zero::zero(); |
402 |
| - |
403 |
| - { |
404 |
| - let mut spans = fetch_spans::<T>( |
405 |
| - params.stash, |
406 |
| - params.window_start, |
407 |
| - &mut reward_payout, |
408 |
| - &mut val_slashed, |
409 |
| - params.reward_proportion, |
410 |
| - ); |
411 |
| - |
412 |
| - let target_span = spans.compare_and_update_span_slash(params.slash_era, own_slash); |
413 |
| - |
414 |
| - if target_span == Some(spans.span_index()) { |
415 |
| - // misbehavior occurred within the current slashing span - end current span. |
416 |
| - // Check <https://github.com/paritytech/polkadot-sdk/issues/2650> for details. |
417 |
| - spans.end_span(params.now); |
418 |
| - } |
419 |
| - } |
420 |
| - |
421 |
| - (val_slashed, reward_payout) |
422 | 317 | }
|
423 | 318 |
|
424 | 319 | /// Slash nominators. Accepts general parameters and the prior slash percentage of the validator.
|
|
0 commit comments