Skip to content

Commit

Permalink
✨ publishing pending revocations should wait and assert transaction h…
Browse files Browse the repository at this point in the history
…as been acked
  • Loading branch information
ff137 committed Apr 24, 2024
1 parent 1d976d2 commit cf91dee
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
26 changes: 25 additions & 1 deletion app/routes/issuer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from typing import List, Optional
from uuid import UUID

Expand Down Expand Up @@ -26,6 +27,7 @@
issuer_from_protocol_version,
)
from app.util.did import did_from_credential_definition_id, qualified_did_sov
from app.util.retry_method import coroutine_with_retry_until_value
from shared.log_config import get_logger
from shared.models.credential_exchange import (
CredentialExchange,
Expand Down Expand Up @@ -362,11 +364,33 @@ async def publish_revocations(

async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Publishing revocations")
await revocation_registry.publish_pending_revocations(
endorser_transaction_id = await revocation_registry.publish_pending_revocations(
controller=aries_controller,
revocation_registry_credential_map=publish_request.revocation_registry_credential_map,
)

# Wait for publish complete

bound_logger.info(
"Wait for publish complete on transaction id: {}", endorser_transaction_id
)
try:
# Wait for transaction to be acknowledged and written to the ledger
await coroutine_with_retry_until_value(
coroutine_func=aries_controller.endorse_transaction.get_transaction,
args=(endorser_transaction_id,),
field_name="state",
expected_value="transaction_acked",
logger=bound_logger,
max_attempts=10,
retry_delay=2,
)
except asyncio.TimeoutError as e:
raise CloudApiException(
"Timeout waiting for endorser to accept the revocations request.",
504,
) from e

bound_logger.info("Successfully published revocations.")


Expand Down
16 changes: 12 additions & 4 deletions app/services/revocation_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def revoke_credential(

async def publish_pending_revocations(
controller: AcaPyClient, revocation_registry_credential_map: Dict[str, List[str]]
) -> None:
) -> str:
"""
Publish pending revocations
Expand All @@ -126,7 +126,7 @@ async def publish_pending_revocations(
Exception: When the pending revocations could not be published
Returns:
result (None): Successful execution returns None.
result (str): Successful execution returns the endorser transaction id.
"""
bound_logger = logger.bind(body=revocation_registry_credential_map)

Expand All @@ -137,7 +137,7 @@ async def publish_pending_revocations(
)

try:
await handle_acapy_call(
result = await handle_acapy_call(
logger=bound_logger,
acapy_call=controller.revocation.publish_revocations,
body=PublishRevocations(rrid2crid=revocation_registry_credential_map),
Expand All @@ -147,7 +147,15 @@ async def publish_pending_revocations(
f"Failed to publish pending revocations: {e.detail}.", e.status_code
) from e

bound_logger.info("Successfully published pending revocations.")
if not result.txn or not result.txn.transaction_id:
raise CloudApiException(f"Failed to publish pending revocations.", 500)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Using an f-string that does not have any interpolated variables Note

Using an f-string that does not have any interpolated variables

Check warning

Code scanning / Prospector (reported by Codacy)

f-string is missing placeholders (F541) Warning

f-string is missing placeholders (F541)

endorse_transaction_id = result.txn.transaction_id
bound_logger.info(
"Successfully published pending revocations. Endorser transaction id: {}.",
endorse_transaction_id,
)
return endorse_transaction_id


async def clear_pending_revocations(
Expand Down
12 changes: 11 additions & 1 deletion app/tests/services/test_revocation_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
PublishRevocations,
RevokeRequest,
RevRegResult,
TransactionRecord,
TxnOrPublishRevocationsResult,
V10CredentialExchange,
V20CredExRecordDetail,
V20CredExRecordIndy,
Expand Down Expand Up @@ -117,7 +119,15 @@ async def test_publish_pending_revocations_success(mock_agent_controller: AcaPyC
# Simulate successful publish revocations call
when(mock_agent_controller.revocation).publish_revocations(
body=PublishRevocations(rrid2crid=revocation_registry_credential_map)
).thenReturn(to_async())
).thenReturn(
to_async(
TxnOrPublishRevocationsResult(
txn=TransactionRecord(
transaction_id="97a46fab-5499-42b3-a2a1-7eb9faad31c0"
)
)
)
)

await rg.publish_pending_revocations(
controller=mock_agent_controller,
Expand Down

0 comments on commit cf91dee

Please sign in to comment.