Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(view_change): only send current and previous view change proof #4929

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading