Offence reporting returns a result (#5082)

* Offence reporting returns a result

* Bump spec_version

* Use unwrap instead of assertions

* Fix more review grumbles
This commit is contained in:
Fedor Sakharov
2020-03-02 13:00:38 +03:00
committed by GitHub
parent d7e4aa41b9
commit 8539b85c99
7 changed files with 51 additions and 22 deletions
+5 -3
View File
@@ -30,7 +30,7 @@ use frame_support::{
};
use sp_runtime::traits::Hash;
use sp_staking::{
offence::{Offence, ReportOffence, Kind, OnOffenceHandler, OffenceDetails},
offence::{Offence, ReportOffence, Kind, OnOffenceHandler, OffenceDetails, OffenceError},
};
use codec::{Encode, Decode};
use frame_system as system;
@@ -90,7 +90,7 @@ impl<T: Trait, O: Offence<T::IdentificationTuple>>
where
T::IdentificationTuple: Clone,
{
fn report_offence(reporters: Vec<T::AccountId>, offence: O) {
fn report_offence(reporters: Vec<T::AccountId>, offence: O) -> Result<(), OffenceError> {
let offenders = offence.offenders();
let time_slot = offence.time_slot();
let validator_set_count = offence.validator_set_count();
@@ -104,7 +104,7 @@ where
) {
Some(triage) => triage,
// The report contained only duplicates, so there is no need to slash again.
None => return,
None => return Err(OffenceError::DuplicateReport),
};
// Deposit the event.
@@ -123,6 +123,8 @@ where
&slash_perbill,
offence.session_index(),
);
Ok(())
}
}