Skip to content

Commit

Permalink
Satisfy clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
woocash2 committed Jul 25, 2023
1 parent e411f32 commit 15c95c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
43 changes: 17 additions & 26 deletions consensus/src/alerts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ type NetworkAlert<H, D, MK> = Option<(
<H as Hasher>::Hash,
)>;

type OnOwnAlertResult<H, D, MK> = (
AlertMessage<H, D, <MK as Keychain>::Signature, <MK as MultiKeychain>::PartialMultisignature>,
Recipient,
<H as Hasher>::Hash,
);

impl<'a, H: Hasher, D: Data, MK: MultiKeychain> Alerter<'a, H, D, MK> {
fn new(keychain: &'a MK, config: AlertConfig) -> Self {
Self {
Expand Down Expand Up @@ -290,14 +296,7 @@ impl<'a, H: Hasher, D: Data, MK: MultiKeychain> Alerter<'a, H, D, MK> {
}

/// `on_own_alert()` registers RMCs and messages but does not actually send them; make sure the returned values are forwarded to IO
fn on_own_alert(
&mut self,
alert: Alert<H, D, MK::Signature>,
) -> (
AlertMessage<H, D, MK::Signature, MK::PartialMultisignature>,
Recipient,
H::Hash,
) {
fn on_own_alert(&mut self, alert: Alert<H, D, MK::Signature>) -> OnOwnAlertResult<H, D, MK> {
let forker = alert.forker();
self.known_forkers.insert(forker, alert.proof.clone());
let alert = Signed::sign(alert, self.keychain);
Expand Down Expand Up @@ -627,7 +626,7 @@ mod tests {
},
);
let fork_proof = make_fork_proof(forker_index, &forker_keychain, 0, n_members);
let alert = Alert::new(alerter_index, fork_proof.clone(), vec![]);
let alert = Alert::new(alerter_index, fork_proof, vec![]);
let alert_hash = Signable::hash(&alert);
let signed_alert_hash =
Signed::sign_with_index(alert_hash, &alerter_keychain).into_unchecked();
Expand Down Expand Up @@ -665,7 +664,7 @@ mod tests {
)
.into_unchecked();
let wrong_fork_proof = (valid_unit.clone(), valid_unit);
let wrong_alert = Alert::new(forker_index, wrong_fork_proof.clone(), vec![]);
let wrong_alert = Alert::new(forker_index, wrong_fork_proof, vec![]);
let signed_wrong_alert = Signed::sign(wrong_alert, &forker_keychain).into_unchecked();
assert_eq!(
this.on_message(AlertMessage::ForkAlert(signed_wrong_alert)),
Expand Down Expand Up @@ -693,7 +692,7 @@ mod tests {
vec![],
);
let alert_hash = Signable::hash(&alert);
let signed_alert = Signed::sign(alert.clone(), &own_keychain).into_unchecked();
let signed_alert = Signed::sign(alert, &own_keychain).into_unchecked();
this.on_message(AlertMessage::ForkAlert(signed_alert.clone()));
for i in 1..n_members.0 {
let node_id = NodeIndex(i);
Expand Down Expand Up @@ -728,7 +727,7 @@ mod tests {
let empty_alert = Alert::new(double_committer, fork_proof.clone(), vec![]);
let empty_alert_hash = Signable::hash(&empty_alert);
let signed_empty_alert =
Signed::sign(empty_alert.clone(), &keychains[double_committer.0]).into_unchecked();
Signed::sign(empty_alert, &keychains[double_committer.0]).into_unchecked();
let signed_empty_alert_hash =
Signed::sign_with_index(empty_alert_hash, &keychains[double_committer.0])
.into_unchecked();
Expand All @@ -749,14 +748,10 @@ mod tests {
Some(AlerterResponse::RmcMessage(message)),
);
let forker_unit = fork_proof.0.clone();
let nonempty_alert = Alert::new(
double_committer,
fork_proof.clone(),
vec![forker_unit.clone()],
);
let nonempty_alert = Alert::new(double_committer, fork_proof, vec![forker_unit]);
let nonempty_alert_hash = Signable::hash(&nonempty_alert);
let signed_nonempty_alert =
Signed::sign(nonempty_alert.clone(), &keychains[double_committer.0]).into_unchecked();
Signed::sign(nonempty_alert, &keychains[double_committer.0]).into_unchecked();
let signed_nonempty_alert_hash =
Signed::sign_with_index(nonempty_alert_hash, &keychains[double_committer.0])
.into_unchecked();
Expand Down Expand Up @@ -808,7 +803,7 @@ mod tests {
let empty_alert = Alert::new(double_committer, fork_proof.clone(), vec![]);
let empty_alert_hash = Signable::hash(&empty_alert);
let signed_empty_alert =
Signed::sign(empty_alert.clone(), &keychains[double_committer.0]).into_unchecked();
Signed::sign(empty_alert, &keychains[double_committer.0]).into_unchecked();
assert_eq!(
this.on_message(AlertMessage::ForkAlert(signed_empty_alert)),
Some(AlerterResponse::ForkResponse(
Expand All @@ -817,14 +812,10 @@ mod tests {
)),
);
let forker_unit = fork_proof.0.clone();
let nonempty_alert = Alert::new(
double_committer,
fork_proof.clone(),
vec![forker_unit.clone()],
);
let nonempty_alert = Alert::new(double_committer, fork_proof, vec![forker_unit]);
let nonempty_alert_hash = Signable::hash(&nonempty_alert);
let signed_nonempty_alert =
Signed::sign(nonempty_alert.clone(), &keychains[double_committer.0]).into_unchecked();
Signed::sign(nonempty_alert, &keychains[double_committer.0]).into_unchecked();
let signed_nonempty_alert_hash =
Signed::sign_with_index(nonempty_alert_hash, &keychains[double_committer.0])
.into_unchecked();
Expand Down Expand Up @@ -976,7 +967,7 @@ mod tests {
let signed_unit_1 = Signed::sign(unit_1, &keychains[forker_index.0]).into_unchecked();
(signed_unit_0, signed_unit_1)
};
let alert = Alert::new(own_index, fork_proof.clone(), vec![]);
let alert = Alert::new(own_index, fork_proof, vec![]);
let alert_hash = Signable::hash(&alert);
let signed_alert = Signed::sign(alert, &keychains[own_index.0]).into_unchecked();
if make_known {
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/runway/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ mod tests {
let (preunit, _) = creator.create_unit(0).expect("Creation should succeed.");
let unit = preunit_to_unchecked_signed_unit(preunit, wrong_session_id, keychain);
let responses = create_responses(
keychains.iter().skip(1).zip(repeat(Some(unit.clone()))),
keychains.iter().skip(1).zip(repeat(Some(unit))),
salt,
creator_id,
);
Expand Down Expand Up @@ -560,7 +560,7 @@ mod tests {
let (preunit, _) = creator.create_unit(0).expect("Creation should succeed.");
let unit = preunit_to_unchecked_signed_unit(preunit, session_id, &keychains[1]);
let responses = create_responses(
keychains.iter().skip(1).zip(repeat(Some(unit.clone()))),
keychains.iter().skip(1).zip(repeat(Some(unit))),
salt,
creator_id,
);
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/units/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ mod tests {
};
use aleph_bft_mock::{Data, Hasher64, Keychain};

fn create_unit<'a>(
fn create_unit(
round: Round,
node_idx: NodeIndex,
count: NodeCount,
Expand Down

0 comments on commit 15c95c3

Please sign in to comment.