-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Offence reporting returns a result #5082
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,14 +91,21 @@ pub trait Offence<Offender> { | |
) -> Perbill; | ||
} | ||
|
||
/// Errors that may happen on offence reports. | ||
#[derive(PartialEq, sp_runtime::RuntimeDebug)] | ||
pub enum OffenceError { | ||
/// The report has already been sumbmitted. | ||
DuplicateReport, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we at least want to have a variant that may takes a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will remind you on your next pr :P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, added it here |
||
} | ||
|
||
/// A trait for decoupling offence reporters from the actual handling of offence reports. | ||
pub trait ReportOffence<Reporter, Offender, O: Offence<Offender>> { | ||
/// Report an `offence` and reward given `reporters`. | ||
fn report_offence(reporters: Vec<Reporter>, offence: O); | ||
fn report_offence(reporters: Vec<Reporter>, offence: O) -> Result<(), OffenceError>; | ||
} | ||
|
||
impl<Reporter, Offender, O: Offence<Offender>> ReportOffence<Reporter, Offender, O> for () { | ||
fn report_offence(_reporters: Vec<Reporter>, _offence: O) {} | ||
fn report_offence(_reporters: Vec<Reporter>, _offence: O) -> Result<(), OffenceError> { Ok(()) } | ||
} | ||
|
||
/// A trait to take action on an offence. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this, it will never be printed (in wasm). This functionality is only for offchain workers (it requires that the
RuntimeLogger
is intialized). Better to just usesp_runtime::print
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the rest of the code in this module uses this format so I decided to keep it the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code you are referring too is offchain, that is the reason it uses this format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done