mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 16:51:02 +00:00
grandpa: minor cleanups in communication module (#6371)
* grandpa: replace Result<(), ()> with Option<()> * grandpa: replace &Option<T> with Option<&T> * grandpa: cleanup local id and keystore usages * grandpa: return bool on check_message_signature * grandpa: fix erroneous log message on startup * grandpa: fix test
This commit is contained in:
@@ -257,7 +257,7 @@ impl<H, N> Equivocation<H, N> {
|
||||
|
||||
/// Verifies the equivocation proof by making sure that both votes target
|
||||
/// different blocks and that its signatures are valid.
|
||||
pub fn check_equivocation_proof<H, N>(report: EquivocationProof<H, N>) -> Result<(), ()>
|
||||
pub fn check_equivocation_proof<H, N>(report: EquivocationProof<H, N>) -> bool
|
||||
where
|
||||
H: Clone + Encode + PartialEq,
|
||||
N: Clone + Encode + PartialEq,
|
||||
@@ -270,27 +270,27 @@ where
|
||||
if $equivocation.first.0.target_hash == $equivocation.second.0.target_hash &&
|
||||
$equivocation.first.0.target_number == $equivocation.second.0.target_number
|
||||
{
|
||||
return Err(());
|
||||
return false;
|
||||
}
|
||||
|
||||
// check signatures on both votes are valid
|
||||
check_message_signature(
|
||||
let valid_first = check_message_signature(
|
||||
&$message($equivocation.first.0),
|
||||
&$equivocation.identity,
|
||||
&$equivocation.first.1,
|
||||
$equivocation.round_number,
|
||||
report.set_id,
|
||||
)?;
|
||||
);
|
||||
|
||||
check_message_signature(
|
||||
let valid_second = check_message_signature(
|
||||
&$message($equivocation.second.0),
|
||||
&$equivocation.identity,
|
||||
&$equivocation.second.1,
|
||||
$equivocation.round_number,
|
||||
report.set_id,
|
||||
)?;
|
||||
);
|
||||
|
||||
return Ok(());
|
||||
return valid_first && valid_second;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ pub fn check_message_signature<H, N>(
|
||||
signature: &AuthoritySignature,
|
||||
round: RoundNumber,
|
||||
set_id: SetId,
|
||||
) -> Result<(), ()>
|
||||
) -> bool
|
||||
where
|
||||
H: Encode,
|
||||
N: Encode,
|
||||
@@ -351,7 +351,7 @@ pub fn check_message_signature_with_buffer<H, N>(
|
||||
round: RoundNumber,
|
||||
set_id: SetId,
|
||||
buf: &mut Vec<u8>,
|
||||
) -> Result<(), ()>
|
||||
) -> bool
|
||||
where
|
||||
H: Encode,
|
||||
N: Encode,
|
||||
@@ -360,20 +360,20 @@ where
|
||||
|
||||
localized_payload_with_buffer(round, set_id, message, buf);
|
||||
|
||||
if id.verify(&buf, signature) {
|
||||
Ok(())
|
||||
} else {
|
||||
let valid = id.verify(&buf, signature);
|
||||
|
||||
if !valid {
|
||||
#[cfg(feature = "std")]
|
||||
debug!(target: "afg", "Bad signature on message from {:?}", id);
|
||||
|
||||
Err(())
|
||||
}
|
||||
|
||||
valid
|
||||
}
|
||||
|
||||
/// Localizes the message to the given set and round and signs the payload.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn sign_message<H, N>(
|
||||
keystore: BareCryptoStorePtr,
|
||||
keystore: &BareCryptoStorePtr,
|
||||
message: grandpa::Message<H, N>,
|
||||
public: AuthorityId,
|
||||
round: RoundNumber,
|
||||
|
||||
Reference in New Issue
Block a user