From c5e531b16132d400d330e4899cb72519f9393b8a Mon Sep 17 00:00:00 2001 From: mjalalzai <33738574+MForensic@users.noreply.github.com> Date: Sun, 15 Oct 2023 16:45:00 -0700 Subject: [PATCH] Building timeout QC --- carnot/carnot-vote-aggregation.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/carnot/carnot-vote-aggregation.py b/carnot/carnot-vote-aggregation.py index 578e56b..5f7cc37 100644 --- a/carnot/carnot-vote-aggregation.py +++ b/carnot/carnot-vote-aggregation.py @@ -488,3 +488,29 @@ def rebuild_overlay_from_timeout_qc(self, timeout_qc: TimeoutQc): # Rebuild the overlay from scratch self.overlay = Overlay() + + +@staticmethod +def build_timeout_qc(msgs: Set[Timeout], sender: Id) -> TimeoutQc: + # Convert the set of Timeout messages to a list + msgs_list = list(msgs) + + # Extract the view and high QC from the list of messages + view = msgs_list[0].view + high_qc_list = [msg.high_qc for msg in msgs_list] + + # Find the highest high QC using the max function + high_qc = max(high_qc_list, key=lambda x: x.view) + + # Extract the QC views and sender IDs + qc_views = [msg.view for msg in msgs_list] + sender_ids = {msg.sender for msg in msgs_list} + + # Build the TimeoutQc object + return TimeoutQc( + view=view, + high_qc=high_qc, + qc_views=qc_views, + sender_ids=sender_ids, + sender=sender + )