Skip to content

Commit

Permalink
fix(prism-agent): infinite loop in proof presentation execution (#540)
Browse files Browse the repository at this point in the history
* feat(prism-agent): add unique constraint to 'presentation_records.thid'

* feat(prism-agent): handle DIDComm error responses appropriately and decrease retry counter

* chore(prism-agent): run scalafmt
  • Loading branch information
bvoiturier authored May 31, 2023
1 parent 6129baf commit 6a26bb7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE public.presentation_records ADD CONSTRAINT presentation_records_unique_thid UNIQUE (thid);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.iohk.atala.agent.server.jobs

import io.iohk.atala.mercury.HttpResponse

sealed trait BackgroundJobError

object BackgroundJobError {
final case class InvalidState(cause: String) extends BackgroundJobError
case object NotImplemented extends BackgroundJobError
final case class ErrorResponseReceivedFromPeerAgent(response: HttpResponse) extends BackgroundJobError {
override def toString: String = s"DIDComm sending error: [${response.status}] - ${response.bodyAsString}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import io.circe.Json
import io.circe.parser.*
import io.circe.syntax.*
import io.iohk.atala.agent.server.config.AppConfig
import io.iohk.atala.agent.server.http.model.{InvalidState, NotImplemented}
import io.iohk.atala.agent.server.jobs.BackgroundJobError.{
ErrorResponseReceivedFromPeerAgent,
InvalidState,
NotImplemented
}
import io.iohk.atala.agent.walletapi.model.*
import io.iohk.atala.agent.walletapi.model.error.*
import io.iohk.atala.agent.walletapi.model.error.DIDSecretStorageError.KeyNotFoundError
Expand Down Expand Up @@ -131,7 +135,7 @@ object BackgroundJobs {
credentialService <- ZIO.service[CredentialService]
_ <- {
if (resp.status >= 200 && resp.status < 300) credentialService.markOfferSent(id)
else ZIO.logWarning(s"DIDComm sending error: [${resp.status}] - ${resp.bodyAsString}")
else ZIO.fail(ErrorResponseReceivedFromPeerAgent(resp))
}
} yield ()

Expand Down Expand Up @@ -201,7 +205,7 @@ object BackgroundJobs {
credentialService <- ZIO.service[CredentialService]
_ <- {
if (resp.status >= 200 && resp.status < 300) credentialService.markRequestSent(id)
else ZIO.logWarning(s"DIDComm sending error: [${resp.status}] - ${resp.bodyAsString}")
else ZIO.fail(ErrorResponseReceivedFromPeerAgent(resp))
}
} yield ()

Expand Down Expand Up @@ -310,7 +314,7 @@ object BackgroundJobs {
credentialService <- ZIO.service[CredentialService]
_ <- {
if (resp.status >= 200 && resp.status < 300) credentialService.markCredentialSent(id)
else ZIO.logWarning(s"DIDComm sending error: [${resp.status}] - ${resp.bodyAsString}")
else ZIO.fail(ErrorResponseReceivedFromPeerAgent(resp))
}
} yield ()

Expand Down Expand Up @@ -343,7 +347,7 @@ object BackgroundJobs {
credentialService <- ZIO.service[CredentialService]
_ <- {
if (resp.status >= 200 && resp.status < 300) credentialService.markCredentialSent(id)
else ZIO.logWarning(s"DIDComm sending error: [${resp.status}] - ${resp.bodyAsString}")
else ZIO.fail(ErrorResponseReceivedFromPeerAgent(resp))
}
} yield ()

Expand Down Expand Up @@ -489,7 +493,7 @@ object BackgroundJobs {
service <- ZIO.service[PresentationService]
_ <- {
if (resp.status >= 200 && resp.status < 300) service.markRequestPresentationSent(id)
else ZIO.logWarning(s"DIDComm sending error: [${resp.status}] - ${resp.bodyAsString}")
else ZIO.fail(ErrorResponseReceivedFromPeerAgent(resp))
}
} yield ()

Expand Down Expand Up @@ -575,7 +579,7 @@ object BackgroundJobs {
service <- ZIO.service[PresentationService]
_ <- {
if (resp.status >= 200 && resp.status < 300) service.markPresentationSent(id)
else ZIO.logWarning(s"DIDComm sending error: [${resp.status}] - ${resp.bodyAsString}")
else ZIO.fail(ErrorResponseReceivedFromPeerAgent(resp))
}
} yield ()
case PresentationRecord(id, _, _, _, _, _, _, _, PresentationSent, _, _, _, _, _, _, _) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.iohk.atala.agent.server.jobs

import com.nimbusds.jose.jwk.OctetKeyPair
import io.iohk.atala.agent.server.config.AppConfig
import io.iohk.atala.agent.server.jobs.BackgroundJobError.ErrorResponseReceivedFromPeerAgent
import io.iohk.atala.agent.walletapi.model.error.DIDSecretStorageError
import io.iohk.atala.agent.walletapi.model.error.DIDSecretStorageError.KeyNotFoundError
import io.iohk.atala.agent.walletapi.service.ManagedDIDService
Expand Down Expand Up @@ -65,7 +66,7 @@ object ConnectBackgroundJobs {
connectionService <- ZIO.service[ConnectionService]
_ <- {
if (resp.status >= 200 && resp.status < 300) connectionService.markConnectionRequestSent(id)
else ZIO.logWarning(s"DIDComm sending error: [${resp.status}] - ${resp.bodyAsString}")
else ZIO.fail(ErrorResponseReceivedFromPeerAgent(resp))
}
} yield ()

Expand Down Expand Up @@ -93,14 +94,10 @@ object ConnectBackgroundJobs {
connectionService <- ZIO.service[ConnectionService]
_ <- {
if (resp.status >= 200 && resp.status < 300) connectionService.markConnectionResponseSent(id)
else ZIO.logWarning(s"DIDComm sending error: [${resp.status}] - ${resp.bodyAsString}")
else ZIO.fail(ErrorResponseReceivedFromPeerAgent(resp))
}
} yield ()
case e
if (e.protocolState == ConnectionRequestPending || e.protocolState == ConnectionResponsePending) && e.metaRetries == 0 =>
ZIO.logWarning( // TODO use logDebug
s"ConnectionRecord '${e.id}' has '${e.metaRetries}' retries and will NOT be processed"
)

case _ => ZIO.unit
}

Expand Down

0 comments on commit 6a26bb7

Please sign in to comment.