Skip to content

Commit 1e9f768

Browse files
Erigaramversic
authored andcommitted
refactor(view_change): only send current and previous view change proof
Signed-off-by: Shanin Roman <[email protected]>
1 parent a348b85 commit 1e9f768

File tree

3 files changed

+294
-91
lines changed

3 files changed

+294
-91
lines changed

core/src/sumeragi/main_loop.rs

+25-5
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ impl Sumeragi {
138138
})
139139
{
140140
should_sleep = false;
141-
if let Err(error) = view_change_proof_chain.merge(
142-
msg.view_change_proofs,
141+
if let Err(error) = view_change_proof_chain.insert_proof(
142+
msg.view_change_proof,
143143
&self.topology,
144144
latest_block,
145145
) {
146-
trace!(%error, "Failed to add proofs into view change proof chain")
146+
trace!(%error, "Failed to add proof into view change proof chain")
147147
}
148148
} else {
149149
break;
@@ -1135,8 +1135,28 @@ pub(crate) fn run(
11351135
.unwrap_or_else(|err| error!("{err}"));
11361136
}
11371137

1138-
let msg = ControlFlowMessage::new(view_change_proof_chain.clone());
1139-
sumeragi.broadcast_control_flow_packet(msg);
1138+
// If exist broadcast latest verified proof in case some peers missed it.
1139+
// Proof doesn't exist in case view_change_index == 0.
1140+
if let Some(latest_verified_proof) =
1141+
view_change_index
1142+
.checked_sub(1)
1143+
.and_then(|view_change_index| {
1144+
view_change_proof_chain.get_proof_for_view_change(view_change_index)
1145+
})
1146+
{
1147+
let msg = ControlFlowMessage::new(latest_verified_proof);
1148+
sumeragi.broadcast_control_flow_packet(msg);
1149+
}
1150+
1151+
// If exist broadcast proof for current view change index.
1152+
// Proof might not exist for example when view_change_time is up,
1153+
// but there is no transactions in the queue so there is nothing to complain about.
1154+
if let Some(proof_for_current_view_change_index) =
1155+
view_change_proof_chain.get_proof_for_view_change(view_change_index)
1156+
{
1157+
let msg = ControlFlowMessage::new(proof_for_current_view_change_index);
1158+
sumeragi.broadcast_control_flow_packet(msg);
1159+
}
11401160

11411161
// NOTE: View change must be periodically suggested until it is accepted.
11421162
// Must be initialized to pipeline time but can increase by chosen amount

core/src/sumeragi/message.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ pub enum BlockMessage {
2626
pub struct ControlFlowMessage {
2727
/// Proof of view change. As part of this message handling, all
2828
/// peers which agree with view change should sign it.
29-
pub view_change_proofs: view_change::ProofChain,
29+
pub view_change_proof: view_change::SignedViewChangeProof,
3030
}
3131

3232
impl ControlFlowMessage {
3333
/// Helper function to construct a `ControlFlowMessage`
34-
pub fn new(view_change_proofs: view_change::ProofChain) -> ControlFlowMessage {
35-
ControlFlowMessage { view_change_proofs }
34+
pub fn new(view_change_proof: view_change::SignedViewChangeProof) -> ControlFlowMessage {
35+
ControlFlowMessage { view_change_proof }
3636
}
3737
}
3838

0 commit comments

Comments
 (0)