improves logging and error handling during tdec req/res.

pull/3115/head
Kieran Prasch 2023-04-24 07:54:25 -07:00
parent 846d5d0be9
commit 25d4efd870
5 changed files with 18 additions and 11 deletions

View File

@ -222,7 +222,7 @@ class ActiveRitualTracker:
def __scan(self, start_block, end_block, account):
# Run the scan
# self.log.debug(f"({account[:8]}) Scanning events from blocks {start_block} - {end_block}")
self.log.debug(f"({account[:8]}) Scanning events from blocks {start_block} - {end_block}")
start = time.time()
result, total_chunks_scanned = self.scanner.scan(start_block, end_block)
if self.persistent:

View File

@ -582,8 +582,8 @@ class Bob(Character):
try:
response = self.network_middleware.get_decryption_share(ursula, bytes(decryption_request))
except NodeSeemsToBeDown:
self.log.warn(f"Node {ursula} is unreachable. Skipping...")
except NodeSeemsToBeDown as e:
self.log.warn(f"Node {ursula} is unreachable. {e}")
continue
if response.status_code != 200:
self.log.warn(f"Node {ursula} returned {response.status_code}.")
@ -618,7 +618,7 @@ class Bob(Character):
params: Optional[DkgPublicParameters] = None,
ursulas: Optional[List['Ursula']] = None,
variant: str = 'simple',
timeout: int = 600, # TODO: coordinate with the timeout in the policy/ritual
peering_timeout: int = 60,
) -> bytes:
# blockchain reads: get the DKG parameters and the cohort.
@ -629,14 +629,18 @@ class Bob(Character):
# P2P: if the Ursulas are not provided, we need to resolve them from published records.
# This is a blocking operation and the ursulas must be part of the cohort.
# if the timeout is 0, peering will be skipped in favor if already cached peers.
ursulas = self.resolve_cohort(ritual=ritual, timeout=timeout)
ursulas = self.resolve_cohort(ritual=ritual, timeout=peering_timeout)
else:
for ursula in ursulas:
if ursula.staking_provider_address not in ritual.participants:
raise ValueError(f"{ursula} is not part of the cohort")
self.remember_node(ursula)
try:
variant = FerveoVariant(getattr(FerveoVariant, variant.upper()).value)
except AttributeError:
raise ValueError(f"Invalid variant: {variant}; Options are: {list(v.name.lower() for v in list(FerveoVariant))}")
threshold = (ritual.shares // 2) + 1 # TODO: get this from the policy
threshold = (ritual.shares // 2) + 1 # TODO: get this from the ritual / put it on-chain?
shares = self.gather_decryption_shares(
ritual_id=ritual_id,
cohort=ursulas,

View File

@ -147,6 +147,8 @@ def _make_rest_app(this_node, log: Logger) -> Flask:
# Deserialize and instantiate ThresholdDecryptionRequest from the request data
decryption_request = ThresholdDecryptionRequest.from_bytes(request.data)
log.info(f"Threshold decryption request for ritual ID #{decryption_request.id}")
# Deserialize and instantiate ConditionLingo from the request data
conditions_data = str(decryption_request.conditions) # nucypher_core.Conditions -> str
lingo = ConditionLingo.from_list(json.loads(conditions_data)) # str -> list -> ConditionLingo
@ -183,7 +185,8 @@ def _make_rest_app(this_node, log: Logger) -> Flask:
# return the decryption share
# TODO: encrypt the response with the requester's public key # 3079
response = ThresholdDecryptionResponse(decryption_share=bytes(decryption_share)) # TODO: Use native DecryptionShare type
# TODO: Use native DecryptionShare type
response = ThresholdDecryptionResponse(decryption_share=bytes(decryption_share))
return Response(bytes(response), headers={'Content-Type': 'application/octet-stream'})
@rest_app.route('/reencrypt', methods=["POST"])

View File

@ -113,7 +113,7 @@ def test_ursula_ritualist(testerchain, coordinator_agent, cohort, alice, bob):
ciphertext=ciphertext,
conditions=CONDITIONS,
# params=cohort[0].dkg_storage.get_dkg_params(RITUAL_ID),
timeout=0
peering_timeout=0
)
assert bytes(cleartext) == PLAINTEXT.encode()
print("==================== DECRYPTION SUCCESSFUL ====================")

View File

@ -139,7 +139,7 @@ def test_ursula_ritualist(testerchain, mock_coordinator_agent, cohort, alice, bo
ciphertext=ciphertext,
conditions=CONDITIONS,
params=params,
timeout=0,
peering_timeout=0,
variant=variant
)
assert bytes(cleartext) == PLAINTEXT.encode()
@ -149,7 +149,7 @@ def test_ursula_ritualist(testerchain, mock_coordinator_agent, cohort, alice, bo
ritual_id=ritual_id,
ciphertext=ciphertext,
conditions=CONDITIONS,
timeout=0,
peering_timeout=0,
variant=variant
)
assert bytes(cleartext) == PLAINTEXT.encode()