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
+3 -100
View File
@@ -22,10 +22,9 @@
use super::*;
use crate::mock::{
Offences, System, Offence, Event, KIND, new_test_ext, with_on_offence_fractions,
offence_reports, set_can_report, set_offence_weight,
offence_reports,
};
use sp_runtime::Perbill;
use frame_support::traits::OnInitialize;
use frame_system::{EventRecord, Phase};
#[test]
@@ -132,7 +131,7 @@ fn should_deposit_event() {
System::events(),
vec![EventRecord {
phase: Phase::Initialization,
event: Event::offences(crate::Event::Offence(KIND, time_slot.encode(), true)),
event: Event::offences(crate::Event::Offence(KIND, time_slot.encode())),
topics: vec![],
}]
);
@@ -167,7 +166,7 @@ fn doesnt_deposit_event_for_dups() {
System::events(),
vec![EventRecord {
phase: Phase::Initialization,
event: Event::offences(crate::Event::Offence(KIND, time_slot.encode(), true)),
event: Event::offences(crate::Event::Offence(KIND, time_slot.encode())),
topics: vec![],
}]
);
@@ -285,99 +284,3 @@ fn should_properly_count_offences() {
);
});
}
#[test]
fn should_queue_and_resubmit_rejected_offence() {
new_test_ext().execute_with(|| {
set_can_report(false);
// will get deferred
let offence = Offence {
validator_set_count: 5,
time_slot: 42,
offenders: vec![5],
};
Offences::report_offence(vec![], offence).unwrap();
assert_eq!(Offences::deferred_offences().len(), 1);
// event also indicates unapplied.
assert_eq!(
System::events(),
vec![EventRecord {
phase: Phase::Initialization,
event: Event::offences(crate::Event::Offence(KIND, 42u128.encode(), false)),
topics: vec![],
}]
);
// will not dequeue
Offences::on_initialize(2);
// again
let offence = Offence {
validator_set_count: 5,
time_slot: 62,
offenders: vec![5],
};
Offences::report_offence(vec![], offence).unwrap();
assert_eq!(Offences::deferred_offences().len(), 2);
set_can_report(true);
// can be submitted
let offence = Offence {
validator_set_count: 5,
time_slot: 72,
offenders: vec![5],
};
Offences::report_offence(vec![], offence).unwrap();
assert_eq!(Offences::deferred_offences().len(), 2);
Offences::on_initialize(3);
assert_eq!(Offences::deferred_offences().len(), 0);
})
}
#[test]
fn weight_soft_limit_is_used() {
new_test_ext().execute_with(|| {
set_can_report(false);
// Only 2 can fit in one block
set_offence_weight(<mock::Runtime as Config>::WeightSoftLimit::get() / 2);
// Queue 3 offences
// #1
let offence = Offence {
validator_set_count: 5,
time_slot: 42,
offenders: vec![5],
};
Offences::report_offence(vec![], offence).unwrap();
// #2
let offence = Offence {
validator_set_count: 5,
time_slot: 62,
offenders: vec![5],
};
Offences::report_offence(vec![], offence).unwrap();
// #3
let offence = Offence {
validator_set_count: 5,
time_slot: 72,
offenders: vec![5],
};
Offences::report_offence(vec![], offence).unwrap();
// 3 are queued
assert_eq!(Offences::deferred_offences().len(), 3);
// Allow reporting
set_can_report(true);
Offences::on_initialize(3);
// Two are completed, one is left in the queue
assert_eq!(Offences::deferred_offences().len(), 1);
Offences::on_initialize(4);
// All are done now
assert_eq!(Offences::deferred_offences().len(), 0);
})
}