Use learner's collection of average latency stats for ordering decryption requests.

pull/3562/head
derekpierre 2024-10-31 13:35:03 -04:00
parent fc17bbfc53
commit 4ef417ee6e
No known key found for this signature in database
1 changed files with 6 additions and 4 deletions

View File

@ -1,6 +1,5 @@
import math
from http import HTTPStatus
from random import shuffle
from typing import Dict, List, Tuple
from eth_typing import ChecksumAddress
@ -81,14 +80,17 @@ class ThresholdDecryptionClient(ThresholdAccessControlClient):
raise self.ThresholdDecryptionRequestFailed(message)
# TODO: Find a better request order, perhaps based on latency data obtained from discovery loop - #3395
requests = list(encrypted_requests)
shuffle(requests)
ursulas_sorted_by_latency = (
self._learner.node_latency_collector.order_addresses_by_latency(
list(encrypted_requests)
)
)
# Discussion about WorkerPool parameters:
# "https://github.com/nucypher/nucypher/pull/3393#discussion_r1456307991"
worker_pool = WorkerPool(
worker=worker,
value_factory=self.ThresholdDecryptionRequestFactory(
ursulas_to_contact=requests,
ursulas_to_contact=ursulas_sorted_by_latency,
batch_size=math.ceil(threshold * 1.25),
threshold=threshold,
),