Sim update overlay (#298)
* Update sim engine on timeout qc * Remove rebuild method
This commit is contained in:
parent
ef5935d572
commit
44367a15a5
|
@ -105,7 +105,6 @@ impl<O: Overlay> Carnot<O> {
|
|||
new_state.update_timeout_qc(timeout_qc.clone());
|
||||
|
||||
new_state.current_view = timeout_qc.view().next();
|
||||
new_state.overlay.rebuild(timeout_qc);
|
||||
|
||||
new_state
|
||||
}
|
||||
|
|
|
@ -50,10 +50,6 @@ where
|
|||
self.nodes.clone().into_iter().collect()
|
||||
}
|
||||
|
||||
fn rebuild(&mut self, _timeout_qc: crate::TimeoutQc) {
|
||||
// do nothing for now
|
||||
}
|
||||
|
||||
fn is_member_of_child_committee(&self, _parent: NodeId, _child: NodeId) -> bool {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ pub trait Overlay: Clone {
|
|||
|
||||
fn new(settings: Self::Settings) -> Self;
|
||||
fn root_committee(&self) -> Committee;
|
||||
fn rebuild(&mut self, timeout_qc: TimeoutQc);
|
||||
fn is_member_of_child_committee(&self, parent: NodeId, child: NodeId) -> bool;
|
||||
fn is_member_of_root_committee(&self, id: NodeId) -> bool;
|
||||
fn is_member_of_leaf_committee(&self, id: NodeId) -> bool;
|
||||
|
|
|
@ -57,10 +57,6 @@ where
|
|||
self.carnot_tree.root_committee().clone()
|
||||
}
|
||||
|
||||
fn rebuild(&mut self, _timeout_qc: crate::TimeoutQc) {
|
||||
// do nothing for now
|
||||
}
|
||||
|
||||
fn is_member_of_child_committee(&self, parent: NodeId, child: NodeId) -> bool {
|
||||
let child_parent = self.parent_committee(child);
|
||||
let parent = self.carnot_tree.committee_by_member_id(&parent);
|
||||
|
|
|
@ -344,21 +344,9 @@ impl<
|
|||
"receive block proposal",
|
||||
);
|
||||
match self.engine.receive_block(block.header().clone()) {
|
||||
Ok(new) => {
|
||||
Ok(mut new) => {
|
||||
if self.engine.current_view() != new.current_view() {
|
||||
// TODO: Refactor this into a method, use for timeout qc as well
|
||||
// new = new
|
||||
// .update_overlay(|overlay| {
|
||||
// let overlay = overlay
|
||||
// .update_leader_selection(|leader_selection| {
|
||||
// leader_selection.on_new_block_received(&block)
|
||||
// })
|
||||
// .expect("Leader selection update should succeed");
|
||||
// overlay.update_committees(|committee_membership| {
|
||||
// committee_membership.on_new_block_received(&block)
|
||||
// })
|
||||
// })
|
||||
// .unwrap_or(new);
|
||||
new = Self::update_overlay_with_block(new, &block);
|
||||
self.engine = new;
|
||||
}
|
||||
}
|
||||
|
@ -455,7 +443,8 @@ impl<
|
|||
timeout_view = %timeout_qc.view(),
|
||||
"receive timeout qc message"
|
||||
);
|
||||
self.engine = self.engine.receive_timeout_qc(timeout_qc);
|
||||
let new = self.engine.receive_timeout_qc(timeout_qc.clone());
|
||||
self.engine = Self::update_overlay_with_timeout_qc(new, &timeout_qc);
|
||||
}
|
||||
Event::RootTimeout { timeouts } => {
|
||||
tracing::debug!("root timeout {:?}", timeouts);
|
||||
|
@ -494,6 +483,39 @@ impl<
|
|||
self.handle_output(event);
|
||||
}
|
||||
}
|
||||
|
||||
fn update_overlay_with_block<Tx: Clone + Eq + Hash>(
|
||||
state: Carnot<O>,
|
||||
block: &nomos_core::block::Block<Tx>,
|
||||
) -> Carnot<O> {
|
||||
state
|
||||
.update_overlay(|overlay| {
|
||||
overlay
|
||||
.update_leader_selection(|leader_selection| {
|
||||
leader_selection.on_new_block_received(block)
|
||||
})
|
||||
.expect("Leader selection update should succeed")
|
||||
.update_committees(|committee_membership| {
|
||||
committee_membership.on_new_block_received(block)
|
||||
})
|
||||
})
|
||||
.unwrap_or(state)
|
||||
}
|
||||
|
||||
fn update_overlay_with_timeout_qc(state: Carnot<O>, qc: &TimeoutQc) -> Carnot<O> {
|
||||
state
|
||||
.update_overlay(|overlay| {
|
||||
overlay
|
||||
.update_leader_selection(|leader_selection| {
|
||||
leader_selection.on_timeout_qc_received(qc)
|
||||
})
|
||||
.expect("Leader selection update should succeed")
|
||||
.update_committees(|committee_membership| {
|
||||
committee_membership.on_timeout_qc_received(qc)
|
||||
})
|
||||
})
|
||||
.unwrap_or(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
|
|
Loading…
Reference in New Issue