Process single events (#267)

This commit is contained in:
Daniel Sanchez 2023-07-20 10:08:09 +02:00 committed by GitHub
parent adf935830e
commit 0866dfc8af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 13 deletions

View File

@ -346,7 +346,7 @@ impl<L: UpdateableLeaderSelection, O: Overlay<LeaderSelection = L>> Node for Car
.step(current_view_messages, &self.engine, elapsed); .step(current_view_messages, &self.engine, elapsed);
for event in events { for event in events {
let mut output: Vec<Output<CarnotTx>> = vec![]; let mut output = None;
match event { match event {
Event::Proposal { block } => { Event::Proposal { block } => {
let current_view = self.engine.current_view(); let current_view = self.engine.current_view();
@ -378,7 +378,7 @@ impl<L: UpdateableLeaderSelection, O: Overlay<LeaderSelection = L>> Node for Car
} }
if self.engine.overlay().is_member_of_leaf_committee(self.id) { if self.engine.overlay().is_member_of_leaf_committee(self.id) {
output.push(Output::Send(consensus_engine::Send { output = Some(Output::Send(consensus_engine::Send {
to: self.engine.parent_committee(), to: self.engine.parent_committee(),
payload: Payload::Vote(Vote { payload: Payload::Vote(Vote {
view: self.engine.current_view(), view: self.engine.current_view(),
@ -400,11 +400,11 @@ impl<L: UpdateableLeaderSelection, O: Overlay<LeaderSelection = L>> Node for Car
); );
let (new, out) = self.engine.approve_block(block); let (new, out) = self.engine.approve_block(block);
tracing::info!(vote=?out, node=%self.id); tracing::info!(vote=?out, node=%self.id);
output = vec![Output::Send(out)]; output = Some(Output::Send(out));
self.engine = new; self.engine = new;
} }
Event::ProposeBlock { qc } => { Event::ProposeBlock { qc } => {
output = vec![Output::BroadcastProposal { output = Some(Output::BroadcastProposal {
proposal: nomos_core::block::Block::new( proposal: nomos_core::block::Block::new(
qc.view().next(), qc.view().next(),
qc.clone(), qc.clone(),
@ -415,7 +415,7 @@ impl<L: UpdateableLeaderSelection, O: Overlay<LeaderSelection = L>> Node for Car
&self.random_beacon_pk, &self.random_beacon_pk,
), ),
), ),
}] });
} }
// This branch means we already get enough new view msgs for this qc // This branch means we already get enough new view msgs for this qc
// So we can just call approve_new_view // So we can just call approve_new_view
@ -430,7 +430,7 @@ impl<L: UpdateableLeaderSelection, O: Overlay<LeaderSelection = L>> Node for Car
"receive new view message" "receive new view message"
); );
let (new, out) = self.engine.approve_new_view(timeout_qc.clone(), new_views); let (new, out) = self.engine.approve_new_view(timeout_qc.clone(), new_views);
output.push(Output::Send(out)); output = Some(Output::Send(out));
self.engine = new; self.engine = new;
} }
Event::TimeoutQc { timeout_qc } => { Event::TimeoutQc { timeout_qc } => {
@ -460,7 +460,7 @@ impl<L: UpdateableLeaderSelection, O: Overlay<LeaderSelection = L>> Node for Car
high_qc, high_qc,
self.id(), self.id(),
); );
output.push(Output::BroadcastTimeoutQc { timeout_qc }); output = Some(Output::BroadcastTimeoutQc { timeout_qc });
} }
} }
Event::LocalTimeout => { Event::LocalTimeout => {
@ -471,18 +471,15 @@ impl<L: UpdateableLeaderSelection, O: Overlay<LeaderSelection = L>> Node for Car
); );
let (new, out) = self.engine.local_timeout(); let (new, out) = self.engine.local_timeout();
self.engine = new; self.engine = new;
if let Some(out) = out { output = out.map(Output::Send);
output.push(Output::Send(out));
}
} }
Event::None => { Event::None => {
tracing::error!("unimplemented none branch"); tracing::error!("unimplemented none branch");
unreachable!("none event will never be constructed") unreachable!("none event will never be constructed")
} }
} }
if let Some(event) = output {
for output_event in output { self.handle_output(event);
self.handle_output(output_event);
} }
} }