Remove Offence delay (#8414)

* Removed can_report api from OnOffenceHandler

* Removed DeferredOffences and create a storage migration

* Removed missing comments

* Mock set_deferred_offences and deferred_offences methods

* OnOffenceHandler::on_offence always succeed

* Fix benchmark tests

* Fix runtime-benchmark cfg methods

* Removed 'applied' attribute from Offence event

* refactor deprecated deferred offences getter

* Validate if offences are submited after on_runtime_upgrade

* update changelog

* Remove empty lines

* Fix remove_deferred_storage weights

* Remove Offence::on_runtime_upgrade benchmark

* Revert CHANGELOG.md update

* Deprecate DeferredOffenceOf type

* Update copyright

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

* Add migration logs

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

* Fix migration log

* Remove unused import

* Add migration tests

* rustfmt

* use generate_storage_alias! macro

* Refactor should_resubmit_deferred_offences test

* Replace spaces by tabs

* Refactor should_resubmit_deferred_offences test

* Removed WeightSoftLimit

* Removed WeightSoftLimit from tests and mocks

* Remove unused imports

* Apply suggestions from code review

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Lohann Paterno Coutinho Ferreira
2021-05-03 04:53:09 -03:00
committed by GitHub
parent c786fb21a0
commit ffca28ba59
13 changed files with 132 additions and 314 deletions
+4 -13
View File
@@ -2765,11 +2765,7 @@ where
>],
slash_fraction: &[Perbill],
slash_session: SessionIndex,
) -> Result<Weight, ()> {
if !Self::can_report() {
return Err(());
}
) -> Weight {
let reward_proportion = SlashRewardFraction::get();
let mut consumed_weight: Weight = 0;
let mut add_db_reads_writes = |reads, writes| {
@@ -2781,7 +2777,7 @@ where
add_db_reads_writes(1, 0);
if active_era.is_none() {
// this offence need not be re-submitted.
return Ok(consumed_weight)
return consumed_weight
}
active_era.expect("value checked not to be `None`; qed").index
};
@@ -2806,7 +2802,7 @@ where
match eras.iter().rev().filter(|&&(_, ref sesh)| sesh <= &slash_session).next() {
Some(&(ref slash_era, _)) => *slash_era,
// before bonding period. defensive - should be filtered out.
None => return Ok(consumed_weight),
None => return consumed_weight,
}
};
@@ -2874,12 +2870,7 @@ where
}
}
Ok(consumed_weight)
}
fn can_report() -> bool {
// TODO: https://github.com/paritytech/substrate/issues/8343
true
consumed_weight
}
}
+2 -2
View File
@@ -715,7 +715,7 @@ pub(crate) fn on_offence_in_era(
let bonded_eras = crate::BondedEras::get();
for &(bonded_era, start_session) in bonded_eras.iter() {
if bonded_era == era {
let _ = Staking::on_offence(offenders, slash_fraction, start_session).unwrap();
let _ = Staking::on_offence(offenders, slash_fraction, start_session);
return;
} else if bonded_era > era {
break;
@@ -728,7 +728,7 @@ pub(crate) fn on_offence_in_era(
offenders,
slash_fraction,
Staking::eras_start_session_index(era).unwrap()
).unwrap();
);
} else {
panic!("cannot slash in era {}", era);
}
+3 -3
View File
@@ -3510,7 +3510,7 @@ fn offences_weight_calculated_correctly() {
ExtBuilder::default().nominate(true).build_and_execute(|| {
// On offence with zero offenders: 4 Reads, 1 Write
let zero_offence_weight = <Test as frame_system::Config>::DbWeight::get().reads_writes(4, 1);
assert_eq!(Staking::on_offence(&[], &[Perbill::from_percent(50)], 0), Ok(zero_offence_weight));
assert_eq!(Staking::on_offence(&[], &[Perbill::from_percent(50)], 0), zero_offence_weight);
// On Offence with N offenders, Unapplied: 4 Reads, 1 Write + 4 Reads, 5 Writes
let n_offence_unapplied_weight = <Test as frame_system::Config>::DbWeight::get().reads_writes(4, 1)
@@ -3523,7 +3523,7 @@ fn offences_weight_calculated_correctly() {
reporters: vec![],
}
).collect();
assert_eq!(Staking::on_offence(&offenders, &[Perbill::from_percent(50)], 0), Ok(n_offence_unapplied_weight));
assert_eq!(Staking::on_offence(&offenders, &[Perbill::from_percent(50)], 0), n_offence_unapplied_weight);
// On Offence with one offenders, Applied
let one_offender = [
@@ -3544,7 +3544,7 @@ fn offences_weight_calculated_correctly() {
// `reward_cost` * reporters (1)
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(2, 2);
assert_eq!(Staking::on_offence(&one_offender, &[Perbill::from_percent(50)], 0), Ok(one_offence_unapplied_weight));
assert_eq!(Staking::on_offence(&one_offender, &[Perbill::from_percent(50)], 0), one_offence_unapplied_weight);
});
}