Skip to content

Commit

Permalink
refactor(view_change): only send current and previous view change pro…
Browse files Browse the repository at this point in the history
…of (#4929)

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
  • Loading branch information
Erigara authored Sep 5, 2024
1 parent 995da4e commit 3e7a77e
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 91 deletions.
30 changes: 25 additions & 5 deletions core/src/sumeragi/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ impl Sumeragi {
})
{
should_sleep = false;
if let Err(error) = view_change_proof_chain.merge(
msg.view_change_proofs,
if let Err(error) = view_change_proof_chain.insert_proof(
msg.view_change_proof,
&self.topology,
latest_block,
) {
trace!(%error, "Failed to add proofs into view change proof chain")
trace!(%error, "Failed to add proof into view change proof chain")
}
} else {
break;
Expand Down Expand Up @@ -1135,8 +1135,28 @@ pub(crate) fn run(
.unwrap_or_else(|err| error!("{err}"));
}

let msg = ControlFlowMessage::new(view_change_proof_chain.clone());
sumeragi.broadcast_control_flow_packet(msg);
// If exist broadcast latest verified proof in case some peers missed it.
// Proof doesn't exist in case view_change_index == 0.
if let Some(latest_verified_proof) =
view_change_index
.checked_sub(1)
.and_then(|view_change_index| {
view_change_proof_chain.get_proof_for_view_change(view_change_index)
})
{
let msg = ControlFlowMessage::new(latest_verified_proof);
sumeragi.broadcast_control_flow_packet(msg);
}

// If exist broadcast proof for current view change index.
// Proof might not exist for example when view_change_time is up,
// but there is no transactions in the queue so there is nothing to complain about.
if let Some(proof_for_current_view_change_index) =
view_change_proof_chain.get_proof_for_view_change(view_change_index)
{
let msg = ControlFlowMessage::new(proof_for_current_view_change_index);
sumeragi.broadcast_control_flow_packet(msg);
}

// NOTE: View change must be periodically suggested until it is accepted.
// Must be initialized to pipeline time but can increase by chosen amount
Expand Down
6 changes: 3 additions & 3 deletions core/src/sumeragi/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ pub enum BlockMessage {
pub struct ControlFlowMessage {
/// Proof of view change. As part of this message handling, all
/// peers which agree with view change should sign it.
pub view_change_proofs: view_change::ProofChain,
pub view_change_proof: view_change::SignedViewChangeProof,
}

impl ControlFlowMessage {
/// Helper function to construct a `ControlFlowMessage`
pub fn new(view_change_proofs: view_change::ProofChain) -> ControlFlowMessage {
ControlFlowMessage { view_change_proofs }
pub fn new(view_change_proof: view_change::SignedViewChangeProof) -> ControlFlowMessage {
ControlFlowMessage { view_change_proof }
}
}

Expand Down
Loading

0 comments on commit 3e7a77e

Please sign in to comment.