From 64a7857ecc0acc6d940e7f2fcce1c68c8163562c Mon Sep 17 00:00:00 2001 From: Fabio Pinheiro Date: Tue, 7 Feb 2023 13:30:31 +0000 Subject: [PATCH] feat(prism-agent): Upgrade libs (#344) Upgrade connect to 0.8.0 Upgrade pollux to 0.22.0 Upgrade mercury to 0.17.0 Fix code --- .../service/project/Dependencies.scala | 6 +-- .../io/iohk/atala/agent/server/Modules.scala | 10 +++- ...sueCredentialsProtocolApiServiceImpl.scala | 8 ++- .../agent/server/jobs/BackgroundJobs.scala | 4 +- .../server/jobs/ConnectBackgroundJobs.scala | 50 +++++++++++++++++-- 5 files changed, 66 insertions(+), 12 deletions(-) diff --git a/prism-agent/service/project/Dependencies.scala b/prism-agent/service/project/Dependencies.scala index e237a96813..b516ee82dc 100644 --- a/prism-agent/service/project/Dependencies.scala +++ b/prism-agent/service/project/Dependencies.scala @@ -9,11 +9,11 @@ object Dependencies { val akka = "2.6.20" val akkaHttp = "10.2.9" val castor = "0.8.0" - val pollux = "0.22.0" - val connect = "0.7.0" + val pollux = "0.23.0" + val connect = "0.9.0" val bouncyCastle = "1.70" val logback = "1.4.5" - val mercury = "0.16.0" + val mercury = "0.17.0" val zioJson = "0.3.0" val tapir = "1.2.3" val flyway = "9.8.3" diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Modules.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Modules.scala index b1013b3182..fab32a75a6 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Modules.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Modules.scala @@ -335,7 +335,10 @@ object Modules { for { _ <- ZIO.logInfo("*" * 100) _ <- ZIO.logInfo("As an Inviter in connect:") - connectionRequest = ConnectionRequest.readFromMessage(msg) + connectionRequest <- ConnectionRequest.fromMessage(msg) match { + case Left(error) => ZIO.fail(new RuntimeException(error)) + case Right(value) => ZIO.succeed(value) + } _ <- ZIO.logInfo("Got ConnectionRequest: " + connectionRequest) // Receive and store ConnectionRequest maybeRecord <- connectionService @@ -360,7 +363,10 @@ object Modules { for { _ <- ZIO.logInfo("*" * 100) _ <- ZIO.logInfo("As an Invitee in connect:") - connectionResponse = ConnectionResponse.readFromMessage(msg) + connectionResponse <- ConnectionResponse.fromMessage(msg) match { + case Left(error) => ZIO.fail(new RuntimeException(error)) + case Right(value) => ZIO.succeed(value) + } _ <- ZIO.logInfo("Got ConnectionResponse: " + connectionResponse) _ <- connectionService .receiveConnectionResponse(connectionResponse) diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/service/IssueCredentialsProtocolApiServiceImpl.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/service/IssueCredentialsProtocolApiServiceImpl.scala index 8627eb575b..a835471811 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/service/IssueCredentialsProtocolApiServiceImpl.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/service/IssueCredentialsProtocolApiServiceImpl.scala @@ -173,7 +173,9 @@ class IssueCredentialsProtocolApiServiceImpl( ProtocolState.ConnectionResponseSent, _, _, - Some(resp) + Some(resp), + _, // metaRetries: Int, + _, // metaLastFailure: Option[String] ) => ZIO.succeed(DidIdPair(resp.from, resp.to)) case ConnectionRecord( @@ -186,7 +188,9 @@ class IssueCredentialsProtocolApiServiceImpl( ProtocolState.ConnectionResponseReceived, _, _, - Some(resp) + Some(resp), + _, // metaRetries: Int, + _, // metaLastFailure: Option[String] ) => ZIO.succeed(DidIdPair(resp.to, resp.from)) case _ => diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/jobs/BackgroundJobs.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/jobs/BackgroundJobs.scala index db3fd9eb29..e19623aa87 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/jobs/BackgroundJobs.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/jobs/BackgroundJobs.scala @@ -510,7 +510,9 @@ object BackgroundJobs { private[this] def performPublishCredentialsToDlt(credentialService: CredentialService) = { val res: ZIO[Any, CredentialServiceError, Unit] = for { - records <- credentialService.getCredentialRecordsByState(IssueCredentialRecord.ProtocolState.CredentialPending) + records <- credentialService.getIssueCredentialRecordsByStates( + IssueCredentialRecord.ProtocolState.CredentialPending + ) // NOTE: the line below is a potentially slow operation, because makes a database SELECT call, // so calling this function n times will make n database SELECT calls, while it can be optimized to get // all data in one query, this function here has to be refactored as well. Consider doing this if this job is too slow diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/jobs/ConnectBackgroundJobs.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/jobs/ConnectBackgroundJobs.scala index f63b4d277b..ded93f4f64 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/jobs/ConnectBackgroundJobs.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/jobs/ConnectBackgroundJobs.scala @@ -37,22 +37,64 @@ object ConnectBackgroundJobs { import Role._ import ProtocolState._ val exchange = record match { - case ConnectionRecord(id, _, _, _, _, Invitee, ConnectionRequestPending, _, Some(request), _) => - for { + case ConnectionRecord( + id, + _, + _, + _, + _, + Invitee, + ConnectionRequestPending, + _, + Some(request), + _, + metaRetries, + _ + ) if metaRetries > 0 => + val aux = for { + didCommAgent <- buildDIDCommAgent(request.from) _ <- MessagingService.send(request.makeMessage).provideSomeLayer(didCommAgent) connectionService <- ZIO.service[ConnectionService] _ <- connectionService.markConnectionRequestSent(id) } yield () - case ConnectionRecord(id, _, _, _, _, Inviter, ConnectionResponsePending, _, _, Some(response)) => - for { + // aux // TODO decrete metaRetries if it has a error + aux + + case ConnectionRecord( + id, + _, + _, + _, + _, + Inviter, + ConnectionResponsePending, + _, + _, + Some(response), + metaRetries, + _ + ) if metaRetries > 0 => + val aux = for { didCommAgent <- buildDIDCommAgent(response.from) _ <- MessagingService.send(response.makeMessage).provideSomeLayer(didCommAgent) connectionService <- ZIO.service[ConnectionService] _ <- connectionService.markConnectionResponseSent(id) } yield () + aux.tapError(ex => + for { + connectionService <- ZIO.service[ConnectionService] + _ <- connectionService + .reportProcessingFailure(id, None) // TODO ex get message + } 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 }