From 8d0a1e4701a6f9ae8c64f1c042ebe79d7aedd52b Mon Sep 17 00:00:00 2001 From: mjalalzai <33738574+MForensic@users.noreply.github.com> Date: Thu, 21 Sep 2023 17:59:25 -0700 Subject: [PATCH] Carnot --- carnot/carnot-vote-aggregation.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/carnot/carnot-vote-aggregation.py b/carnot/carnot-vote-aggregation.py index 3fe316a..38b6945 100644 --- a/carnot/carnot-vote-aggregation.py +++ b/carnot/carnot-vote-aggregation.py @@ -235,3 +235,22 @@ class Carnot: # Return True if both conditions are met return is_view_incremented and is_standard_qc + +def latest_committed_view(self) -> View: + return self.latest_committed_block().view + +# Return a list of blocks received by a node for a specific view. +# More than one block is returned only in case of a malicious leader. +def blocks_in_view(self, view: View) -> List[Block]: + return [block for block in self.safe_blocks.values() if block.view == view] + +def genesis_block(self) -> Block: + return self.blocks_in_view(0)[0] + +def latest_committed_block(self) -> Block: + for view in range(self.current_view, 0, -1): + for block in self.blocks_in_view(view): + if self.can_commit_grandparent(block): + return self.safe_blocks.get(self.safe_blocks.get(block.parent()).parent()) + # The genesis block is always considered committed. + return self.genesis_block()