Merge pull request #3287 from derekpierre/potpourri

Potpourri
pull/3297/head
KPrasch 2023-10-19 14:13:28 +02:00 committed by GitHub
commit 533d4a3a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 11 deletions

View File

@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Dict, List, Tuple
from eth_typing import ChecksumAddress
@ -26,7 +27,7 @@ class ThresholdDecryptionClient(ThresholdAccessControlClient):
self,
encrypted_requests: Dict[ChecksumAddress, EncryptedThresholdDecryptionRequest],
threshold: int,
timeout: float = 10,
timeout: float = 15,
) -> Tuple[
Dict[ChecksumAddress, EncryptedThresholdDecryptionResponse],
Dict[ChecksumAddress, str],
@ -52,7 +53,7 @@ class ThresholdDecryptionClient(ThresholdAccessControlClient):
timeout=timeout,
)
)
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
return EncryptedThresholdDecryptionResponse.from_bytes(
response.content
)
@ -70,6 +71,9 @@ class ThresholdDecryptionClient(ThresholdAccessControlClient):
ursula_to_contact=list(encrypted_requests.keys()), threshold=threshold
),
target_successes=threshold,
threadpool_size=len(
encrypted_requests
), # TODO should we cap this (say 40?)
timeout=timeout,
)
worker_pool.start()

View File

@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Dict, Iterable, List, Optional, Sequence
import maya
@ -95,7 +96,7 @@ class Policy:
response = network_middleware.ping(node=ursula)
status_code = response.status_code
if status_code == 200:
if status_code == HTTPStatus.OK:
return ursula
else:
raise RuntimeError(f"{ursula} is not available for selection ({status_code}).")

View File

@ -1,7 +1,5 @@
import random
from http import HTTPStatus
from ipaddress import ip_address
from typing import Optional, Union
@ -63,7 +61,7 @@ def _request(url: str, certificate=None) -> Union[str, None]:
response = requests.get(url, verify=certificate)
except RequestErrors:
return None
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
return response.text
@ -86,7 +84,7 @@ def _request_from_node(
except NodeSeemsToBeDown:
# This node is unreachable. Move on.
return
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
try:
ip = str(ip_address(response.text))
except ValueError:

View File

@ -9,9 +9,14 @@ class Profiler(cProfile.Profile):
PROFILER_ENV_VAR = "COLLECT_PROFILER_STATS"
def __init__(
self, sort_by: SortKey = SortKey.TIME, top_n_entries: int = 10, **kwargs
self,
label: str = "",
sort_by: SortKey = SortKey.TIME,
top_n_entries: int = 10,
**kwargs,
) -> None:
self.active = self.PROFILER_ENV_VAR in os.environ
self.label = label
self.top_n = top_n_entries
self.sort_by = sort_by
super().__init__(**kwargs)
@ -25,7 +30,8 @@ class Profiler(cProfile.Profile):
if self.active:
super().__exit__(exc_info)
profiler_stats = Stats(self).sort_stats(self.sort_by)
print("\n------ Profile Stats -------")
label = f"[{self.label}]" if self.label else ""
print(f"\n------ Profile Stats {label} -------")
profiler_stats.print_stats(self.top_n)
print("\n- Caller Info -")
print(f"\n- Caller Info {label} -")
profiler_stats.print_callers(self.top_n)