This commit is contained in:
mjalalzai 2023-09-21 17:59:25 -07:00
parent dd29051497
commit 8d0a1e4701

View File

@ -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()