From aeb83ce2e8d17d3a066f42f3128e87866b484081 Mon Sep 17 00:00:00 2001 From: mjalalzai <33738574+MForensic@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:31:54 -0700 Subject: [PATCH] update fixing Event and add Approve Block --- carnot/carnot-vote-aggregation.py | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/carnot/carnot-vote-aggregation.py b/carnot/carnot-vote-aggregation.py index b815b8f..9f26430 100644 --- a/carnot/carnot-vote-aggregation.py +++ b/carnot/carnot-vote-aggregation.py @@ -116,7 +116,7 @@ class Send: payload: Payload -TypeAlias = Union[BroadCast, Send] +Event: TypeAlias = Union[BroadCast, Send] class Overlay: @@ -303,3 +303,33 @@ class Carnot: self.safe_blocks[block.id()] = block self.update_high_qc(block.qc) + def approve_block(self, block: Block, votes: Set[Vote]) -> Event: + # Assertions for input validation + assert block.id() in self.safe_blocks + assert len(votes) == self.overlay.super_majority_threshold(self.id) + assert all(self.overlay.is_member_of_child_committee(self.id, vote.voter) for vote in votes) + assert all(vote.block == block.id() for vote in votes) + assert self.highest_voted_view < block.view + + # Create a QC based on committee membership + qc = self.build_qc(block.view, block, None) if self.overlay.is_member_of_root_committee(self.id) else None + + # Create a new vote + vote = Vote( + block=block.id(), + voter=self.id, + view=block.view, + qc=qc + ) + + # Update the highest voted view + self.highest_voted_view = max(self.highest_voted_view, block.view) + + # Determine the recipient based on committee membership + if self.overlay.is_member_of_root_committee(self.id): + recipient = self.overlay.leader(block.view + 1) + else: + recipient = self.overlay.parent_committee(self.id) + + # Return a Send event to the appropriate recipient + return Send(to=recipient, payload=vote)