Skip to content

Commit

Permalink
Make logs less noisy
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Jun 24, 2024
1 parent 631ac30 commit cac97f1
Showing 1 changed file with 77 additions and 15 deletions.
92 changes: 77 additions & 15 deletions code/crates/actors/src/consensus.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::btree_map::Entry;
use std::collections::{BTreeMap, BTreeSet, VecDeque};
use std::fmt::Display;
use std::fmt;
use std::sync::Arc;

use async_trait::async_trait;
Expand Down Expand Up @@ -231,10 +231,11 @@ where

let validator_address = signed_vote.validator_address();

info!(%from, %validator_address, "Received vote: {:?}", signed_vote.vote);
info!(%from, validator = %validator_address, "Received vote: {}", PrettyVote::<Ctx>(&signed_vote.vote));

if signed_vote.vote.height() != state.driver.height() {
warn!(
%from, validator = %validator_address,
"Ignoring vote for height {}, current height: {}",
signed_vote.vote.height(),
state.driver.height()
Expand All @@ -244,15 +245,23 @@ where
}

let Some(validator) = state.validator_set.get_by_address(validator_address) else {
warn!(%from, %validator_address, "Received vote from unknown validator");
warn!(
%from, validator = %validator_address,
"Received vote from unknown validator"
);

return Ok(());
};

if !self
.ctx
.verify_signed_vote(&signed_vote, validator.public_key())
{
warn!(%from, %validator_address, "Received invalid vote: {signed_vote:?}");
warn!(
%from, validator = %validator_address,
"Received invalid vote: {}", PrettyVote::<Ctx>(&signed_vote.vote)
);

return Ok(());
}

Expand All @@ -272,13 +281,12 @@ where
return Ok(());
};

let validator_address = signed_proposal.proposal.validator_address();
let validator = signed_proposal.proposal.validator_address();

info!(%from, %validator_address, "Received proposal: (h: {}, r: {}, id: {:?})",
signed_proposal.proposal.height(), signed_proposal.proposal.round(), signed_proposal.proposal.value().id());
info!(%from, %validator, "Received proposal: {}", PrettyProposal::<Ctx>(&signed_proposal.proposal));

let Some(validator) = state.validator_set.get_by_address(validator_address) else {
warn!(%from, %validator_address, "Received proposal from unknown validator");
let Some(validator) = state.validator_set.get_by_address(validator) else {
warn!(%from, %validator, "Received proposal from unknown validator");
return Ok(());
};

Expand Down Expand Up @@ -309,8 +317,8 @@ where
.verify_signed_proposal(&signed_proposal, validator.public_key())
{
error!(
"Received invalid signature for proposal ({proposal_height}, {proposal_round}, {:?}",
proposal.value()
"Received invalid signature for proposal: {}",
PrettyProposal::<Ctx>(&signed_proposal.proposal)
);

return Ok(());
Expand Down Expand Up @@ -359,7 +367,7 @@ where
.ctx
.verify_signed_block_part(&signed_block_part, validator.public_key())
{
warn!(%from, %validator_address, "Received invalid block part: {signed_block_part:?}");
warn!(%from, validator = %validator_address, "Received invalid block part: {signed_block_part:?}");
return Ok(());
}

Expand Down Expand Up @@ -567,9 +575,9 @@ where

DriverOutput::Vote(vote) => {
info!(
"Voting {:?} for value {:?} at round {}",
"Voting {:?} for value {} at round {}",
vote.vote_type(),
vote.value(),
PrettyVal(vote.value().as_ref()),
vote.round()
);

Expand Down Expand Up @@ -699,7 +707,7 @@ where
impl<Ctx> Actor for Consensus<Ctx>
where
Ctx: Context,
Ctx::Height: Display,
Ctx::Height: fmt::Display,
Ctx::Vote: Protobuf<Proto = proto::Vote>,
Ctx::Proposal: Protobuf<Proto = proto::Proposal>,
Ctx::BlockPart: Protobuf<Proto = proto::BlockPart>,
Expand Down Expand Up @@ -969,3 +977,57 @@ where
Ok(())
}
}

struct PrettyVal<'a, T>(NilOrVal<&'a T>);

impl<T> fmt::Display for PrettyVal<'_, T>
where
T: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.0 {
NilOrVal::Nil => "Nil".fmt(f),
NilOrVal::Val(v) => v.fmt(f),
}
}
}

struct PrettyVote<'a, Ctx: Context>(&'a Ctx::Vote);

impl<Ctx> fmt::Display for PrettyVote<'_, Ctx>
where
Ctx: Context,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use malachite_common::Vote;

write!(
f,
"{:?} at height {}, round {}, for value {}, from {}",
self.0.vote_type(),
self.0.height(),
self.0.round(),
PrettyVal(self.0.value().as_ref()),
self.0.validator_address()
)
}
}

struct PrettyProposal<'a, Ctx: Context>(&'a Ctx::Proposal);

impl<Ctx> fmt::Display for PrettyProposal<'_, Ctx>
where
Ctx: Context,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Proposal at height {}, round {}, POL round {}, for value {}, from {}",
self.0.height(),
self.0.round(),
self.0.pol_round(),
self.0.value().id(),
self.0.validator_address()
)
}
}

0 comments on commit cac97f1

Please sign in to comment.