mirror of
https://github.com/logos-blockchain/logos-blockchain-specs.git
synced 2026-01-25 08:23:07 +00:00
Merging committees
This commit is contained in:
parent
cacb977ef7
commit
d6738d1eaf
@ -401,7 +401,7 @@ class Carnot:
|
||||
# Forward the vote to the parent committee
|
||||
return Send(to=self.overlay.parent_committee, payload=vote)
|
||||
|
||||
# ToDo: Is not needed anymore
|
||||
|
||||
def forward_timeout_qc(self, msg: TimeoutQc) -> Optional[Event]:
|
||||
# Assertions for input validation
|
||||
assert msg.view == self.current_view, "Received TimeoutQc with correct view"
|
||||
|
||||
29
carnot/merging_committees.py
Normal file
29
carnot/merging_committees.py
Normal file
@ -0,0 +1,29 @@
|
||||
def merge_committees(committees):
|
||||
num_committees = len(committees)
|
||||
merged_committees = []
|
||||
|
||||
# Sort the committees by size
|
||||
sorted_committees = sorted(committees, key=len)
|
||||
|
||||
# Divide the committees into two groups: smaller and larger
|
||||
smaller_committees = sorted_committees[:num_committees // 2]
|
||||
larger_committees = sorted_committees[num_committees // 2:]
|
||||
|
||||
# Merge smaller and larger committees pairwise
|
||||
for smaller, larger in zip(smaller_committees, larger_committees):
|
||||
merged_committee = set(smaller)
|
||||
merged_committee.update(larger)
|
||||
merged_committees.append(merged_committee)
|
||||
|
||||
# Handle the leftover committee, if it exists
|
||||
if num_committees % 2 == 1:
|
||||
leftover_committee = set(sorted_committees[-1])
|
||||
num_merged_committees = len(merged_committees)
|
||||
|
||||
# Distribute leftover members evenly among merged committees
|
||||
for member in leftover_committee:
|
||||
# Find the index of the merged committee with the smallest size
|
||||
smallest_idx = min(range(num_merged_committees), key=lambda i: len(merged_committees[i]))
|
||||
merged_committees[smallest_idx].add(member)
|
||||
|
||||
return merged_committees
|
||||
Loading…
x
Reference in New Issue
Block a user