diff --git a/carnot/carnot.py b/carnot/carnot.py index 874c016..d8cf332 100644 --- a/carnot/carnot.py +++ b/carnot/carnot.py @@ -68,7 +68,13 @@ class TimeoutQc: high_qc: AggregateQc -Quorum: TypeAlias = Set[Vote] | Set[TimeoutQc] +@dataclass +class Timeout: + view: View + high_qc: Qc + + +Quorum: TypeAlias = Set[Vote] | Set[Timeout] class Overlay: @@ -294,6 +300,11 @@ class Carnot: self.current_view = qc.view + 1 return True + def get_max_timeout(timeouts: List[Timeout]) -> Optional[Timeout]: + if not timeouts: + return None + return max(timeouts, key=lambda time: time.qc.view) + if __name__ == "__main__": pass diff --git a/carnot/test_happy_path.py b/carnot/test_happy_path.py index e05ddfe..35cab65 100644 --- a/carnot/test_happy_path.py +++ b/carnot/test_happy_path.py @@ -208,7 +208,7 @@ class TestCarnotHappyPath(TestCase): self.assertEqual(carnot.highest_voted_view, 1) self.assertEqual(carnot.current_view, 1) - #2 If last_voted_view is incremented after calling vote. + #2 If last_voted_view is incremented after calling vote with votes lower than. def test_vote_for_received_block_if_threshold_votes_has_not_reached(self): class MockOverlay(Overlay): @@ -236,11 +236,11 @@ class TestCarnotHappyPath(TestCase): view=1, block=block1.id(), qc=StandardQc(block=block1.id(), view=1) - ) for i in range(9) + ) for i in range(10) ) carnot.vote(block1, votes) - self.assertEqual(carnot.highest_voted_view, 0) - self.assertEqual(carnot.current_view, 0) + self.assertEqual(carnot.highest_voted_view, 1) + self.assertEqual(carnot.current_view, 1)