Skip to content

Commit 5cd0a4e

Browse files
revert uploaded state for IssuerRevRegRecord; fix interaction with transaction endorsement
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
1 parent 252a9b3 commit 5cd0a4e

8 files changed

Lines changed: 80 additions & 66 deletions

File tree

aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from ....messaging.credential_definitions.util import notify_cred_def_event
1616
from ....messaging.schemas.util import notify_schema_event
1717
from ....revocation.util import (
18-
notify_revocation_entry_event,
1918
notify_revocation_reg_endorsed_event,
19+
notify_revocation_entry_endorsed_event,
2020
)
2121
from ....storage.error import StorageError, StorageNotFoundError
2222
from ....transport.inbound.receipt import MessageReceipt
@@ -777,30 +777,18 @@ async def endorsed_txn_post_processing(
777777
# revocation registry transaction
778778
rev_reg_id = ledger_response["result"]["txnMetadata"]["txnId"]
779779
meta_data["context"]["rev_reg_id"] = rev_reg_id
780-
auto_create_rev_reg = meta_data["processing"].get(
781-
"auto_create_rev_reg", False
780+
await notify_revocation_reg_endorsed_event(
781+
self._profile, rev_reg_id, meta_data
782782
)
783783

784-
# If "auto_processing" is enabled, also create the revocation entry record
785-
if auto_create_rev_reg:
786-
await notify_revocation_entry_event(
787-
self._profile, rev_reg_id, meta_data
788-
)
789-
790784
elif ledger_response["result"]["txn"]["type"] == "114":
791785
# revocation entry transaction
792786
rev_reg_id = ledger_response["result"]["txn"]["data"]["revocRegDefId"]
793787
meta_data["context"]["rev_reg_id"] = rev_reg_id
794-
auto_create_rev_reg = meta_data["processing"].get(
795-
"auto_create_rev_reg", False
788+
await notify_revocation_entry_endorsed_event(
789+
self._profile, rev_reg_id, meta_data
796790
)
797791

798-
# If "auto_processing" is enabled, also upload tails file for this registry
799-
if auto_create_rev_reg:
800-
await notify_revocation_reg_endorsed_event(
801-
self._profile, rev_reg_id, meta_data
802-
)
803-
804792
elif ledger_response["result"]["txn"]["type"] == "1":
805793
# write DID to ledger
806794
did = ledger_response["result"]["txn"]["data"]["dest"]

aries_cloudagent/revocation/indy.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ async def init_issuer_registry(
4343
tag: str = None,
4444
create_pending_rev_reg: bool = False,
4545
endorser_connection_id: str = None,
46+
notify: bool = True,
4647
) -> "IssuerRevRegRecord":
4748
"""Create a new revocation registry record for a credential definition."""
4849
multitenant_mgr = self._profile.inject_or(BaseMultitenantManager)
@@ -86,12 +87,13 @@ async def init_issuer_registry(
8687
if not endorser_connection_id:
8788
raise RevocationError(reason="Endorser connection not found")
8889

89-
await notify_revocation_reg_init_event(
90-
self._profile,
91-
record.record_id,
92-
create_pending_rev_reg=create_pending_rev_reg,
93-
endorser_connection_id=endorser_connection_id,
94-
)
90+
if notify:
91+
await notify_revocation_reg_init_event(
92+
self._profile,
93+
record.record_id,
94+
create_pending_rev_reg=create_pending_rev_reg,
95+
endorser_connection_id=endorser_connection_id,
96+
)
9597

9698
return record
9799

aries_cloudagent/revocation/models/issuer_rev_reg_record.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class Meta:
6767
STATE_INIT = "init"
6868
STATE_GENERATED = "generated"
6969
STATE_POSTED = "posted" # definition published
70-
STATE_UPLOADED = "uploaded" # tails file uploaded
7170
STATE_ACTIVE = "active" # initial entry published, possibly subsequent entries
7271
STATE_FULL = "full" # includes corrupt
7372

@@ -279,7 +278,7 @@ async def send_entry(
279278
self._check_url(self.tails_public_uri)
280279

281280
if self.state not in (
282-
IssuerRevRegRecord.STATE_UPLOADED,
281+
IssuerRevRegRecord.STATE_POSTED,
283282
IssuerRevRegRecord.STATE_ACTIVE,
284283
IssuerRevRegRecord.STATE_FULL, # can still publish revocation deltas
285284
):
@@ -299,7 +298,7 @@ async def send_entry(
299298
write_ledger=write_ledger,
300299
endorser_did=endorser_did,
301300
)
302-
if self.state == IssuerRevRegRecord.STATE_UPLOADED:
301+
if self.state == IssuerRevRegRecord.STATE_POSTED:
303302
self.state = IssuerRevRegRecord.STATE_ACTIVE # initial entry activates
304303
async with profile.session() as session:
305304
await self.save(
@@ -321,7 +320,7 @@ async def upload_tails_file(self, profile: Profile):
321320
if not self.has_local_tails_file:
322321
raise RevocationError("Local tails file not found")
323322

324-
(upload_success, reason) = await tails_server.upload_tails_file(
323+
(upload_success, result) = await tails_server.upload_tails_file(
325324
profile.context,
326325
self.revoc_reg_id,
327326
self.tails_local_path,
@@ -331,12 +330,9 @@ async def upload_tails_file(self, profile: Profile):
331330
)
332331
if not upload_success:
333332
raise RevocationError(
334-
f"Tails file for rev reg {self.revoc_reg_id} failed to upload: {reason}"
333+
f"Tails file for rev reg {self.revoc_reg_id} failed to upload: {result}"
335334
)
336-
337-
self.state = IssuerRevRegRecord.STATE_UPLOADED
338-
async with profile.session() as session:
339-
await self.save(session, reason="Uploaded tails file")
335+
await self.set_tails_file_public_uri(profile, result)
340336

341337
async def mark_pending(self, session: ProfileSession, cred_rev_id: str) -> None:
342338
"""Mark a credential revocation id as revoked pending publication to ledger.

aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def setUp(self):
6565
TailsServer = async_mock.MagicMock(BaseTailsServer, autospec=True)
6666
self.tails_server = TailsServer()
6767
self.tails_server.upload_tails_file = async_mock.CoroutineMock(
68-
return_value=(True, None)
68+
return_value=(True, "http://1.2.3.4:8088/rev-reg-id")
6969
)
7070
self.profile.context.injector.bind_instance(BaseTailsServer, self.tails_server)
7171

@@ -126,7 +126,10 @@ async def test_generate_registry_etc(self):
126126

127127
with async_mock.patch.object(test_module.Path, "is_file", lambda _: True):
128128
await rec.upload_tails_file(self.profile)
129-
assert rec.state == IssuerRevRegRecord.STATE_UPLOADED
129+
assert (
130+
rec.tails_public_uri
131+
and rec.revoc_reg_def.value.tails_location == rec.tails_public_uri
132+
)
130133
self.tails_server.upload_tails_file.assert_called_once()
131134

132135
await rec.send_entry(self.profile)

aries_cloudagent/revocation/routes.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ async def create_rev_reg(request: web.BaseRequest):
550550
issuer_rev_reg_rec = await revoc.init_issuer_registry(
551551
credential_definition_id,
552552
max_cred_num=max_cred_num,
553+
notify=False,
553554
)
554555
except RevocationNotSupportedError as e:
555556
raise web.HTTPBadRequest(reason=e.message) from e
@@ -1128,17 +1129,16 @@ async def send_rev_reg_entry(request: web.BaseRequest):
11281129
raise web.HTTPBadRequest(reason="No endorser connection found")
11291130

11301131
if not write_ledger:
1131-
try:
1132-
async with profile.session() as session:
1132+
async with profile.session() as session:
1133+
try:
11331134
connection_record = await ConnRecord.retrieve_by_id(
11341135
session, connection_id
11351136
)
1136-
except StorageNotFoundError as err:
1137-
raise web.HTTPNotFound(reason=err.roll_up) from err
1138-
except BaseModelError as err:
1139-
raise web.HTTPBadRequest(reason=err.roll_up) from err
1137+
except StorageNotFoundError as err:
1138+
raise web.HTTPNotFound(reason=err.roll_up) from err
1139+
except BaseModelError as err:
1140+
raise web.HTTPBadRequest(reason=err.roll_up) from err
11401141

1141-
async with profile.session() as session:
11421142
endorser_info = await connection_record.metadata_get(
11431143
session, "endorser_info"
11441144
)
@@ -1295,14 +1295,16 @@ async def on_revocation_registry_init_event(profile: Profile, event: Event):
12951295
meta_data = event.payload
12961296
if "endorser" in meta_data:
12971297
# TODO error handling - for now just let exceptions get raised
1298+
endorser_connection_id = meta_data["endorser"]["connection_id"]
12981299
async with profile.session() as session:
12991300
connection = await ConnRecord.retrieve_by_id(
1300-
session, meta_data["endorser"]["connection_id"]
1301+
session, endorser_connection_id
13011302
)
13021303
endorser_info = await connection.metadata_get(session, "endorser_info")
13031304
endorser_did = endorser_info["endorser_did"]
13041305
write_ledger = False
13051306
else:
1307+
endorser_connection_id = None
13061308
endorser_did = None
13071309
write_ledger = True
13081310

@@ -1313,10 +1315,8 @@ async def on_revocation_registry_init_event(profile: Profile, event: Event):
13131315
# Generate the registry and upload the tails file
13141316
async def generate(rr_record: IssuerRevRegRecord) -> dict:
13151317
await rr_record.generate_registry(profile)
1316-
await rr_record.set_tails_file_public_uri(
1317-
profile,
1318-
f"{tails_base_url}/{registry_record.revoc_reg_id}",
1319-
)
1318+
public_uri = tails_base_url.rstrip("/") + f"/{registry_record.revoc_reg_id}"
1319+
await rr_record.set_tails_file_public_uri(profile, public_uri)
13201320
rev_reg_resp = await rr_record.send_def(
13211321
profile,
13221322
write_ledger=write_ledger,
@@ -1381,6 +1381,7 @@ async def generate(rr_record: IssuerRevRegRecord) -> dict:
13811381
registry_record.cred_def_id,
13821382
registry_record.max_cred_num,
13831383
registry_record.revoc_def_type,
1384+
endorser_connection_id=endorser_connection_id,
13841385
)
13851386

13861387

@@ -1450,18 +1451,25 @@ async def on_revocation_entry_event(profile: Profile, event: Event):
14501451

14511452

14521453
async def on_revocation_registry_endorsed_event(profile: Profile, event: Event):
1453-
"""Handle revocation tails file event."""
1454+
"""Handle revocation registry endorsement event."""
14541455
meta_data = event.payload
14551456
rev_reg_id = meta_data["context"]["rev_reg_id"]
14561457
revoc = IndyRevocation(profile)
14571458
registry_record = await revoc.get_issuer_rev_reg_record(rev_reg_id)
1458-
# NOTE: if there are multiple pods, then the one processing this
1459-
# event may not be the one that generated the tails file.
1460-
await registry_record.upload_tails_file(profile)
1459+
1460+
if profile.settings.get_value("endorser.auto_request"):
1461+
# NOTE: if there are multiple pods, then the one processing this
1462+
# event may not be the one that generated the tails file.
1463+
await registry_record.upload_tails_file(profile)
1464+
1465+
# Post the initial revocation entry
1466+
await notify_revocation_entry_event(
1467+
profile, registry_record.record_id, meta_data
1468+
)
14611469

14621470
# create a "pending" registry if one is requested
14631471
# (this is done automatically when creating a credential definition, so that when a
1464-
# revocation registry fills up, we ca continue to issue credentials without a
1472+
# revocation registry fills up, we can continue to issue credentials without a
14651473
# delay)
14661474
create_pending_rev_reg = meta_data["processing"].get(
14671475
"create_pending_rev_reg", False

aries_cloudagent/revocation/util.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
EVENT_LISTENER_PATTERN = re.compile(f"^{REVOCATION_EVENT_PREFIX}(.*)?$")
1111
REVOCATION_REG_INIT_EVENT = "REGISTRY_INIT"
1212
REVOCATION_REG_ENDORSED_EVENT = "REGISTRY_ENDORSED"
13-
REVOCATION_ENTRY_EVENT = "ENTRY"
13+
REVOCATION_ENTRY_ENDORSED_EVENT = "ENTRY_ENDORSED"
14+
REVOCATION_ENTRY_EVENT = "SEND_ENTRY"
1415
REVOCATION_PUBLISHED_EVENT = "published"
1516
REVOCATION_CLEAR_PENDING_EVENT = "clear-pending"
1617

@@ -50,6 +51,14 @@ async def notify_revocation_reg_endorsed_event(
5051
await profile.notify(topic, meta_data)
5152

5253

54+
async def notify_revocation_entry_endorsed_event(
55+
profile: Profile, rev_reg_id: str, meta_data: dict
56+
):
57+
"""Send notification for a revocation registry entry endorsement event."""
58+
topic = f"{REVOCATION_EVENT_PREFIX}{REVOCATION_ENTRY_ENDORSED_EVENT}::{rev_reg_id}"
59+
await profile.notify(topic, meta_data)
60+
61+
5362
async def notify_revocation_published_event(
5463
profile: Profile,
5564
rev_reg_id: str,

aries_cloudagent/tails/indy_tails_server.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Indy tails server interface class."""
22

3-
from typing import Tuple
43
import logging
54

5+
from typing import Tuple
6+
67
from ..config.injection_context import InjectionContext
78
from ..ledger.multiple_ledger.base_manager import BaseMultipleLedgerManager
89
from ..utils.http import put_file, PutError
@@ -58,17 +59,18 @@ async def upload_tails_file(
5859
"tails_server_upload_url setting is not set"
5960
)
6061

62+
upload_url = tails_server_upload_url.rstrip("/") + f"/{rev_reg_id}"
63+
6164
try:
62-
return (
63-
True,
64-
await put_file(
65-
f"{tails_server_upload_url}/{rev_reg_id}",
66-
{"tails": tails_file_path},
67-
{"genesis": genesis_transactions},
68-
interval=interval,
69-
backoff=backoff,
70-
max_attempts=max_attempts,
71-
),
65+
await put_file(
66+
upload_url,
67+
{"tails": tails_file_path},
68+
{"genesis": genesis_transactions},
69+
interval=interval,
70+
backoff=backoff,
71+
max_attempts=max_attempts,
7272
)
7373
except PutError as x_put:
7474
return (False, x_put.message)
75+
76+
return True, upload_url

aries_cloudagent/tails/tests/test_indy.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ async def test_upload(self):
3838
"/tmp/dummy/path",
3939
)
4040
assert ok
41-
assert text == "tails-hash"
41+
assert (
42+
text == context.settings["tails_server_upload_url"] + "/" + REV_REG_ID
43+
)
4244

4345
async def test_upload_indy_sdk(self):
4446
profile = InMemoryProfile.test_profile()
@@ -68,7 +70,9 @@ async def test_upload_indy_sdk(self):
6870
"/tmp/dummy/path",
6971
)
7072
assert ok
71-
assert text == "tails-hash"
73+
assert (
74+
text == profile.settings["tails_server_upload_url"] + "/" + REV_REG_ID
75+
)
7276

7377
async def test_upload_indy_vdr(self):
7478
profile = InMemoryProfile.test_profile()
@@ -98,7 +102,9 @@ async def test_upload_indy_vdr(self):
98102
"/tmp/dummy/path",
99103
)
100104
assert ok
101-
assert text == "tails-hash"
105+
assert (
106+
text == profile.settings["tails_server_upload_url"] + "/" + REV_REG_ID
107+
)
102108

103109
async def test_upload_x(self):
104110
context = InjectionContext(

0 commit comments

Comments
 (0)