@@ -23,14 +23,18 @@ def get_next_block_confirmations(next_block_number) -> list[BlockConfirmation]:
23
23
return list (BlockConfirmation .objects .filter (number = next_block_number , signer__in = cv_identifiers ))
24
24
25
25
26
- def get_consensus_block_hash_with_confirmations (confirmations ,
27
- minimum_consensus ) -> Optional [tuple [Hash , list [BlockConfirmation ]]]:
26
+ def get_consensus_block_hash_with_confirmations (
27
+ confirmations : list [BlockConfirmation ], minimum_consensus : int
28
+ ) -> Optional [tuple [Hash , list [BlockConfirmation ]]]:
29
+
30
+ assert len (set (confirmation .number for confirmation in confirmations )) <= 1
31
+
28
32
key_func = attrgetter ('hash' )
29
- grouped_confirmations = [(Hash (hash_ ), list (confirmations ))
30
- for hash_ , confirmations in groupby (sorted (confirmations , key = key_func ), key = key_func )]
31
- finalizable_hashes = [(hash_ , confirmations )
32
- for hash_ , confirmations in grouped_confirmations
33
- if len (confirmations ) >= minimum_consensus ]
33
+ grouped_confirmations = [(Hash (hash_ ), list (confirmations_ ))
34
+ for hash_ , confirmations_ in groupby (sorted (confirmations , key = key_func ), key = key_func )]
35
+ finalizable_hashes = [(hash_ , confirmations_ )
36
+ for hash_ , confirmations_ in grouped_confirmations
37
+ if len (confirmations_ ) >= minimum_consensus ]
34
38
35
39
if not finalizable_hashes :
36
40
return None # No consensus, yet
@@ -44,7 +48,7 @@ def get_consensus_block_hash_with_confirmations(confirmations,
44
48
return block_hash , consensus_confirmations
45
49
46
50
47
- def is_valid_consensus (confirmations : list [BlockConfirmation ], minimum_consensus ):
51
+ def is_valid_consensus (confirmations : list [BlockConfirmation ], minimum_consensus : int ):
48
52
# Validate confirmations, since they may have not been validated on API call because some of them were added
49
53
# much earlier then the next block number become equal to confirmation block number
50
54
assert len (set (confirmation .signer for confirmation in confirmations )) == len (confirmations )
0 commit comments