77
88from ..core .profile import Profile
99from ..ledger .base import BaseLedger
10+ from ..ledger .error import LedgerError
1011from ..ledger .multiple_ledger .ledger_requests_executor import (
1112 GET_CRED_DEF ,
1213 GET_REVOC_REG_DEF ,
@@ -260,6 +261,7 @@ async def get_or_create_active_registry(
260261 except StorageNotFoundError :
261262 pass
262263
264+ posted_registries = []
263265 async with self ._profile .session () as session :
264266 full_registries = await IssuerRevRegRecord .query_by_cred_def_id (
265267 session , cred_def_id , None , IssuerRevRegRecord .STATE_FULL , 1
@@ -280,19 +282,30 @@ async def get_or_create_active_registry(
280282 cred_def_id ,
281283 max_cred_num = any_registry .max_cred_num ,
282284 )
283- # if there is a posted registry, activate oldest
285+ # if there is a posted registry, complete its setup and activate it
284286 else :
285287 posted_registries = await IssuerRevRegRecord .query_by_cred_def_id (
286288 session , cred_def_id , IssuerRevRegRecord .STATE_POSTED , None , None
287289 )
288- if posted_registries :
289- posted_registries = sorted (
290- posted_registries , key = lambda r : r .created_at
291- )
292- await self ._set_registry_status (
293- revoc_reg_id = posted_registries [0 ].revoc_reg_id ,
294- state = IssuerRevRegRecord .STATE_ACTIVE ,
295- )
290+
291+ if posted_registries :
292+ # A registry is only left posted when its setup stalled after the
293+ # definition reached the ledger: the tails file upload and/or the
294+ # initial accumulator entry are still outstanding. Complete those
295+ # steps instead of activating with a bare state change, which would
296+ # break every credential later issued against the registry
297+ # (unresolvable tailsLocation, missing initial entry).
298+ rec = min (posted_registries , key = lambda r : r .created_at )
299+ try :
300+ await rec .upload_tails_file (self ._profile )
301+ # publishing the initial entry transitions posted -> active
302+ await rec .send_entry (self ._profile )
303+ except (RevocationError , LedgerError ):
304+ LOGGER .exception (
305+ "Setup of posted revocation registry %s could not be completed; "
306+ "not activating (will retry on next issuance attempt)" ,
307+ rec .revoc_reg_id ,
308+ )
296309 return None
297310
298311 async def get_ledger_registry (self , revoc_reg_id : str ) -> RevocationRegistry :
0 commit comments