mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 01:11:04 +00:00
grandpa: missing equivocation reporting nits (#5953)
* primitives: move reporting key type to common key types * session: remove useless methods on MembershipProof * grandpa: remove std special-casing when checking signatures * grandpa: add some more docs * grandpa: use proper error types rather than strings
This commit is contained in:
@@ -29,6 +29,12 @@
|
||||
//! And in a runtime context, so that the GRANDPA module can validate the
|
||||
//! equivocation proofs in the extrinsic and report the offences.
|
||||
//!
|
||||
//! IMPORTANT:
|
||||
//! When using this module for enabling equivocation reporting it is required
|
||||
//! that the `ValidateEquivocationReport` signed extension is used in the runtime
|
||||
//! definition. Failure to do so will allow invalid equivocation reports to be
|
||||
//! accepted by the runtime.
|
||||
//!
|
||||
|
||||
use sp_std::prelude::*;
|
||||
|
||||
@@ -395,12 +401,12 @@ impl GetValidatorCount for frame_support::Void {
|
||||
|
||||
impl GetSessionNumber for sp_session::MembershipProof {
|
||||
fn session(&self) -> SessionIndex {
|
||||
self.session()
|
||||
self.session
|
||||
}
|
||||
}
|
||||
|
||||
impl GetValidatorCount for sp_session::MembershipProof {
|
||||
fn validator_count(&self) -> sp_session::ValidatorCount {
|
||||
self.validator_count()
|
||||
self.validator_count
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +184,10 @@ decl_error! {
|
||||
ChangePending,
|
||||
/// Cannot signal forced change so soon after last.
|
||||
TooSoon,
|
||||
/// A key ownership proof provided as part of an equivocation report is invalid.
|
||||
InvalidKeyOwnershipProof,
|
||||
/// A given equivocation report is valid but already previously reported.
|
||||
DuplicateOffenceReport,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,8 +232,9 @@ decl_module! {
|
||||
/// against the extracted offender. If both are valid, the offence
|
||||
/// will be reported.
|
||||
///
|
||||
/// Since the weight is 0 in order to avoid DoS pre-validation is implemented in a
|
||||
/// `SignedExtension`.
|
||||
/// Since the weight of the extrinsic is 0, in order to avoid DoS by
|
||||
/// submission of invalid equivocation reports, a mandatory pre-validation of
|
||||
/// the extrinsic is implemented in a `SignedExtension`.
|
||||
#[weight = 0]
|
||||
fn report_equivocation(
|
||||
origin,
|
||||
@@ -249,7 +254,7 @@ decl_module! {
|
||||
T::KeyOwnerProofSystem::check_proof(
|
||||
(fg_primitives::KEY_TYPE, equivocation_proof.offender().clone()),
|
||||
key_owner_proof,
|
||||
).ok_or("Invalid key ownership proof.")?;
|
||||
).ok_or(Error::<T>::InvalidKeyOwnershipProof)?;
|
||||
|
||||
// the set id and round when the offence happened
|
||||
let set_id = equivocation_proof.set_id();
|
||||
@@ -265,7 +270,7 @@ decl_module! {
|
||||
set_id,
|
||||
round,
|
||||
),
|
||||
).map_err(|_| "Duplicate offence report.")?;
|
||||
).map_err(|_| Error::<T>::DuplicateOffenceReport)?;
|
||||
}
|
||||
|
||||
fn on_finalize(block_number: T::BlockNumber) {
|
||||
@@ -440,9 +445,9 @@ impl<T: Trait> Module<T> {
|
||||
Self::set_grandpa_authorities(authorities);
|
||||
}
|
||||
|
||||
// NOTE: initialize first session of first set. this is necessary
|
||||
// because we only update this `on_new_session` which isn't called
|
||||
// for the genesis session.
|
||||
// NOTE: initialize first session of first set. this is necessary for
|
||||
// the genesis set and session since we only update the set -> session
|
||||
// mapping whenever a new session starts, i.e. through `on_new_session`.
|
||||
SetIdSession::insert(0, 0);
|
||||
}
|
||||
|
||||
@@ -454,10 +459,7 @@ impl<T: Trait> Module<T> {
|
||||
equivocation_proof: EquivocationProof<T::Hash, T::BlockNumber>,
|
||||
key_owner_proof: T::KeyOwnerProof,
|
||||
) -> Option<()> {
|
||||
T::HandleEquivocation::submit_equivocation_report(equivocation_proof, key_owner_proof)
|
||||
.ok()?;
|
||||
|
||||
Some(())
|
||||
T::HandleEquivocation::submit_equivocation_report(equivocation_proof, key_owner_proof).ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user