mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 13:57:58 +00:00
Offences Weight for OnInitialize (#5961)
* Weight accounting for on_offence. * Try to compute weight. * Guesstimate upper bounds on db read/writes for slashing * greater than or equal to * add new trait * Update mock.rs * Add basic weight test * one more test * Update frame/staking/src/lib.rs Co-authored-by: thiolliere <gui.thiolliere@gmail.com> * Update frame/staking/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Add test for offences queue Co-authored-by: Tomasz Drwięga <tomasz@parity.io> Co-authored-by: thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
use super::*;
|
||||
use crate::mock::{
|
||||
Offences, System, Offence, TestEvent, KIND, new_test_ext, with_on_offence_fractions,
|
||||
offence_reports, set_can_report,
|
||||
offence_reports, set_can_report, set_offence_weight,
|
||||
};
|
||||
use sp_runtime::Perbill;
|
||||
use frame_support::traits::OnInitialize;
|
||||
@@ -265,3 +265,48 @@ fn should_queue_and_resubmit_rejected_offence() {
|
||||
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 Trait>::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);
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user