Skip to content

Commit

Permalink
Log a warning whenever parameterized timeout exceeds maximum allowed …
Browse files Browse the repository at this point in the history
…timeout.

Ensure that timeout for decryption is always passed to ThresholdDecryptionClient.
  • Loading branch information
derekpierre committed Nov 17, 2023
1 parent 9a92af5 commit 386612f
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions porter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,16 @@ def get_ursulas(
include_ursulas: Optional[Sequence[ChecksumAddress]] = None,
timeout: Optional[int] = None,
) -> List[UrsulaInfo]:
timeout = (
min(timeout, self.MAX_GET_URSULAS_TIMEOUT)
if timeout
else self.MAX_GET_URSULAS_TIMEOUT
)
if timeout and timeout > self.MAX_GET_URSULAS_TIMEOUT:
self.log.warn(
f"Provided sampling timeout ({timeout}s) exceeds "
f"maximum ({self.MAX_GET_URSULAS_TIMEOUT}s); "
f"using {self.MAX_GET_URSULAS_TIMEOUT}s instead"
)
timeout = self.MAX_GET_URSULAS_TIMEOUT
else:
timeout = timeout or self.MAX_GET_URSULAS_TIMEOUT

reservoir = self._make_reservoir(exclude_ursulas, include_ursulas)
available_nodes_to_sample = len(reservoir.values) + len(reservoir.reservoir)
if available_nodes_to_sample < quantity:
Expand Down Expand Up @@ -221,14 +226,20 @@ def decrypt(
timeout: Optional[int] = None,
) -> DecryptOutcome:
decryption_client = ThresholdDecryptionClient(self)
if timeout and timeout > self.MAX_DECRYPTION_TIMEOUT:
self.log.warn(
f"Provided decryption timeout ({timeout}s) exceeds "
f"maximum ({self.MAX_DECRYPTION_TIMEOUT}s); "
f"using {self.MAX_DECRYPTION_TIMEOUT}s instead"
)
timeout = self.MAX_DECRYPTION_TIMEOUT
else:
timeout = timeout or self.MAX_DECRYPTION_TIMEOUT

kwargs = dict(
encrypted_requests=encrypted_decryption_requests, threshold=threshold
)
if timeout:
kwargs["timeout"] = min(self.MAX_DECRYPTION_TIMEOUT, timeout)
successes, failures = decryption_client.gather_encrypted_decryption_shares(
**kwargs
encrypted_requests=encrypted_decryption_requests,
threshold=threshold,
timeout=timeout,
)

decrypt_outcome = Porter.DecryptOutcome(
Expand Down

0 comments on commit 386612f

Please sign in to comment.