Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pollux): function that allocates status list credential does not work correctly in multi threaded environment #941

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading