Skip to content

Commit

Permalink
✨ assert that the tails URI has been updated in the revocation regist…
Browse files Browse the repository at this point in the history
…ry in AcaPyStorage before proceeding to public the rev_reg on ledger
  • Loading branch information
ff137 committed Feb 17, 2024
1 parent 4ee654b commit 2fc90f6
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions app/routes/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List, Optional

from aries_cloudcontroller import (
AcaPyClient,
ApiException,
CredentialDefinitionSendRequest,
RevRegUpdateTailsFileUri,
Expand Down Expand Up @@ -39,6 +40,7 @@
credential_definition_from_acapy,
credential_schema_from_acapy,
)
from app.util.retry_method import coroutine_with_retry_until_value
from shared import ACAPY_ENDORSER_ALIAS, ACAPY_TAILS_SERVER_BASE_URL
from shared.log_config import get_logger

Expand Down Expand Up @@ -321,9 +323,12 @@ async def create_credential_definition(
)

rev_reg_id = revoc_reg_creation_result.revoc_reg_id
tails_public_uri = f"{ACAPY_TAILS_SERVER_BASE_URL}/{rev_reg_id}"

update_tails_file_uri_request = RevRegUpdateTailsFileUri(
tails_public_uri=f"{ACAPY_TAILS_SERVER_BASE_URL}/{rev_reg_id}"
tails_public_uri=tails_public_uri
)

bound_logger.debug("Updating revocation registry")
await aries_controller.revocation.update_registry(
rev_reg_id=rev_reg_id,
Expand All @@ -336,8 +341,26 @@ async def create_credential_definition(
# Otherwise onboarding should have created an endorser connection
# for tenants so this fails correctly

# Allow time for record to be updated with new tails file uri
await asyncio.sleep(1)
# We must allow time for record to be updated with new tails file uri
# Therefore, define coroutine that will be retried until expected value is returned
async def get_rev_reg_record_tails_uri(
controller: AcaPyClient, reg_id: str
):
fetched_record = await controller.revocation.get_registry(reg_id)
return fetched_record.result.tails_public_uri

# Wait until the registry record has been updated in AcaPyStorage
if not await coroutine_with_retry_until_value(
coroutine_func=get_rev_reg_record_tails_uri,
args=(aries_controller, rev_reg_id),
expected_value=tails_public_uri,
logger=logger,
max_attempts=20,
retry_delay=0.5, # maximum 10 seconds duration
):
raise CloudApiException(
"Could not set the Tails public URI for revocation registry. Please try again."
)

bound_logger.debug("Publish revocation registry")
await publish_revocation_registry_on_ledger(
Expand Down

0 comments on commit 2fc90f6

Please sign in to comment.