Skip to content

Commit

Permalink
refactor(sumeragi): log incoming messages at trace level
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
  • Loading branch information
Erigara committed Sep 3, 2024
1 parent 91879da commit e63df38
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
20 changes: 11 additions & 9 deletions core/src/sumeragi/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,23 @@ impl Sumeragi {
})
.ok()?;

let block_vc_index = match &block_msg {
match &block_msg {
BlockMessage::BlockCreated(bc) => {
Some(bc.block.header().view_change_index as usize)
if (bc.block.header().view_change_index as usize) < current_view_change_index {
trace!(
ty="BlockCreated",
block=%bc.block.hash(),
"Discarding message due to outdated view change index",
);
// ignore block_message
continue;
}
}
// Signed and Committed contain no block.
// Block sync updates are exempt from early pruning.
BlockMessage::BlockSigned(_)
| BlockMessage::BlockCommitted(_)
| BlockMessage::BlockSyncUpdate(_) => None,
};
if let Some(block_vc_index) = block_vc_index {
if block_vc_index < current_view_change_index {
// ignore block_message
continue;
}
| BlockMessage::BlockSyncUpdate(_) => {}
}
return Some(block_msg);
}
Expand Down
15 changes: 14 additions & 1 deletion core/src/sumeragi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct SumeragiHandle {
impl SumeragiHandle {
/// Deposit a sumeragi control flow network message.
pub fn incoming_control_flow_message(&self, msg: ControlFlowMessage) {
trace!(ty = "ViewChangeProofChain", "Incoming message");
if let Err(error) = self.control_message_sender.try_send(msg) {
self.dropped_messages_metric.inc();

Expand All @@ -59,7 +60,19 @@ impl SumeragiHandle {

/// Deposit a sumeragi network message.
pub fn incoming_block_message(&self, msg: impl Into<BlockMessage>) {
if let Err(error) = self.message_sender.try_send(msg.into()) {
let msg = msg.into();
let (ty, block) = match &msg {
BlockMessage::BlockCommitted(BlockCommitted { hash, .. }) => ("BlockCommitted", *hash),
BlockMessage::BlockCreated(BlockCreated { block }) => ("BlockCreated", block.hash()),
BlockMessage::BlockSigned(BlockSigned { hash, .. }) => ("BlockSigned", *hash),
BlockMessage::BlockSyncUpdate(BlockSyncUpdate { block }) => {
trace!(ty="BlockSyncUpdate", block=%block.hash(), "Incoming message");
("BlockSyncUpdate", block.hash())
}
};
trace!(ty, %block, "Incoming message");

if let Err(error) = self.message_sender.try_send(msg) {
self.dropped_messages_metric.inc();

error!(
Expand Down
5 changes: 3 additions & 2 deletions core/src/sumeragi/view_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ pub enum Error {
ViewChangeNotFound,
}

#[derive(Debug, Clone, Decode, Encode)]
struct ViewChangeProofPayload {
/// Payload of view change.
#[derive(Debug, Clone, Copy, Decode, Encode)]
pub struct ViewChangeProofPayload {
/// Hash of the latest committed block.
latest_block: HashOf<BlockHeader>,
/// Within a round, what is the index of the view change this proof is trying to prove.
Expand Down

0 comments on commit e63df38

Please sign in to comment.