mirror of
https://github.com/logos-blockchain/logos-blockchain-specs.git
synced 2026-01-07 15:43:07 +00:00
Naming fixed
This commit is contained in:
parent
189c4c8244
commit
c7c5750b92
@ -9,7 +9,7 @@ from heapq import heappush, heappop, heapify
|
|||||||
|
|
||||||
DeclarationId: TypeAlias = bytes
|
DeclarationId: TypeAlias = bytes
|
||||||
Assignations: TypeAlias = List[Set[DeclarationId]]
|
Assignations: TypeAlias = List[Set[DeclarationId]]
|
||||||
ChaCha20: TypeAlias = Any
|
BlakeRng: TypeAlias = Any
|
||||||
|
|
||||||
|
|
||||||
@dataclass(order=True)
|
@dataclass(order=True)
|
||||||
@ -36,11 +36,11 @@ class Subnetwork:
|
|||||||
return len(self.participants)
|
return len(self.participants)
|
||||||
|
|
||||||
|
|
||||||
def are_subnetworks_filled_up_to_replication_factor(subnetworks: Sequence[Subnetwork], replication_factor: int) -> bool:
|
def subnetworks_filled_up_to_replication_factor(subnetworks: Sequence[Subnetwork], replication_factor: int) -> bool:
|
||||||
return all(len(subnetwork) >= replication_factor for subnetwork in subnetworks)
|
return all(len(subnetwork) >= replication_factor for subnetwork in subnetworks)
|
||||||
|
|
||||||
|
|
||||||
def all_nodes_are_assigned(participants: Sequence[Participant], average_participation: int) -> bool:
|
def all_nodes_assigned(participants: Sequence[Participant], average_participation: int) -> bool:
|
||||||
return all(participant.participation >= average_participation for participant in participants)
|
return all(participant.participation >= average_participation for participant in participants)
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ def heappop_next_for_subnetwork(subnetwork: Subnetwork, participants: List[Parti
|
|||||||
return participant
|
return participant
|
||||||
|
|
||||||
# sample using fisher yates shuffling, returning
|
# sample using fisher yates shuffling, returning
|
||||||
def sample(elements: Sequence[Any], random: ChaCha20, k: int) -> List[Any]:
|
def sample(elements: Sequence[Any], random: BlakeRng, k: int) -> List[Any]:
|
||||||
# list is sorted for reproducibility
|
# list is sorted for reproducibility
|
||||||
elements = sorted(elements)
|
elements = sorted(elements)
|
||||||
# pythons built-in is fisher yates shuffling
|
# pythons built-in is fisher yates shuffling
|
||||||
@ -73,8 +73,8 @@ def fill_subnetworks(
|
|||||||
heapify(subnetworks)
|
heapify(subnetworks)
|
||||||
|
|
||||||
while not (
|
while not (
|
||||||
are_subnetworks_filled_up_to_replication_factor(subnetworks, replication_factor) and
|
subnetworks_filled_up_to_replication_factor(subnetworks, replication_factor) and
|
||||||
all_nodes_are_assigned(available_nodes, average_participation)
|
all_nodes_assigned(available_nodes, average_participation)
|
||||||
):
|
):
|
||||||
# take the fewest participants subnetwork
|
# take the fewest participants subnetwork
|
||||||
subnetwork = heappop(subnetworks)
|
subnetwork = heappop(subnetworks)
|
||||||
@ -92,7 +92,7 @@ def fill_subnetworks(
|
|||||||
|
|
||||||
def balance_subnetworks_shrink(
|
def balance_subnetworks_shrink(
|
||||||
subnetworks: List[Subnetwork],
|
subnetworks: List[Subnetwork],
|
||||||
random: ChaCha20,
|
random: BlakeRng,
|
||||||
):
|
):
|
||||||
while (len(max(subnetworks)) - len(min(subnetworks))) > 1:
|
while (len(max(subnetworks)) - len(min(subnetworks))) > 1:
|
||||||
max_subnetwork = max(subnetworks)
|
max_subnetwork = max(subnetworks)
|
||||||
@ -108,7 +108,7 @@ def balance_subnetworks_grow(
|
|||||||
subnetworks: List[Subnetwork],
|
subnetworks: List[Subnetwork],
|
||||||
participants: List[Participant],
|
participants: List[Participant],
|
||||||
average_participation: int,
|
average_participation: int,
|
||||||
random: ChaCha20,
|
random: BlakeRng,
|
||||||
):
|
):
|
||||||
for participant in filter(lambda x: x.participation > average_participation, sorted(participants)):
|
for participant in filter(lambda x: x.participation > average_participation, sorted(participants)):
|
||||||
for subnework in sample(
|
for subnework in sample(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user