Skip to content

Commit

Permalink
fix(pollux): function that allocates status list credential does not …
Browse files Browse the repository at this point in the history
…work correctly in multi threaded environment (#941)

Signed-off-by: Shota Jolbordi <shota.jolbordi@iohk.io>
  • Loading branch information
shotexa authored Mar 20, 2024
1 parent bb5ead1 commit ecc3c01
Showing 1 changed file with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ private class CredentialServiceImpl(
statusListRegistryUrl: String,
jwtIssuer: JwtIssuer
): ZIO[WalletAccessContext, CredentialServiceError, CredentialStatus] = {
for {
val effect = for {
lastStatusList <- credentialStatusListRepository.getLatestOfTheWallet.mapError(RepositoryError.apply)
currentStatusList <- lastStatusList
.fold(credentialStatusListRepository.createNewForTheWallet(jwtIssuer, statusListRegistryUrl))(
Expand All @@ -1120,31 +1120,27 @@ private class CredentialServiceImpl(
.mapError(RepositoryError.apply)
size = currentStatusList.size
lastUsedIndex = currentStatusList.lastUsedIndex
statusListToBeUsed <- issueCredentialSem.withPermit {
for {
statusListToBeUsed <-
if lastUsedIndex < size then ZIO.succeed(currentStatusList)
else
credentialStatusListRepository
.createNewForTheWallet(jwtIssuer, statusListRegistryUrl)
.mapError(RepositoryError.apply)

_ <- credentialStatusListRepository
.allocateSpaceForCredential(
issueCredentialRecordId = record.id,
credentialStatusListId = statusListToBeUsed.id,
statusListIndex = statusListToBeUsed.lastUsedIndex + 1
)
statusListToBeUsed <-
if lastUsedIndex < size then ZIO.succeed(currentStatusList)
else
credentialStatusListRepository
.createNewForTheWallet(jwtIssuer, statusListRegistryUrl)
.mapError(RepositoryError.apply)
} yield statusListToBeUsed
}
_ <- credentialStatusListRepository
.allocateSpaceForCredential(
issueCredentialRecordId = record.id,
credentialStatusListId = statusListToBeUsed.id,
statusListIndex = statusListToBeUsed.lastUsedIndex + 1
)
.mapError(RepositoryError.apply)
} yield CredentialStatus(
id = s"$statusListRegistryUrl/credential-status/${statusListToBeUsed.id}#${statusListToBeUsed.lastUsedIndex + 1}",
`type` = "StatusList2021Entry",
statusPurpose = StatusPurpose.Revocation,
statusListIndex = lastUsedIndex + 1,
statusListCredential = s"$statusListRegistryUrl/credential-status/${statusListToBeUsed.id}"
)
issueCredentialSem.withPermit(effect)
}

override def generateAnonCredsCredential(
Expand Down

0 comments on commit ecc3c01

Please sign in to comment.