From 3140a7ee89e6b1329d170bf019ec5ff9c1323901 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Fri, 17 Mar 2023 15:49:33 +0100 Subject: [PATCH 01/77] Check `canUpdateReplicateStatus` a single time per update --- build.gradle | 3 ++ .../core/replicate/ReplicatesController.java | 26 +++++++------- .../core/replicate/ReplicatesService.java | 35 ++++++++++--------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/build.gradle b/build.gradle index 21d6b46e2..2b8bb3d94 100644 --- a/build.gradle +++ b/build.gradle @@ -100,6 +100,9 @@ dependencies { implementation "com.github.cloudyrock.mongock:mongock-spring-v5:${mongockVersion}" implementation "com.github.cloudyrock.mongock:mongodb-springdata-v2-driver:${mongockVersion}" + // vavr + implementation 'io.vavr:vavr:0.10.4' + testImplementation 'org.springframework.boot:spring-boot-starter-test' // awaitility diff --git a/src/main/java/com/iexec/core/replicate/ReplicatesController.java b/src/main/java/com/iexec/core/replicate/ReplicatesController.java index 3ee9b748b..4278d0f03 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicatesController.java +++ b/src/main/java/com/iexec/core/replicate/ReplicatesController.java @@ -22,6 +22,8 @@ import com.iexec.core.security.JwtTokenProvider; import com.iexec.core.worker.WorkerService; import feign.FeignException; +import io.vavr.control.Either; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -31,6 +33,7 @@ import static org.springframework.http.ResponseEntity.status; +@Slf4j @RestController public class ReplicatesController { @@ -127,22 +130,21 @@ public ResponseEntity updateReplicateStatus( chainTaskId, walletAddress, statusUpdate); - final ReplicateStatusUpdateError replicateStatusUpdateError = replicatesService.canUpdateReplicateStatus( - chainTaskId, - walletAddress, - statusUpdate, - updateReplicateStatusArgs); - switch (replicateStatusUpdateError) { - case NO_ERROR: - return replicatesService - .updateReplicateStatus(chainTaskId, walletAddress, statusUpdate, updateReplicateStatusArgs) - .map(ResponseEntity::ok) - .orElse(ResponseEntity.status(HttpStatus.ACCEPTED) - .body(TaskNotificationType.PLEASE_ABORT)); + final Either updateResult = replicatesService + .updateReplicateStatus(chainTaskId, walletAddress, statusUpdate, updateReplicateStatusArgs); + if (updateResult.isRight()) { + return ResponseEntity.ok(updateResult.get()); + } + + switch (updateResult.getLeft()) { case ALREADY_REPORTED: return ResponseEntity.status(HttpStatus.ALREADY_REPORTED) .body(TaskNotificationType.PLEASE_WAIT); + case NO_ERROR: + log.warn("An error has been detected on replicate update but no error is returned" + + " [chainTaskId:{}, statusUpdate:{}]", chainTaskId, statusUpdate); + return ResponseEntity.internalServerError().build(); case UNKNOWN_REPLICATE: case BAD_WORKFLOW_TRANSITION: case GENERIC_CANT_UPDATE: diff --git a/src/main/java/com/iexec/core/replicate/ReplicatesService.java b/src/main/java/com/iexec/core/replicate/ReplicatesService.java index 06b965530..280cedc73 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicatesService.java +++ b/src/main/java/com/iexec/core/replicate/ReplicatesService.java @@ -26,6 +26,7 @@ import com.iexec.core.result.ResultService; import com.iexec.core.logs.TaskLogsService; import com.iexec.core.workflow.ReplicateWorkflow; +import io.vavr.control.Either; import lombok.extern.slf4j.Slf4j; import org.springframework.context.ApplicationEventPublisher; import org.springframework.dao.OptimisticLockingFailureException; @@ -311,7 +312,7 @@ public void updateReplicateStatus(OptimisticLockingFailureException exception, } @Retryable(value = {OptimisticLockingFailureException.class}, maxAttempts = 100) - public Optional updateReplicateStatus(String chainTaskId, + public Either updateReplicateStatus(String chainTaskId, String walletAddress, ReplicateStatusUpdate statusUpdate) { final UpdateReplicateStatusArgs updateReplicateStatusArgs = computeUpdateReplicateStatusArgs( @@ -327,12 +328,12 @@ public Optional updateReplicateStatus(String chainTaskId, } @Recover - public Optional updateReplicateStatus(OptimisticLockingFailureException exception, + public Either updateReplicateStatus(OptimisticLockingFailureException exception, String chainTaskId, String walletAddress, ReplicateStatusUpdate statusUpdate) { logUpdateReplicateStatusRecover(exception); - return Optional.empty(); + return null; } /* @@ -355,10 +356,11 @@ public Optional updateReplicateStatus(OptimisticLockingFai * @param walletAddress Wallet address of the worker whose replicate should be updated. * @param statusUpdate Info about the status update - new status, date of update, ... * @param updateReplicateStatusArgs Optional args used to update the status. - * @return An optional next action for the worker. + * @return Either a {@link ReplicateStatusUpdateError} if the status can't be updated, + * or a next action for the worker. */ @Retryable(value = {OptimisticLockingFailureException.class}, maxAttempts = 100) - public Optional updateReplicateStatus(String chainTaskId, + public Either updateReplicateStatus(String chainTaskId, String walletAddress, ReplicateStatusUpdate statusUpdate, UpdateReplicateStatusArgs updateReplicateStatusArgs) { @@ -372,14 +374,14 @@ public Optional updateReplicateStatus(String chainTaskId, } @Recover - public Optional updateReplicateStatus( + public Either updateReplicateStatus( OptimisticLockingFailureException exception, String chainTaskId, String walletAddress, ReplicateStatusUpdate statusUpdate, UpdateReplicateStatusArgs updateReplicateStatusArgs) { logUpdateReplicateStatusRecover(exception); - return Optional.empty(); + return null; } /** @@ -393,18 +395,19 @@ public Optional updateReplicateStatus( * @param walletAddress Wallet address of the worker whose replicate should be updated. * @param statusUpdate Info about the status update - new status, date of update, ... * @param updateReplicateStatusArgs Optional args used to update the status. - * @return An optional next action for the worker. + * @return Either a {@link ReplicateStatusUpdateError} if the status can't be updated, + * or a next action for the worker. */ - Optional updateReplicateStatusWithoutThreadSafety(String chainTaskId, - String walletAddress, - ReplicateStatusUpdate statusUpdate, - UpdateReplicateStatusArgs updateReplicateStatusArgs) { + Either updateReplicateStatusWithoutThreadSafety(String chainTaskId, + String walletAddress, + ReplicateStatusUpdate statusUpdate, + UpdateReplicateStatusArgs updateReplicateStatusArgs) { log.info("Replicate update request [status:{}, chainTaskId:{}, walletAddress:{}, details:{}]", statusUpdate.getStatus(), chainTaskId, walletAddress, statusUpdate.getDetailsWithoutLogs()); - if (ReplicateStatusUpdateError.NO_ERROR - != canUpdateReplicateStatus(chainTaskId, walletAddress, statusUpdate, updateReplicateStatusArgs)) { - return Optional.empty(); + final ReplicateStatusUpdateError error = canUpdateReplicateStatus(chainTaskId, walletAddress, statusUpdate, updateReplicateStatusArgs); + if (ReplicateStatusUpdateError.NO_ERROR != error) { + return Either.left(error); } ReplicatesList replicatesList = getReplicatesList(chainTaskId).orElseThrow(); // "get" could be used there but triggers a warning @@ -441,7 +444,7 @@ Optional updateReplicateStatusWithoutThreadSafety(String c "nextAction:{}, chainTaskId:{}, walletAddress:{}]", replicate.getCurrentStatus(), newStatusCause, nextAction, chainTaskId, walletAddress); - return Optional.ofNullable(nextAction); + return Either.right(nextAction); } private void logUpdateReplicateStatusRecover(OptimisticLockingFailureException exception) { From f6ac07bbb43bd544134a79c3a1df2f16555fcb74 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Mon, 20 Mar 2023 15:10:29 +0100 Subject: [PATCH 02/77] Update tests on replicates --- .../core/replicate/ReplicateControllerTests.java | 13 +++++++------ .../iexec/core/replicate/ReplicateServiceTests.java | 6 ++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java b/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java index bbd4316ff..d2390a490 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java @@ -6,6 +6,7 @@ import com.iexec.common.replicate.*; import com.iexec.core.security.JwtTokenProvider; import com.iexec.core.worker.WorkerService; +import io.vavr.control.Either; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -178,7 +179,7 @@ void shouldUpdateReplicate() { when(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE, UPDATE_ARGS)) .thenReturn(ReplicateStatusUpdateError.NO_ERROR); when(replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE, UPDATE_ARGS)) - .thenReturn(Optional.of(TaskNotificationType.PLEASE_DOWNLOAD_APP)); + .thenReturn(Either.right(TaskNotificationType.PLEASE_DOWNLOAD_APP)); ResponseEntity response = replicatesController.updateReplicateStatus(TOKEN, CHAIN_TASK_ID, UPDATE); @@ -203,7 +204,7 @@ void shouldUpdateReplicateAndSetWalletAddress() { when(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_ADDRESS, updateWithLogs, UPDATE_ARGS)) .thenReturn(ReplicateStatusUpdateError.NO_ERROR); when(replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_ADDRESS, updateWithLogs, UPDATE_ARGS)) - .thenReturn(Optional.of(TaskNotificationType.PLEASE_DOWNLOAD_APP)); + .thenReturn(Either.right((TaskNotificationType.PLEASE_DOWNLOAD_APP))); ResponseEntity response = replicatesController.updateReplicateStatus(TOKEN, CHAIN_TASK_ID, updateWithLogs); @@ -233,8 +234,8 @@ void shouldReturnPleaseAbortSinceCantUpdate() { .thenReturn(WALLET_ADDRESS); when(replicatesService.computeUpdateReplicateStatusArgs(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE)) .thenReturn(UPDATE_ARGS); - when(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE, UPDATE_ARGS)) - .thenReturn(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE); + when(replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE, UPDATE_ARGS)) + .thenReturn(Either.left(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE)); ResponseEntity response = replicatesController.updateReplicateStatus(TOKEN, CHAIN_TASK_ID, UPDATE); @@ -249,8 +250,8 @@ void shouldReply208AlreadyReported() { .thenReturn(WALLET_ADDRESS); when(replicatesService.computeUpdateReplicateStatusArgs(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE)) .thenReturn(UPDATE_ARGS); - when(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE, UPDATE_ARGS)) - .thenReturn(ReplicateStatusUpdateError.ALREADY_REPORTED); + when(replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE, UPDATE_ARGS)) + .thenReturn(Either.left(ReplicateStatusUpdateError.ALREADY_REPORTED)); ResponseEntity response = replicatesController.updateReplicateStatus(TOKEN, CHAIN_TASK_ID, UPDATE); diff --git a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java index 58115905a..18a254233 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java @@ -26,6 +26,7 @@ import com.iexec.core.chain.Web3jService; import com.iexec.core.logs.TaskLogsService; import com.iexec.core.result.ResultService; +import io.vavr.control.Either; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -627,8 +628,9 @@ void shouldNotUpdateReplicateStatusSinceAlreadyReported() { .status(CONTRIBUTED) .build(); - final Optional result = replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate); - assertThat(result).isEmpty(); + final Either result = + replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate); + assertThat(result.getLeft()).isEqualTo(ReplicateStatusUpdateError.ALREADY_REPORTED); } @Test From f1ede2e804fdc517b2a8fdda2a3fa4259a26470b Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Mon, 20 Mar 2023 16:57:04 +0100 Subject: [PATCH 03/77] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cfc61433..e7d35da5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. ### Bug Fixes * Remove explicit version on `micrometer-registry-prometheus` dependency. (#563) * Send a `TaskNotificationType` to worker through a 2XX HTTP status code. (#564) +* Prevent race condition on replicate update. (#568) ### Quality ### Dependency Upgrades From 039995f98658b3c35054d02b76adb52066b666e7 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Mon, 20 Mar 2023 17:07:08 +0100 Subject: [PATCH 04/77] Improve code coverage --- .../core/replicate/ReplicateControllerTests.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java b/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java index d2390a490..728537415 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java @@ -260,5 +260,20 @@ void shouldReply208AlreadyReported() { assertThat(response.getBody()) .isEqualTo(TaskNotificationType.PLEASE_WAIT); } + + @Test + void shouldReply500WhenErrorNoExpected() { + when(jwtTokenProvider.getWalletAddressFromBearerToken(TOKEN)) + .thenReturn(WALLET_ADDRESS); + when(replicatesService.computeUpdateReplicateStatusArgs(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE)) + .thenReturn(UPDATE_ARGS); + when(replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE, UPDATE_ARGS)) + .thenReturn(Either.left(ReplicateStatusUpdateError.NO_ERROR)); + + ResponseEntity response = + replicatesController.updateReplicateStatus(TOKEN, CHAIN_TASK_ID, UPDATE); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + } //endregion } From 382cbcc8ddb76be2cd6c26982ccbaf80ec3ae807 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Tue, 21 Mar 2023 10:39:12 +0100 Subject: [PATCH 05/77] Init next changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5b090c71..1a36d40cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## [[NEXT]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/vNEXT) 2023 + +### New Features +### Bug Fixes +### Quality +### Dependency Upgrades + ## [[8.0.1]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.0.1) 2023-03-20 ### Bug Fixes From ec0a9ecc34bd6f08d339d08217dcabd935e49a75 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton <87655102+mcornaton@users.noreply.github.com> Date: Wed, 22 Mar 2023 14:12:14 +0100 Subject: [PATCH 06/77] Update src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java Co-authored-by: Jeremy Bernard --- .../java/com/iexec/core/replicate/ReplicateControllerTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java b/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java index 728537415..2cabc2695 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java @@ -262,7 +262,7 @@ void shouldReply208AlreadyReported() { } @Test - void shouldReply500WhenErrorNoExpected() { + void shouldReply500WhenErrorNotExpected() { when(jwtTokenProvider.getWalletAddressFromBearerToken(TOKEN)) .thenReturn(WALLET_ADDRESS); when(replicatesService.computeUpdateReplicateStatusArgs(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE)) From ef3d1b4a288891a8b26665a00e16f818b019ba16 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Wed, 22 Mar 2023 14:20:31 +0100 Subject: [PATCH 07/77] Reformat methods parameters --- .../core/replicate/ReplicatesService.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/iexec/core/replicate/ReplicatesService.java b/src/main/java/com/iexec/core/replicate/ReplicatesService.java index a00b0aaae..2526493d3 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicatesService.java +++ b/src/main/java/com/iexec/core/replicate/ReplicatesService.java @@ -313,9 +313,10 @@ public void updateReplicateStatus(OptimisticLockingFailureException exception, } @Retryable(value = {OptimisticLockingFailureException.class}, maxAttempts = 100) - public Either updateReplicateStatus(String chainTaskId, - String walletAddress, - ReplicateStatusUpdate statusUpdate) { + public Either updateReplicateStatus( + String chainTaskId, + String walletAddress, + ReplicateStatusUpdate statusUpdate) { final UpdateReplicateStatusArgs updateReplicateStatusArgs = computeUpdateReplicateStatusArgs( chainTaskId, walletAddress, @@ -329,10 +330,11 @@ public Either updateReplicateS } @Recover - public Either updateReplicateStatus(OptimisticLockingFailureException exception, - String chainTaskId, - String walletAddress, - ReplicateStatusUpdate statusUpdate) { + public Either updateReplicateStatus( + OptimisticLockingFailureException exception, + String chainTaskId, + String walletAddress, + ReplicateStatusUpdate statusUpdate) { logUpdateReplicateStatusRecover(exception); return null; } @@ -361,10 +363,11 @@ public Either updateReplicateS * or a next action for the worker. */ @Retryable(value = {OptimisticLockingFailureException.class}, maxAttempts = 100) - public Either updateReplicateStatus(String chainTaskId, - String walletAddress, - ReplicateStatusUpdate statusUpdate, - UpdateReplicateStatusArgs updateReplicateStatusArgs) { + public Either updateReplicateStatus( + String chainTaskId, + String walletAddress, + ReplicateStatusUpdate statusUpdate, + UpdateReplicateStatusArgs updateReplicateStatusArgs) { // Synchronization is mandatory there to avoid race conditions. // Lock key should be unique, e.g. `chainTaskId + walletAddress`. final String lockKey = chainTaskId + walletAddress; @@ -399,10 +402,11 @@ public Either updateReplicateS * @return Either a {@link ReplicateStatusUpdateError} if the status can't be updated, * or a next action for the worker. */ - Either updateReplicateStatusWithoutThreadSafety(String chainTaskId, - String walletAddress, - ReplicateStatusUpdate statusUpdate, - UpdateReplicateStatusArgs updateReplicateStatusArgs) { + Either updateReplicateStatusWithoutThreadSafety( + String chainTaskId, + String walletAddress, + ReplicateStatusUpdate statusUpdate, + UpdateReplicateStatusArgs updateReplicateStatusArgs) { log.info("Replicate update request [status:{}, chainTaskId:{}, walletAddress:{}, details:{}]", statusUpdate.getStatus(), chainTaskId, walletAddress, statusUpdate.getDetailsWithoutLogs()); From 8449700afc29df1b3b8c5152a5be238a9460676f Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Fri, 14 Apr 2023 13:41:29 +0200 Subject: [PATCH 08/77] Use iexec-common@8.0.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d1686eefd..9c89d1f0f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ version=8.0.1 -iexecCommonVersion=7.0.0 +iexecCommonVersion=8.0.0 iexecBlockchainAdapterVersion=8.0.0 iexecResultVersion=8.0.0 iexecSmsVersion=8.0.0 From f195df6d4cae564f3e4898d834307cc50107adb3 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Fri, 14 Apr 2023 13:42:21 +0200 Subject: [PATCH 09/77] Use iexec-commons-poco@1.0.2 --- build.gradle | 1 + gradle.properties | 1 + 2 files changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index 2b8bb3d94..48f7e0096 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ dependencyManagement { dependencies { // iexec + implementation "com.iexec.commons:iexec-commons-poco:$iexecCommonsPocoVersion" implementation "com.iexec.common:iexec-common:$iexecCommonVersion" implementation "com.iexec.blockchain:iexec-blockchain-adapter-api-library:$iexecBlockchainAdapterVersion" implementation "com.iexec.result-proxy:iexec-result-proxy-library:$iexecResultVersion" diff --git a/gradle.properties b/gradle.properties index 9c89d1f0f..298b5cce5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,6 @@ version=8.0.1 iexecCommonVersion=8.0.0 +iexecCommonsPocoVersion=1.0.2 iexecBlockchainAdapterVersion=8.0.0 iexecResultVersion=8.0.0 iexecSmsVersion=8.0.0 From 1e5e9423950a5babe19495d5b12255c85aa82368 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Fri, 14 Apr 2023 14:05:04 +0200 Subject: [PATCH 10/77] Update classes --- .../java/com/iexec/core/chain/DealEvent.java | 6 ++-- .../iexec/core/chain/DealWatcherService.java | 10 +++--- .../com/iexec/core/chain/IexecHubService.java | 14 ++++---- .../iexec/core/chain/SignatureService.java | 10 +++--- .../com/iexec/core/chain/Web3jService.java | 4 +-- .../ContributionUnnotifiedDetector.java | 4 +-- .../replicate/RevealUnnotifiedDetector.java | 4 +-- .../replicate/UnnotifiedAbstractDetector.java | 6 ++-- .../detector/task/FinalizedTaskDetector.java | 6 ++-- .../task/InitializedTaskDetector.java | 6 ++-- .../detector/task/ReopenedTaskDetector.java | 6 ++-- .../core/pubsub/NotificationService.java | 4 +-- .../com/iexec/core/replicate/Replicate.java | 4 +-- .../replicate/ReplicateSupplyService.java | 12 +++---- .../core/replicate/ReplicatesController.java | 6 ++-- .../core/replicate/ReplicatesService.java | 10 +++--- .../replicate/UpdateReplicateStatusArgs.java | 6 ++-- .../java/com/iexec/core/sms/SmsService.java | 8 ++--- src/main/java/com/iexec/core/task/Task.java | 10 +++--- .../com/iexec/core/task/TaskController.java | 8 ++--- .../java/com/iexec/core/task/TaskModel.java | 4 +-- .../java/com/iexec/core/task/TaskService.java | 8 ++--- .../com/iexec/core/task/TaskStatusChange.java | 4 +-- .../core/task/listener/TaskListeners.java | 10 +++--- .../core/task/update/TaskUpdateManager.java | 8 ++--- .../iexec/core/worker/WorkerController.java | 8 ++--- .../core/workflow/ReplicateWorkflow.java | 10 +++--- .../core/chain/DealWatcherServiceTests.java | 19 ++++++----- .../core/chain/SignatureServiceTests.java | 10 +++--- .../ContributionUnnotifiedDetectorTests.java | 4 +-- .../RevealUnnotifiedDetectorTests.java | 4 +-- .../iexec/core/logs/TaskLogsServiceTests.java | 6 ++-- .../core/pubsub/NotificationServiceTests.java | 4 +-- .../replicate/ReplicateControllerTests.java | 22 ++++++++++-- .../core/replicate/ReplicateServiceTests.java | 14 ++++---- .../ReplicateSupplyServiceTests.java | 16 ++++----- .../core/replicate/ReplicatesListTests.java | 18 +++++++++- .../com/iexec/core/sms/SmsServiceTests.java | 22 ++++++++++-- .../iexec/core/task/TaskControllerTests.java | 4 +-- .../com/iexec/core/task/TaskModelTests.java | 4 +-- .../task/TaskServiceRealRepositoryTest.java | 2 +- .../com/iexec/core/task/TaskServiceTests.java | 6 ++-- .../com/iexec/core/task/TaskTestsUtils.java | 6 ++-- .../core/task/listener/TaskListenerTest.java | 8 ++--- .../task/update/TaskUpdateManagerTest.java | 12 +++---- .../core/worker/WorkerControllerTests.java | 34 ++++++++++++++----- .../core/workflow/ReplicateWorkflowTests.java | 6 ++-- 47 files changed, 242 insertions(+), 175 deletions(-) diff --git a/src/main/java/com/iexec/core/chain/DealEvent.java b/src/main/java/com/iexec/core/chain/DealEvent.java index afa9be86d..cf65843f7 100644 --- a/src/main/java/com/iexec/core/chain/DealEvent.java +++ b/src/main/java/com/iexec/core/chain/DealEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package com.iexec.core.chain; -import com.iexec.common.contract.generated.IexecHubContract; -import com.iexec.common.utils.BytesUtils; +import com.iexec.commons.poco.contract.generated.IexecHubContract; +import com.iexec.commons.poco.utils.BytesUtils; import lombok.Getter; import java.math.BigInteger; diff --git a/src/main/java/com/iexec/core/chain/DealWatcherService.java b/src/main/java/com/iexec/core/chain/DealWatcherService.java index 61e242b8e..bf76e0e78 100644 --- a/src/main/java/com/iexec/core/chain/DealWatcherService.java +++ b/src/main/java/com/iexec/core/chain/DealWatcherService.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ package com.iexec.core.chain; -import com.iexec.common.chain.ChainDeal; -import com.iexec.common.contract.generated.IexecHubContract; -import com.iexec.common.utils.BytesUtils; +import com.iexec.commons.poco.chain.ChainDeal; +import com.iexec.commons.poco.contract.generated.IexecHubContract; +import com.iexec.commons.poco.utils.BytesUtils; import com.iexec.core.configuration.ConfigurationService; import com.iexec.core.task.Task; import com.iexec.core.task.TaskService; @@ -41,7 +41,7 @@ import java.math.BigInteger; import java.util.Optional; -import static com.iexec.common.contract.generated.IexecHubContract.SCHEDULERNOTICE_EVENT; +import static com.iexec.commons.poco.contract.generated.IexecHubContract.SCHEDULERNOTICE_EVENT; @Slf4j @Service diff --git a/src/main/java/com/iexec/core/chain/IexecHubService.java b/src/main/java/com/iexec/core/chain/IexecHubService.java index 0dfe9b62d..04f9072c0 100644 --- a/src/main/java/com/iexec/core/chain/IexecHubService.java +++ b/src/main/java/com/iexec/core/chain/IexecHubService.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ package com.iexec.core.chain; -import com.iexec.common.chain.*; -import com.iexec.common.contract.generated.IexecHubContract; -import com.iexec.common.utils.BytesUtils; +import com.iexec.commons.poco.chain.*; +import com.iexec.commons.poco.contract.generated.IexecHubContract; +import com.iexec.commons.poco.utils.BytesUtils; import io.reactivex.Flowable; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.Pair; @@ -39,10 +39,10 @@ import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; -import static com.iexec.common.chain.ChainTaskStatus.ACTIVE; -import static com.iexec.common.chain.ChainTaskStatus.COMPLETED; -import static com.iexec.common.utils.BytesUtils.stringToBytes; import static com.iexec.common.utils.DateTimeUtils.now; +import static com.iexec.commons.poco.chain.ChainTaskStatus.ACTIVE; +import static com.iexec.commons.poco.chain.ChainTaskStatus.COMPLETED; +import static com.iexec.commons.poco.utils.BytesUtils.stringToBytes; @Slf4j @Service diff --git a/src/main/java/com/iexec/core/chain/SignatureService.java b/src/main/java/com/iexec/core/chain/SignatureService.java index b0f9bfd45..e309cb528 100644 --- a/src/main/java/com/iexec/core/chain/SignatureService.java +++ b/src/main/java/com/iexec/core/chain/SignatureService.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ package com.iexec.core.chain; -import com.iexec.common.chain.WorkerpoolAuthorization; -import com.iexec.common.security.Signature; -import com.iexec.common.utils.BytesUtils; -import com.iexec.common.utils.HashUtils; +import com.iexec.commons.poco.chain.WorkerpoolAuthorization; +import com.iexec.commons.poco.security.Signature; +import com.iexec.commons.poco.utils.BytesUtils; +import com.iexec.commons.poco.utils.HashUtils; import org.springframework.stereotype.Service; import org.web3j.crypto.Sign; diff --git a/src/main/java/com/iexec/core/chain/Web3jService.java b/src/main/java/com/iexec/core/chain/Web3jService.java index 99ec1d817..cc9af84bd 100644 --- a/src/main/java/com/iexec/core/chain/Web3jService.java +++ b/src/main/java/com/iexec/core/chain/Web3jService.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package com.iexec.core.chain; -import com.iexec.common.chain.Web3jAbstractService; +import com.iexec.commons.poco.chain.Web3jAbstractService; import org.springframework.stereotype.Service; @Service diff --git a/src/main/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetector.java b/src/main/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetector.java index 9b1b5a6f7..af2731af6 100644 --- a/src/main/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetector.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package com.iexec.core.detector.replicate; -import com.iexec.common.chain.ChainContributionStatus; import com.iexec.common.replicate.ReplicateStatus; +import com.iexec.commons.poco.chain.ChainContributionStatus; import com.iexec.core.chain.IexecHubService; import com.iexec.core.chain.Web3jService; import com.iexec.core.configuration.CronConfiguration; diff --git a/src/main/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetector.java b/src/main/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetector.java index 6fa03973b..82743f8ab 100644 --- a/src/main/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetector.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package com.iexec.core.detector.replicate; -import com.iexec.common.chain.ChainContributionStatus; import com.iexec.common.replicate.ReplicateStatus; +import com.iexec.commons.poco.chain.ChainContributionStatus; import com.iexec.core.chain.IexecHubService; import com.iexec.core.chain.Web3jService; import com.iexec.core.configuration.CronConfiguration; diff --git a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java index 47a588c1a..d8c4bdc66 100644 --- a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ package com.iexec.core.detector.replicate; -import com.iexec.common.chain.ChainContributionStatus; -import com.iexec.common.chain.ChainReceipt; import com.iexec.common.replicate.ReplicateStatus; import com.iexec.common.replicate.ReplicateStatusDetails; +import com.iexec.commons.poco.chain.ChainContributionStatus; +import com.iexec.commons.poco.chain.ChainReceipt; import com.iexec.core.chain.IexecHubService; import com.iexec.core.chain.Web3jService; import com.iexec.core.replicate.Replicate; diff --git a/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java b/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java index 2f3f1cd3d..e2558b21f 100644 --- a/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java +++ b/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package com.iexec.core.detector.task; -import com.iexec.common.chain.ChainTask; -import com.iexec.common.chain.ChainTaskStatus; +import com.iexec.commons.poco.chain.ChainTask; +import com.iexec.commons.poco.chain.ChainTaskStatus; import com.iexec.core.chain.IexecHubService; import com.iexec.core.detector.Detector; import com.iexec.core.task.Task; diff --git a/src/main/java/com/iexec/core/detector/task/InitializedTaskDetector.java b/src/main/java/com/iexec/core/detector/task/InitializedTaskDetector.java index eab889cff..0ff9bee28 100644 --- a/src/main/java/com/iexec/core/detector/task/InitializedTaskDetector.java +++ b/src/main/java/com/iexec/core/detector/task/InitializedTaskDetector.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package com.iexec.core.detector.task; -import com.iexec.common.chain.ChainTask; -import com.iexec.common.chain.ChainTaskStatus; +import com.iexec.commons.poco.chain.ChainTask; +import com.iexec.commons.poco.chain.ChainTaskStatus; import com.iexec.core.chain.IexecHubService; import com.iexec.core.detector.Detector; import com.iexec.core.task.Task; diff --git a/src/main/java/com/iexec/core/detector/task/ReopenedTaskDetector.java b/src/main/java/com/iexec/core/detector/task/ReopenedTaskDetector.java index e4edec531..299f0a0fa 100644 --- a/src/main/java/com/iexec/core/detector/task/ReopenedTaskDetector.java +++ b/src/main/java/com/iexec/core/detector/task/ReopenedTaskDetector.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package com.iexec.core.detector.task; -import com.iexec.common.chain.ChainTask; -import com.iexec.common.chain.ChainTaskStatus; +import com.iexec.commons.poco.chain.ChainTask; +import com.iexec.commons.poco.chain.ChainTaskStatus; import com.iexec.core.chain.IexecHubService; import com.iexec.core.detector.Detector; import com.iexec.core.task.Task; diff --git a/src/main/java/com/iexec/core/pubsub/NotificationService.java b/src/main/java/com/iexec/core/pubsub/NotificationService.java index 4130b4f2a..67ac75769 100644 --- a/src/main/java/com/iexec/core/pubsub/NotificationService.java +++ b/src/main/java/com/iexec/core/pubsub/NotificationService.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package com.iexec.core.pubsub; -import com.iexec.common.notification.TaskNotification; +import com.iexec.commons.poco.notification.TaskNotification; import lombok.extern.slf4j.Slf4j; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/iexec/core/replicate/Replicate.java b/src/main/java/com/iexec/core/replicate/Replicate.java index f87ec6c1a..819643d61 100644 --- a/src/main/java/com/iexec/core/replicate/Replicate.java +++ b/src/main/java/com/iexec/core/replicate/Replicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.iexec.common.chain.ChainReceipt; import com.iexec.common.replicate.*; +import com.iexec.commons.poco.chain.ChainReceipt; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/iexec/core/replicate/ReplicateSupplyService.java b/src/main/java/com/iexec/core/replicate/ReplicateSupplyService.java index 5d632ec6b..d1d5d3707 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicateSupplyService.java +++ b/src/main/java/com/iexec/core/replicate/ReplicateSupplyService.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,18 +16,18 @@ package com.iexec.core.replicate; -import com.iexec.common.chain.WorkerpoolAuthorization; import com.iexec.common.lifecycle.purge.ExpiringTaskMapFactory; import com.iexec.common.lifecycle.purge.Purgeable; -import com.iexec.common.notification.TaskNotification; -import com.iexec.common.notification.TaskNotificationExtra; -import com.iexec.common.notification.TaskNotificationType; import com.iexec.common.replicate.ReplicateStatus; import com.iexec.common.replicate.ReplicateStatusDetails; import com.iexec.common.replicate.ReplicateStatusUpdate; import com.iexec.common.replicate.ReplicateTaskSummary; import com.iexec.common.replicate.ReplicateTaskSummary.ReplicateTaskSummaryBuilder; -import com.iexec.common.task.TaskAbortCause; +import com.iexec.commons.poco.chain.WorkerpoolAuthorization; +import com.iexec.commons.poco.notification.TaskNotification; +import com.iexec.commons.poco.notification.TaskNotificationExtra; +import com.iexec.commons.poco.notification.TaskNotificationType; +import com.iexec.commons.poco.task.TaskAbortCause; import com.iexec.core.chain.SignatureService; import com.iexec.core.chain.Web3jService; import com.iexec.core.contribution.ConsensusHelper; diff --git a/src/main/java/com/iexec/core/replicate/ReplicatesController.java b/src/main/java/com/iexec/core/replicate/ReplicatesController.java index 4278d0f03..57ed54b72 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicatesController.java +++ b/src/main/java/com/iexec/core/replicate/ReplicatesController.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ package com.iexec.core.replicate; -import com.iexec.common.notification.TaskNotification; -import com.iexec.common.notification.TaskNotificationType; import com.iexec.common.replicate.*; +import com.iexec.commons.poco.notification.TaskNotification; +import com.iexec.commons.poco.notification.TaskNotificationType; import com.iexec.core.security.JwtTokenProvider; import com.iexec.core.worker.WorkerService; import feign.FeignException; diff --git a/src/main/java/com/iexec/core/replicate/ReplicatesService.java b/src/main/java/com/iexec/core/replicate/ReplicatesService.java index 2526493d3..bd4e64990 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicatesService.java +++ b/src/main/java/com/iexec/core/replicate/ReplicatesService.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,15 @@ package com.iexec.core.replicate; -import com.iexec.common.chain.ChainContribution; -import com.iexec.common.notification.TaskNotificationType; import com.iexec.common.replicate.*; -import com.iexec.common.task.TaskDescription; import com.iexec.common.utils.ContextualLockRunner; +import com.iexec.commons.poco.chain.ChainContribution; +import com.iexec.commons.poco.notification.TaskNotificationType; +import com.iexec.commons.poco.task.TaskDescription; import com.iexec.core.chain.IexecHubService; import com.iexec.core.chain.Web3jService; -import com.iexec.core.result.ResultService; import com.iexec.core.logs.TaskLogsService; +import com.iexec.core.result.ResultService; import com.iexec.core.workflow.ReplicateWorkflow; import io.vavr.control.Either; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/iexec/core/replicate/UpdateReplicateStatusArgs.java b/src/main/java/com/iexec/core/replicate/UpdateReplicateStatusArgs.java index ab47faa84..da51e709f 100644 --- a/src/main/java/com/iexec/core/replicate/UpdateReplicateStatusArgs.java +++ b/src/main/java/com/iexec/core/replicate/UpdateReplicateStatusArgs.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 IEXEC BLOCKCHAIN TECH + * Copyright 2021-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package com.iexec.core.replicate; -import com.iexec.common.chain.ChainContribution; -import com.iexec.common.task.TaskDescription; +import com.iexec.commons.poco.chain.ChainContribution; +import com.iexec.commons.poco.task.TaskDescription; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/com/iexec/core/sms/SmsService.java b/src/main/java/com/iexec/core/sms/SmsService.java index ecef27718..ab486e391 100644 --- a/src/main/java/com/iexec/core/sms/SmsService.java +++ b/src/main/java/com/iexec/core/sms/SmsService.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ package com.iexec.core.sms; -import com.iexec.common.tee.TeeFramework; -import com.iexec.common.tee.TeeUtils; -import com.iexec.common.utils.BytesUtils; +import com.iexec.commons.poco.tee.TeeFramework; +import com.iexec.commons.poco.tee.TeeUtils; +import com.iexec.commons.poco.utils.BytesUtils; import com.iexec.core.registry.PlatformRegistryConfiguration; import com.iexec.sms.api.SmsClient; import com.iexec.sms.api.SmsClientProvider; diff --git a/src/main/java/com/iexec/core/task/Task.java b/src/main/java/com/iexec/core/task/Task.java index 5f95fdaab..1d5b6b6c9 100644 --- a/src/main/java/com/iexec/core/task/Task.java +++ b/src/main/java/com/iexec/core/task/Task.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,10 @@ package com.iexec.core.task; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.iexec.common.chain.ChainReceipt; -import com.iexec.common.chain.ChainUtils; -import com.iexec.common.dapp.DappType; -import com.iexec.common.tee.TeeUtils; +import com.iexec.commons.poco.chain.ChainReceipt; +import com.iexec.commons.poco.chain.ChainUtils; +import com.iexec.commons.poco.dapp.DappType; +import com.iexec.commons.poco.tee.TeeUtils; import lombok.*; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Version; diff --git a/src/main/java/com/iexec/core/task/TaskController.java b/src/main/java/com/iexec/core/task/TaskController.java index 848a19b19..d57accab8 100644 --- a/src/main/java/com/iexec/core/task/TaskController.java +++ b/src/main/java/com/iexec/core/task/TaskController.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ import com.iexec.common.chain.eip712.entity.EIP712Challenge; import com.iexec.common.replicate.ComputeLogs; -import com.iexec.common.security.Signature; import com.iexec.common.security.SignedChallenge; -import com.iexec.common.task.TaskDescription; -import com.iexec.common.utils.SignatureUtils; +import com.iexec.commons.poco.security.Signature; +import com.iexec.commons.poco.task.TaskDescription; +import com.iexec.commons.poco.utils.SignatureUtils; import com.iexec.core.chain.IexecHubService; import com.iexec.core.logs.TaskLogs; import com.iexec.core.logs.TaskLogsService; diff --git a/src/main/java/com/iexec/core/task/TaskModel.java b/src/main/java/com/iexec/core/task/TaskModel.java index 93b73c811..ea6a08f63 100644 --- a/src/main/java/com/iexec/core/task/TaskModel.java +++ b/src/main/java/com/iexec/core/task/TaskModel.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package com.iexec.core.task; -import com.iexec.common.dapp.DappType; +import com.iexec.commons.poco.dapp.DappType; import com.iexec.core.replicate.ReplicateModel; import lombok.*; diff --git a/src/main/java/com/iexec/core/task/TaskService.java b/src/main/java/com/iexec/core/task/TaskService.java index cb8f6cb76..dcaae8e42 100644 --- a/src/main/java/com/iexec/core/task/TaskService.java +++ b/src/main/java/com/iexec/core/task/TaskService.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ package com.iexec.core.task; -import com.iexec.common.chain.ChainTask; -import com.iexec.common.chain.ChainTaskStatus; -import com.iexec.common.tee.TeeUtils; +import com.iexec.commons.poco.chain.ChainTask; +import com.iexec.commons.poco.chain.ChainTaskStatus; +import com.iexec.commons.poco.tee.TeeUtils; import com.iexec.core.chain.IexecHubService; import com.iexec.core.replicate.ReplicatesList; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/iexec/core/task/TaskStatusChange.java b/src/main/java/com/iexec/core/task/TaskStatusChange.java index 11b93e5af..a24225bb7 100644 --- a/src/main/java/com/iexec/core/task/TaskStatusChange.java +++ b/src/main/java/com/iexec/core/task/TaskStatusChange.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import java.util.Date; -import com.iexec.common.chain.ChainReceipt; +import com.iexec.commons.poco.chain.ChainReceipt; @Data @NoArgsConstructor diff --git a/src/main/java/com/iexec/core/task/listener/TaskListeners.java b/src/main/java/com/iexec/core/task/listener/TaskListeners.java index a2ee4d0db..a5e386e60 100644 --- a/src/main/java/com/iexec/core/task/listener/TaskListeners.java +++ b/src/main/java/com/iexec/core/task/listener/TaskListeners.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,10 @@ package com.iexec.core.task.listener; import com.iexec.common.lifecycle.purge.PurgeService; -import com.iexec.common.notification.TaskNotification; -import com.iexec.common.notification.TaskNotificationExtra; -import com.iexec.common.notification.TaskNotificationType; -import com.iexec.common.task.TaskAbortCause; +import com.iexec.commons.poco.notification.TaskNotification; +import com.iexec.commons.poco.notification.TaskNotificationExtra; +import com.iexec.commons.poco.notification.TaskNotificationType; +import com.iexec.commons.poco.task.TaskAbortCause; import com.iexec.core.pubsub.NotificationService; import com.iexec.core.replicate.Replicate; import com.iexec.core.replicate.ReplicatesService; diff --git a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java index 7d65e2d26..96d57cd7e 100644 --- a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java +++ b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 IEXEC BLOCKCHAIN TECH + * Copyright 2021-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ package com.iexec.core.task.update; -import com.iexec.common.chain.ChainReceipt; -import com.iexec.common.chain.ChainTask; -import com.iexec.common.chain.ChainTaskStatus; import com.iexec.common.replicate.ReplicateStatus; +import com.iexec.commons.poco.chain.ChainReceipt; +import com.iexec.commons.poco.chain.ChainTask; +import com.iexec.commons.poco.chain.ChainTaskStatus; import com.iexec.core.chain.IexecHubService; import com.iexec.core.chain.adapter.BlockchainAdapterService; import com.iexec.core.replicate.Replicate; diff --git a/src/main/java/com/iexec/core/worker/WorkerController.java b/src/main/java/com/iexec/core/worker/WorkerController.java index 31cf37567..90a2a90ca 100644 --- a/src/main/java/com/iexec/core/worker/WorkerController.java +++ b/src/main/java/com/iexec/core/worker/WorkerController.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,9 @@ import com.iexec.common.config.PublicConfiguration; import com.iexec.common.config.WorkerModel; -import com.iexec.common.security.Signature; -import com.iexec.common.utils.BytesUtils; -import com.iexec.common.utils.SignatureUtils; +import com.iexec.commons.poco.security.Signature; +import com.iexec.commons.poco.utils.BytesUtils; +import com.iexec.commons.poco.utils.SignatureUtils; import com.iexec.core.configuration.PublicConfigurationService; import com.iexec.core.security.ChallengeService; import com.iexec.core.security.JwtTokenProvider; diff --git a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java index b21b525e7..eb83fb229 100644 --- a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java +++ b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,18 +16,18 @@ package com.iexec.core.workflow; -import com.iexec.common.notification.TaskNotificationType; import com.iexec.common.replicate.ReplicateStatus; import com.iexec.common.replicate.ReplicateStatusCause; - -import static com.iexec.common.notification.TaskNotificationType.*; -import static com.iexec.common.replicate.ReplicateStatus.*; +import com.iexec.commons.poco.notification.TaskNotificationType; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import static com.iexec.common.replicate.ReplicateStatus.*; +import static com.iexec.commons.poco.notification.TaskNotificationType.*; + public class ReplicateWorkflow extends Workflow { diff --git a/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java b/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java index c86a48816..a546085b5 100644 --- a/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java +++ b/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package com.iexec.core.chain; -import com.iexec.common.chain.ChainApp; -import com.iexec.common.chain.ChainCategory; -import com.iexec.common.chain.ChainDeal; -import com.iexec.common.chain.DealParams; -import com.iexec.common.contract.generated.IexecHubContract; -import com.iexec.common.utils.BytesUtils; +import com.iexec.commons.poco.chain.ChainApp; +import com.iexec.commons.poco.chain.ChainCategory; +import com.iexec.commons.poco.chain.ChainDeal; +import com.iexec.commons.poco.chain.DealParams; +import com.iexec.commons.poco.contract.generated.IexecHubContract; +import com.iexec.commons.poco.utils.BytesUtils; import com.iexec.core.configuration.ConfigurationService; import com.iexec.core.task.Task; import com.iexec.core.task.TaskService; @@ -29,7 +29,10 @@ import io.reactivex.Flowable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.*; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.springframework.context.ApplicationEventPublisher; import org.web3j.protocol.core.methods.response.Log; diff --git a/src/test/java/com/iexec/core/chain/SignatureServiceTests.java b/src/test/java/com/iexec/core/chain/SignatureServiceTests.java index 08b91b57a..89ceef731 100644 --- a/src/test/java/com/iexec/core/chain/SignatureServiceTests.java +++ b/src/test/java/com/iexec/core/chain/SignatureServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ package com.iexec.core.chain; -import com.iexec.common.chain.WorkerpoolAuthorization; -import com.iexec.common.security.Signature; -import com.iexec.common.utils.BytesUtils; -import com.iexec.common.utils.HashUtils; +import com.iexec.commons.poco.chain.WorkerpoolAuthorization; +import com.iexec.commons.poco.security.Signature; +import com.iexec.commons.poco.utils.BytesUtils; +import com.iexec.commons.poco.utils.HashUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java b/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java index fac3f70aa..bad0aee23 100644 --- a/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ package com.iexec.core.detector.replicate; -import com.iexec.common.chain.ChainReceipt; import com.iexec.common.replicate.ReplicateStatusDetails; import com.iexec.common.replicate.ReplicateStatusUpdate; +import com.iexec.commons.poco.chain.ChainReceipt; import com.iexec.core.chain.IexecHubService; import com.iexec.core.chain.Web3jService; import com.iexec.core.configuration.CronConfiguration; diff --git a/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java b/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java index dc6e18e56..936c16f9b 100644 --- a/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ package com.iexec.core.detector.replicate; -import com.iexec.common.chain.ChainReceipt; import com.iexec.common.replicate.ReplicateStatusDetails; import com.iexec.common.replicate.ReplicateStatusUpdate; +import com.iexec.commons.poco.chain.ChainReceipt; import com.iexec.core.chain.IexecHubService; import com.iexec.core.chain.Web3jService; import com.iexec.core.configuration.CronConfiguration; diff --git a/src/test/java/com/iexec/core/logs/TaskLogsServiceTests.java b/src/test/java/com/iexec/core/logs/TaskLogsServiceTests.java index 7975f2797..a483e0fbf 100644 --- a/src/test/java/com/iexec/core/logs/TaskLogsServiceTests.java +++ b/src/test/java/com/iexec/core/logs/TaskLogsServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 IEXEC BLOCKCHAIN TECH + * Copyright 2022-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import java.util.List; import java.util.Optional; -import static com.iexec.common.utils.TestUtils.CHAIN_TASK_ID; -import static com.iexec.common.utils.TestUtils.WORKER_ADDRESS; +import static com.iexec.commons.poco.utils.TestUtils.CHAIN_TASK_ID; +import static com.iexec.commons.poco.utils.TestUtils.WORKER_ADDRESS; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; diff --git a/src/test/java/com/iexec/core/pubsub/NotificationServiceTests.java b/src/test/java/com/iexec/core/pubsub/NotificationServiceTests.java index 473a5155b..444eab6e0 100644 --- a/src/test/java/com/iexec/core/pubsub/NotificationServiceTests.java +++ b/src/test/java/com/iexec/core/pubsub/NotificationServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import org.mockito.Spy; import org.springframework.messaging.simp.SimpMessagingTemplate; -import com.iexec.common.notification.TaskNotification; +import com.iexec.commons.poco.notification.TaskNotification; class NotificationServiceTests { diff --git a/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java b/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java index 2cabc2695..bc7a4860a 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java @@ -1,9 +1,25 @@ +/* + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.iexec.core.replicate; -import com.iexec.common.chain.WorkerpoolAuthorization; -import com.iexec.common.notification.TaskNotification; -import com.iexec.common.notification.TaskNotificationType; import com.iexec.common.replicate.*; +import com.iexec.commons.poco.chain.WorkerpoolAuthorization; +import com.iexec.commons.poco.notification.TaskNotification; +import com.iexec.commons.poco.notification.TaskNotificationType; import com.iexec.core.security.JwtTokenProvider; import com.iexec.core.worker.WorkerService; import io.vavr.control.Either; diff --git a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java index 18a254233..282a970cb 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package com.iexec.core.replicate; -import com.iexec.common.chain.ChainContribution; -import com.iexec.common.chain.ChainContributionStatus; -import com.iexec.common.notification.TaskNotificationType; import com.iexec.common.replicate.*; -import com.iexec.common.task.TaskDescription; -import com.iexec.common.utils.BytesUtils; +import com.iexec.commons.poco.chain.ChainContribution; +import com.iexec.commons.poco.chain.ChainContributionStatus; +import com.iexec.commons.poco.notification.TaskNotificationType; +import com.iexec.commons.poco.task.TaskDescription; +import com.iexec.commons.poco.utils.BytesUtils; import com.iexec.core.chain.IexecHubService; import com.iexec.core.chain.Web3jService; import com.iexec.core.logs.TaskLogsService; @@ -38,7 +38,7 @@ import static com.iexec.common.replicate.ReplicateStatus.*; import static com.iexec.common.replicate.ReplicateStatusModifier.WORKER; -import static com.iexec.common.utils.TestUtils.*; +import static com.iexec.commons.poco.utils.TestUtils.*; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; diff --git a/src/test/java/com/iexec/core/replicate/ReplicateSupplyServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateSupplyServiceTests.java index 208ab1358..19169f3f4 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateSupplyServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateSupplyServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,15 @@ package com.iexec.core.replicate; -import com.iexec.common.chain.WorkerpoolAuthorization; -import com.iexec.common.notification.TaskNotification; -import com.iexec.common.notification.TaskNotificationExtra; -import com.iexec.common.notification.TaskNotificationType; import com.iexec.common.replicate.*; -import com.iexec.common.task.TaskAbortCause; -import com.iexec.common.tee.TeeUtils; -import com.iexec.common.utils.BytesUtils; import com.iexec.common.utils.DateTimeUtils; +import com.iexec.commons.poco.chain.WorkerpoolAuthorization; +import com.iexec.commons.poco.notification.TaskNotification; +import com.iexec.commons.poco.notification.TaskNotificationExtra; +import com.iexec.commons.poco.notification.TaskNotificationType; +import com.iexec.commons.poco.task.TaskAbortCause; +import com.iexec.commons.poco.tee.TeeUtils; +import com.iexec.commons.poco.utils.BytesUtils; import com.iexec.core.chain.SignatureService; import com.iexec.core.chain.Web3jService; import com.iexec.core.task.Task; diff --git a/src/test/java/com/iexec/core/replicate/ReplicatesListTests.java b/src/test/java/com/iexec/core/replicate/ReplicatesListTests.java index 5589ac69a..0f8d81ff9 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicatesListTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicatesListTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022-2023 IEXEC BLOCKCHAIN TECH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.iexec.core.replicate; import com.iexec.common.replicate.ReplicateStatusModifier; @@ -7,7 +23,7 @@ import static com.iexec.common.replicate.ReplicateStatus.*; import static com.iexec.common.replicate.ReplicateStatus.STARTING; -import static com.iexec.common.utils.TestUtils.*; +import static com.iexec.commons.poco.utils.TestUtils.*; import static org.assertj.core.api.Assertions.assertThat; class ReplicatesListTests { diff --git a/src/test/java/com/iexec/core/sms/SmsServiceTests.java b/src/test/java/com/iexec/core/sms/SmsServiceTests.java index cb3c0e9a9..56060cfb7 100644 --- a/src/test/java/com/iexec/core/sms/SmsServiceTests.java +++ b/src/test/java/com/iexec/core/sms/SmsServiceTests.java @@ -1,8 +1,24 @@ +/* + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.iexec.core.sms; -import com.iexec.common.tee.TeeFramework; -import com.iexec.common.tee.TeeUtils; -import com.iexec.common.utils.BytesUtils; +import com.iexec.commons.poco.tee.TeeFramework; +import com.iexec.commons.poco.tee.TeeUtils; +import com.iexec.commons.poco.utils.BytesUtils; import com.iexec.core.registry.PlatformRegistryConfiguration; import com.iexec.sms.api.SmsClient; import com.iexec.sms.api.SmsClientProvider; diff --git a/src/test/java/com/iexec/core/task/TaskControllerTests.java b/src/test/java/com/iexec/core/task/TaskControllerTests.java index 5702f0755..d2434aa9a 100644 --- a/src/test/java/com/iexec/core/task/TaskControllerTests.java +++ b/src/test/java/com/iexec/core/task/TaskControllerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 IEXEC BLOCKCHAIN TECH + * Copyright 2022-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import com.iexec.common.chain.eip712.entity.Challenge; import com.iexec.common.chain.eip712.entity.EIP712Challenge; import com.iexec.common.replicate.ComputeLogs; -import com.iexec.common.task.TaskDescription; +import com.iexec.commons.poco.task.TaskDescription; import com.iexec.core.chain.IexecHubService; import com.iexec.core.logs.TaskLogs; import com.iexec.core.logs.TaskLogsService; diff --git a/src/test/java/com/iexec/core/task/TaskModelTests.java b/src/test/java/com/iexec/core/task/TaskModelTests.java index 74d63704a..78494efb5 100644 --- a/src/test/java/com/iexec/core/task/TaskModelTests.java +++ b/src/test/java/com/iexec/core/task/TaskModelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 IEXEC BLOCKCHAIN TECH + * Copyright 2022-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package com.iexec.core.task; -import com.iexec.common.dapp.DappType; +import com.iexec.commons.poco.dapp.DappType; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/iexec/core/task/TaskServiceRealRepositoryTest.java b/src/test/java/com/iexec/core/task/TaskServiceRealRepositoryTest.java index ed8b08a04..d974924fc 100644 --- a/src/test/java/com/iexec/core/task/TaskServiceRealRepositoryTest.java +++ b/src/test/java/com/iexec/core/task/TaskServiceRealRepositoryTest.java @@ -16,7 +16,7 @@ package com.iexec.core.task; -import com.iexec.common.chain.ChainUtils; +import com.iexec.commons.poco.chain.ChainUtils; import com.iexec.core.chain.IexecHubService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/iexec/core/task/TaskServiceTests.java b/src/test/java/com/iexec/core/task/TaskServiceTests.java index 7d9d0ddf3..8a6c93e1d 100644 --- a/src/test/java/com/iexec/core/task/TaskServiceTests.java +++ b/src/test/java/com/iexec/core/task/TaskServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package com.iexec.core.task; -import com.iexec.common.chain.ChainTask; -import com.iexec.common.chain.ChainTaskStatus; +import com.iexec.commons.poco.chain.ChainTask; +import com.iexec.commons.poco.chain.ChainTaskStatus; import com.iexec.core.chain.IexecHubService; import com.iexec.core.replicate.ReplicatesList; import com.iexec.core.replicate.ReplicatesService; diff --git a/src/test/java/com/iexec/core/task/TaskTestsUtils.java b/src/test/java/com/iexec/core/task/TaskTestsUtils.java index 769a71a31..d66bc03f2 100644 --- a/src/test/java/com/iexec/core/task/TaskTestsUtils.java +++ b/src/test/java/com/iexec/core/task/TaskTestsUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 IEXEC BLOCKCHAIN TECH + * Copyright 2021-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package com.iexec.core.task; -import com.iexec.common.tee.TeeUtils; -import com.iexec.common.utils.BytesUtils; +import com.iexec.commons.poco.tee.TeeUtils; +import com.iexec.commons.poco.utils.BytesUtils; import java.time.Instant; import java.time.temporal.ChronoUnit; diff --git a/src/test/java/com/iexec/core/task/listener/TaskListenerTest.java b/src/test/java/com/iexec/core/task/listener/TaskListenerTest.java index 16a096af9..a3a63a543 100644 --- a/src/test/java/com/iexec/core/task/listener/TaskListenerTest.java +++ b/src/test/java/com/iexec/core/task/listener/TaskListenerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,9 @@ package com.iexec.core.task.listener; import com.iexec.common.lifecycle.purge.PurgeService; -import com.iexec.common.notification.TaskNotification; -import com.iexec.common.notification.TaskNotificationType; -import com.iexec.common.task.TaskAbortCause; +import com.iexec.commons.poco.notification.TaskNotification; +import com.iexec.commons.poco.notification.TaskNotificationType; +import com.iexec.commons.poco.task.TaskAbortCause; import com.iexec.core.pubsub.NotificationService; import com.iexec.core.replicate.Replicate; import com.iexec.core.replicate.ReplicatesService; diff --git a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java index 5bd4ca9f7..055570d0d 100644 --- a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java +++ b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 IEXEC BLOCKCHAIN TECH + * Copyright 2021-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,15 @@ package com.iexec.core.task.update; -import com.iexec.common.chain.ChainReceipt; -import com.iexec.common.chain.ChainTask; -import com.iexec.common.chain.ChainTaskStatus; import com.iexec.common.replicate.ReplicateStatus; import com.iexec.common.replicate.ReplicateStatusModifier; import com.iexec.common.replicate.ReplicateStatusUpdate; -import com.iexec.common.tee.TeeUtils; -import com.iexec.common.utils.BytesUtils; import com.iexec.common.utils.DateTimeUtils; +import com.iexec.commons.poco.chain.ChainReceipt; +import com.iexec.commons.poco.chain.ChainTask; +import com.iexec.commons.poco.chain.ChainTaskStatus; +import com.iexec.commons.poco.tee.TeeUtils; +import com.iexec.commons.poco.utils.BytesUtils; import com.iexec.core.chain.IexecHubService; import com.iexec.core.chain.Web3jService; import com.iexec.core.chain.adapter.BlockchainAdapterService; diff --git a/src/test/java/com/iexec/core/worker/WorkerControllerTests.java b/src/test/java/com/iexec/core/worker/WorkerControllerTests.java index 5ba24c968..d69399cff 100644 --- a/src/test/java/com/iexec/core/worker/WorkerControllerTests.java +++ b/src/test/java/com/iexec/core/worker/WorkerControllerTests.java @@ -1,8 +1,24 @@ +/* + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.iexec.core.worker; import com.iexec.common.config.PublicConfiguration; import com.iexec.common.config.WorkerModel; -import com.iexec.common.security.Signature; +import com.iexec.commons.poco.security.Signature; import com.iexec.core.configuration.PublicConfigurationService; import com.iexec.core.security.ChallengeService; import com.iexec.core.security.JwtTokenProvider; @@ -191,24 +207,24 @@ void shouldRegisterWorker() { .thenReturn(WALLET); when(workerService.addWorker(any())).thenReturn(WORKER); - ResponseEntity response = - workerController.registerWorker(TOKEN, WORKER_MODEL); + ResponseEntity response = workerController.registerWorker(TOKEN, WORKER_MODEL); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getWalletAddress()).isEqualTo(WALLET); verify(workerService).addWorker(any()); } @Test void shouldRegisterGPUWorkerWithMaxNbTasksEqualToOne() { - WORKER_MODEL.setGpuEnabled(true); - WORKER.setMaxNbTasks(1); + WorkerModel model = WorkerModel.builder().walletAddress(WALLET).gpuEnabled(true).build(); + Worker worker = Worker.builder().walletAddress(WALLET).maxNbTasks(1).build(); when(jwtTokenProvider.getWalletAddressFromBearerToken(TOKEN)) .thenReturn(WALLET); - when(workerService.addWorker(any())).thenReturn(WORKER); + when(workerService.addWorker(any())).thenReturn(worker); - ResponseEntity response = - workerController.registerWorker(TOKEN, WORKER_MODEL); + ResponseEntity response = workerController.registerWorker(TOKEN, model); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getWalletAddress()).isEqualTo(WALLET); assertThat(response.getBody().getMaxNbTasks()).isEqualTo(1); verify(workerService).addWorker(any()); @@ -228,7 +244,7 @@ void shouldNotRegisterWorkerSinceUnauthorized() { //region getPublicConfiguration @Test void shouldGetPublicConfiguration() { - when(publicConfigurationService.getPublicConfiguration()).thenReturn(new PublicConfiguration()); + when(publicConfigurationService.getPublicConfiguration()).thenReturn(PublicConfiguration.builder().build()); assertThat(workerController.getPublicConfiguration().getStatusCode()) .isEqualTo(HttpStatus.OK); } diff --git a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java index e757de083..facb569ea 100644 --- a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java +++ b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 IEXEC BLOCKCHAIN TECH + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ package com.iexec.core.workflow; -import com.iexec.common.notification.TaskNotificationType; import com.iexec.common.replicate.ReplicateStatus; import com.iexec.common.replicate.ReplicateStatusCause; +import com.iexec.commons.poco.notification.TaskNotificationType; import org.junit.Rule; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,8 +34,8 @@ import java.util.List; import java.util.Map; -import static com.iexec.common.notification.TaskNotificationType.*; import static com.iexec.common.replicate.ReplicateStatus.*; +import static com.iexec.commons.poco.notification.TaskNotificationType.*; import static org.assertj.core.api.Assertions.assertThat; class ReplicateWorkflowTests { From e70c0a1719ab6f8295f33cbae4c531871dedb64e Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Fri, 14 Apr 2023 16:28:22 +0200 Subject: [PATCH 11/77] Use `-NEXT-SNAPSHOT` dependencies --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 298b5cce5..5a02ee072 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ version=8.0.1 iexecCommonVersion=8.0.0 iexecCommonsPocoVersion=1.0.2 -iexecBlockchainAdapterVersion=8.0.0 -iexecResultVersion=8.0.0 -iexecSmsVersion=8.0.0 +iexecBlockchainAdapterVersion=8.0.1-NEXT-SNAPSHOT +iexecResultVersion=8.0.0-NEXT-SNAPSHOT +iexecSmsVersion=8.0.0-NEXT-SNAPSHOT nexusUser nexusPassword From 38a10e75f800b32e443bf4df7e963e289909cb7b Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Fri, 14 Apr 2023 16:50:25 +0200 Subject: [PATCH 12/77] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f0c428ab..bfa277e4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file. - Prevent race condition on replicate update. (#568) ### Quality ### Dependency Upgrades +- Upgrade to `iexec-common` 8.0.0. (#571) +- Add new `iexec-commons-poco` 1.0.2 dependency. (#571) ## [[8.0.1]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.0.1) 2023-03-20 From 9220fb33584d09a5d22456a71cc40713ade7b333 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Tue, 18 Apr 2023 10:01:11 +0200 Subject: [PATCH 13/77] Remove unused methods in `IexecHubService` --- .../com/iexec/core/chain/IexecHubService.java | 147 ------------------ 1 file changed, 147 deletions(-) diff --git a/src/main/java/com/iexec/core/chain/IexecHubService.java b/src/main/java/com/iexec/core/chain/IexecHubService.java index 04f9072c0..d9978bb53 100644 --- a/src/main/java/com/iexec/core/chain/IexecHubService.java +++ b/src/main/java/com/iexec/core/chain/IexecHubService.java @@ -18,19 +18,12 @@ import com.iexec.commons.poco.chain.*; import com.iexec.commons.poco.contract.generated.IexecHubContract; -import com.iexec.commons.poco.utils.BytesUtils; import io.reactivex.Flowable; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.tuple.Pair; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.web3j.protocol.core.RemoteCall; import org.web3j.protocol.core.methods.request.EthFilter; -import org.web3j.protocol.core.methods.response.BaseEventResponse; import org.web3j.protocol.core.methods.response.TransactionReceipt; -import java.math.BigInteger; -import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.List; import java.util.Optional; @@ -40,8 +33,6 @@ import java.util.concurrent.ThreadPoolExecutor; import static com.iexec.common.utils.DateTimeUtils.now; -import static com.iexec.commons.poco.chain.ChainTaskStatus.ACTIVE; -import static com.iexec.commons.poco.chain.ChainTaskStatus.COMPLETED; import static com.iexec.commons.poco.utils.BytesUtils.stringToBytes; @Slf4j @@ -52,7 +43,6 @@ public class IexecHubService extends IexecHubAbstractService { private final CredentialsService credentialsService; private final Web3jService web3jService; - @Autowired public IexecHubService(CredentialsService credentialsService, Web3jService web3jService, ChainConfig chainConfig) { @@ -68,22 +58,6 @@ public IexecHubService(CredentialsService credentialsService, } } - /** - * Check if a deal's task can be initialized. - * An initializable task should have the status - * UNSET onchain and have a contribution deadline - * that is still in the future. - * - * @param chainDealId - * @param taskIndex - * @return true if the task is initializable, false otherwise. - */ - public boolean isInitializableOnchain(String chainDealId, int taskIndex) { - boolean isTaskUnsetOnChain = isTaskInUnsetStatusOnChain(chainDealId, taskIndex); - boolean isBeforeContributionDeadline = isBeforeContributionDeadline(chainDealId); - return isBeforeContributionDeadline && isTaskUnsetOnChain; - } - /** * Check if the task is defined onchain and * has the status {@link ChainTaskStatus#UNSET}. @@ -167,52 +141,6 @@ public Date getChainDealFinalDeadline(ChainDeal chainDeal) { return new Date(startTime + maxTime * 10); } - @Deprecated - public Optional> initialize(String chainDealId, int taskIndex) { - log.info("Requested initialize [chainDealId:{}, taskIndex:{}, waitingTxCount:{}]", chainDealId, taskIndex, getWaitingTransactionCount()); - try { - return CompletableFuture.supplyAsync(() -> sendInitializeTransaction(chainDealId, taskIndex), executor).get(); - } catch (InterruptedException | ExecutionException e) { - log.error("initialize asynchronous execution did not complete", e); - } - return Optional.empty(); - } - - private Optional> sendInitializeTransaction(String chainDealId, int taskIndex) { - byte[] chainDealIdBytes = stringToBytes(chainDealId); - String computedChainTaskId = ChainUtils.generateChainTaskId(chainDealId, taskIndex); - RemoteCall initializeCall = - getHubContract(web3jService.getWritingContractGasProvider()) - .initialize(chainDealIdBytes, BigInteger.valueOf(taskIndex)); - - TransactionReceipt initializeReceipt; - try { - initializeReceipt = initializeCall.send(); - } catch (Exception e) { - log.error("Failed to send initialize [chainDealId:{}, taskIndex:{}]", chainDealId, taskIndex, e); - return Optional.empty(); - } - - List initializeEvents = getHubContract().getTaskInitializeEvents(initializeReceipt); - - IexecHubContract.TaskInitializeEventResponse initializeEvent = null; - if (initializeEvents != null && !initializeEvents.isEmpty()) { - initializeEvent = initializeEvents.get(0); - } - - if (isSuccessTx(computedChainTaskId, initializeEvent, ACTIVE)) { - String chainTaskId = BytesUtils.bytesToString(initializeEvent.taskid); - ChainReceipt chainReceipt = buildChainReceipt(initializeReceipt); - log.info("Initialized [chainTaskId:{}, chainDealId:{}, taskIndex:{}, gasUsed:{}, block:{}]", - computedChainTaskId, chainDealId, taskIndex, - initializeReceipt.getGasUsed(), chainReceipt.getBlockNumber()); - return Optional.of(Pair.of(chainTaskId, chainReceipt)); - } - - log.error("Failed to initialize [chainDealId:{}, taskIndex:{}]", chainDealId, taskIndex); - return Optional.empty(); - } - public boolean canFinalize(String chainTaskId) { Optional optional = getChainTask(chainTaskId); if (optional.isEmpty()) { @@ -236,73 +164,6 @@ public boolean canFinalize(String chainTaskId) { return ret; } - public Optional finalizeTask(String chainTaskId, String resultLink, String callbackData) { - log.info("Requested finalize [chainTaskId:{}, waitingTxCount:{}]", chainTaskId, getWaitingTransactionCount()); - try { - return CompletableFuture.supplyAsync(() -> sendFinalizeTransaction(chainTaskId, resultLink, callbackData), executor).get(); - } catch (InterruptedException | ExecutionException e) { - log.error("finalizeTask asynchronous execution did not complete", e); - } - return Optional.empty(); - } - - private Optional sendFinalizeTransaction(String chainTaskId, String resultLink, String callbackData) { - byte[] chainTaskIdBytes = stringToBytes(chainTaskId); - byte[] results = new byte[0]; - byte[] resultsCallback = new byte[0]; - - boolean shouldSendCallback = callbackData != null && !callbackData.isEmpty(); - if (!shouldSendCallback) { - results = resultLink.getBytes(StandardCharsets.UTF_8); - } else { - resultsCallback = stringToBytes(callbackData); - } - - TransactionReceipt finalizeReceipt; - - RemoteCall finalizeCall = getHubContract(web3jService.getWritingContractGasProvider()) - .finalize(chainTaskIdBytes, results, resultsCallback); - - try { - finalizeReceipt = finalizeCall.send(); - } catch (Exception e) { - log.error("Failed to send finalize [chainTaskId:{}, resultLink:{}, callbackData:{}, shouldSendCallback:{}]", - chainTaskId, resultLink, callbackData, shouldSendCallback, e); - return Optional.empty(); - } - - List finalizeEvents = getHubContract().getTaskFinalizeEvents(finalizeReceipt); - - IexecHubContract.TaskFinalizeEventResponse finalizeEvent = null; - if (finalizeEvents != null && !finalizeEvents.isEmpty()) { - finalizeEvent = finalizeEvents.get(0); - } - - if (isSuccessTx(chainTaskId, finalizeEvent, COMPLETED)) { - ChainReceipt chainReceipt = buildChainReceipt(finalizeReceipt); - log.info("Finalized [chainTaskId:{}, resultLink:{}, callbackData:{}, " + - "shouldSendCallback:{}, gasUsed:{}, block:{}]", - chainTaskId, resultLink, callbackData, shouldSendCallback, - finalizeReceipt.getGasUsed(), chainReceipt.getBlockNumber()); - return Optional.of(chainReceipt); - } - - log.error("Failed to finalize [chainTaskId:{}]", chainTaskId); - return Optional.empty(); - } - - private boolean isSuccessTx(String chainTaskId, BaseEventResponse txEvent, ChainTaskStatus pretendedStatus) { - if (txEvent == null || txEvent.log == null) { - return false; - } - - if (txEvent.log.getType() == null || txEvent.log.getType().equals(PENDING_RECEIPT_STATUS)) { - return isStatusValidOnChainAfterPendingReceipt(chainTaskId, pretendedStatus, this::isTaskStatusValidOnChain); - } - - return true; - } - public boolean canReopen(String chainTaskId) { Optional optional = getChainTask(chainTaskId); if (optional.isEmpty()) { @@ -371,14 +232,6 @@ public boolean hasEnoughGas() { return hasEnoughGas(credentialsService.getCredentials().getAddress()); } - private Boolean isTaskStatusValidOnChain(String chainTaskId, ChainStatus chainTaskStatus) { - if (chainTaskStatus instanceof ChainTaskStatus) { - Optional optionalChainTask = getChainTask(chainTaskId); - return optionalChainTask.isPresent() && optionalChainTask.get().getStatus().equals(chainTaskStatus); - } - return false; - } - private ChainReceipt buildChainReceipt(TransactionReceipt receipt) { return ChainReceipt.builder() .txHash(receipt.getTransactionHash()) From 1ce18a7ef73ca59932dc7fc70f8b45ac00860482 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Tue, 18 Apr 2023 10:14:45 +0200 Subject: [PATCH 14/77] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfa277e4a..19c4b4af4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. ### Bug Fixes - Prevent race condition on replicate update. (#568) ### Quality +- Remove unused methods in `IexecHubService`. (#572) ### Dependency Upgrades - Upgrade to `iexec-common` 8.0.0. (#571) - Add new `iexec-commons-poco` 1.0.2 dependency. (#571) From 8fece11e9cd18719af566bc80fff3cb6102be597 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 27 Apr 2023 14:36:52 +0200 Subject: [PATCH 15/77] Clean unused `Replicate` methods and update tests --- .../com/iexec/core/replicate/Replicate.java | 9 ----- .../replicate/ReplicateListenersTests.java | 40 +++++++++++-------- .../iexec/core/replicate/ReplicateTests.java | 27 ------------- 3 files changed, 23 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/iexec/core/replicate/Replicate.java b/src/main/java/com/iexec/core/replicate/Replicate.java index 819643d61..55bafa3a9 100644 --- a/src/main/java/com/iexec/core/replicate/Replicate.java +++ b/src/main/java/com/iexec/core/replicate/Replicate.java @@ -139,15 +139,6 @@ public boolean isCreatedMoreThanNPeriodsAgo(int numberPeriod, long maxExecutionT return now.after(numberPeriodsAfterCreationDate); } - public boolean isLostAfterStatus(ReplicateStatus status) { - return getCurrentStatus() == ReplicateStatus.WORKER_LOST && - getLastButOneStatus() == status; - } - - public boolean isBusyComputing() { - return ReplicateStatus.getSuccessStatusesBeforeComputed().contains(getCurrentStatus()); - } - public boolean isRecoverable() { ReplicateStatus currentStatus = getLastRelevantStatus(); return ReplicateStatus.isRecoverable(currentStatus); diff --git a/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java b/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java index c25a9fa46..73486eafb 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java @@ -25,12 +25,17 @@ import com.iexec.core.worker.WorkerService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import java.util.Arrays; import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; import static com.iexec.common.replicate.ReplicateStatus.*; import static com.iexec.common.replicate.ReplicateStatusCause.TASK_NOT_ACTIVE; @@ -146,29 +151,30 @@ void shouldNotTriggerDetectOnchainContributedSinceCauseIsNull() { Mockito.verify(contributionUnnotifiedDetector, Mockito.times(0)).detectOnchainContributed(); } - @Test - void shouldAddFailedStatusSinceUncompletableReplicateStatus() { - List uncompletableStatuses = ReplicateStatus.getUncompletableStatuses(); - - for (ReplicateStatus uncompletableStatus: uncompletableStatuses){ - ReplicateUpdatedEvent replicateUpdatedEvent = getMockReplicate(uncompletableStatus); + static Stream getUncompletableStatuses() { + return ReplicateStatus.getUncompletableStatuses().stream(); + } - replicateListeners.onReplicateUpdatedEvent(replicateUpdatedEvent); - } + @ParameterizedTest + @MethodSource("getUncompletableStatuses") + void shouldAddFailedStatusSinceUncompletableReplicateStatus(ReplicateStatus uncompletableStatus) { + ReplicateUpdatedEvent replicateUpdatedEvent = getMockReplicate(uncompletableStatus); + replicateListeners.onReplicateUpdatedEvent(replicateUpdatedEvent); - Mockito.verify(replicatesService, Mockito.times(uncompletableStatuses.size())) + Mockito.verify(replicatesService, Mockito.times(1)) .updateReplicateStatus(CHAIN_TASK_ID, WORKER_WALLET, FAILED); } - @Test - void shouldNotAddFailedStatusSinceCompletableReplicateStatus() { - List completableStatuses = ReplicateStatus.getCompletableStatuses(); - - for (ReplicateStatus completableStatus: completableStatuses){ - ReplicateUpdatedEvent replicateUpdatedEvent = getMockReplicate(completableStatus); + static Stream getCompletableStatuses() { + return Arrays.stream(values()) + .filter(Predicate.not(ReplicateStatus.getUncompletableStatuses()::contains)); + } - replicateListeners.onReplicateUpdatedEvent(replicateUpdatedEvent); - } + @ParameterizedTest + @MethodSource("getCompletableStatuses") + void shouldNotAddFailedStatusSinceCompletableReplicateStatus(ReplicateStatus completableStatus) { + ReplicateUpdatedEvent replicateUpdatedEvent = getMockReplicate(completableStatus); + replicateListeners.onReplicateUpdatedEvent(replicateUpdatedEvent); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(CHAIN_TASK_ID, WORKER_WALLET, FAILED); diff --git a/src/test/java/com/iexec/core/replicate/ReplicateTests.java b/src/test/java/com/iexec/core/replicate/ReplicateTests.java index a2fc7efd1..246a35f67 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateTests.java @@ -159,33 +159,6 @@ void shouldNotBeCreatedLongAgo(){ assertThat(replicate.isCreatedMoreThanNPeriodsAgo(2, maxExecutionTime)).isFalse(); } - @Test - void shouldBeBusyComputing() { - Replicate replicate = new Replicate(WALLET_WORKER, CHAIN_TASK_ID); - assertThat(replicate.isBusyComputing()).isTrue(); - replicate.updateStatus(STARTING, ReplicateStatusModifier.WORKER); - assertThat(replicate.isBusyComputing()).isTrue(); - replicate.updateStatus(ReplicateStatus.APP_DOWNLOADING, ReplicateStatusModifier.WORKER); - assertThat(replicate.isBusyComputing()).isTrue(); - replicate.updateStatus(ReplicateStatus.APP_DOWNLOADED, ReplicateStatusModifier.WORKER); - assertThat(replicate.isBusyComputing()).isTrue(); - replicate.updateStatus(ReplicateStatus.COMPUTING, ReplicateStatusModifier.WORKER); - assertThat(replicate.isBusyComputing()).isTrue(); - - replicate.updateStatus(ReplicateStatus.COMPUTED, ReplicateStatusModifier.WORKER); - assertThat(replicate.isBusyComputing()).isFalse(); - replicate.updateStatus(ReplicateStatus.CONTRIBUTING, ReplicateStatusModifier.WORKER); - assertThat(replicate.isBusyComputing()).isFalse(); - replicate.updateStatus(ReplicateStatus.CONTRIBUTED, ReplicateStatusModifier.WORKER); - assertThat(replicate.isBusyComputing()).isFalse(); - replicate.updateStatus(ReplicateStatus.REVEALING, ReplicateStatusModifier.WORKER); - assertThat(replicate.isBusyComputing()).isFalse(); - replicate.updateStatus(ReplicateStatus.REVEALED, ReplicateStatusModifier.WORKER); - assertThat(replicate.isBusyComputing()).isFalse(); - replicate.updateStatus(ReplicateStatus.COMPLETED, ReplicateStatusModifier.WORKER); - assertThat(replicate.isBusyComputing()).isFalse(); - } - // region getLastRelevantStatus @Test void shouldGetLastRelevantStatusWhenOnlyRelevantStatus() { From 87b20fe04b6c1320cf6196c6594c146c93c1cd33 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 27 Apr 2023 14:38:43 +0200 Subject: [PATCH 16/77] Update `CHANGELOG.md` --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfa277e4a..33534ef81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. ### Bug Fixes - Prevent race condition on replicate update. (#568) ### Quality +- Clean unused Replicate methods and update tests. (#573) ### Dependency Upgrades - Upgrade to `iexec-common` 8.0.0. (#571) - Add new `iexec-commons-poco` 1.0.2 dependency. (#571) From c19910ed1ad10cd02996caa8d0cbddbded5f35cf Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Fri, 28 Apr 2023 09:15:33 +0200 Subject: [PATCH 17/77] Revert `isBusyComputing` cleaning --- .../com/iexec/core/replicate/Replicate.java | 4 +++ .../iexec/core/replicate/ReplicateTests.java | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/main/java/com/iexec/core/replicate/Replicate.java b/src/main/java/com/iexec/core/replicate/Replicate.java index 55bafa3a9..da15cf238 100644 --- a/src/main/java/com/iexec/core/replicate/Replicate.java +++ b/src/main/java/com/iexec/core/replicate/Replicate.java @@ -139,6 +139,10 @@ public boolean isCreatedMoreThanNPeriodsAgo(int numberPeriod, long maxExecutionT return now.after(numberPeriodsAfterCreationDate); } + public boolean isBusyComputing() { + return ReplicateStatus.getSuccessStatusesBeforeComputed().contains(getCurrentStatus()); + } + public boolean isRecoverable() { ReplicateStatus currentStatus = getLastRelevantStatus(); return ReplicateStatus.isRecoverable(currentStatus); diff --git a/src/test/java/com/iexec/core/replicate/ReplicateTests.java b/src/test/java/com/iexec/core/replicate/ReplicateTests.java index 246a35f67..a2fc7efd1 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateTests.java @@ -159,6 +159,33 @@ void shouldNotBeCreatedLongAgo(){ assertThat(replicate.isCreatedMoreThanNPeriodsAgo(2, maxExecutionTime)).isFalse(); } + @Test + void shouldBeBusyComputing() { + Replicate replicate = new Replicate(WALLET_WORKER, CHAIN_TASK_ID); + assertThat(replicate.isBusyComputing()).isTrue(); + replicate.updateStatus(STARTING, ReplicateStatusModifier.WORKER); + assertThat(replicate.isBusyComputing()).isTrue(); + replicate.updateStatus(ReplicateStatus.APP_DOWNLOADING, ReplicateStatusModifier.WORKER); + assertThat(replicate.isBusyComputing()).isTrue(); + replicate.updateStatus(ReplicateStatus.APP_DOWNLOADED, ReplicateStatusModifier.WORKER); + assertThat(replicate.isBusyComputing()).isTrue(); + replicate.updateStatus(ReplicateStatus.COMPUTING, ReplicateStatusModifier.WORKER); + assertThat(replicate.isBusyComputing()).isTrue(); + + replicate.updateStatus(ReplicateStatus.COMPUTED, ReplicateStatusModifier.WORKER); + assertThat(replicate.isBusyComputing()).isFalse(); + replicate.updateStatus(ReplicateStatus.CONTRIBUTING, ReplicateStatusModifier.WORKER); + assertThat(replicate.isBusyComputing()).isFalse(); + replicate.updateStatus(ReplicateStatus.CONTRIBUTED, ReplicateStatusModifier.WORKER); + assertThat(replicate.isBusyComputing()).isFalse(); + replicate.updateStatus(ReplicateStatus.REVEALING, ReplicateStatusModifier.WORKER); + assertThat(replicate.isBusyComputing()).isFalse(); + replicate.updateStatus(ReplicateStatus.REVEALED, ReplicateStatusModifier.WORKER); + assertThat(replicate.isBusyComputing()).isFalse(); + replicate.updateStatus(ReplicateStatus.COMPLETED, ReplicateStatusModifier.WORKER); + assertThat(replicate.isBusyComputing()).isFalse(); + } + // region getLastRelevantStatus @Test void shouldGetLastRelevantStatusWhenOnlyRelevantStatus() { From 322da813c2051b090f9000de418131767547c590 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Fri, 28 Apr 2023 11:19:23 +0200 Subject: [PATCH 18/77] Update Replicate Statuses transitions --- gradle.properties | 4 ++-- .../com/iexec/core/workflow/ReplicateWorkflowTests.java | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5a02ee072..1bcb12249 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ version=8.0.1 -iexecCommonVersion=8.0.0 -iexecCommonsPocoVersion=1.0.2 +iexecCommonVersion=8.0.0-NEXT-SNAPSHOT +iexecCommonsPocoVersion=1.0.2-NEXT-SNAPSHOT iexecBlockchainAdapterVersion=8.0.1-NEXT-SNAPSHOT iexecResultVersion=8.0.0-NEXT-SNAPSHOT iexecSmsVersion=8.0.0-NEXT-SNAPSHOT diff --git a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java index facb569ea..38e23bb3c 100644 --- a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java +++ b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java @@ -198,14 +198,17 @@ void workflowToJson() throws IOException { expectedTransitions.put(RESULT_UPLOADING, List.of(RESULT_UPLOADED, RESULT_UPLOAD_FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(RESULT_UPLOAD_FAILED, List.of(COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(RESULT_UPLOADED, List.of(COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); + expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_ONGOING, List.of(FAILED, WORKER_LOST, RECOVERING, ABORTED)); + expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_DONE, List.of(WORKER_LOST, RECOVERING, ABORTED)); + expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_FAILED, List.of(FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(COMPLETING, List.of(COMPLETED, COMPLETE_FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(START_FAILED, List.of(FAILED, WORKER_LOST, ABORTED)); expectedTransitions.put(COMPUTE_FAILED, List.of(FAILED, WORKER_LOST, ABORTED)); expectedTransitions.put(CONTRIBUTE_FAILED, List.of(FAILED, WORKER_LOST, ABORTED)); expectedTransitions.put(REVEAL_FAILED, List.of(FAILED, WORKER_LOST, ABORTED)); expectedTransitions.put(ABORTED, List.of(FAILED, WORKER_LOST, COMPLETED, FAILED)); - expectedTransitions.put(WORKER_LOST, List.of(FAILED, CREATED, STARTING, START_FAILED, STARTED, APP_DOWNLOADING, APP_DOWNLOAD_FAILED, APP_DOWNLOADED, DATA_DOWNLOADING, DATA_DOWNLOAD_FAILED, DATA_DOWNLOADED, COMPUTING, COMPUTE_FAILED, COMPUTED, CONTRIBUTING, CONTRIBUTE_FAILED, CONTRIBUTED, REVEALING, REVEAL_FAILED, REVEALED, RESULT_UPLOAD_REQUESTED, RESULT_UPLOAD_REQUEST_FAILED, RESULT_UPLOADING, RESULT_UPLOAD_FAILED, RESULT_UPLOADED, COMPLETING, COMPLETE_FAILED, COMPLETED, FAILED, RECOVERING, ABORTED, RECOVERING, ABORTED, ABORTED)); - expectedTransitions.put(RECOVERING, List.of(FAILED, WORKER_LOST, RECOVERING, START_FAILED, STARTED, APP_DOWNLOADING, APP_DOWNLOAD_FAILED, APP_DOWNLOADED, DATA_DOWNLOADING, DATA_DOWNLOAD_FAILED, DATA_DOWNLOADED, COMPUTING, COMPUTE_FAILED, COMPUTED, CONTRIBUTING, CONTRIBUTE_FAILED, CONTRIBUTED, REVEALING, REVEAL_FAILED, REVEALED, RESULT_UPLOAD_REQUESTED, RESULT_UPLOAD_REQUEST_FAILED, RESULT_UPLOADING, RESULT_UPLOAD_FAILED, RESULT_UPLOADED, COMPLETING, COMPLETE_FAILED, COMPLETED, FAILED, ABORTED, RECOVERING, WORKER_LOST)); + expectedTransitions.put(WORKER_LOST, List.of(FAILED, CREATED, STARTING, START_FAILED, STARTED, APP_DOWNLOADING, APP_DOWNLOAD_FAILED, APP_DOWNLOADED, DATA_DOWNLOADING, DATA_DOWNLOAD_FAILED, DATA_DOWNLOADED, COMPUTING, COMPUTE_FAILED, COMPUTED, CONTRIBUTING, CONTRIBUTE_FAILED, CONTRIBUTED, REVEALING, REVEAL_FAILED, REVEALED, RESULT_UPLOAD_REQUESTED, RESULT_UPLOAD_REQUEST_FAILED, RESULT_UPLOADING, RESULT_UPLOAD_FAILED, RESULT_UPLOADED, CONTRIBUTE_AND_FINALIZE_ONGOING, CONTRIBUTE_AND_FINALIZE_FAILED, CONTRIBUTE_AND_FINALIZE_DONE, COMPLETING, COMPLETE_FAILED, COMPLETED, FAILED, RECOVERING, ABORTED, RECOVERING, ABORTED, ABORTED)); + expectedTransitions.put(RECOVERING, List.of(FAILED, WORKER_LOST, RECOVERING, START_FAILED, STARTED, APP_DOWNLOADING, APP_DOWNLOAD_FAILED, APP_DOWNLOADED, DATA_DOWNLOADING, DATA_DOWNLOAD_FAILED, DATA_DOWNLOADED, COMPUTING, COMPUTE_FAILED, COMPUTED, CONTRIBUTING, CONTRIBUTE_FAILED, CONTRIBUTED, REVEALING, REVEAL_FAILED, REVEALED, RESULT_UPLOAD_REQUESTED, RESULT_UPLOAD_REQUEST_FAILED, RESULT_UPLOADING, RESULT_UPLOAD_FAILED, RESULT_UPLOADED, CONTRIBUTE_AND_FINALIZE_ONGOING, CONTRIBUTE_AND_FINALIZE_FAILED, CONTRIBUTE_AND_FINALIZE_DONE, COMPLETING, COMPLETE_FAILED, COMPLETED, FAILED, ABORTED, RECOVERING, WORKER_LOST)); expectedTransitions.put(COMPLETE_FAILED, List.of(WORKER_LOST, ABORTED)); assertThat(actualTransitions).isEqualTo(expectedTransitions); From 9ec1cd52f891d721fefb49de91c5cca1fdfbd8d6 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Wed, 3 May 2023 16:43:16 +0200 Subject: [PATCH 19/77] Add `CONTRIBUTE_AND_FINALIZE` statuses to `ReplicateWorkflow` --- .../java/com/iexec/core/workflow/ReplicateWorkflow.java | 6 +++++- .../com/iexec/core/workflow/ReplicateWorkflowTests.java | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java index eb83fb229..6430de31e 100644 --- a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java +++ b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java @@ -80,7 +80,7 @@ private void setDefaultWorkflowTransitions() { // computation addTransition(COMPUTING, toList(COMPUTED, COMPUTE_FAILED)); - addTransition(COMPUTED, CONTRIBUTING); + addTransition(COMPUTED, toList(CONTRIBUTING, CONTRIBUTE_AND_FINALIZE_ONGOING)); // contribution addTransition(CONTRIBUTING, toList(CONTRIBUTED, CONTRIBUTE_FAILED)); @@ -98,6 +98,10 @@ private void setDefaultWorkflowTransitions() { addTransition(RESULT_UPLOAD_FAILED, toList(COMPLETING)); addTransition(RESULT_UPLOADED, toList(COMPLETING)); + // contribute and finalize + addTransition(CONTRIBUTE_AND_FINALIZE_ONGOING, toList(CONTRIBUTE_AND_FINALIZE_FAILED, CONTRIBUTE_AND_FINALIZE_DONE)); + addTransition(CONTRIBUTE_AND_FINALIZE_DONE, COMPLETING); + // complete addTransition(COMPLETING, toList(COMPLETED, COMPLETE_FAILED)); } diff --git a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java index 38e23bb3c..1c1bf4bcf 100644 --- a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java +++ b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java @@ -188,7 +188,7 @@ void workflowToJson() throws IOException { expectedTransitions.put(DATA_DOWNLOAD_FAILED, List.of(CONTRIBUTING, FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(DATA_DOWNLOADED, List.of(COMPUTING, FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(COMPUTING, List.of(COMPUTED, COMPUTE_FAILED, FAILED, WORKER_LOST, RECOVERING, ABORTED)); - expectedTransitions.put(COMPUTED, List.of(CONTRIBUTING, FAILED, WORKER_LOST, RECOVERING, ABORTED)); + expectedTransitions.put(COMPUTED, List.of(CONTRIBUTING, CONTRIBUTE_AND_FINALIZE_ONGOING, FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(CONTRIBUTING, List.of(CONTRIBUTED, CONTRIBUTE_FAILED, FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(CONTRIBUTED, List.of(REVEALING, FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(REVEALING, List.of(REVEALED, REVEAL_FAILED, FAILED, WORKER_LOST, RECOVERING, ABORTED)); @@ -198,8 +198,8 @@ void workflowToJson() throws IOException { expectedTransitions.put(RESULT_UPLOADING, List.of(RESULT_UPLOADED, RESULT_UPLOAD_FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(RESULT_UPLOAD_FAILED, List.of(COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(RESULT_UPLOADED, List.of(COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); - expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_ONGOING, List.of(FAILED, WORKER_LOST, RECOVERING, ABORTED)); - expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_DONE, List.of(WORKER_LOST, RECOVERING, ABORTED)); + expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_ONGOING, List.of(CONTRIBUTE_AND_FINALIZE_FAILED, CONTRIBUTE_AND_FINALIZE_DONE, FAILED, WORKER_LOST, RECOVERING, ABORTED)); + expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_DONE, List.of(COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_FAILED, List.of(FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(COMPLETING, List.of(COMPLETED, COMPLETE_FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(START_FAILED, List.of(FAILED, WORKER_LOST, ABORTED)); From 15256801a238821abce05518df2be4a934c53de0 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Wed, 3 May 2023 17:01:32 +0200 Subject: [PATCH 20/77] Add `CONTRIBUTE_AND_FINALIZE` transitions to `ReplicateWorkflow` --- src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java | 4 ++++ .../java/com/iexec/core/workflow/ReplicateWorkflowTests.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java index 6430de31e..92bc9c823 100644 --- a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java +++ b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java @@ -245,6 +245,10 @@ private void setNextActions() { setNextAction(RESULT_UPLOADED, PLEASE_WAIT); setNextAction(RESULT_UPLOAD_FAILED, PLEASE_ABORT); + setNextAction(CONTRIBUTE_AND_FINALIZE_ONGOING, PLEASE_CONTINUE); + setNextAction(CONTRIBUTE_AND_FINALIZE_DONE, PLEASE_WAIT); + setNextAction(CONTRIBUTE_AND_FINALIZE_FAILED, PLEASE_ABORT); + setNextAction(COMPLETING, PLEASE_CONTINUE); setNextAction(COMPLETED, PLEASE_WAIT); setNextAction(COMPLETE_FAILED, PLEASE_ABORT); diff --git a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java index 1c1bf4bcf..bd5944590 100644 --- a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java +++ b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java @@ -239,6 +239,9 @@ void workflowToJson() throws IOException { expectedActions.put(RESULT_UPLOADING, PLEASE_CONTINUE); expectedActions.put(RESULT_UPLOADED, PLEASE_WAIT); expectedActions.put(RESULT_UPLOAD_FAILED, PLEASE_ABORT); + expectedActions.put(CONTRIBUTE_AND_FINALIZE_ONGOING, PLEASE_CONTINUE); + expectedActions.put(CONTRIBUTE_AND_FINALIZE_DONE, PLEASE_WAIT); + expectedActions.put(CONTRIBUTE_AND_FINALIZE_FAILED, PLEASE_ABORT); expectedActions.put(COMPLETING, PLEASE_CONTINUE); expectedActions.put(COMPLETED, PLEASE_WAIT); expectedActions.put(COMPLETE_FAILED, PLEASE_ABORT); From 6305293f13aa7e2406c8238b7664fe7c71babecd Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Wed, 3 May 2023 17:13:01 +0200 Subject: [PATCH 21/77] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19c4b4af4..57f750f18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. ## [[NEXT]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/vNEXT) 2023 ### New Features +- Add ContributeAndFinalize to `ReplicateWorkflow`. (#574) ### Bug Fixes - Prevent race condition on replicate update. (#568) ### Quality @@ -12,6 +13,7 @@ All notable changes to this project will be documented in this file. ### Dependency Upgrades - Upgrade to `iexec-common` 8.0.0. (#571) - Add new `iexec-commons-poco` 1.0.2 dependency. (#571) +- Update `iexec-commons-poco` to 1.0.2-NEXT-SNAPSHOT. (#574) ## [[8.0.1]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.0.1) 2023-03-20 From 43293b6a423f46e7ec4517b6706790dc98dbbec9 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 4 May 2023 14:32:31 +0200 Subject: [PATCH 22/77] Permute values in replicate workflow --- src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java | 2 +- .../java/com/iexec/core/workflow/ReplicateWorkflowTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java index 92bc9c823..f7095565b 100644 --- a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java +++ b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java @@ -99,7 +99,7 @@ private void setDefaultWorkflowTransitions() { addTransition(RESULT_UPLOADED, toList(COMPLETING)); // contribute and finalize - addTransition(CONTRIBUTE_AND_FINALIZE_ONGOING, toList(CONTRIBUTE_AND_FINALIZE_FAILED, CONTRIBUTE_AND_FINALIZE_DONE)); + addTransition(CONTRIBUTE_AND_FINALIZE_ONGOING, toList(CONTRIBUTE_AND_FINALIZE_DONE, CONTRIBUTE_AND_FINALIZE_FAILED)); addTransition(CONTRIBUTE_AND_FINALIZE_DONE, COMPLETING); // complete diff --git a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java index bd5944590..5e8625d53 100644 --- a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java +++ b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java @@ -198,7 +198,7 @@ void workflowToJson() throws IOException { expectedTransitions.put(RESULT_UPLOADING, List.of(RESULT_UPLOADED, RESULT_UPLOAD_FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(RESULT_UPLOAD_FAILED, List.of(COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(RESULT_UPLOADED, List.of(COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); - expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_ONGOING, List.of(CONTRIBUTE_AND_FINALIZE_FAILED, CONTRIBUTE_AND_FINALIZE_DONE, FAILED, WORKER_LOST, RECOVERING, ABORTED)); + expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_ONGOING, List.of(CONTRIBUTE_AND_FINALIZE_DONE, CONTRIBUTE_AND_FINALIZE_FAILED, FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_DONE, List.of(COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(CONTRIBUTE_AND_FINALIZE_FAILED, List.of(FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(COMPLETING, List.of(COMPLETED, COMPLETE_FAILED, WORKER_LOST, RECOVERING, ABORTED)); From b71f106e22124bace52fc9ff383fdc7082937605 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 4 May 2023 16:58:55 +0200 Subject: [PATCH 23/77] Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED` --- CHANGELOG.md | 1 + .../replicate/ReplicateResultUploadTimeoutDetector.java | 4 +--- .../java/com/iexec/core/workflow/ReplicateWorkflow.java | 3 +-- .../ReplicateResultUploadTimeoutDetectorTests.java | 4 ++-- .../com/iexec/core/workflow/ReplicateWorkflowTests.java | 7 +++---- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c907b2c6a..2d18bf657 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. ### Quality - Remove unused methods in `IexecHubService`. (#572) - Clean unused Replicate methods and update tests. (#573) +- Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#) ### Dependency Upgrades - Upgrade to `iexec-common` 8.0.0. (#571) - Add new `iexec-commons-poco` 1.0.2 dependency. (#571) diff --git a/src/main/java/com/iexec/core/detector/replicate/ReplicateResultUploadTimeoutDetector.java b/src/main/java/com/iexec/core/detector/replicate/ReplicateResultUploadTimeoutDetector.java index 7607dca04..e7f2201e8 100644 --- a/src/main/java/com/iexec/core/detector/replicate/ReplicateResultUploadTimeoutDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/ReplicateResultUploadTimeoutDetector.java @@ -31,7 +31,6 @@ import java.util.Optional; import static com.iexec.common.replicate.ReplicateStatus.RESULT_UPLOAD_FAILED; -import static com.iexec.common.replicate.ReplicateStatus.RESULT_UPLOAD_REQUEST_FAILED; import static com.iexec.common.utils.DateTimeUtils.addMinutesToDate; @Slf4j @@ -71,8 +70,7 @@ public void detect() { Replicate uploadingReplicate = oUploadingReplicate.get(); boolean startedUploadLongAgo = new Date().after(addMinutesToDate(task.getLatestStatusChange().getDate(), 2)); - boolean hasReplicateAlreadyFailedToUpload = uploadingReplicate.containsStatus(RESULT_UPLOAD_REQUEST_FAILED) || - uploadingReplicate.containsStatus(RESULT_UPLOAD_FAILED); + boolean hasReplicateAlreadyFailedToUpload = uploadingReplicate.containsStatus(RESULT_UPLOAD_FAILED); if (!startedUploadLongAgo) { return; diff --git a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java index f7095565b..cede1d1b1 100644 --- a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java +++ b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java @@ -92,8 +92,7 @@ private void setDefaultWorkflowTransitions() { addTransition(REVEALED, toList(RESULT_UPLOAD_REQUESTED, COMPLETING)); // result upload - addTransition(RESULT_UPLOAD_REQUESTED, toList(RESULT_UPLOADING, RESULT_UPLOAD_REQUEST_FAILED)); - addTransition(RESULT_UPLOAD_REQUEST_FAILED, toList(COMPLETING)); + addTransition(RESULT_UPLOAD_REQUESTED, toList(RESULT_UPLOADING)); addTransition(RESULT_UPLOADING, toList(RESULT_UPLOADED, RESULT_UPLOAD_FAILED)); addTransition(RESULT_UPLOAD_FAILED, toList(COMPLETING)); addTransition(RESULT_UPLOADED, toList(COMPLETING)); diff --git a/src/test/java/com/iexec/core/detector/replicate/ReplicateResultUploadTimeoutDetectorTests.java b/src/test/java/com/iexec/core/detector/replicate/ReplicateResultUploadTimeoutDetectorTests.java index 14c8c856b..9f7e3a471 100644 --- a/src/test/java/com/iexec/core/detector/replicate/ReplicateResultUploadTimeoutDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/replicate/ReplicateResultUploadTimeoutDetectorTests.java @@ -136,7 +136,7 @@ void shouldNotDetectReplicatePreviouslyDetected() { replicate.updateStatus(ReplicateStatus.COMPUTED, ReplicateStatusModifier.WORKER); // we suppose that the status has already been set in a previous detect - replicate.updateStatus(ReplicateStatus.RESULT_UPLOAD_REQUEST_FAILED, ReplicateStatusModifier.POOL_MANAGER); + replicate.updateStatus(ReplicateStatus.RESULT_UPLOAD_FAILED, ReplicateStatusModifier.POOL_MANAGER); TaskStatusChange change1 = new TaskStatusChange(fourMinutesAgo, TaskStatus.INITIALIZED); TaskStatusChange change2 = new TaskStatusChange(threeMinutesAgo, TaskStatus.RUNNING); @@ -152,6 +152,6 @@ void shouldNotDetectReplicatePreviouslyDetected() { // trying to detect any timeout timeoutDetector.detect(); Mockito.verify(replicatesService, Mockito.times(0)) - .updateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, RESULT_UPLOAD_REQUEST_FAILED); + .updateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, RESULT_UPLOAD_FAILED); } } diff --git a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java index 5e8625d53..2c150e7db 100644 --- a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java +++ b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java @@ -193,8 +193,7 @@ void workflowToJson() throws IOException { expectedTransitions.put(CONTRIBUTED, List.of(REVEALING, FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(REVEALING, List.of(REVEALED, REVEAL_FAILED, FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(REVEALED, List.of(RESULT_UPLOAD_REQUESTED, COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); - expectedTransitions.put(RESULT_UPLOAD_REQUESTED, List.of(RESULT_UPLOADING, RESULT_UPLOAD_REQUEST_FAILED, WORKER_LOST, RECOVERING, ABORTED)); - expectedTransitions.put(RESULT_UPLOAD_REQUEST_FAILED, List.of(COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); + expectedTransitions.put(RESULT_UPLOAD_REQUESTED, List.of(RESULT_UPLOADING, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(RESULT_UPLOADING, List.of(RESULT_UPLOADED, RESULT_UPLOAD_FAILED, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(RESULT_UPLOAD_FAILED, List.of(COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); expectedTransitions.put(RESULT_UPLOADED, List.of(COMPLETING, WORKER_LOST, RECOVERING, ABORTED)); @@ -207,8 +206,8 @@ void workflowToJson() throws IOException { expectedTransitions.put(CONTRIBUTE_FAILED, List.of(FAILED, WORKER_LOST, ABORTED)); expectedTransitions.put(REVEAL_FAILED, List.of(FAILED, WORKER_LOST, ABORTED)); expectedTransitions.put(ABORTED, List.of(FAILED, WORKER_LOST, COMPLETED, FAILED)); - expectedTransitions.put(WORKER_LOST, List.of(FAILED, CREATED, STARTING, START_FAILED, STARTED, APP_DOWNLOADING, APP_DOWNLOAD_FAILED, APP_DOWNLOADED, DATA_DOWNLOADING, DATA_DOWNLOAD_FAILED, DATA_DOWNLOADED, COMPUTING, COMPUTE_FAILED, COMPUTED, CONTRIBUTING, CONTRIBUTE_FAILED, CONTRIBUTED, REVEALING, REVEAL_FAILED, REVEALED, RESULT_UPLOAD_REQUESTED, RESULT_UPLOAD_REQUEST_FAILED, RESULT_UPLOADING, RESULT_UPLOAD_FAILED, RESULT_UPLOADED, CONTRIBUTE_AND_FINALIZE_ONGOING, CONTRIBUTE_AND_FINALIZE_FAILED, CONTRIBUTE_AND_FINALIZE_DONE, COMPLETING, COMPLETE_FAILED, COMPLETED, FAILED, RECOVERING, ABORTED, RECOVERING, ABORTED, ABORTED)); - expectedTransitions.put(RECOVERING, List.of(FAILED, WORKER_LOST, RECOVERING, START_FAILED, STARTED, APP_DOWNLOADING, APP_DOWNLOAD_FAILED, APP_DOWNLOADED, DATA_DOWNLOADING, DATA_DOWNLOAD_FAILED, DATA_DOWNLOADED, COMPUTING, COMPUTE_FAILED, COMPUTED, CONTRIBUTING, CONTRIBUTE_FAILED, CONTRIBUTED, REVEALING, REVEAL_FAILED, REVEALED, RESULT_UPLOAD_REQUESTED, RESULT_UPLOAD_REQUEST_FAILED, RESULT_UPLOADING, RESULT_UPLOAD_FAILED, RESULT_UPLOADED, CONTRIBUTE_AND_FINALIZE_ONGOING, CONTRIBUTE_AND_FINALIZE_FAILED, CONTRIBUTE_AND_FINALIZE_DONE, COMPLETING, COMPLETE_FAILED, COMPLETED, FAILED, ABORTED, RECOVERING, WORKER_LOST)); + expectedTransitions.put(WORKER_LOST, List.of(FAILED, CREATED, STARTING, START_FAILED, STARTED, APP_DOWNLOADING, APP_DOWNLOAD_FAILED, APP_DOWNLOADED, DATA_DOWNLOADING, DATA_DOWNLOAD_FAILED, DATA_DOWNLOADED, COMPUTING, COMPUTE_FAILED, COMPUTED, CONTRIBUTING, CONTRIBUTE_FAILED, CONTRIBUTED, REVEALING, REVEAL_FAILED, REVEALED, RESULT_UPLOAD_REQUESTED, RESULT_UPLOADING, RESULT_UPLOAD_FAILED, RESULT_UPLOADED, CONTRIBUTE_AND_FINALIZE_ONGOING, CONTRIBUTE_AND_FINALIZE_FAILED, CONTRIBUTE_AND_FINALIZE_DONE, COMPLETING, COMPLETE_FAILED, COMPLETED, FAILED, RECOVERING, ABORTED, RECOVERING, ABORTED, ABORTED)); + expectedTransitions.put(RECOVERING, List.of(FAILED, WORKER_LOST, RECOVERING, START_FAILED, STARTED, APP_DOWNLOADING, APP_DOWNLOAD_FAILED, APP_DOWNLOADED, DATA_DOWNLOADING, DATA_DOWNLOAD_FAILED, DATA_DOWNLOADED, COMPUTING, COMPUTE_FAILED, COMPUTED, CONTRIBUTING, CONTRIBUTE_FAILED, CONTRIBUTED, REVEALING, REVEAL_FAILED, REVEALED, RESULT_UPLOAD_REQUESTED, RESULT_UPLOADING, RESULT_UPLOAD_FAILED, RESULT_UPLOADED, CONTRIBUTE_AND_FINALIZE_ONGOING, CONTRIBUTE_AND_FINALIZE_FAILED, CONTRIBUTE_AND_FINALIZE_DONE, COMPLETING, COMPLETE_FAILED, COMPLETED, FAILED, ABORTED, RECOVERING, WORKER_LOST)); expectedTransitions.put(COMPLETE_FAILED, List.of(WORKER_LOST, ABORTED)); assertThat(actualTransitions).isEqualTo(expectedTransitions); From 8004cfa951fa4c3bf0fd07cd4d8e91fd9a97dbfd Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 4 May 2023 17:00:42 +0200 Subject: [PATCH 24/77] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d18bf657..47e598c8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ All notable changes to this project will be documented in this file. ### Quality - Remove unused methods in `IexecHubService`. (#572) - Clean unused Replicate methods and update tests. (#573) -- Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#) +- Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#575) ### Dependency Upgrades - Upgrade to `iexec-common` 8.0.0. (#571) - Add new `iexec-commons-poco` 1.0.2 dependency. (#571) From 9fd56816e45e9755ed7470feac6cacf442336c9e Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Fri, 5 May 2023 11:48:04 +0200 Subject: [PATCH 25/77] Update CHANGELOG.md --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47e598c8f..36875ad67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,9 +13,8 @@ All notable changes to this project will be documented in this file. - Clean unused Replicate methods and update tests. (#573) - Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#575) ### Dependency Upgrades -- Upgrade to `iexec-common` 8.0.0. (#571) -- Add new `iexec-commons-poco` 1.0.2 dependency. (#571) -- Update `iexec-commons-poco` to 1.0.2-NEXT-SNAPSHOT. (#574) +- Upgrade to `iexec-common` 8.0.0-NEXT-SNAPSHOT. (#571 #575) +- Add new `iexec-commons-poco` 1.0.2-NEXT-SNAPSHOT dependency. (#571 #574) ## [[8.0.1]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.0.1) 2023-03-20 From fb0aa98a4def9346afde3a636449d927a4360ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Tue, 9 May 2023 12:18:46 +0200 Subject: [PATCH 26/77] Add check for ContributeAndFinalize in ReplicatesService --- CHANGELOG.md | 1 + .../com/iexec/core/chain/IexecHubService.java | 7 ++ .../core/replicate/ReplicatesService.java | 3 + .../core/replicate/ReplicateServiceTests.java | 79 +++++++++++++++++++ 4 files changed, 90 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36875ad67..c2b533b28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ### New Features - Add ContributeAndFinalize to `ReplicateWorkflow`. (#574) +- Add check for ContributeAndFinalize in `ReplicatesService`. ### Bug Fixes - Prevent race condition on replicate update. (#568) ### Quality diff --git a/src/main/java/com/iexec/core/chain/IexecHubService.java b/src/main/java/com/iexec/core/chain/IexecHubService.java index d9978bb53..cf63c0a32 100644 --- a/src/main/java/com/iexec/core/chain/IexecHubService.java +++ b/src/main/java/com/iexec/core/chain/IexecHubService.java @@ -33,6 +33,7 @@ import java.util.concurrent.ThreadPoolExecutor; import static com.iexec.common.utils.DateTimeUtils.now; +import static com.iexec.commons.poco.chain.ChainContributionStatus.CONTRIBUTED; import static com.iexec.commons.poco.utils.BytesUtils.stringToBytes; @Slf4j @@ -74,6 +75,12 @@ public boolean isTaskInUnsetStatusOnChain(String chainDealId, int taskIndex) { || ChainTaskStatus.UNSET.equals(chainTask.get().getStatus()); } + + public boolean isTaskInCompletedStatusOnChain(String chainTaskId) { + Optional oTask = getChainTask(chainTaskId); + return oTask.filter(chainTask -> ChainTaskStatus.COMPLETED.equals(chainTask.getStatus())).isPresent(); + } + /** * Check if a deal's contribution deadline * is still not reached. diff --git a/src/main/java/com/iexec/core/replicate/ReplicatesService.java b/src/main/java/com/iexec/core/replicate/ReplicatesService.java index bd4e64990..4a181f22a 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicatesService.java +++ b/src/main/java/com/iexec/core/replicate/ReplicatesService.java @@ -203,6 +203,7 @@ public ReplicateStatusUpdateError canUpdateReplicateStatus(String chainTaskId, case REVEAL_FAILED: canUpdate = false; break; + case CONTRIBUTE_AND_FINALIZE_DONE: case RESULT_UPLOAD_FAILED: canUpdate = verifyStatus(chainTaskId, walletAddress, newStatus, updateReplicateStatusArgs); break; @@ -537,6 +538,8 @@ private boolean verifyStatus(String chainTaskId, return isResultUploaded(updateReplicateStatusArgs.getTaskDescription()); case RESULT_UPLOAD_FAILED: return !isResultUploaded(updateReplicateStatusArgs.getTaskDescription()); + case CONTRIBUTE_AND_FINALIZE_DONE: + return iexecHubService.repeatIsRevealedTrue(chainTaskId,walletAddress) && iexecHubService.isTaskInCompletedStatusOnChain(chainTaskId); default: return true; } diff --git a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java index 282a970cb..1cd769d56 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java @@ -19,6 +19,8 @@ import com.iexec.common.replicate.*; import com.iexec.commons.poco.chain.ChainContribution; import com.iexec.commons.poco.chain.ChainContributionStatus; +import com.iexec.commons.poco.chain.ChainTask; +import com.iexec.commons.poco.chain.ChainTaskStatus; import com.iexec.commons.poco.notification.TaskNotificationType; import com.iexec.commons.poco.task.TaskDescription; import com.iexec.commons.poco.utils.BytesUtils; @@ -1255,6 +1257,83 @@ void shouldNotAuthorizeUpdateOnResultUploadedSinceResultNotUploaded() { .isEqualTo(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE); } + @Test + void shouldAuthorizeUpdateOnContributeAndFinalizeOnGoing() { + final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); + replicate.updateStatus(COMPUTED, ReplicateStatusModifier.WORKER); + + final ReplicatesList replicatesList = new ReplicatesList(CHAIN_TASK_ID, Collections.singletonList(replicate)); + final ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder() + .modifier(WORKER) + .status(CONTRIBUTE_AND_FINALIZE_ONGOING) + .build(); + + when(replicatesRepository.findByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + + assertThat(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate, null)) + .isEqualTo(ReplicateStatusUpdateError.NO_ERROR); + } + + @Test + void shouldAuthorizeUpdateOnContributeAndFinalizeDone() { + final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); + replicate.updateStatus(CONTRIBUTE_AND_FINALIZE_ONGOING, ReplicateStatusModifier.WORKER); + + final ReplicatesList replicatesList = new ReplicatesList(CHAIN_TASK_ID, Collections.singletonList(replicate)); + final ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder() + .modifier(WORKER) + .status(CONTRIBUTE_AND_FINALIZE_DONE) + .build(); + + when(replicatesRepository.findByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + when(iexecHubService.repeatIsRevealedTrue(CHAIN_TASK_ID, WALLET_WORKER_1)) + .thenReturn(true); + when(iexecHubService.isTaskInCompletedStatusOnChain(CHAIN_TASK_ID)).thenReturn(true); + + assertThat(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate, null)) + .isEqualTo(ReplicateStatusUpdateError.NO_ERROR); + } + + @Test + void shouldNotAuthorizeUpdateOnContributeAndFinalizeDoneWhenNotRevealed() { + final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); + replicate.updateStatus(CONTRIBUTE_AND_FINALIZE_ONGOING, ReplicateStatusModifier.WORKER); + + final ReplicatesList replicatesList = new ReplicatesList(CHAIN_TASK_ID, Collections.singletonList(replicate)); + final ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder() + .modifier(WORKER) + .status(CONTRIBUTE_AND_FINALIZE_DONE) + .build(); + + when(replicatesRepository.findByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + when(iexecHubService.repeatIsRevealedTrue(CHAIN_TASK_ID, WALLET_WORKER_1)) + .thenReturn(false); + when(iexecHubService.isTaskInCompletedStatusOnChain(CHAIN_TASK_ID)).thenReturn(true); + + assertThat(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate, null)) + .isEqualTo(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE); + } + + @Test + void shouldNotAuthorizeUpdateOnContributeAndFinalizeDoneWhenTaskNotCompleted() { + final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); + replicate.updateStatus(CONTRIBUTE_AND_FINALIZE_ONGOING, ReplicateStatusModifier.WORKER); + + final ReplicatesList replicatesList = new ReplicatesList(CHAIN_TASK_ID, Collections.singletonList(replicate)); + final ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder() + .modifier(WORKER) + .status(CONTRIBUTE_AND_FINALIZE_DONE) + .build(); + + when(replicatesRepository.findByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + when(iexecHubService.repeatIsRevealedTrue(CHAIN_TASK_ID, WALLET_WORKER_1)) + .thenReturn(true); + when(iexecHubService.isTaskInCompletedStatusOnChain(CHAIN_TASK_ID)).thenReturn(false); + + assertThat(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate, null)) + .isEqualTo(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE); + } + // computeUpdateReplicateStatusArgs @Test From f5a900820d1126b06f013296287a5ea62494faac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Tue, 9 May 2023 12:21:47 +0200 Subject: [PATCH 27/77] update changelog with PR ID --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2b533b28..13f1a2537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. ### New Features - Add ContributeAndFinalize to `ReplicateWorkflow`. (#574) -- Add check for ContributeAndFinalize in `ReplicatesService`. +- Add check for ContributeAndFinalize in `ReplicatesService`. (#576) ### Bug Fixes - Prevent race condition on replicate update. (#568) ### Quality From d7bfb9345eccbf8a190ac35955cbe0b415b5d3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Tue, 9 May 2023 13:41:06 +0200 Subject: [PATCH 28/77] fix format --- .../com/iexec/core/chain/IexecHubService.java | 21 ++++++++++--------- .../core/replicate/ReplicatesService.java | 20 ++++++++++-------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/iexec/core/chain/IexecHubService.java b/src/main/java/com/iexec/core/chain/IexecHubService.java index cf63c0a32..83dc9cc59 100644 --- a/src/main/java/com/iexec/core/chain/IexecHubService.java +++ b/src/main/java/com/iexec/core/chain/IexecHubService.java @@ -62,7 +62,7 @@ public IexecHubService(CredentialsService credentialsService, /** * Check if the task is defined onchain and * has the status {@link ChainTaskStatus#UNSET}. - * + * * @param chainDealId * @param taskIndex * @return true if the task is found with the status UNSET, false otherwise. @@ -77,14 +77,15 @@ public boolean isTaskInUnsetStatusOnChain(String chainDealId, int taskIndex) { public boolean isTaskInCompletedStatusOnChain(String chainTaskId) { - Optional oTask = getChainTask(chainTaskId); - return oTask.filter(chainTask -> ChainTaskStatus.COMPLETED.equals(chainTask.getStatus())).isPresent(); + return getChainTask(chainTaskId) + .filter(chainTask -> ChainTaskStatus.COMPLETED == chainTask.getStatus()) + .isPresent(); } /** * Check if a deal's contribution deadline * is still not reached. - * + * * @param chainDealId * @return true if deadline is not reached, false otherwise. */ @@ -97,7 +98,7 @@ public boolean isBeforeContributionDeadline(String chainDealId) { /** * Check if a deal's contribution deadline * is still not reached. - * + * * @param chainDeal * @return true if deadline is not reached, false otherwise. */ @@ -110,13 +111,13 @@ public boolean isBeforeContributionDeadline(ChainDeal chainDeal) { *

Get deal's contribution deadline date. The deadline * is calculated as follow: * start + maxCategoryTime * maxNbOfPeriods. - * + * *

    *
  • start: the start time of the deal. *
  • maxCategoryTime: duration of the deal's category. *
  • nbOfCategoryUnits: number of category units dedicated * for the contribution phase. - * + * * @param chainDeal * @return */ @@ -132,13 +133,13 @@ public Date getChainDealContributionDeadline(ChainDeal chainDeal) { *

    Get deal's final deadline date. The deadline * is calculated as follow: * start + maxCategoryTime * 10. - * + * *

      *
    • start: the start time of the deal. *
    • maxCategoryTime: duration of the deal's category. *
    • 10: number of category units dedicated * for the hole execution. - * + * * @param chainDeal * @return */ @@ -242,7 +243,7 @@ public boolean hasEnoughGas() { private ChainReceipt buildChainReceipt(TransactionReceipt receipt) { return ChainReceipt.builder() .txHash(receipt.getTransactionHash()) - .blockNumber(receipt.getBlockNumber() != null? + .blockNumber(receipt.getBlockNumber() != null ? receipt.getBlockNumber().longValue() : 0) .build(); } diff --git a/src/main/java/com/iexec/core/replicate/ReplicatesService.java b/src/main/java/com/iexec/core/replicate/ReplicatesService.java index 4a181f22a..bb265aa6d 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicatesService.java +++ b/src/main/java/com/iexec/core/replicate/ReplicatesService.java @@ -350,15 +350,16 @@ public Either updateReplicateS * 3) if worker did succeed onChain when CONTRIBUTED/REVEALED. * 4) if worker did upload when RESULT_UPLOADING. */ + /** * This method updates a replicate while caring about thread safety. * A single replicate can then NOT be updated twice at the same time. * This method should be preferred to * {@link ReplicatesService#updateReplicateStatusWithoutThreadSafety(String, String, ReplicateStatusUpdate, UpdateReplicateStatusArgs)}! * - * @param chainTaskId Chain task id of the task whose replicate should be updated. - * @param walletAddress Wallet address of the worker whose replicate should be updated. - * @param statusUpdate Info about the status update - new status, date of update, ... + * @param chainTaskId Chain task id of the task whose replicate should be updated. + * @param walletAddress Wallet address of the worker whose replicate should be updated. + * @param statusUpdate Info about the status update - new status, date of update, ... * @param updateReplicateStatusArgs Optional args used to update the status. * @return Either a {@link ReplicateStatusUpdateError} if the status can't be updated, * or a next action for the worker. @@ -396,9 +397,9 @@ public Either updateReplicateS * This method has to be used with a synchronization mechanism, e.g. * {@link ReplicatesService#updateReplicateStatus(String, String, ReplicateStatus, ReplicateStatusDetails)} * - * @param chainTaskId Chain task id of the task whose replicate should be updated. - * @param walletAddress Wallet address of the worker whose replicate should be updated. - * @param statusUpdate Info about the status update - new status, date of update, ... + * @param chainTaskId Chain task id of the task whose replicate should be updated. + * @param walletAddress Wallet address of the worker whose replicate should be updated. + * @param statusUpdate Info about the status update - new status, date of update, ... * @param updateReplicateStatusArgs Optional args used to update the status. * @return Either a {@link ReplicateStatusUpdateError} if the status can't be updated, * or a next action for the worker. @@ -539,7 +540,8 @@ private boolean verifyStatus(String chainTaskId, case RESULT_UPLOAD_FAILED: return !isResultUploaded(updateReplicateStatusArgs.getTaskDescription()); case CONTRIBUTE_AND_FINALIZE_DONE: - return iexecHubService.repeatIsRevealedTrue(chainTaskId,walletAddress) && iexecHubService.isTaskInCompletedStatusOnChain(chainTaskId); + return iexecHubService.repeatIsRevealedTrue(chainTaskId, walletAddress) + && iexecHubService.isTaskInCompletedStatusOnChain(chainTaskId); default: return true; } @@ -586,7 +588,7 @@ private String getStatusUpdateLogs(String chainTaskId, Replicate replicate, Repl public boolean isResultUploaded(String chainTaskId) { Optional task = iexecHubService.getTaskDescriptionFromChain(chainTaskId); - if (task.isEmpty()){ + if (task.isEmpty()) { return false; } @@ -595,7 +597,7 @@ public boolean isResultUploaded(String chainTaskId) { public boolean isResultUploaded(TaskDescription task) { // Offchain computing - basic & tee - if (task.containsCallback()){ + if (task.containsCallback()) { return true; } From f34adb8b7e0f493e18c286c97ce62e448a3287cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Tue, 9 May 2023 14:55:43 +0200 Subject: [PATCH 29/77] add some tests for iexecHubService and remove unused import --- .../core/chain/IexecHubServiceTests.java | 75 +++++++++++++++++++ .../core/replicate/ReplicateServiceTests.java | 2 - 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/iexec/core/chain/IexecHubServiceTests.java diff --git a/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java new file mode 100644 index 000000000..953c554cb --- /dev/null +++ b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java @@ -0,0 +1,75 @@ +package com.iexec.core.chain; + +import com.iexec.commons.poco.chain.ChainTask; +import com.iexec.commons.poco.chain.ChainTaskStatus; +import com.iexec.commons.poco.contract.generated.IexecHubContract; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.web3j.crypto.Credentials; +import org.web3j.crypto.Keys; +import org.web3j.protocol.core.RemoteFunctionCall; +import org.web3j.tx.TransactionManager; + +import java.math.BigInteger; +import java.util.Optional; + +import static com.iexec.commons.poco.utils.TestUtils.CHAIN_TASK_ID; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +public class IexecHubServiceTests { + + @Mock + private CredentialsService credentialsService; + + @Mock + private Web3jService web3jService; + + @Mock + private ChainConfig chainConfig; + + private IexecHubService iexecHubService; + + @BeforeEach + void init() throws Exception { + MockitoAnnotations.openMocks(this); + + final Credentials credentials = Credentials.create(Keys.createEcKeyPair()); + + when(credentialsService.getCredentials()).thenReturn(credentials); + when(web3jService.hasEnoughGas(any())).thenReturn(true); + when(chainConfig.getHubAddress()).thenReturn("0x748e091bf16048cb5103E0E10F9D5a8b7fBDd860"); + + try (MockedStatic iexecHubContract = Mockito.mockStatic(IexecHubContract.class)) { + final IexecHubContract mockIexecContract = mock(IexecHubContract.class); + final RemoteFunctionCall mockRemoteFunctionCall = mock(RemoteFunctionCall.class); + iexecHubContract.when(() -> IexecHubContract.load(any(), any(), (TransactionManager) any(), any())) + .thenReturn(mockIexecContract); + when(mockIexecContract.contribution_deadline_ratio()).thenReturn(mockRemoteFunctionCall); + when(mockRemoteFunctionCall.send()).thenReturn(BigInteger.ONE); + iexecHubService = spy(new IexecHubService(credentialsService, web3jService, chainConfig)); + } + } + + + @Test + void shouldTaskBeInCompletedStatusOnChain() { + final ChainTask task = ChainTask.builder().status(ChainTaskStatus.COMPLETED).build(); + doReturn(Optional.of(task)).when(iexecHubService).getChainTask(CHAIN_TASK_ID); + + assertThat(iexecHubService.isTaskInCompletedStatusOnChain(CHAIN_TASK_ID)).isTrue(); + } + + @Test + void shouldTaskNotBeInCompletedStatusOnChain() { + final ChainTask task = ChainTask.builder().status(ChainTaskStatus.REVEALING).build(); + doReturn(Optional.of(task)).when(iexecHubService).getChainTask(CHAIN_TASK_ID); + + assertThat(iexecHubService.isTaskInCompletedStatusOnChain(CHAIN_TASK_ID)).isFalse(); + } +} diff --git a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java index 1cd769d56..7fa511104 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java @@ -19,8 +19,6 @@ import com.iexec.common.replicate.*; import com.iexec.commons.poco.chain.ChainContribution; import com.iexec.commons.poco.chain.ChainContributionStatus; -import com.iexec.commons.poco.chain.ChainTask; -import com.iexec.commons.poco.chain.ChainTaskStatus; import com.iexec.commons.poco.notification.TaskNotificationType; import com.iexec.commons.poco.task.TaskDescription; import com.iexec.commons.poco.utils.BytesUtils; From a541f3787699c016c23635195446cee734be91e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Tue, 9 May 2023 14:57:48 +0200 Subject: [PATCH 30/77] remove unused import --- src/main/java/com/iexec/core/chain/IexecHubService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/iexec/core/chain/IexecHubService.java b/src/main/java/com/iexec/core/chain/IexecHubService.java index 83dc9cc59..94b582fc9 100644 --- a/src/main/java/com/iexec/core/chain/IexecHubService.java +++ b/src/main/java/com/iexec/core/chain/IexecHubService.java @@ -33,7 +33,6 @@ import java.util.concurrent.ThreadPoolExecutor; import static com.iexec.common.utils.DateTimeUtils.now; -import static com.iexec.commons.poco.chain.ChainContributionStatus.CONTRIBUTED; import static com.iexec.commons.poco.utils.BytesUtils.stringToBytes; @Slf4j From 92977d733c40baad1b73a85deb09a2366d57d71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Tue, 9 May 2023 15:01:05 +0200 Subject: [PATCH 31/77] Remove public modifier in tests --- src/test/java/com/iexec/core/chain/IexecHubServiceTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java index 953c554cb..f4f92921a 100644 --- a/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java +++ b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java @@ -22,7 +22,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -public class IexecHubServiceTests { +class IexecHubServiceTests { @Mock private CredentialsService credentialsService; From 906b68ee888ff9a8dad421454d0e6898b79200e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Tue, 9 May 2023 16:33:57 +0200 Subject: [PATCH 32/77] Add running2Finalized2Completed in TaskUpdateManager --- CHANGELOG.md | 1 + .../core/task/update/TaskUpdateManager.java | 52 ++++++++++-- .../task/update/TaskUpdateManagerTest.java | 82 +++++++++++++++++++ 3 files changed, 129 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13f1a2537..f8a8394ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### New Features - Add ContributeAndFinalize to `ReplicateWorkflow`. (#574) - Add check for ContributeAndFinalize in `ReplicatesService`. (#576) +- Add `running2Finalized2Completed` in `TaskUpdateManager`. (#577) ### Bug Fixes - Prevent race condition on replicate update. (#568) ### Quality diff --git a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java index 96d57cd7e..5c5f39916 100644 --- a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java +++ b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java @@ -46,7 +46,7 @@ @Service @Slf4j -class TaskUpdateManager { +class TaskUpdateManager { private final TaskService taskService; private final IexecHubService iexecHubService; private final ReplicatesService replicatesService; @@ -82,7 +82,7 @@ void updateTask(String chainTaskId) { boolean isFinalDeadlinePossible = !TaskStatus.getStatusesWhereFinalDeadlineIsImpossible().contains(currentStatus); - if (isFinalDeadlinePossible && new Date().after(task.getFinalDeadline())){ + if (isFinalDeadlinePossible && new Date().after(task.getFinalDeadline())) { updateTaskStatusAndSave(task, FINAL_DEADLINE_REACHED); // Eventually should fire a "final deadline reached" notification to worker, // but here let's just trigger an toFailed(task) leading to a failed status @@ -175,7 +175,7 @@ Task updateTaskStatusAndSave(Task task, TaskStatus newStatus, ChainReceipt chain return savedTask.get(); } else { log.warn("UpdateTaskStatus failed. Chain Task is probably unknown." + - " [chainTaskId:{}, currentStatus:{}, wishedStatus:{}]", + " [chainTaskId:{}, currentStatus:{}, wishedStatus:{}]", task.getChainTaskId(), currentStatus, newStatus); return null; } @@ -204,7 +204,7 @@ void received2Initializing(Task task) { if (task.isTeeTask()) { Optional smsUrl = smsService.getVerifiedSmsUrl(task.getChainTaskId(), task.getTag()); - if(smsUrl.isEmpty()){ + if (smsUrl.isEmpty()) { log.error("Couldn't get verified SMS url [chainTaskId: {}]", task.getChainTaskId()); updateTaskStatusAndSave(task, INITIALIZE_FAILED); updateTaskStatusAndSave(task, FAILED); @@ -241,7 +241,7 @@ void received2Initializing(Task task) { } void initializing2Initialized(Task task) { - if (!INITIALIZING.equals(task.getCurrentStatus())){ + if (!INITIALIZING.equals(task.getCurrentStatus())) { return; } // TODO: the block where initialization happened can be found @@ -262,7 +262,7 @@ void initializing2Initialized(Task task) { updateTaskStatusAndSave(task, INITIALIZE_FAILED); updateTaskStatusAndSave(task, FAILED); }, () -> log.error("Unable to check initialization on blockchain " + - "(likely too long), should use a detector [chainTaskId:{}]", + "(likely too long), should use a detector [chainTaskId:{}]", task.getChainTaskId())); } @@ -326,6 +326,46 @@ void running2ConsensusReached(Task task) { } } + void running2Finalized2Completed(Task task) { + boolean isTaskInRunningStatus = task.getCurrentStatus().equals(RUNNING); + final String chainTaskId = task.getChainTaskId(); + final Optional oReplicatesList = replicatesService.getReplicatesList(chainTaskId); + + if (!isTaskInRunningStatus) { + log.error("Can't transition task to `Finalized` or `Completed` when task is not `Running` " + + " [chainTaskId:{}]", chainTaskId); + return; + } + + if (oReplicatesList.isEmpty()) { + log.error("Can't transition task to `Finalized` or `Completed` when no replicatesList exists" + + " [chainTaskId:{}]", chainTaskId); + return; + } + + if (!task.isTeeTask()) { + log.debug("Task not running in a TEE, flow running2Finalized2Completed is not possible" + + " [chainTaskId:{}]", chainTaskId); + return; + } + final ReplicatesList replicates = oReplicatesList.get(); + final int nbReplicatesWithContributeAndFinalizeStatus = replicates.getNbReplicatesWithCurrentStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE); + + if (nbReplicatesWithContributeAndFinalizeStatus == 0) { + log.debug("No replicate in ContributeAndFinalize status" + + " [chainTaskId:{}]", chainTaskId); + return; + } else if (nbReplicatesWithContributeAndFinalizeStatus > 1) { + log.error("Too many replicates in ContributeAndFinalize status" + + " [chainTaskId:{}, nbReplicates:{}]", chainTaskId, nbReplicatesWithContributeAndFinalizeStatus); + toFailed(task); + return; + } + + updateTaskStatusAndSave(task, FINALIZED); + finalizedToCompleted(task); + } + void initializedOrRunning2ContributionTimeout(Task task) { boolean isInitializedOrRunningTask = task.getCurrentStatus().equals(INITIALIZED) || task.getCurrentStatus().equals(RUNNING); diff --git a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java index 055570d0d..dd53ae3b4 100644 --- a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java +++ b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java @@ -682,6 +682,88 @@ void shouldUpdateFromInitializedOrRunning2ContributionTimeout() { assertThat(task.getLastButOneStatus()).isEqualTo(CONTRIBUTION_TIMEOUT); } + // Tests on running2Finalized2Completed transition + + @Test + void shouldUpdateRunning2Finalized2Completed() { + Task task = getStubTask(maxExecutionTime); + task.changeStatus(RUNNING); + task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); + + final ReplicatesList replicatesList = Mockito.spy(new ReplicatesList(CHAIN_TASK_ID)); + + when(replicatesService.getReplicatesList(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + when(replicatesList.getNbReplicatesWithCurrentStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE)).thenReturn(1); + when(taskService.updateTask(task)).thenReturn(Optional.of(task)); + doNothing().when(applicationEventPublisher).publishEvent(any()); + + taskUpdateManager.running2Finalized2Completed(task); + assertThat(task.getLastButOneStatus()).isEqualTo(FINALIZED); + assertThat(task.getCurrentStatus()).isEqualTo(COMPLETED); + } + + @Test + void shouldNotUpdateRunning2Finalized2CompletedWhenTaskNotRunning() { + Task task = getStubTask(maxExecutionTime); + task.changeStatus(INITIALIZED); + + taskUpdateManager.running2Finalized2Completed(task); + assertThat(task.getCurrentStatus()).isEqualTo(INITIALIZED); + } + + @Test + void shouldNotUpdateRunning2Finalized2CompletedWhenNoReplicates() { + Task task = getStubTask(maxExecutionTime); + task.changeStatus(RUNNING); + + when(replicatesService.getReplicatesList(CHAIN_TASK_ID)).thenReturn(Optional.empty()); + + taskUpdateManager.running2Finalized2Completed(task); + assertThat(task.getCurrentStatus()).isEqualTo(RUNNING); + } + + @Test + void shouldNotUpdateRunning2Finalized2CompletedWhenTaskIsNotTee() { + Task task = getStubTask(maxExecutionTime); + task.changeStatus(RUNNING); + task.setTag(NO_TEE_TAG); + final ReplicatesList replicatesList = Mockito.spy(new ReplicatesList(CHAIN_TASK_ID)); + + when(replicatesService.getReplicatesList(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + taskUpdateManager.running2Finalized2Completed(task); + assertThat(task.getCurrentStatus()).isEqualTo(RUNNING); + } + + @Test + void shouldNotUpdateRunning2Finalized2CompletedWhenNoReplicatesOnContributeAndFinalizeStatus() { + Task task = getStubTask(maxExecutionTime); + task.changeStatus(RUNNING); + task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); + + final ReplicatesList replicatesList = Mockito.spy(new ReplicatesList(CHAIN_TASK_ID)); + + when(replicatesService.getReplicatesList(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + when(replicatesList.getNbReplicatesWithCurrentStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE)).thenReturn(0); + + taskUpdateManager.running2Finalized2Completed(task); + assertThat(task.getCurrentStatus()).isEqualTo(RUNNING); + } + + @Test + void shouldNotUpdateRunning2Finalized2CompletedWhenMoreThanOneReplicatesOnContributeAndFinalizeStatus() { + Task task = getStubTask(maxExecutionTime); + task.changeStatus(RUNNING); + task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); + + final ReplicatesList replicatesList = Mockito.spy(new ReplicatesList(CHAIN_TASK_ID)); + + when(replicatesService.getReplicatesList(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + when(replicatesList.getNbReplicatesWithCurrentStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE)).thenReturn(2); + doNothing().when(applicationEventPublisher).publishEvent(any()); + + taskUpdateManager.running2Finalized2Completed(task); + assertThat(task.getCurrentStatus()).isEqualTo(FAILED); + } // Tests on running2ConsensusReached transition From fd3471e02910d42af5d114d33c5104953362c13d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Wed, 10 May 2023 15:44:22 +0200 Subject: [PATCH 33/77] Enable running2Finalized2Completed in TaskUpdateManager --- CHANGELOG.md | 2 +- .../replicate/ReplicateStatusUpdateError.java | 1 + .../core/replicate/ReplicatesController.java | 1 + .../core/replicate/ReplicatesService.java | 9 ++- .../core/task/update/TaskUpdateManager.java | 1 + .../core/workflow/ReplicateWorkflow.java | 54 +++++++++++------- .../replicate/ReplicateControllerTests.java | 14 ++++- .../core/replicate/ReplicateServiceTests.java | 44 ++++++++++++++ .../task/update/TaskUpdateManagerTest.java | 22 ++++++- .../core/workflow/ReplicateWorkflowTests.java | 57 ++++++++++++++++--- 10 files changed, 171 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8a8394ab..f382c0920 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ All notable changes to this project will be documented in this file. ### New Features - Add ContributeAndFinalize to `ReplicateWorkflow`. (#574) - Add check for ContributeAndFinalize in `ReplicatesService`. (#576) -- Add `running2Finalized2Completed` in `TaskUpdateManager`. (#577) +- Add `running2Finalized2Completed` in `TaskUpdateManager`. (#577 #578) ### Bug Fixes - Prevent race condition on replicate update. (#568) ### Quality diff --git a/src/main/java/com/iexec/core/replicate/ReplicateStatusUpdateError.java b/src/main/java/com/iexec/core/replicate/ReplicateStatusUpdateError.java index c5409b42a..4723dd39a 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicateStatusUpdateError.java +++ b/src/main/java/com/iexec/core/replicate/ReplicateStatusUpdateError.java @@ -18,6 +18,7 @@ public enum ReplicateStatusUpdateError { UNKNOWN_REPLICATE, + UNKNOWN_TASK, BAD_WORKFLOW_TRANSITION, ALREADY_REPORTED, GENERIC_CANT_UPDATE, diff --git a/src/main/java/com/iexec/core/replicate/ReplicatesController.java b/src/main/java/com/iexec/core/replicate/ReplicatesController.java index 57ed54b72..37c0dc81c 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicatesController.java +++ b/src/main/java/com/iexec/core/replicate/ReplicatesController.java @@ -146,6 +146,7 @@ public ResponseEntity updateReplicateStatus( " [chainTaskId:{}, statusUpdate:{}]", chainTaskId, statusUpdate); return ResponseEntity.internalServerError().build(); case UNKNOWN_REPLICATE: + case UNKNOWN_TASK: case BAD_WORKFLOW_TRANSITION: case GENERIC_CANT_UPDATE: default: diff --git a/src/main/java/com/iexec/core/replicate/ReplicatesService.java b/src/main/java/com/iexec/core/replicate/ReplicatesService.java index bb265aa6d..d7ae66cb0 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicatesService.java +++ b/src/main/java/com/iexec/core/replicate/ReplicatesService.java @@ -196,6 +196,12 @@ public ReplicateStatusUpdateError canUpdateReplicateStatus(String chainTaskId, return ReplicateStatusUpdateError.BAD_WORKFLOW_TRANSITION; } + if (newStatus == COMPUTED && updateReplicateStatusArgs.getTaskDescription() == null) { + log.warn("TaskDescription is null with a COMPUTED status, this case shouldn't happen {}", + getStatusUpdateLogs(chainTaskId, replicate, statusUpdate)); + return ReplicateStatusUpdateError.UNKNOWN_TASK; + } + boolean canUpdate = true; switch (newStatus) { @@ -253,6 +259,7 @@ public UpdateReplicateStatusArgs computeUpdateReplicateStatusArgs(String chainTa } taskDescription = iexecHubService.getTaskDescriptionFromChain(chainTaskId).orElse(null); break; + case COMPUTED: case RESULT_UPLOAD_FAILED: taskDescription = iexecHubService.getTaskDescriptionFromChain(chainTaskId).orElse(null); break; @@ -445,7 +452,7 @@ Either updateReplicateStatusWi applicationEventPublisher.publishEvent(new ReplicateUpdatedEvent(chainTaskId, walletAddress, statusUpdate)); ReplicateStatusCause newStatusCause = statusUpdate.getDetails() != null ? statusUpdate.getDetails().getCause() : null; - TaskNotificationType nextAction = ReplicateWorkflow.getInstance().getNextAction(newStatus, newStatusCause); + TaskNotificationType nextAction = ReplicateWorkflow.getInstance().getNextAction(newStatus, newStatusCause, updateReplicateStatusArgs.getTaskDescription()); log.info("Replicate updated successfully [newStatus:{}, newStatusCause:{} " + "nextAction:{}, chainTaskId:{}, walletAddress:{}]", diff --git a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java index 5c5f39916..c447a4c4a 100644 --- a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java +++ b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java @@ -106,6 +106,7 @@ void updateTask(String chainTaskId) { toFailed(task); break; case RUNNING: + running2Finalized2Completed(task); // running2Finalized2Completed must be the first call to prevent other transition execution running2ConsensusReached(task); running2RunningFailed(task); initializedOrRunning2ContributionTimeout(task); diff --git a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java index cede1d1b1..5e105c700 100644 --- a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java +++ b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java @@ -19,6 +19,8 @@ import com.iexec.common.replicate.ReplicateStatus; import com.iexec.common.replicate.ReplicateStatusCause; import com.iexec.commons.poco.notification.TaskNotificationType; +import com.iexec.commons.poco.task.TaskDescription; +import lombok.extern.slf4j.Slf4j; import java.util.Arrays; import java.util.LinkedHashMap; @@ -28,7 +30,7 @@ import static com.iexec.common.replicate.ReplicateStatus.*; import static com.iexec.commons.poco.notification.TaskNotificationType.*; - +@Slf4j public class ReplicateWorkflow extends Workflow { private static ReplicateWorkflow instance; @@ -64,14 +66,14 @@ private void setWorkflowTransitions() { private void setDefaultWorkflowTransitions() { // start - addTransition(CREATED, toList(STARTING)); - addTransition(STARTING, toList(STARTED, START_FAILED)); - addTransition(STARTED, toList(APP_DOWNLOADING)); + addTransition(CREATED, toList(STARTING)); + addTransition(STARTING, toList(STARTED, START_FAILED)); + addTransition(STARTED, toList(APP_DOWNLOADING)); // app - addTransition(APP_DOWNLOADING, toList(APP_DOWNLOADED, APP_DOWNLOAD_FAILED)); - addTransition(APP_DOWNLOAD_FAILED, toList(CONTRIBUTING)); - addTransition(APP_DOWNLOADED, toList(DATA_DOWNLOADING)); + addTransition(APP_DOWNLOADING, toList(APP_DOWNLOADED, APP_DOWNLOAD_FAILED)); + addTransition(APP_DOWNLOAD_FAILED, toList(CONTRIBUTING)); + addTransition(APP_DOWNLOADED, toList(DATA_DOWNLOADING)); // data addTransition(DATA_DOWNLOADING, toList(DATA_DOWNLOADED, DATA_DOWNLOAD_FAILED)); @@ -121,7 +123,7 @@ private void addTransitionsToFailed() { * - Default* --- --- Default * - RECOVERING ---|-- WORKER_LOST --|--- RECOVERING * - ABORTED --- --- ABORTED - * + * * (*) except COMPLETED and FAILED */ private void addWorkerLostTransitions() { @@ -138,7 +140,7 @@ private void addWorkerLostTransitions() { } /* - * - Recoverable --- All statuses + * - Recoverable --- All statuses * |-- RECOVERING --| except CREATED, * - WORKER_LOST --- STARTING */ @@ -158,7 +160,7 @@ private void addRecoveringTransitions() { * Default* --- --- COMPLETED * |--- ABORTED ---| * WORKER_LOST --- --- FAILED - * + * * (*) except COMPLETED and FAILED */ private void addAbortedTransitions() { @@ -175,31 +177,43 @@ private void setNextAction(ReplicateStatus whenStatus, TaskNotificationType next actionMap.putIfAbsent(whenStatus, nextAction); } - public TaskNotificationType getNextAction(ReplicateStatus whenStatus, ReplicateStatusCause whenCause) { - TaskNotificationType nextAction = getNextActionWhenStatusAndCause(whenStatus, whenCause); - if (nextAction == null){ + public TaskNotificationType getNextAction(ReplicateStatus whenStatus, ReplicateStatusCause whenCause, TaskDescription taskDescription) { + TaskNotificationType nextAction = getNextActionWhenStatusAndCause(whenStatus, whenCause, taskDescription); + if (nextAction == null) { nextAction = getNextActionWhenStatus(whenStatus); } return nextAction; } - TaskNotificationType getNextActionWhenStatusAndCause(ReplicateStatus whenStatus, ReplicateStatusCause whenCause) { - if (whenStatus == null){ + TaskNotificationType getNextActionWhenStatusAndCause(ReplicateStatus whenStatus, ReplicateStatusCause whenCause, TaskDescription taskDescription) { + if (whenStatus == null) { return null; } - if (whenCause == null){ + + if (whenStatus == COMPUTED) { + + if (null == taskDescription) { + log.error("TaskDescription is null with a COMPUTED status, this case shouldn't happen"); + return PLEASE_ABORT; + } + if (taskDescription.isTeeTask()) { + return PLEASE_CONTRIBUTE_AND_FINALIZE; + } + } + + if (whenCause == null) { return null; } - switch (whenStatus){ + switch (whenStatus) { case APP_DOWNLOAD_FAILED: - if (whenCause.equals(ReplicateStatusCause.APP_IMAGE_DOWNLOAD_FAILED)){ + if (whenCause.equals(ReplicateStatusCause.APP_IMAGE_DOWNLOAD_FAILED)) { return PLEASE_CONTRIBUTE; } return PLEASE_ABORT; case DATA_DOWNLOAD_FAILED: if (whenCause.equals(ReplicateStatusCause.DATASET_FILE_DOWNLOAD_FAILED) || whenCause.equals(ReplicateStatusCause.DATASET_FILE_BAD_CHECKSUM) - || whenCause.equals(ReplicateStatusCause.INPUT_FILES_DOWNLOAD_FAILED)){ + || whenCause.equals(ReplicateStatusCause.INPUT_FILES_DOWNLOAD_FAILED)) { return PLEASE_CONTRIBUTE; } return PLEASE_ABORT; @@ -209,7 +223,7 @@ TaskNotificationType getNextActionWhenStatusAndCause(ReplicateStatus whenStatus, } TaskNotificationType getNextActionWhenStatus(ReplicateStatus whenStatus) { - if (actionMap.containsKey(whenStatus)){ + if (actionMap.containsKey(whenStatus)) { return actionMap.get(whenStatus); } return null; diff --git a/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java b/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java index bc7a4860a..9121fe58d 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateControllerTests.java @@ -25,6 +25,8 @@ import io.vavr.control.Either; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -244,14 +246,20 @@ void shouldNotUpdateReplicateSinceUnauthorized() { assertThat(response.getBody()).isNull(); } - @Test - void shouldReturnPleaseAbortSinceCantUpdate() { + @ParameterizedTest + @EnumSource(value = ReplicateStatusUpdateError.class, names = { + "UNKNOWN_REPLICATE", + "UNKNOWN_TASK", + "BAD_WORKFLOW_TRANSITION", + "GENERIC_CANT_UPDATE" + }) + void shouldReturnPleaseAbortSinceCantUpdate(ReplicateStatusUpdateError error) { when(jwtTokenProvider.getWalletAddressFromBearerToken(TOKEN)) .thenReturn(WALLET_ADDRESS); when(replicatesService.computeUpdateReplicateStatusArgs(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE)) .thenReturn(UPDATE_ARGS); when(replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_ADDRESS, UPDATE, UPDATE_ARGS)) - .thenReturn(Either.left(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE)); + .thenReturn(Either.left(error)); ResponseEntity response = replicatesController.updateReplicateStatus(TOKEN, CHAIN_TASK_ID, UPDATE); diff --git a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java index 7fa511104..e53dd35a4 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java @@ -441,6 +441,8 @@ void shouldUpdateReplicateStatusWithStdoutIfComputed(){ ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(ReplicateUpdatedEvent.class); when(replicatesRepository.findByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); when(replicatesRepository.save(replicatesList)).thenReturn(replicatesList); + when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)) + .thenReturn(Optional.of(TaskDescription.builder().isTeeTask(true).build())); replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate); Mockito.verify(applicationEventPublisher, Mockito.times(1)) @@ -1332,6 +1334,48 @@ void shouldNotAuthorizeUpdateOnContributeAndFinalizeDoneWhenTaskNotCompleted() { .isEqualTo(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE); } + @Test + void shouldNotAuthorizeUpdateOnComputedWhenTaskDescriptionIsNull() { + final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); + replicate.updateStatus(COMPUTING, ReplicateStatusModifier.WORKER); + + final ReplicatesList replicatesList = new ReplicatesList(CHAIN_TASK_ID, Collections.singletonList(replicate)); + final ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder() + .modifier(WORKER) + .status(COMPUTED) + .build(); + final UpdateReplicateStatusArgs updateArgs = UpdateReplicateStatusArgs + .builder() + .build(); + + when(replicatesRepository.findByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + + assertThat(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate, updateArgs)) + .isEqualTo(ReplicateStatusUpdateError.UNKNOWN_TASK); + } + + + @Test + void shouldAuthorizeUpdateOnComputedWhenTaskDescriptionIsFilled() { + final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); + replicate.updateStatus(COMPUTING, ReplicateStatusModifier.WORKER); + + final ReplicatesList replicatesList = new ReplicatesList(CHAIN_TASK_ID, Collections.singletonList(replicate)); + final ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder() + .modifier(WORKER) + .status(COMPUTED) + .build(); + final UpdateReplicateStatusArgs updateArgs = UpdateReplicateStatusArgs + .builder() + .taskDescription(TaskDescription.builder().build()) + .build(); + + when(replicatesRepository.findByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + + assertThat(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate, updateArgs)) + .isEqualTo(ReplicateStatusUpdateError.NO_ERROR); + } + // computeUpdateReplicateStatusArgs @Test diff --git a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java index dd53ae3b4..f4226e9bd 100644 --- a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java +++ b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java @@ -685,7 +685,7 @@ void shouldUpdateFromInitializedOrRunning2ContributionTimeout() { // Tests on running2Finalized2Completed transition @Test - void shouldUpdateRunning2Finalized2Completed() { + void shouldUpdateRunning2Finalized2Completed_deprec() { Task task = getStubTask(maxExecutionTime); task.changeStatus(RUNNING); task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); @@ -1711,6 +1711,26 @@ void shouldNotUpdateFromResultUploadedToFinalizingSinceNotEnoughGas() { assertThat(task.getCurrentStatus()).isEqualTo(RESULT_UPLOADED); } + @Test + void shouldUpdateTaskRunning2Finalized2Completed() { + Task task = getStubTask(maxExecutionTime); + task.changeStatus(RUNNING); + task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); + + final ReplicatesList replicatesList = Mockito.spy(new ReplicatesList(CHAIN_TASK_ID)); + + when(replicatesService.getReplicatesList(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + when(replicatesList.getNbReplicatesWithCurrentStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE)).thenReturn(1); + when(taskService.updateTask(task)).thenReturn(Optional.of(task)); + doNothing().when(applicationEventPublisher).publishEvent(any()); + + when(taskService.getTaskByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(task)); + + taskUpdateManager.updateTask(CHAIN_TASK_ID); + assertThat(task.getCurrentStatus()).isEqualTo(COMPLETED); + assertThat(task.getDateStatusList().get(task.getDateStatusList().size() - 2).getStatus()).isEqualTo(FINALIZED); + assertThat(task.getDateStatusList().get(task.getDateStatusList().size() - 3).getStatus()).isEqualTo(RUNNING); + } @Test void shouldUpdateFromAnyInProgressStatus2FinalDeadlineReached() { diff --git a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java index 2c150e7db..89f98263e 100644 --- a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java +++ b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java @@ -19,6 +19,7 @@ import com.iexec.common.replicate.ReplicateStatus; import com.iexec.common.replicate.ReplicateStatusCause; import com.iexec.commons.poco.notification.TaskNotificationType; +import com.iexec.commons.poco.task.TaskDescription; import org.junit.Rule; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -67,7 +68,8 @@ void shouldNotGetNextActionWhenStatusSinceStatusIsUnknown(){ void shouldNotGetNextActionWhenStatusAndCauseSinceCauseIsNull(){ assertThat(replicateWorkflow .getNextActionWhenStatusAndCause(null, - ReplicateStatusCause.INPUT_FILES_DOWNLOAD_FAILED)) //any + ReplicateStatusCause.INPUT_FILES_DOWNLOAD_FAILED, + null)) //any .isNull(); } @@ -75,7 +77,8 @@ void shouldNotGetNextActionWhenStatusAndCauseSinceCauseIsNull(){ void shouldNotGetNextActionWhenStatusAndCauseSinceStatusIsUnknown(){ assertThat(replicateWorkflow .getNextActionWhenStatusAndCause(ReplicateStatus.ABORTED, //unknown - ReplicateStatusCause.ABORTED_BY_WORKER)) //any + ReplicateStatusCause.ABORTED_BY_WORKER, + null)) //any .isNull(); } @@ -85,6 +88,7 @@ void shouldNotGetNextActionWhenStatusAndCauseSinceStatusIsUnknown(){ void shouldGetNextActionOnAppDownloadFailed(){ assertThat(replicateWorkflow .getNextAction(ReplicateStatus.APP_DOWNLOAD_FAILED, + null, null)) .isEqualTo(PLEASE_ABORT); } @@ -93,7 +97,8 @@ void shouldGetNextActionOnAppDownloadFailed(){ void shouldGetNextActionOnAppDownloadFailedWithPostComputeFailed(){ assertThat(replicateWorkflow .getNextAction(ReplicateStatus.APP_DOWNLOAD_FAILED, - ReplicateStatusCause.POST_COMPUTE_FAILED_UNKNOWN_ISSUE)) + ReplicateStatusCause.POST_COMPUTE_FAILED_UNKNOWN_ISSUE, + null)) .isEqualTo(PLEASE_ABORT); } @@ -101,7 +106,8 @@ void shouldGetNextActionOnAppDownloadFailedWithPostComputeFailed(){ void shouldGetNextActionOnAppDownloadFailedWithAppImageDownloadFailed(){ assertThat(replicateWorkflow .getNextAction(ReplicateStatus.APP_DOWNLOAD_FAILED, - ReplicateStatusCause.APP_IMAGE_DOWNLOAD_FAILED)) + ReplicateStatusCause.APP_IMAGE_DOWNLOAD_FAILED, + null)) .isEqualTo(TaskNotificationType.PLEASE_CONTRIBUTE); } @@ -111,6 +117,7 @@ void shouldGetNextActionOnAppDownloadFailedWithAppImageDownloadFailed(){ void shouldGetNextActionOnDataDownloadFailed(){ assertThat(replicateWorkflow .getNextAction(ReplicateStatus.DATA_DOWNLOAD_FAILED, + null, null)) .isEqualTo(PLEASE_ABORT); } @@ -119,7 +126,8 @@ void shouldGetNextActionOnDataDownloadFailed(){ void shouldGetNextActionOnDataDownloadFailedWithPostComputeFailed(){ assertThat(replicateWorkflow .getNextAction(ReplicateStatus.DATA_DOWNLOAD_FAILED, - ReplicateStatusCause.POST_COMPUTE_FAILED_UNKNOWN_ISSUE)) + ReplicateStatusCause.POST_COMPUTE_FAILED_UNKNOWN_ISSUE, + null)) .isEqualTo(PLEASE_ABORT); } @@ -127,7 +135,8 @@ void shouldGetNextActionOnDataDownloadFailedWithPostComputeFailed(){ void shouldGetNextActionOnDataDownloadFailedWithDatasetDownloadFailed(){ assertThat(replicateWorkflow .getNextAction(ReplicateStatus.DATA_DOWNLOAD_FAILED, - ReplicateStatusCause.DATASET_FILE_DOWNLOAD_FAILED)) + ReplicateStatusCause.DATASET_FILE_DOWNLOAD_FAILED, + null)) .isEqualTo(TaskNotificationType.PLEASE_CONTRIBUTE); } @@ -135,7 +144,8 @@ void shouldGetNextActionOnDataDownloadFailedWithDatasetDownloadFailed(){ void shouldGetNextActionOnDataDownloadFailedWithDatasetBadChecksum(){ assertThat(replicateWorkflow .getNextAction(ReplicateStatus.DATA_DOWNLOAD_FAILED, - ReplicateStatusCause.DATASET_FILE_BAD_CHECKSUM)) + ReplicateStatusCause.DATASET_FILE_BAD_CHECKSUM, + null)) .isEqualTo(TaskNotificationType.PLEASE_CONTRIBUTE); } @@ -143,10 +153,41 @@ void shouldGetNextActionOnDataDownloadFailedWithDatasetBadChecksum(){ void shouldGetNextActionOnDataDownloadFailedWithInputFilesDownloadFailed(){ assertThat(replicateWorkflow .getNextAction(ReplicateStatus.DATA_DOWNLOAD_FAILED, - ReplicateStatusCause.INPUT_FILES_DOWNLOAD_FAILED)) + ReplicateStatusCause.INPUT_FILES_DOWNLOAD_FAILED, + null)) .isEqualTo(TaskNotificationType.PLEASE_CONTRIBUTE); } + // region computed + + @Test + void shouldGetNextActionOnComputedWithTeeTaskShouldBePleaseContributeAndFinalize(){ + assertThat(replicateWorkflow + .getNextAction(COMPUTED, + null, + TaskDescription.builder().isTeeTask(true).build())) + .isEqualTo(PLEASE_CONTRIBUTE_AND_FINALIZE); + } + + @Test + void shouldGetNextActionOnComputedWithStandardTaskShouldBePleaseContribute(){ + assertThat(replicateWorkflow + .getNextAction(COMPUTED, + null, + TaskDescription.builder().isTeeTask(false).build())) + .isEqualTo(PLEASE_CONTRIBUTE); + } + + @Test + void shouldGetNextActionOnComputedWithoutTaskDescriptionShouldBePleaseAbort(){ + assertThat(replicateWorkflow + .getNextAction(COMPUTED, + null, + null)) + .isEqualTo(PLEASE_ABORT); + } + + // endregion /* * This updates the json files when transitions From 94622de295971d21dea67b5f356a2cfae038fcec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Wed, 10 May 2023 15:57:08 +0200 Subject: [PATCH 34/77] Fix format and remove useless test --- .../iexec/core/workflow/ReplicateWorkflow.java | 1 - .../task/update/TaskUpdateManagerTest.java | 18 ------------------ 2 files changed, 19 deletions(-) diff --git a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java index 5e105c700..60f955ef6 100644 --- a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java +++ b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java @@ -191,7 +191,6 @@ TaskNotificationType getNextActionWhenStatusAndCause(ReplicateStatus whenStatus, } if (whenStatus == COMPUTED) { - if (null == taskDescription) { log.error("TaskDescription is null with a COMPUTED status, this case shouldn't happen"); return PLEASE_ABORT; diff --git a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java index f4226e9bd..8aef17a45 100644 --- a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java +++ b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java @@ -684,24 +684,6 @@ void shouldUpdateFromInitializedOrRunning2ContributionTimeout() { // Tests on running2Finalized2Completed transition - @Test - void shouldUpdateRunning2Finalized2Completed_deprec() { - Task task = getStubTask(maxExecutionTime); - task.changeStatus(RUNNING); - task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); - - final ReplicatesList replicatesList = Mockito.spy(new ReplicatesList(CHAIN_TASK_ID)); - - when(replicatesService.getReplicatesList(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); - when(replicatesList.getNbReplicatesWithCurrentStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE)).thenReturn(1); - when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - doNothing().when(applicationEventPublisher).publishEvent(any()); - - taskUpdateManager.running2Finalized2Completed(task); - assertThat(task.getLastButOneStatus()).isEqualTo(FINALIZED); - assertThat(task.getCurrentStatus()).isEqualTo(COMPLETED); - } - @Test void shouldNotUpdateRunning2Finalized2CompletedWhenTaskNotRunning() { Task task = getStubTask(maxExecutionTime); From 2983ff52879e86b2d7f346ed1c8e869977dbdc75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Fri, 12 May 2023 15:18:59 +0200 Subject: [PATCH 35/77] disable contribute and finalize when callback is filled --- .../java/com/iexec/core/workflow/ReplicateWorkflow.java | 4 +++- .../com/iexec/core/workflow/ReplicateWorkflowTests.java | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java index 60f955ef6..ca0ac07fb 100644 --- a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java +++ b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java @@ -21,6 +21,7 @@ import com.iexec.commons.poco.notification.TaskNotificationType; import com.iexec.commons.poco.task.TaskDescription; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import java.util.Arrays; import java.util.LinkedHashMap; @@ -195,7 +196,8 @@ TaskNotificationType getNextActionWhenStatusAndCause(ReplicateStatus whenStatus, log.error("TaskDescription is null with a COMPUTED status, this case shouldn't happen"); return PLEASE_ABORT; } - if (taskDescription.isTeeTask()) { + // We must check CallBack is empty because there is an issue in poco (transaction is revert) + if (taskDescription.isTeeTask() && StringUtils.isEmpty(taskDescription.getCallback())) { return PLEASE_CONTRIBUTE_AND_FINALIZE; } } diff --git a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java index 89f98263e..d311063cb 100644 --- a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java +++ b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java @@ -187,6 +187,15 @@ void shouldGetNextActionOnComputedWithoutTaskDescriptionShouldBePleaseAbort(){ .isEqualTo(PLEASE_ABORT); } + @Test + void shouldGetNextActionOnComputedWithTeeTaskAndCallBackShouldBePlease(){ + assertThat(replicateWorkflow + .getNextAction(COMPUTED, + null, + TaskDescription.builder().isTeeTask(true).callback("callback").build())) + .isEqualTo(PLEASE_CONTRIBUTE); + } + // endregion /* From e624e2ae09939bcaca6189ce2054196ef03c1410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Fri, 12 May 2023 16:09:39 +0200 Subject: [PATCH 36/77] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f382c0920..e5210e618 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - Add ContributeAndFinalize to `ReplicateWorkflow`. (#574) - Add check for ContributeAndFinalize in `ReplicatesService`. (#576) - Add `running2Finalized2Completed` in `TaskUpdateManager`. (#577 #578) +- Disable `contributeAndFinalize` with CallBack. (#579) ### Bug Fixes - Prevent race condition on replicate update. (#568) ### Quality From f6d30f11d575c000aaf04e722206bbf96e6a185f Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Fri, 12 May 2023 09:42:43 +0200 Subject: [PATCH 37/77] Refactor unnotified detectors --- CHANGELOG.md | 1 + .../ContributionUnnotifiedDetector.java | 75 ++----------- .../replicate/RevealUnnotifiedDetector.java | 71 ++---------- .../replicate/UnnotifiedAbstractDetector.java | 105 ++++++++++++------ .../task/listener/ReplicateListeners.java | 2 +- .../ContributionUnnotifiedDetectorTests.java | 12 +- .../RevealUnnotifiedDetectorTests.java | 12 +- .../replicate/ReplicateListenersTests.java | 9 +- 8 files changed, 112 insertions(+), 175 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5210e618..73de6f092 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. - Remove unused methods in `IexecHubService`. (#572) - Clean unused Replicate methods and update tests. (#573) - Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#575) +- Refactor unnotified detectors to avoid code duplication. (#580) ### Dependency Upgrades - Upgrade to `iexec-common` 8.0.0-NEXT-SNAPSHOT. (#571 #575) - Add new `iexec-commons-poco` 1.0.2-NEXT-SNAPSHOT dependency. (#571 #574) diff --git a/src/main/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetector.java b/src/main/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetector.java index af2731af6..19c0f9884 100644 --- a/src/main/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetector.java @@ -19,7 +19,6 @@ import com.iexec.common.replicate.ReplicateStatus; import com.iexec.commons.poco.chain.ChainContributionStatus; import com.iexec.core.chain.IexecHubService; -import com.iexec.core.chain.Web3jService; import com.iexec.core.configuration.CronConfiguration; import com.iexec.core.replicate.ReplicatesService; import com.iexec.core.task.TaskService; @@ -28,80 +27,28 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import java.util.List; - @Slf4j @Service public class ContributionUnnotifiedDetector extends UnnotifiedAbstractDetector { - private static final int LESS_OFTEN_DETECTOR_FREQUENCY = 10; - private final List dectectWhenOffchainTaskStatuses; - private final ReplicateStatus offchainCompleting; - private final ReplicateStatus offchainCompleted; - private final ChainContributionStatus onchainCompleted; - private final int detectorRate; - - private int detectorOccurrence; - public ContributionUnnotifiedDetector(TaskService taskService, ReplicatesService replicatesService, IexecHubService iexecHubService, - Web3jService web3jService, CronConfiguration cronConfiguration) { - super(taskService, replicatesService, iexecHubService, web3jService); - dectectWhenOffchainTaskStatuses = TaskStatus.getWaitingContributionStatuses(); - offchainCompleting = ReplicateStatus.CONTRIBUTING; - offchainCompleted = ReplicateStatus.CONTRIBUTED; - onchainCompleted = ChainContributionStatus.CONTRIBUTED; - this.detectorRate = cronConfiguration.getContribute(); + super( + taskService, + replicatesService, + iexecHubService, + TaskStatus.getWaitingContributionStatuses(), + ReplicateStatus.CONTRIBUTING, + ReplicateStatus.CONTRIBUTED, + ChainContributionStatus.CONTRIBUTED, + cronConfiguration.getContribute()); } - /** - * Detects onchain CONTRIBUTED only if replicates are offchain CONTRIBUTING and - * onchain CONTRIBUTED if replicates are not CONTRIBUTED. - * The second detection is not always ran, depending on the detector run occurrences. - */ + @Override @Scheduled(fixedRateString = "#{@cronConfiguration.getContribute()}") public void detectOnChainChanges() { - detectOnchainContributedWhenOffchainContributing(); - - detectorOccurrence++; - if (detectorOccurrence % LESS_OFTEN_DETECTOR_FREQUENCY == 0) { - detectOnchainContributed(); - } + super.detectOnChainChanges(); } - - /* - * Detecting onchain CONTRIBUTED only if replicates are offchain CONTRIBUTING - * (worker didn't notify last offchain CONTRIBUTED) - * We want to detect them very often since it's highly probable - */ - public void detectOnchainContributedWhenOffchainContributing() { - log.debug("Detect onchain Contributed (when offchain Contributing) [retryIn:{}]", - this.detectorRate); - dectectOnchainCompletedWhenOffchainCompleting( - dectectWhenOffchainTaskStatuses, - offchainCompleting, - offchainCompleted, - onchainCompleted - ); - } - - /* - * Detecting onchain CONTRIBUTED if replicates are not CONTRIBUTED - * (worker didn't notify any status) - * We want to detect them: - * - Frequently but no so often since it's eth node resource consuming and less probable - * - When we receive a CANT_CONTRIBUTE_SINCE_TASK_NOT_ACTIVE - */ - public void detectOnchainContributed() { - log.debug("Detect onchain Contributed [retryIn:{}]", this.detectorRate * LESS_OFTEN_DETECTOR_FREQUENCY); - dectectOnchainCompleted( - dectectWhenOffchainTaskStatuses, - offchainCompleting, - offchainCompleted, - onchainCompleted - ); - } - } diff --git a/src/main/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetector.java b/src/main/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetector.java index 82743f8ab..cfd8cc3bd 100644 --- a/src/main/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetector.java @@ -19,7 +19,6 @@ import com.iexec.common.replicate.ReplicateStatus; import com.iexec.commons.poco.chain.ChainContributionStatus; import com.iexec.core.chain.IexecHubService; -import com.iexec.core.chain.Web3jService; import com.iexec.core.configuration.CronConfiguration; import com.iexec.core.replicate.ReplicatesService; import com.iexec.core.task.TaskService; @@ -28,76 +27,28 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import java.util.List; - @Slf4j @Service public class RevealUnnotifiedDetector extends UnnotifiedAbstractDetector { - private static final int LESS_OFTEN_DETECTOR_FREQUENCY = 10; - private final List dectectWhenTaskStatuses; - private final ReplicateStatus offchainCompleting; - private final ReplicateStatus offchainCompleted; - private final ChainContributionStatus onchainCompleted; - private final CronConfiguration cronConfiguration; - - private int detectorOccurrence; - public RevealUnnotifiedDetector(TaskService taskService, ReplicatesService replicatesService, IexecHubService iexecHubService, - Web3jService web3jService, CronConfiguration cronConfiguration) { - super(taskService, replicatesService, iexecHubService, web3jService); - this.cronConfiguration = cronConfiguration; - dectectWhenTaskStatuses = TaskStatus.getWaitingRevealStatuses(); - offchainCompleting = ReplicateStatus.REVEALING; - offchainCompleted = ReplicateStatus.REVEALED; - onchainCompleted = ChainContributionStatus.REVEALED; + super( + taskService, + replicatesService, + iexecHubService, + TaskStatus.getWaitingRevealStatuses(), + ReplicateStatus.REVEALING, + ReplicateStatus.REVEALED, + ChainContributionStatus.REVEALED, + cronConfiguration.getReveal()); } + @Override @Scheduled(fixedRateString = "#{@cronConfiguration.getReveal()}") public void detectOnChainChanges() { - detectOnchainRevealedWhenOffchainRevealed(); - - detectorOccurrence++; - if (detectorOccurrence % LESS_OFTEN_DETECTOR_FREQUENCY == 0) { - detectOnchainRevealed(); - } + super.detectOnChainChanges(); } - - /* - * Detecting onchain REVEALED only if replicates are offchain REVEALING - * (worker didn't notify last offchain REVEALED) - * We want to detect them very often since it's highly probable - */ - public void detectOnchainRevealedWhenOffchainRevealed() { - log.debug("Detect onchain Revealed (when offchain Revealing) [retryIn:{}]", - cronConfiguration.getReveal()); - dectectOnchainCompletedWhenOffchainCompleting( - dectectWhenTaskStatuses, - offchainCompleting, - offchainCompleted, - onchainCompleted - ); - } - - /* - * Detecting onchain REVEALED if replicates are not REVEALED - * (worker didn't notify any status) - * We want to detect them: - * - Frequently but no so often since it's eth node resource consuming and less probable - * - When we receive a CANT_REVEAL - */ - public void detectOnchainRevealed() { - log.debug("Detect onchain Revealed [retryIn:{}]", - cronConfiguration.getReveal() * LESS_OFTEN_DETECTOR_FREQUENCY); - dectectOnchainCompleted( - dectectWhenTaskStatuses, - offchainCompleting, - offchainCompleted, - onchainCompleted - ); - } - } diff --git a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java index d8c4bdc66..5a59a454b 100644 --- a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java @@ -21,7 +21,6 @@ import com.iexec.commons.poco.chain.ChainContributionStatus; import com.iexec.commons.poco.chain.ChainReceipt; import com.iexec.core.chain.IexecHubService; -import com.iexec.core.chain.Web3jService; import com.iexec.core.replicate.Replicate; import com.iexec.core.replicate.ReplicatesService; import com.iexec.core.task.Task; @@ -36,27 +35,65 @@ @Slf4j public abstract class UnnotifiedAbstractDetector { - - - protected TaskService taskService; - protected ReplicatesService replicatesService; - protected IexecHubService iexecHubService; - protected Web3jService web3jService; - - public UnnotifiedAbstractDetector(TaskService taskService, - ReplicatesService replicatesService, - IexecHubService iexecHubService, - Web3jService web3jService) { + private static final int LESS_OFTEN_DETECTOR_FREQUENCY = 10; + + private final TaskService taskService; + private final ReplicatesService replicatesService; + private final IexecHubService iexecHubService; + + private final List detectWhenOffChainTaskStatuses; + private final ReplicateStatus offchainCompleting; + private final ReplicateStatus offchainCompleted; + private final ChainContributionStatus onchainCompleted; + private final int detectorRate; + + private int detectorOccurrence = 0; + + protected UnnotifiedAbstractDetector(TaskService taskService, + ReplicatesService replicatesService, + IexecHubService iexecHubService, + List detectWhenOffChainTaskStatuses, + ReplicateStatus offchainCompleting, + ReplicateStatus offchainCompleted, + ChainContributionStatus onchainCompleted, + int detectorRate) { this.taskService = taskService; this.replicatesService = replicatesService; this.iexecHubService = iexecHubService; - this.web3jService = web3jService; + + this.detectWhenOffChainTaskStatuses = detectWhenOffChainTaskStatuses; + this.offchainCompleting = offchainCompleting; + this.offchainCompleted = offchainCompleted; + this.onchainCompleted = onchainCompleted; + this.detectorRate = detectorRate; + } + + /** + * Detects the following issues: + *
        + *
      • `onchainCompleted` status only if replicates are in `offchainCompleting` status;
      • + *
      • `onchainCompleted` if replicates are not in `offchainCompleted` status.
      • + *
    + * The second detection is not always ran, depending on the detector run occurrences. + */ + void detectOnChainChanges() { + detectOnchainCompletedWhenOffchainCompleting(); + + detectorOccurrence++; + if (detectorOccurrence % LESS_OFTEN_DETECTOR_FREQUENCY == 0) { + detectOnchainCompleted(); + } } - void dectectOnchainCompletedWhenOffchainCompleting(List detectWhenOffChainTaskStatuses, - ReplicateStatus offchainCompleting, - ReplicateStatus offchainCompleted, - ChainContributionStatus onchainCompleted) { + /** + * Detecting onchain `offchainCompleted` status only if replicates are offchain `offchainCompleting` + * (worker didn't notify last offchain `offchainCompleted` status) + * We want to detect them very often since it's highly probable + */ + void detectOnchainCompletedWhenOffchainCompleting() { + log.debug("Detect onchain {} (when offchain {}) [retryIn:{}]", + this.offchainCompleted, this.offchainCompleting, this.detectorRate); + for (Task task : taskService.findByCurrentStatus(detectWhenOffChainTaskStatuses)) { for (Replicate replicate : replicatesService.getReplicates(task.getChainTaskId())) { ReplicateStatus lastRelevantStatus = replicate.getLastRelevantStatus(); @@ -69,16 +106,21 @@ void dectectOnchainCompletedWhenOffchainCompleting(List detectWhenOf if (statusTrueOnChain) { log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]", lastRelevantStatus, onchainCompleted, task.getChainTaskId()); - updateReplicateStatuses(task, replicate, offchainCompleted); + updateReplicateStatuses(task, replicate); } } } } - void dectectOnchainCompleted(List detectWhenOffChainTaskStatuses, - ReplicateStatus offchainCompleting, - ReplicateStatus offchainCompleted, - ChainContributionStatus onchainCompleted) { + /** + * Detecting `onchainCompleted` if replicates are not in `offchainCompleted` status + * (worker didn't notify any status) + * We want to detect them: + * - Frequently but no so often since it's eth node resource consuming and less probable + * - When we receive a "can't do " relative to the `onchainCompleted` status (e.g.: `CANNOT_REVEAL`) + */ + public void detectOnchainCompleted() { + log.debug("Detect onchain {} [retryIn:{}]", onchainCompleted, this.detectorRate * LESS_OFTEN_DETECTOR_FREQUENCY); for (Task task : taskService.findByCurrentStatus(detectWhenOffChainTaskStatuses)) { for (Replicate replicate : replicatesService.getReplicates(task.getChainTaskId())) { ReplicateStatus lastRelevantStatus = replicate.getLastRelevantStatus(); @@ -92,7 +134,7 @@ void dectectOnchainCompleted(List detectWhenOffChainTaskStatuses, if (statusTrueOnChain) { log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]", lastRelevantStatus, onchainCompleted, task.getChainTaskId()); - updateReplicateStatuses(task, replicate, offchainCompleted); + updateReplicateStatuses(task, replicate); } } } @@ -106,17 +148,16 @@ void dectectOnchainCompleted(List detectWhenOffChainTaskStatuses, * we couldn't get the metadata (block number) of the tx. * In this case we put 0 as default block number. */ - private void updateReplicateStatuses(Task task, Replicate replicate, ReplicateStatus offchainCompleted) { - String chainTaskId = task.getChainTaskId(); + private void updateReplicateStatuses(Task task, Replicate replicate) { + final String chainTaskId = task.getChainTaskId(); long initBlockNumber = task.getInitializationBlockNumber(); - List statusesToUpdate; - if (replicate.getCurrentStatus().equals(WORKER_LOST)) { - statusesToUpdate = getMissingStatuses(replicate.getLastButOneStatus(), offchainCompleted); - } else { - statusesToUpdate = getMissingStatuses(replicate.getCurrentStatus(), offchainCompleted); - } - String wallet = replicate.getWalletAddress(); + final ReplicateStatus retrieveFrom = replicate.getCurrentStatus().equals(WORKER_LOST) + ? replicate.getLastButOneStatus() + : replicate.getCurrentStatus(); + final List statusesToUpdate = getMissingStatuses(retrieveFrom, offchainCompleted); + + final String wallet = replicate.getWalletAddress(); for (ReplicateStatus statusToUpdate : statusesToUpdate) { // add details to the update if needed diff --git a/src/main/java/com/iexec/core/task/listener/ReplicateListeners.java b/src/main/java/com/iexec/core/task/listener/ReplicateListeners.java index 1f06240b9..47449f9da 100644 --- a/src/main/java/com/iexec/core/task/listener/ReplicateListeners.java +++ b/src/main/java/com/iexec/core/task/listener/ReplicateListeners.java @@ -78,7 +78,7 @@ public void onReplicateUpdatedEvent(ReplicateUpdatedEvent event) { * task to consensus_reached */ if (cause != null && cause.equals(TASK_NOT_ACTIVE)) { - contributionUnnotifiedDetector.detectOnchainContributed(); + contributionUnnotifiedDetector.detectOnchainCompleted(); } /* diff --git a/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java b/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java index bad0aee23..d8305c65f 100644 --- a/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java @@ -114,7 +114,7 @@ void shouldDetectUnNotifiedContributedAfterContributing() { when(iexecHubService.getContributionBlock(anyString(), anyString(), anyLong())) .thenReturn(ChainReceipt.builder().blockNumber(10L).txHash("0xabcef").build()); - contributionDetector.detectOnchainContributedWhenOffchainContributing(); + contributionDetector.detectOnchainCompletedWhenOffchainCompleting(); Mockito.verify(replicatesService, Mockito.times(1)) // Missed CONTRIBUTED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -133,7 +133,7 @@ void shouldDetectUnNotifiedContributedAfterContributingSinceBeforeContributing() when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true); - contributionDetector.detectOnchainContributedWhenOffchainContributing(); + contributionDetector.detectOnchainCompletedWhenOffchainCompleting(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -151,7 +151,7 @@ void shouldNotDetectUnNotifiedContributedAfterContributingSinceNotContributedOnC // when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD); when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(false); - contributionDetector.detectOnchainContributedWhenOffchainContributing(); + contributionDetector.detectOnchainCompletedWhenOffchainCompleting(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -178,7 +178,7 @@ void shouldDetectUnNotifiedContributed1() { .txHash("0xabcef") .build()); - contributionDetector.detectOnchainContributed(); + contributionDetector.detectOnchainCompleted(); Mockito.verify(replicatesService, Mockito.times(1))//Missed CONTRIBUTED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -202,7 +202,7 @@ void shouldDetectUnNotifiedContributed2() { .txHash("0xabcef") .build()); - contributionDetector.detectOnchainContributed(); + contributionDetector.detectOnchainCompleted(); Mockito.verify(replicatesService, Mockito.times(1))//Missed CONTRIBUTING & CONTRIBUTED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -220,7 +220,7 @@ void shouldNotDetectUnNotifiedContributedSinceContributed() { when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD); when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true); - contributionDetector.detectOnchainContributed(); + contributionDetector.detectOnchainCompleted(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); diff --git a/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java b/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java index 936c16f9b..99b8b8266 100644 --- a/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java @@ -115,7 +115,7 @@ void shouldDetectUnNotifiedRevealedAfterRevealing() { .txHash("0xabcef") .build()); - revealDetector.detectOnchainRevealedWhenOffchainRevealed(); + revealDetector.detectOnchainCompletedWhenOffchainCompleting(); Mockito.verify(replicatesService, Mockito.times(1))//Missed REVEALED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -133,7 +133,7 @@ void shouldDetectUnNotifiedRevealedAfterRevealingSinceBeforeRevealing() { when(cronConfiguration.getReveal()).thenReturn(DETECTOR_PERIOD); when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true); - revealDetector.detectOnchainRevealedWhenOffchainRevealed(); + revealDetector.detectOnchainCompletedWhenOffchainCompleting(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -150,7 +150,7 @@ void shouldNotDetectUnNotifiedRevealedAfterRevealingSinceNotRevealedOnChain() { when(cronConfiguration.getReveal()).thenReturn(DETECTOR_PERIOD); when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(false); - revealDetector.detectOnchainRevealedWhenOffchainRevealed(); + revealDetector.detectOnchainCompletedWhenOffchainCompleting(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -177,7 +177,7 @@ void shouldDetectUnNotifiedRevealed1() { .txHash("0xabcef") .build()); - revealDetector.detectOnchainRevealed(); + revealDetector.detectOnchainCompleted(); Mockito.verify(replicatesService, Mockito.times(1))//Missed REVEALED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -206,7 +206,7 @@ void shouldDetectUnNotifiedRevealed2() { .txHash("0xabcef") .build()); - revealDetector.detectOnchainRevealed(); + revealDetector.detectOnchainCompleted(); Mockito.verify(replicatesService, Mockito.times(1))//Missed REVEALING & REVEALED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -224,7 +224,7 @@ void shouldNotDetectUnNotifiedRevealedSinceRevealed() { when(cronConfiguration.getReveal()).thenReturn(DETECTOR_PERIOD); when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true); - revealDetector.detectOnchainRevealed(); + revealDetector.detectOnchainCompleted(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); diff --git a/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java b/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java index 73486eafb..c250bc7c4 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java @@ -19,7 +19,6 @@ import com.iexec.common.replicate.ReplicateStatus; import com.iexec.common.replicate.ReplicateStatusUpdate; import com.iexec.core.detector.replicate.ContributionUnnotifiedDetector; -import com.iexec.core.task.TaskService; import com.iexec.core.task.listener.ReplicateListeners; import com.iexec.core.task.update.TaskUpdateRequestManager; import com.iexec.core.worker.WorkerService; @@ -46,8 +45,6 @@ class ReplicateListenersTests { private final static String CHAIN_TASK_ID = "chainTaskId"; private final static String WORKER_WALLET = "0xwallet1"; - @Mock - private TaskService taskService; @Mock private WorkerService workerService; @Mock @@ -121,7 +118,7 @@ void shouldTriggerDetectOnchainContributedSinceTaskNotActive() { replicateListeners.onReplicateUpdatedEvent(replicateUpdatedEvent); - Mockito.verify(contributionUnnotifiedDetector, Mockito.times(1)).detectOnchainContributed(); + Mockito.verify(contributionUnnotifiedDetector, Mockito.times(1)).detectOnchainCompleted(); } @Test @@ -135,7 +132,7 @@ void shouldNotTriggerDetectOnchain() { replicateListeners.onReplicateUpdatedEvent(replicateUpdatedEvent); } - Mockito.verify(contributionUnnotifiedDetector, Mockito.times(0)).detectOnchainContributed(); + Mockito.verify(contributionUnnotifiedDetector, Mockito.times(0)).detectOnchainCompleted(); } @Test @@ -148,7 +145,7 @@ void shouldNotTriggerDetectOnchainContributedSinceCauseIsNull() { replicateListeners.onReplicateUpdatedEvent(replicateUpdatedEvent); - Mockito.verify(contributionUnnotifiedDetector, Mockito.times(0)).detectOnchainContributed(); + Mockito.verify(contributionUnnotifiedDetector, Mockito.times(0)).detectOnchainCompleted(); } static Stream getUncompletableStatuses() { From b6428d0210efd10652ee728c38bb8cb173b1d51e Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Fri, 12 May 2023 16:35:34 +0200 Subject: [PATCH 38/77] Make variables final --- .../replicate/UnnotifiedAbstractDetector.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java index 5a59a454b..0b5b5da68 100644 --- a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java @@ -96,12 +96,16 @@ void detectOnchainCompletedWhenOffchainCompleting() { for (Task task : taskService.findByCurrentStatus(detectWhenOffChainTaskStatuses)) { for (Replicate replicate : replicatesService.getReplicates(task.getChainTaskId())) { - ReplicateStatus lastRelevantStatus = replicate.getLastRelevantStatus(); + final ReplicateStatus lastRelevantStatus = replicate.getLastRelevantStatus(); if (lastRelevantStatus != offchainCompleting) { continue; } - boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain(task.getChainTaskId(), replicate.getWalletAddress(), onchainCompleted); + final boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain( + task.getChainTaskId(), + replicate.getWalletAddress(), + onchainCompleted + ); if (statusTrueOnChain) { log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]", @@ -123,13 +127,17 @@ public void detectOnchainCompleted() { log.debug("Detect onchain {} [retryIn:{}]", onchainCompleted, this.detectorRate * LESS_OFTEN_DETECTOR_FREQUENCY); for (Task task : taskService.findByCurrentStatus(detectWhenOffChainTaskStatuses)) { for (Replicate replicate : replicatesService.getReplicates(task.getChainTaskId())) { - ReplicateStatus lastRelevantStatus = replicate.getLastRelevantStatus(); + final ReplicateStatus lastRelevantStatus = replicate.getLastRelevantStatus(); if (lastRelevantStatus == offchainCompleted) { continue; } - boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain(task.getChainTaskId(), replicate.getWalletAddress(), onchainCompleted); + final boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain( + task.getChainTaskId(), + replicate.getWalletAddress(), + onchainCompleted + ); if (statusTrueOnChain) { log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]", @@ -150,7 +158,7 @@ public void detectOnchainCompleted() { */ private void updateReplicateStatuses(Task task, Replicate replicate) { final String chainTaskId = task.getChainTaskId(); - long initBlockNumber = task.getInitializationBlockNumber(); + final long initBlockNumber = task.getInitializationBlockNumber(); final ReplicateStatus retrieveFrom = replicate.getCurrentStatus().equals(WORKER_LOST) ? replicate.getLastButOneStatus() @@ -164,17 +172,17 @@ private void updateReplicateStatuses(Task task, Replicate replicate) { switch (statusToUpdate) { case CONTRIBUTED: // retrieve the contribution block for that wallet - ChainReceipt contributedBlock = iexecHubService.getContributionBlock(chainTaskId, + final ChainReceipt contributedBlock = iexecHubService.getContributionBlock(chainTaskId, wallet, initBlockNumber); - long contributedBlockNumber = contributedBlock != null ? contributedBlock.getBlockNumber() : 0; + final long contributedBlockNumber = contributedBlock != null ? contributedBlock.getBlockNumber() : 0; replicatesService.updateReplicateStatus(chainTaskId, wallet, statusToUpdate, new ReplicateStatusDetails(contributedBlockNumber)); break; case REVEALED: // retrieve the reveal block for that wallet - ChainReceipt revealedBlock = iexecHubService.getRevealBlock(chainTaskId, wallet, + final ChainReceipt revealedBlock = iexecHubService.getRevealBlock(chainTaskId, wallet, initBlockNumber); - long revealedBlockNumber = revealedBlock != null ? revealedBlock.getBlockNumber() : 0; + final long revealedBlockNumber = revealedBlock != null ? revealedBlock.getBlockNumber() : 0; replicatesService.updateReplicateStatus(chainTaskId, wallet, statusToUpdate, new ReplicateStatusDetails(revealedBlockNumber)); break; From 52a7d912ba57804866ec0e0afd9a3a9e4a324a54 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Mon, 15 May 2023 08:45:11 +0200 Subject: [PATCH 39/77] =?UTF-8?q?Fix=20callback=20check=20in=20=CC=80Repli?= =?UTF-8?q?cateWorkflow`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java | 3 +-- .../java/com/iexec/core/workflow/ReplicateWorkflowTests.java | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73de6f092..5e5285c29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. - Add ContributeAndFinalize to `ReplicateWorkflow`. (#574) - Add check for ContributeAndFinalize in `ReplicatesService`. (#576) - Add `running2Finalized2Completed` in `TaskUpdateManager`. (#577 #578) -- Disable `contributeAndFinalize` with CallBack. (#579) +- Disable `contributeAndFinalize` with CallBack. (#579 #581) ### Bug Fixes - Prevent race condition on replicate update. (#568) ### Quality diff --git a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java index ca0ac07fb..2713aa548 100644 --- a/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java +++ b/src/main/java/com/iexec/core/workflow/ReplicateWorkflow.java @@ -21,7 +21,6 @@ import com.iexec.commons.poco.notification.TaskNotificationType; import com.iexec.commons.poco.task.TaskDescription; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import java.util.Arrays; import java.util.LinkedHashMap; @@ -197,7 +196,7 @@ TaskNotificationType getNextActionWhenStatusAndCause(ReplicateStatus whenStatus, return PLEASE_ABORT; } // We must check CallBack is empty because there is an issue in poco (transaction is revert) - if (taskDescription.isTeeTask() && StringUtils.isEmpty(taskDescription.getCallback())) { + if (taskDescription.isTeeTask() && !taskDescription.containsCallback()) { return PLEASE_CONTRIBUTE_AND_FINALIZE; } } diff --git a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java index d311063cb..336280344 100644 --- a/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java +++ b/src/test/java/com/iexec/core/workflow/ReplicateWorkflowTests.java @@ -20,6 +20,7 @@ import com.iexec.common.replicate.ReplicateStatusCause; import com.iexec.commons.poco.notification.TaskNotificationType; import com.iexec.commons.poco.task.TaskDescription; +import com.iexec.commons.poco.utils.BytesUtils; import org.junit.Rule; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -165,7 +166,7 @@ void shouldGetNextActionOnComputedWithTeeTaskShouldBePleaseContributeAndFinalize assertThat(replicateWorkflow .getNextAction(COMPUTED, null, - TaskDescription.builder().isTeeTask(true).build())) + TaskDescription.builder().isTeeTask(true).callback(BytesUtils.EMPTY_ADDRESS).build())) .isEqualTo(PLEASE_CONTRIBUTE_AND_FINALIZE); } From 74ca699d1cddbe6623f4455e447b466759117cc1 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Mon, 15 May 2023 16:19:30 +0200 Subject: [PATCH 40/77] Check result has been uploaded in ContributeAndFinalize flow --- CHANGELOG.md | 2 +- .../core/replicate/ReplicatesService.java | 1 + .../core/replicate/ReplicateServiceTests.java | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e5285c29..c0f18f8a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. ### New Features - Add ContributeAndFinalize to `ReplicateWorkflow`. (#574) -- Add check for ContributeAndFinalize in `ReplicatesService`. (#576) +- Add check for ContributeAndFinalize in `ReplicatesService`. (#576 #582) - Add `running2Finalized2Completed` in `TaskUpdateManager`. (#577 #578) - Disable `contributeAndFinalize` with CallBack. (#579 #581) ### Bug Fixes diff --git a/src/main/java/com/iexec/core/replicate/ReplicatesService.java b/src/main/java/com/iexec/core/replicate/ReplicatesService.java index d7ae66cb0..8560957e4 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicatesService.java +++ b/src/main/java/com/iexec/core/replicate/ReplicatesService.java @@ -548,6 +548,7 @@ private boolean verifyStatus(String chainTaskId, return !isResultUploaded(updateReplicateStatusArgs.getTaskDescription()); case CONTRIBUTE_AND_FINALIZE_DONE: return iexecHubService.repeatIsRevealedTrue(chainTaskId, walletAddress) + && isResultUploaded(chainTaskId) && iexecHubService.isTaskInCompletedStatusOnChain(chainTaskId); default: return true; diff --git a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java index e53dd35a4..1c09463ff 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java @@ -1284,10 +1284,13 @@ void shouldAuthorizeUpdateOnContributeAndFinalizeDone() { .modifier(WORKER) .status(CONTRIBUTE_AND_FINALIZE_DONE) .build(); + final TaskDescription task = TaskDescription.builder().chainTaskId(CHAIN_TASK_ID).build(); when(replicatesRepository.findByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); when(iexecHubService.repeatIsRevealedTrue(CHAIN_TASK_ID, WALLET_WORKER_1)) .thenReturn(true); + when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)).thenReturn(Optional.of(task)); + when(resultService.isResultUploaded(CHAIN_TASK_ID)).thenReturn(true); when(iexecHubService.isTaskInCompletedStatusOnChain(CHAIN_TASK_ID)).thenReturn(true); assertThat(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate, null)) @@ -1314,6 +1317,29 @@ void shouldNotAuthorizeUpdateOnContributeAndFinalizeDoneWhenNotRevealed() { .isEqualTo(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE); } + @Test + void shouldNotAuthorizeUpdateOnContributeAndFinalizeDoneWhenNotUploaded() { + final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); + replicate.updateStatus(CONTRIBUTE_AND_FINALIZE_ONGOING, ReplicateStatusModifier.WORKER); + + final ReplicatesList replicatesList = new ReplicatesList(CHAIN_TASK_ID, Collections.singletonList(replicate)); + final ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder() + .modifier(WORKER) + .status(CONTRIBUTE_AND_FINALIZE_DONE) + .build(); + final TaskDescription task = TaskDescription.builder().chainTaskId(CHAIN_TASK_ID).build(); + + when(replicatesRepository.findByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); + when(iexecHubService.repeatIsRevealedTrue(CHAIN_TASK_ID, WALLET_WORKER_1)) + .thenReturn(true); + when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)).thenReturn(Optional.of(task)); + when(resultService.isResultUploaded(CHAIN_TASK_ID)).thenReturn(false); + + assertThat(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate, null)) + .isEqualTo(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE); + } + + @Test void shouldNotAuthorizeUpdateOnContributeAndFinalizeDoneWhenTaskNotCompleted() { final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); From 44084c0fab3c73ea7834e98ea3fc5e64115f9c4b Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Tue, 16 May 2023 09:07:56 +0200 Subject: [PATCH 41/77] Remove call to `getTaskDescriptionFromChain` --- .../core/replicate/ReplicatesService.java | 10 +++--- .../core/replicate/ReplicateServiceTests.java | 32 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/iexec/core/replicate/ReplicatesService.java b/src/main/java/com/iexec/core/replicate/ReplicatesService.java index 8560957e4..ea793ceab 100644 --- a/src/main/java/com/iexec/core/replicate/ReplicatesService.java +++ b/src/main/java/com/iexec/core/replicate/ReplicatesService.java @@ -257,11 +257,11 @@ public UpdateReplicateStatusArgs computeUpdateReplicateStatusArgs(String chainTa resultLink = details.getResultLink(); chainCallbackData = details.getChainCallbackData(); } - taskDescription = iexecHubService.getTaskDescriptionFromChain(chainTaskId).orElse(null); + taskDescription = iexecHubService.getTaskDescription(chainTaskId); break; case COMPUTED: case RESULT_UPLOAD_FAILED: - taskDescription = iexecHubService.getTaskDescriptionFromChain(chainTaskId).orElse(null); + taskDescription = iexecHubService.getTaskDescription(chainTaskId); break; default: break; @@ -594,13 +594,13 @@ private String getStatusUpdateLogs(String chainTaskId, Replicate replicate, Repl } public boolean isResultUploaded(String chainTaskId) { - Optional task = iexecHubService.getTaskDescriptionFromChain(chainTaskId); + TaskDescription task = iexecHubService.getTaskDescription(chainTaskId); - if (task.isEmpty()) { + if (task == null) { return false; } - return isResultUploaded(task.get()); + return isResultUploaded(task); } public boolean isResultUploaded(TaskDescription task) { diff --git a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java index 1c09463ff..4d65fbc36 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java @@ -441,8 +441,8 @@ void shouldUpdateReplicateStatusWithStdoutIfComputed(){ ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(ReplicateUpdatedEvent.class); when(replicatesRepository.findByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); when(replicatesRepository.save(replicatesList)).thenReturn(replicatesList); - when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)) - .thenReturn(Optional.of(TaskDescription.builder().isTeeTask(true).build())); + when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)) + .thenReturn(TaskDescription.builder().isTeeTask(true).build()); replicatesService.updateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate); Mockito.verify(applicationEventPublisher, Mockito.times(1)) @@ -797,8 +797,8 @@ void shouldCheckResultServiceAndReturnTrue() { .callback(BytesUtils.EMPTY_ADDRESS) .isTeeTask(false) .build(); - when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)) - .thenReturn(Optional.of(taskDescription)); + when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)) + .thenReturn(taskDescription); when(resultService.isResultUploaded(CHAIN_TASK_ID)).thenReturn(true); boolean isResultUploaded = replicatesService.isResultUploaded(CHAIN_TASK_ID); @@ -813,8 +813,8 @@ void shouldCheckResultServiceAndReturnFalse() { .callback(BytesUtils.EMPTY_ADDRESS) .isTeeTask(false) .build(); - when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)) - .thenReturn(Optional.of(taskDescription)); + when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)) + .thenReturn(taskDescription); when(resultService.isResultUploaded(CHAIN_TASK_ID)).thenReturn(false); boolean isResultUploaded = replicatesService.isResultUploaded(CHAIN_TASK_ID); @@ -824,8 +824,8 @@ void shouldCheckResultServiceAndReturnFalse() { @Test void shouldReturnFalseSinceTaskNotFound() { - when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)) - .thenReturn(Optional.empty()); + when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)) + .thenReturn(null); boolean isResultUploaded = replicatesService.isResultUploaded(CHAIN_TASK_ID); assertThat(isResultUploaded).isFalse(); @@ -839,8 +839,8 @@ void shouldReturnTrueForCallbackTask() { .callback("callback") .isTeeTask(false) .build(); - when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)) - .thenReturn(Optional.of(taskDescription)); + when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)) + .thenReturn(taskDescription); boolean isResultUploaded = replicatesService.isResultUploaded(CHAIN_TASK_ID); assertThat(isResultUploaded).isTrue(); @@ -854,8 +854,8 @@ void shouldReturnTrueForTeeTask() { .callback(BytesUtils.EMPTY_ADDRESS) .isTeeTask(true) .build(); - when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)) - .thenReturn(Optional.of(taskDescription)); + when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)) + .thenReturn(taskDescription); boolean isResultUploaded = replicatesService.isResultUploaded(CHAIN_TASK_ID); assertThat(isResultUploaded).isTrue(); @@ -1453,8 +1453,8 @@ void computeUpdateReplicateStatusArgsResultUploaded() { when(iexecHubService.getWorkerWeight(WALLET_WORKER_1)).thenReturn(unexpectedWorkerWeight); when(iexecHubService.getChainContribution(CHAIN_TASK_ID, WALLET_WORKER_1)) .thenReturn(Optional.of(unexpectedChainContribution)); - when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)) - .thenReturn(Optional.of(expectedTaskDescription)); + when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)) + .thenReturn(expectedTaskDescription); final UpdateReplicateStatusArgs actualResult = replicatesService.computeUpdateReplicateStatusArgs(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate); @@ -1487,8 +1487,8 @@ void computeUpdateReplicateStatusArgsResultUploadFailed() { when(iexecHubService.getWorkerWeight(WALLET_WORKER_1)).thenReturn(unexpectedWorkerWeight); when(iexecHubService.getChainContribution(CHAIN_TASK_ID, WALLET_WORKER_1)) .thenReturn(Optional.of(unexpectedChainContribution)); - when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)) - .thenReturn(Optional.of(expectedTaskDescription)); + when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)) + .thenReturn(expectedTaskDescription); final UpdateReplicateStatusArgs actualResult = replicatesService.computeUpdateReplicateStatusArgs(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate); From 02f42513fb624c0ee2d34ac9b15d2c113b06d875 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Wed, 17 May 2023 09:19:44 +0200 Subject: [PATCH 42/77] Fix `shouldAuthorizeUpdateOnContributeAndFinalizeDone` test --- .../com/iexec/core/replicate/ReplicateServiceTests.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java index 4d65fbc36..2e1e82c03 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java @@ -1284,13 +1284,16 @@ void shouldAuthorizeUpdateOnContributeAndFinalizeDone() { .modifier(WORKER) .status(CONTRIBUTE_AND_FINALIZE_DONE) .build(); - final TaskDescription task = TaskDescription.builder().chainTaskId(CHAIN_TASK_ID).build(); + final TaskDescription task = TaskDescription + .builder() + .chainTaskId(CHAIN_TASK_ID) + .isTeeTask(true) + .build(); when(replicatesRepository.findByChainTaskId(CHAIN_TASK_ID)).thenReturn(Optional.of(replicatesList)); when(iexecHubService.repeatIsRevealedTrue(CHAIN_TASK_ID, WALLET_WORKER_1)) .thenReturn(true); - when(iexecHubService.getTaskDescriptionFromChain(CHAIN_TASK_ID)).thenReturn(Optional.of(task)); - when(resultService.isResultUploaded(CHAIN_TASK_ID)).thenReturn(true); + when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)).thenReturn(task); when(iexecHubService.isTaskInCompletedStatusOnChain(CHAIN_TASK_ID)).thenReturn(true); assertThat(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate, null)) From c7da225c1f426ae01f0681cadf0e8de372ed4b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Wed, 17 May 2023 09:57:23 +0200 Subject: [PATCH 43/77] Use or operators to test the equality of enums --- CHANGELOG.md | 1 + .../core/task/update/TaskUpdateManager.java | 30 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0f18f8a0..877610ddf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. - Clean unused Replicate methods and update tests. (#573) - Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#575) - Refactor unnotified detectors to avoid code duplication. (#580) +- Use `==` or `!=` operators to test the equality of enums. (#584) ### Dependency Upgrades - Upgrade to `iexec-common` 8.0.0-NEXT-SNAPSHOT. (#571 #575) - Add new `iexec-commons-poco` 1.0.2-NEXT-SNAPSHOT dependency. (#571 #574) diff --git a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java index c447a4c4a..bf818527a 100644 --- a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java +++ b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java @@ -183,7 +183,7 @@ Task updateTaskStatusAndSave(Task task, TaskStatus newStatus, ChainReceipt chain } void received2Initializing(Task task) { - boolean isCurrentStatusReceived = task.getCurrentStatus().equals(RECEIVED); + boolean isCurrentStatusReceived = task.getCurrentStatus() == RECEIVED; if (!isCurrentStatusReceived) { log.error("Cannot initialize task [chainTaskId:{}, currentStatus:{}]", @@ -242,7 +242,7 @@ void received2Initializing(Task task) { } void initializing2Initialized(Task task) { - if (!INITIALIZING.equals(task.getCurrentStatus())) { + if (INITIALIZING != task.getCurrentStatus()) { return; } // TODO: the block where initialization happened can be found @@ -289,7 +289,7 @@ void initialized2Running(Task task) { }; final int nbReplicatesContainingStartingStatus = replicatesService.getNbReplicatesWithLastRelevantStatus(chainTaskId, acceptableStatus); boolean condition1 = nbReplicatesContainingStartingStatus > 0; - boolean condition2 = task.getCurrentStatus().equals(INITIALIZED); + boolean condition2 = task.getCurrentStatus() == INITIALIZED; if (condition1 && condition2) { updateTaskStatusAndSave(task, RUNNING); @@ -297,7 +297,7 @@ void initialized2Running(Task task) { } void running2ConsensusReached(Task task) { - boolean isTaskInRunningStatus = task.getCurrentStatus().equals(RUNNING); + boolean isTaskInRunningStatus = task.getCurrentStatus() == RUNNING; final String chainTaskId = task.getChainTaskId(); final Optional oReplicatesList = replicatesService.getReplicatesList(chainTaskId); if (oReplicatesList.isEmpty()) { @@ -328,7 +328,7 @@ void running2ConsensusReached(Task task) { } void running2Finalized2Completed(Task task) { - boolean isTaskInRunningStatus = task.getCurrentStatus().equals(RUNNING); + boolean isTaskInRunningStatus = task.getCurrentStatus() == RUNNING; final String chainTaskId = task.getChainTaskId(); final Optional oReplicatesList = replicatesService.getReplicatesList(chainTaskId); @@ -368,8 +368,8 @@ void running2Finalized2Completed(Task task) { } void initializedOrRunning2ContributionTimeout(Task task) { - boolean isInitializedOrRunningTask = task.getCurrentStatus().equals(INITIALIZED) || - task.getCurrentStatus().equals(RUNNING); + boolean isInitializedOrRunningTask = task.getCurrentStatus() == INITIALIZED || + task.getCurrentStatus() == RUNNING; boolean isNowAfterContributionDeadline = task.getContributionDeadline() != null && new Date().after(task.getContributionDeadline()); if (isInitializedOrRunningTask && isNowAfterContributionDeadline) { @@ -391,7 +391,7 @@ void initializedOrRunning2ContributionTimeout(Task task) { * @param task Task to check and to make become {@link TaskStatus#RUNNING_FAILED}. */ void running2RunningFailed(Task task) { - boolean isRunningTask = task.getCurrentStatus().equals(RUNNING); + boolean isRunningTask = task.getCurrentStatus() == RUNNING; if (!isRunningTask || !task.isTeeTask()) { return; } @@ -435,7 +435,7 @@ void running2RunningFailed(Task task) { } void consensusReached2AtLeastOneReveal2ResultUploading(Task task) { - boolean condition1 = task.getCurrentStatus().equals(CONSENSUS_REACHED); + boolean condition1 = task.getCurrentStatus() == CONSENSUS_REACHED; boolean condition2 = replicatesService.getNbReplicatesWithCurrentStatus(task.getChainTaskId(), ReplicateStatus.REVEALED) > 0; if (condition1 && condition2) { @@ -447,7 +447,7 @@ void consensusReached2AtLeastOneReveal2ResultUploading(Task task) { void consensusReached2Reopening(Task task) { Date now = new Date(); - boolean isConsensusReachedStatus = task.getCurrentStatus().equals(CONSENSUS_REACHED); + boolean isConsensusReachedStatus = task.getCurrentStatus() == CONSENSUS_REACHED; boolean isAfterRevealDeadline = task.getRevealDeadline() != null && now.after(task.getRevealDeadline()); boolean hasAtLeastOneReveal = replicatesService.getNbReplicatesWithCurrentStatus(task.getChainTaskId(), ReplicateStatus.REVEALED) > 0; @@ -488,7 +488,7 @@ void reopening2Reopened(Task task, ChainReceipt chainReceipt) { ChainTask chainTask = oChainTask.get(); // re-initialize the task if it has been reopened - if (chainTask.getStatus().equals(ChainTaskStatus.ACTIVE)) { + if (chainTask.getStatus() == ChainTaskStatus.ACTIVE) { // set replicates to REVEAL_TIMEOUT for (Replicate replicate : replicatesService.getReplicates(task.getChainTaskId())) { @@ -504,7 +504,7 @@ void reopening2Reopened(Task task, ChainReceipt chainReceipt) { } void resultUploading2Uploaded(Task task) { - boolean isTaskInResultUploading = task.getCurrentStatus().equals(RESULT_UPLOADING); + boolean isTaskInResultUploading = task.getCurrentStatus() == RESULT_UPLOADING; Optional oUploadedReplicate = replicatesService.getReplicateWithResultUploadedStatus(task.getChainTaskId()); boolean didReplicateUpload = oUploadedReplicate.isPresent(); @@ -546,7 +546,7 @@ void resultUploading2Uploaded(Task task) { } void resultUploading2UploadTimeout(Task task) { - boolean isTaskInResultUploading = task.getCurrentStatus().equals(RESULT_UPLOADING); + boolean isTaskInResultUploading = task.getCurrentStatus() == RESULT_UPLOADING; boolean isNowAfterFinalDeadline = task.getFinalDeadline() != null && new Date().after(task.getFinalDeadline()); @@ -585,7 +585,7 @@ void requestUpload(Task task) { } void resultUploaded2Finalizing(Task task) { - boolean isTaskInResultUploaded = task.getCurrentStatus().equals(RESULT_UPLOADED); + boolean isTaskInResultUploaded = task.getCurrentStatus() == RESULT_UPLOADED; boolean canFinalize = iexecHubService.canFinalize(task.getChainTaskId()); Optional optional = iexecHubService.getChainTask(task.getChainTaskId()); @@ -644,7 +644,7 @@ void finalizing2Finalized2Completed(Task task) { } void finalizedToCompleted(Task task) { - if (!task.getCurrentStatus().equals(FINALIZED)) { + if (task.getCurrentStatus() != FINALIZED) { return; } updateTaskStatusAndSave(task, COMPLETED); From af446fe6d301a7a80ef1cbe14b2b7950330b05e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Wed, 17 May 2023 11:33:14 +0200 Subject: [PATCH 44/77] Make `task.isTeeTask()` the first test in `TaskUpdateManager#running2Finalized2Completed` --- CHANGELOG.md | 1 + .../iexec/core/task/update/TaskUpdateManager.java | 13 +++++++------ .../core/task/update/TaskUpdateManagerTest.java | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 877610ddf..7ba34d12d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. - Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#575) - Refactor unnotified detectors to avoid code duplication. (#580) - Use `==` or `!=` operators to test the equality of enums. (#584) +- Make `task.isTeeTask()` the first test in `TaskUpdateManager#running2Finalized2Completed` to avoid unnecessary calls to the database. (#585) ### Dependency Upgrades - Upgrade to `iexec-common` 8.0.0-NEXT-SNAPSHOT. (#571 #575) - Add new `iexec-commons-poco` 1.0.2-NEXT-SNAPSHOT dependency. (#571 #574) diff --git a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java index bf818527a..940894284 100644 --- a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java +++ b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java @@ -330,7 +330,12 @@ void running2ConsensusReached(Task task) { void running2Finalized2Completed(Task task) { boolean isTaskInRunningStatus = task.getCurrentStatus() == RUNNING; final String chainTaskId = task.getChainTaskId(); - final Optional oReplicatesList = replicatesService.getReplicatesList(chainTaskId); + + if (!task.isTeeTask()) { + log.debug("Task not running in a TEE, flow running2Finalized2Completed is not possible" + + " [chainTaskId:{}]", chainTaskId); + return; + } if (!isTaskInRunningStatus) { log.error("Can't transition task to `Finalized` or `Completed` when task is not `Running` " + @@ -338,17 +343,13 @@ void running2Finalized2Completed(Task task) { return; } + final Optional oReplicatesList = replicatesService.getReplicatesList(chainTaskId); if (oReplicatesList.isEmpty()) { log.error("Can't transition task to `Finalized` or `Completed` when no replicatesList exists" + " [chainTaskId:{}]", chainTaskId); return; } - if (!task.isTeeTask()) { - log.debug("Task not running in a TEE, flow running2Finalized2Completed is not possible" - + " [chainTaskId:{}]", chainTaskId); - return; - } final ReplicatesList replicates = oReplicatesList.get(); final int nbReplicatesWithContributeAndFinalizeStatus = replicates.getNbReplicatesWithCurrentStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE); diff --git a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java index 8aef17a45..eb82b0c74 100644 --- a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java +++ b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java @@ -688,6 +688,7 @@ void shouldUpdateFromInitializedOrRunning2ContributionTimeout() { void shouldNotUpdateRunning2Finalized2CompletedWhenTaskNotRunning() { Task task = getStubTask(maxExecutionTime); task.changeStatus(INITIALIZED); + task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); taskUpdateManager.running2Finalized2Completed(task); assertThat(task.getCurrentStatus()).isEqualTo(INITIALIZED); @@ -697,6 +698,7 @@ void shouldNotUpdateRunning2Finalized2CompletedWhenTaskNotRunning() { void shouldNotUpdateRunning2Finalized2CompletedWhenNoReplicates() { Task task = getStubTask(maxExecutionTime); task.changeStatus(RUNNING); + task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); when(replicatesService.getReplicatesList(CHAIN_TASK_ID)).thenReturn(Optional.empty()); From a5a8e9af590b775faada4032b19fd33830c3fc40 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Wed, 17 May 2023 12:16:33 +0200 Subject: [PATCH 45/77] Use iexec-commons-poco@2.0.0 and iexec-common@8.1.0-NEXT-SNAPSHOT --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 1bcb12249..c85b2e2d5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ version=8.0.1 -iexecCommonVersion=8.0.0-NEXT-SNAPSHOT -iexecCommonsPocoVersion=1.0.2-NEXT-SNAPSHOT +iexecCommonVersion=8.1.0-NEXT-SNAPSHOT +iexecCommonsPocoVersion=2.0.0 iexecBlockchainAdapterVersion=8.0.1-NEXT-SNAPSHOT iexecResultVersion=8.0.0-NEXT-SNAPSHOT iexecSmsVersion=8.0.0-NEXT-SNAPSHOT From 3760cb30353eb177019551628de0a695d9b8850c Mon Sep 17 00:00:00 2001 From: Frederic Date: Wed, 17 May 2023 12:26:02 +0200 Subject: [PATCH 46/77] Update CHANGELOG.md Co-authored-by: Maxence Cornaton <87655102+mcornaton@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ba34d12d..9372368df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ All notable changes to this project will be documented in this file. - Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#575) - Refactor unnotified detectors to avoid code duplication. (#580) - Use `==` or `!=` operators to test the equality of enums. (#584) -- Make `task.isTeeTask()` the first test in `TaskUpdateManager#running2Finalized2Completed` to avoid unnecessary calls to the database. (#585) +- Rearrange checks order to avoid call to database. (#585) ### Dependency Upgrades - Upgrade to `iexec-common` 8.0.0-NEXT-SNAPSHOT. (#571 #575) - Add new `iexec-commons-poco` 1.0.2-NEXT-SNAPSHOT dependency. (#571 #574) From 5f202147180765419824d93e1e5e542a18ac67f3 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Wed, 17 May 2023 13:54:00 +0200 Subject: [PATCH 47/77] Update imports in classes --- src/main/java/com/iexec/core/result/ResultService.java | 4 ++-- .../com/iexec/core/security/EIP712ChallengeService.java | 6 +++--- src/main/java/com/iexec/core/task/TaskController.java | 2 +- .../iexec/core/security/EIP712ChallengeServiceTests.java | 2 +- src/test/java/com/iexec/core/task/TaskControllerTests.java | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/iexec/core/result/ResultService.java b/src/main/java/com/iexec/core/result/ResultService.java index bca13ff5e..5dfc2b400 100644 --- a/src/main/java/com/iexec/core/result/ResultService.java +++ b/src/main/java/com/iexec/core/result/ResultService.java @@ -16,8 +16,8 @@ package com.iexec.core.result; -import com.iexec.common.chain.eip712.EIP712Domain; -import com.iexec.common.chain.eip712.entity.EIP712Challenge; +import com.iexec.commons.poco.eip712.EIP712Domain; +import com.iexec.commons.poco.eip712.entity.EIP712Challenge; import com.iexec.core.chain.ChainConfig; import com.iexec.core.chain.CredentialsService; import com.iexec.resultproxy.api.ResultProxyClient; diff --git a/src/main/java/com/iexec/core/security/EIP712ChallengeService.java b/src/main/java/com/iexec/core/security/EIP712ChallengeService.java index c7e2106c5..6839a53c7 100644 --- a/src/main/java/com/iexec/core/security/EIP712ChallengeService.java +++ b/src/main/java/com/iexec/core/security/EIP712ChallengeService.java @@ -16,9 +16,9 @@ package com.iexec.core.security; -import com.iexec.common.chain.eip712.EIP712Domain; -import com.iexec.common.chain.eip712.entity.Challenge; -import com.iexec.common.chain.eip712.entity.EIP712Challenge; +import com.iexec.commons.poco.eip712.EIP712Domain; +import com.iexec.commons.poco.eip712.entity.Challenge; +import com.iexec.commons.poco.eip712.entity.EIP712Challenge; import net.jodah.expiringmap.ExpirationPolicy; import net.jodah.expiringmap.ExpiringMap; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/iexec/core/task/TaskController.java b/src/main/java/com/iexec/core/task/TaskController.java index d57accab8..04dce180d 100644 --- a/src/main/java/com/iexec/core/task/TaskController.java +++ b/src/main/java/com/iexec/core/task/TaskController.java @@ -16,9 +16,9 @@ package com.iexec.core.task; -import com.iexec.common.chain.eip712.entity.EIP712Challenge; import com.iexec.common.replicate.ComputeLogs; import com.iexec.common.security.SignedChallenge; +import com.iexec.commons.poco.eip712.entity.EIP712Challenge; import com.iexec.commons.poco.security.Signature; import com.iexec.commons.poco.task.TaskDescription; import com.iexec.commons.poco.utils.SignatureUtils; diff --git a/src/test/java/com/iexec/core/security/EIP712ChallengeServiceTests.java b/src/test/java/com/iexec/core/security/EIP712ChallengeServiceTests.java index fbf1e4895..ac4bf86bb 100644 --- a/src/test/java/com/iexec/core/security/EIP712ChallengeServiceTests.java +++ b/src/test/java/com/iexec/core/security/EIP712ChallengeServiceTests.java @@ -16,7 +16,7 @@ package com.iexec.core.security; -import com.iexec.common.chain.eip712.entity.EIP712Challenge; +import com.iexec.commons.poco.eip712.entity.EIP712Challenge; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.web3j.crypto.Keys; diff --git a/src/test/java/com/iexec/core/task/TaskControllerTests.java b/src/test/java/com/iexec/core/task/TaskControllerTests.java index d2434aa9a..163552e33 100644 --- a/src/test/java/com/iexec/core/task/TaskControllerTests.java +++ b/src/test/java/com/iexec/core/task/TaskControllerTests.java @@ -16,10 +16,10 @@ package com.iexec.core.task; -import com.iexec.common.chain.eip712.EIP712Domain; -import com.iexec.common.chain.eip712.entity.Challenge; -import com.iexec.common.chain.eip712.entity.EIP712Challenge; import com.iexec.common.replicate.ComputeLogs; +import com.iexec.commons.poco.eip712.EIP712Domain; +import com.iexec.commons.poco.eip712.entity.Challenge; +import com.iexec.commons.poco.eip712.entity.EIP712Challenge; import com.iexec.commons.poco.task.TaskDescription; import com.iexec.core.chain.IexecHubService; import com.iexec.core.logs.TaskLogs; From fdbafceb305392a05cac386cfd9ae55b19d0344a Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Wed, 17 May 2023 14:14:33 +0200 Subject: [PATCH 48/77] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 877610ddf..68a4942bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,8 +18,8 @@ All notable changes to this project will be documented in this file. - Refactor unnotified detectors to avoid code duplication. (#580) - Use `==` or `!=` operators to test the equality of enums. (#584) ### Dependency Upgrades -- Upgrade to `iexec-common` 8.0.0-NEXT-SNAPSHOT. (#571 #575) -- Add new `iexec-commons-poco` 1.0.2-NEXT-SNAPSHOT dependency. (#571 #574) +- Upgrade to `iexec-common` 8.1.0-NEXT-SNAPSHOT. (#571 #575 #586) +- Add new `iexec-commons-poco` 2.0.0 dependency. (#571 #574 #586) ## [[8.0.1]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.0.1) 2023-03-20 From 0788ac82d4f956cf5e4741f0a97437acb5746e52 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Tue, 23 May 2023 16:41:11 +0200 Subject: [PATCH 49/77] Purge cached task descriptions --- gradle.properties | 2 +- .../java/com/iexec/core/chain/IexecHubService.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index c85b2e2d5..92010b360 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ version=8.0.1 iexecCommonVersion=8.1.0-NEXT-SNAPSHOT -iexecCommonsPocoVersion=2.0.0 +iexecCommonsPocoVersion=2.0.1 iexecBlockchainAdapterVersion=8.0.1-NEXT-SNAPSHOT iexecResultVersion=8.0.0-NEXT-SNAPSHOT iexecSmsVersion=8.0.0-NEXT-SNAPSHOT diff --git a/src/main/java/com/iexec/core/chain/IexecHubService.java b/src/main/java/com/iexec/core/chain/IexecHubService.java index 94b582fc9..aee5172b0 100644 --- a/src/main/java/com/iexec/core/chain/IexecHubService.java +++ b/src/main/java/com/iexec/core/chain/IexecHubService.java @@ -16,6 +16,7 @@ package com.iexec.core.chain; +import com.iexec.common.lifecycle.purge.Purgeable; import com.iexec.commons.poco.chain.*; import com.iexec.commons.poco.contract.generated.IexecHubContract; import io.reactivex.Flowable; @@ -37,7 +38,7 @@ @Slf4j @Service -public class IexecHubService extends IexecHubAbstractService { +public class IexecHubService extends IexecHubAbstractService implements Purgeable { private final ThreadPoolExecutor executor; private final CredentialsService credentialsService; @@ -247,4 +248,13 @@ private ChainReceipt buildChainReceipt(TransactionReceipt receipt) { .build(); } + @Override + public boolean purgeTask(String chainTaskId) { + return super.purgeTask(chainTaskId); + } + + @Override + public void purgeAllTasksData() { + super.purgeAllTasksData(); + } } From 6555b12dbc2bdad43c66c9b9ffd4bfbb2bd461f8 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Tue, 23 May 2023 16:43:08 +0200 Subject: [PATCH 50/77] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 094c2af9a..9375276c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. - Add check for ContributeAndFinalize in `ReplicatesService`. (#576 #582) - Add `running2Finalized2Completed` in `TaskUpdateManager`. (#577 #578) - Disable `contributeAndFinalize` with CallBack. (#579 #581) +- Add purge cached task descriptions ability. (#587) ### Bug Fixes - Prevent race condition on replicate update. (#568) ### Quality @@ -20,7 +21,7 @@ All notable changes to this project will be documented in this file. - Rearrange checks order to avoid call to database. (#585) ### Dependency Upgrades - Upgrade to `iexec-common` 8.1.0-NEXT-SNAPSHOT. (#571 #575 #586) -- Add new `iexec-commons-poco` 2.0.0 dependency. (#571 #574 #586) +- Add new `iexec-commons-poco` 2.0.1 dependency. (#571 #574 #586 #587) ## [[8.0.1]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.0.1) 2023-03-20 From 3fe90f7a0b635ee8317ced47b8713e4f9c5adcef Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 25 May 2023 13:46:15 +0200 Subject: [PATCH 51/77] Use builders in test classes --- .../iexec/core/chain/DealWatcherServiceTests.java | 8 ++++---- .../iexec/core/replicate/ReplicateServiceTests.java | 8 ++++---- .../core/task/update/TaskUpdateManagerTest.java | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java b/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java index a546085b5..c59a7170c 100644 --- a/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java +++ b/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java @@ -103,10 +103,10 @@ void shouldUpdateLastSeenBlockWhenOneDeal() { @Test void shouldUpdateLastSeenBlockWhenOneDealAndCreateTask() { - ChainApp chainApp = new ChainApp(); - chainApp.setUri("0x00"); + ChainApp chainApp = ChainApp.builder() + .uri("0x00").build(); - ChainCategory chainCategory = new ChainCategory(); + ChainCategory chainCategory = ChainCategory.builder().build(); ChainDeal chainDeal = ChainDeal.builder() .botFirst(BigInteger.valueOf(0)) @@ -146,7 +146,7 @@ void shouldUpdateLastSeenBlockWhenOneDealAndNotCreateTaskSinceDealIsExpired() { .botFirst(BigInteger.valueOf(0)) .botSize(BigInteger.valueOf(1)) .chainApp(ChainApp.builder().uri("0x00").build()) - .chainCategory(new ChainCategory()) + .chainCategory(ChainCategory.builder().build()) .params(DealParams.builder().iexecArgs("args").build()) .trust(BigInteger.valueOf(3)) .build(); diff --git a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java index 2e1e82c03..d8139c545 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java @@ -1410,7 +1410,7 @@ void shouldAuthorizeUpdateOnComputedWhenTaskDescriptionIsFilled() { @Test void computeUpdateReplicateStatusArgsContributed() { final int expectedWorkerWeight = 1; - final ChainContribution expectedChainContribution = new ChainContribution(); + final ChainContribution expectedChainContribution = ChainContribution.builder().build(); final String unexpectedResultLink = "resultLink"; final String unexpectedChainCallbackData = "chainCallbackData"; @@ -1426,7 +1426,7 @@ void computeUpdateReplicateStatusArgsContributed() { when(iexecHubService.getWorkerWeight(WALLET_WORKER_1)).thenReturn(expectedWorkerWeight); when(iexecHubService.getChainContribution(CHAIN_TASK_ID, WALLET_WORKER_1)) - .thenReturn(Optional.of(new ChainContribution())); + .thenReturn(Optional.of(ChainContribution.builder().build())); assertThat(replicatesService.computeUpdateReplicateStatusArgs(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate)) .isEqualTo(UpdateReplicateStatusArgs.builder() @@ -1438,7 +1438,7 @@ void computeUpdateReplicateStatusArgsContributed() { @Test void computeUpdateReplicateStatusArgsResultUploaded() { final int unexpectedWorkerWeight = 1; - final ChainContribution unexpectedChainContribution = new ChainContribution(); + final ChainContribution unexpectedChainContribution = ChainContribution.builder().build(); final String expectedResultLink = "resultLink"; final String expectedChainCallbackData = "chainCallbackData"; final TaskDescription expectedTaskDescription = TaskDescription.builder().build(); @@ -1472,7 +1472,7 @@ void computeUpdateReplicateStatusArgsResultUploaded() { @Test void computeUpdateReplicateStatusArgsResultUploadFailed() { final int unexpectedWorkerWeight = 1; - final ChainContribution unexpectedChainContribution = new ChainContribution(); + final ChainContribution unexpectedChainContribution = ChainContribution.builder().build(); final String unexpectedResultLink = "resultLink"; final String unexpectedChainCallbackData = "chainCallbackData"; final TaskDescription expectedTaskDescription = TaskDescription.builder().build(); diff --git a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java index eb82b0c74..6df4977e4 100644 --- a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java +++ b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java @@ -119,7 +119,7 @@ void shouldNotUpgrade2ReopenedSinceCurrentStatusWrong() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(true); when(iexecHubService.hasEnoughGas()).thenReturn(true); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); taskUpdateManager.consensusReached2Reopening(task); @@ -136,7 +136,7 @@ void shouldNotUpgrade2ReopenedSinceNotAfterRevealDeadline() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(true); when(iexecHubService.hasEnoughGas()).thenReturn(true); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); taskUpdateManager.consensusReached2Reopening(task); @@ -153,7 +153,7 @@ void shouldNotUpgrade2ReopenedSinceNotWeHaveSomeRevealed() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(true); when(iexecHubService.hasEnoughGas()).thenReturn(true); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); taskUpdateManager.consensusReached2Reopening(task); @@ -170,7 +170,7 @@ void shouldNotUpgrade2ReopenedSinceCantReopenOnChain() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(false); when(iexecHubService.hasEnoughGas()).thenReturn(true); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); taskUpdateManager.consensusReached2Reopening(task); @@ -187,7 +187,7 @@ void shouldNotUpgrade2ReopenedSinceNotEnoughtGas() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(true); when(iexecHubService.hasEnoughGas()).thenReturn(false); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); taskUpdateManager.consensusReached2Reopening(task); @@ -224,7 +224,7 @@ void shouldUpgrade2Reopened() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(true); when(iexecHubService.hasEnoughGas()).thenReturn(true); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); when(iexecHubService.getChainTask(CHAIN_TASK_ID)).thenReturn(Optional.of(ChainTask.builder() .status(ChainTaskStatus.ACTIVE) .build())); From ec016c6eeb9708efc0cfdcdd9e06af45e3c7a848 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 25 May 2023 13:53:12 +0200 Subject: [PATCH 52/77] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9375276c7..a1436e77e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. - Add purge cached task descriptions ability. (#587) ### Bug Fixes - Prevent race condition on replicate update. (#568) +- Ue builders in test classes. (#589) ### Quality - Remove unused methods in `IexecHubService`. (#572) - Clean unused Replicate methods and update tests. (#573) From 9360cc5e7789520348a58be695002d6e1a0cdd2c Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 25 May 2023 13:55:43 +0200 Subject: [PATCH 53/77] Update CHANGELOG.md Co-authored-by: Maxence Cornaton <87655102+mcornaton@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1436e77e..f9afa0055 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ All notable changes to this project will be documented in this file. - Add purge cached task descriptions ability. (#587) ### Bug Fixes - Prevent race condition on replicate update. (#568) -- Ue builders in test classes. (#589) +- Use builders in test classes. (#589) ### Quality - Remove unused methods in `IexecHubService`. (#572) - Clean unused Replicate methods and update tests. (#573) From 540893e46b835e3755ae3dfb3f6f5dfcb247e768 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 25 May 2023 10:49:02 +0200 Subject: [PATCH 54/77] Move methods to get event blocks from `iexec-commons-poco` to `iexec-core` --- CHANGELOG.md | 1 + .../com/iexec/core/chain/IexecHubService.java | 132 ++++++++++++++++++ 2 files changed, 133 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9afa0055..c87092d42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file. - Refactor unnotified detectors to avoid code duplication. (#580) - Use `==` or `!=` operators to test the equality of enums. (#584) - Rearrange checks order to avoid call to database. (#585) +- Move methods to get event blocks from `iexec-commons-poco`. (#588) ### Dependency Upgrades - Upgrade to `iexec-common` 8.1.0-NEXT-SNAPSHOT. (#571 #575 #586) - Add new `iexec-commons-poco` 2.0.1 dependency. (#571 #574 #586 #587) diff --git a/src/main/java/com/iexec/core/chain/IexecHubService.java b/src/main/java/com/iexec/core/chain/IexecHubService.java index aee5172b0..f3228fcf1 100644 --- a/src/main/java/com/iexec/core/chain/IexecHubService.java +++ b/src/main/java/com/iexec/core/chain/IexecHubService.java @@ -19,12 +19,17 @@ import com.iexec.common.lifecycle.purge.Purgeable; import com.iexec.commons.poco.chain.*; import com.iexec.commons.poco.contract.generated.IexecHubContract; +import com.iexec.commons.poco.utils.BytesUtils; import io.reactivex.Flowable; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.web3j.abi.EventEncoder; +import org.web3j.abi.datatypes.Event; +import org.web3j.protocol.core.DefaultBlockParameter; import org.web3j.protocol.core.methods.request.EthFilter; import org.web3j.protocol.core.methods.response.TransactionReceipt; +import java.math.BigInteger; import java.util.Date; import java.util.List; import java.util.Optional; @@ -34,6 +39,8 @@ import java.util.concurrent.ThreadPoolExecutor; import static com.iexec.common.utils.DateTimeUtils.now; +import static com.iexec.commons.poco.contract.generated.IexecHubContract.*; +import static com.iexec.commons.poco.contract.generated.IexecHubContract.TASKFINALIZE_EVENT; import static com.iexec.commons.poco.utils.BytesUtils.stringToBytes; @Slf4j @@ -248,6 +255,131 @@ private ChainReceipt buildChainReceipt(TransactionReceipt receipt) { .build(); } + // region Get event blocks + public ChainReceipt getContributionBlock(String chainTaskId, String workerWallet, + long fromBlock) { + long latestBlock = web3jService.getLatestBlockNumber(); + if (fromBlock > latestBlock) { + return ChainReceipt.builder().build(); + } + + IexecHubContract iexecHub = getHubContract(); + EthFilter ethFilter = createContributeEthFilter(fromBlock, latestBlock); + + // filter only taskContribute events for the chainTaskId and the worker's wallet + // and retrieve the block number of the event + return iexecHub.taskContributeEventFlowable(ethFilter) + .filter(eventResponse -> + chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid)) && + workerWallet.equals(eventResponse.worker) + ) + .map(eventResponse -> ChainReceipt.builder() + .blockNumber(eventResponse.log.getBlockNumber().longValue()) + .txHash(eventResponse.log.getTransactionHash()) + .build()) + .blockingFirst(); + } + + public ChainReceipt getConsensusBlock(String chainTaskId, long fromBlock) { + long latestBlock = web3jService.getLatestBlockNumber(); + if (fromBlock > latestBlock) { + return ChainReceipt.builder().build(); + } + IexecHubContract iexecHub = getHubContract(); + EthFilter ethFilter = createConsensusEthFilter(fromBlock, latestBlock); + + // filter only taskConsensus events for the chainTaskId (there should be only one) + // and retrieve the block number of the event + return iexecHub.taskConsensusEventFlowable(ethFilter) + .filter(eventResponse -> chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid))) + .map(eventResponse -> ChainReceipt.builder() + .blockNumber(eventResponse.log.getBlockNumber().longValue()) + .txHash(eventResponse.log.getTransactionHash()) + .build()) + .blockingFirst(); + } + + public ChainReceipt getRevealBlock(String chainTaskId, String workerWallet, + long fromBlock) { + long latestBlock = web3jService.getLatestBlockNumber(); + if (fromBlock > latestBlock) { + return ChainReceipt.builder().build(); + } + + IexecHubContract iexecHub = getHubContract(); + EthFilter ethFilter = createRevealEthFilter(fromBlock, latestBlock); + + // filter only taskReveal events for the chainTaskId and the worker's wallet + // and retrieve the block number of the event + return iexecHub.taskRevealEventFlowable(ethFilter) + .filter(eventResponse -> + chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid)) && + workerWallet.equals(eventResponse.worker) + ) + .map(eventResponse -> ChainReceipt.builder() + .blockNumber(eventResponse.log.getBlockNumber().longValue()) + .txHash(eventResponse.log.getTransactionHash()) + .build()) + .blockingFirst(); + } + + public ChainReceipt getFinalizeBlock(String chainTaskId, long fromBlock) { + long latestBlock = web3jService.getLatestBlockNumber(); + if (fromBlock > latestBlock) { + return ChainReceipt.builder().build(); + } + + IexecHubContract iexecHub = getHubContract(); + EthFilter ethFilter = createFinalizeEthFilter(fromBlock, latestBlock); + + // filter only taskFinalize events for the chainTaskId (there should be only one) + // and retrieve the block number of the event + return iexecHub.taskFinalizeEventFlowable(ethFilter) + .filter(eventResponse -> + chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid)) + ) + .map(eventResponse -> ChainReceipt.builder() + .blockNumber(eventResponse.log.getBlockNumber().longValue()) + .txHash(eventResponse.log.getTransactionHash()) + .build()) + .blockingFirst(); + } + + private EthFilter createContributeEthFilter(long fromBlock, long toBlock) { + return createEthFilter(fromBlock, toBlock, TASKCONTRIBUTE_EVENT); + } + + private EthFilter createConsensusEthFilter(long fromBlock, long toBlock) { + return createEthFilter(fromBlock, toBlock, TASKCONSENSUS_EVENT); + } + + private EthFilter createRevealEthFilter(long fromBlock, long toBlock) { + return createEthFilter(fromBlock, toBlock, TASKREVEAL_EVENT); + } + + private EthFilter createFinalizeEthFilter(long fromBlock, long toBlock) { + return createEthFilter(fromBlock, toBlock, TASKFINALIZE_EVENT); + } + + private EthFilter createEthFilter(long fromBlock, long toBlock, Event event) { + IexecHubContract iexecHub = getHubContract(); + DefaultBlockParameter startBlock = + DefaultBlockParameter.valueOf(BigInteger.valueOf(fromBlock)); + DefaultBlockParameter endBlock = + DefaultBlockParameter.valueOf(BigInteger.valueOf(toBlock)); + + // define the filter + EthFilter ethFilter = new EthFilter( + startBlock, + endBlock, + iexecHub.getContractAddress() + ); + ethFilter.addSingleTopic(EventEncoder.encode(event)); + + return ethFilter; + } + // endregion + @Override public boolean purgeTask(String chainTaskId) { return super.purgeTask(chainTaskId); From 9b5499944ebfe0d7a2522e62b5380e2c3b5bbea1 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 25 May 2023 11:25:49 +0200 Subject: [PATCH 55/77] Upgrade to `iexec-commons-poco@2.0.1-NEXT-SNAPSHOT` --- CHANGELOG.md | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c87092d42..758ffbe6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ All notable changes to this project will be documented in this file. - Move methods to get event blocks from `iexec-commons-poco`. (#588) ### Dependency Upgrades - Upgrade to `iexec-common` 8.1.0-NEXT-SNAPSHOT. (#571 #575 #586) -- Add new `iexec-commons-poco` 2.0.1 dependency. (#571 #574 #586 #587) +- Add new `iexec-commons-poco` 2.0.1-NEXT-SNAPSHOT dependency. (#571 #574 #586 #587 #588) ## [[8.0.1]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.0.1) 2023-03-20 diff --git a/gradle.properties b/gradle.properties index 92010b360..c5ca6f7cb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ version=8.0.1 iexecCommonVersion=8.1.0-NEXT-SNAPSHOT -iexecCommonsPocoVersion=2.0.1 +iexecCommonsPocoVersion=2.0.1-NEXT-SNAPSHOT iexecBlockchainAdapterVersion=8.0.1-NEXT-SNAPSHOT iexecResultVersion=8.0.0-NEXT-SNAPSHOT iexecSmsVersion=8.0.0-NEXT-SNAPSHOT From 5b3bcef21aa36feb5c93faed87c3d9b8f991f5c3 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 25 May 2023 15:41:22 +0200 Subject: [PATCH 56/77] Add tests on event block getters --- .../com/iexec/core/chain/IexecHubService.java | 6 +- .../core/chain/IexecHubServiceTests.java | 169 ++++++++++++++++++ 2 files changed, 173 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/iexec/core/chain/IexecHubService.java b/src/main/java/com/iexec/core/chain/IexecHubService.java index f3228fcf1..80fc4182c 100644 --- a/src/main/java/com/iexec/core/chain/IexecHubService.java +++ b/src/main/java/com/iexec/core/chain/IexecHubService.java @@ -256,7 +256,8 @@ private ChainReceipt buildChainReceipt(TransactionReceipt receipt) { } // region Get event blocks - public ChainReceipt getContributionBlock(String chainTaskId, String workerWallet, + public ChainReceipt getContributionBlock(String chainTaskId, + String workerWallet, long fromBlock) { long latestBlock = web3jService.getLatestBlockNumber(); if (fromBlock > latestBlock) { @@ -299,7 +300,8 @@ public ChainReceipt getConsensusBlock(String chainTaskId, long fromBlock) { .blockingFirst(); } - public ChainReceipt getRevealBlock(String chainTaskId, String workerWallet, + public ChainReceipt getRevealBlock(String chainTaskId, + String workerWallet, long fromBlock) { long latestBlock = web3jService.getLatestBlockNumber(); if (fromBlock > latestBlock) { diff --git a/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java index f4f92921a..d116f7ef7 100644 --- a/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java +++ b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java @@ -1,10 +1,15 @@ package com.iexec.core.chain; +import com.iexec.commons.poco.chain.ChainReceipt; import com.iexec.commons.poco.chain.ChainTask; import com.iexec.commons.poco.chain.ChainTaskStatus; import com.iexec.commons.poco.contract.generated.IexecHubContract; +import com.iexec.commons.poco.utils.BytesUtils; +import io.reactivex.Flowable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; @@ -12,18 +17,24 @@ import org.web3j.crypto.Credentials; import org.web3j.crypto.Keys; import org.web3j.protocol.core.RemoteFunctionCall; +import org.web3j.protocol.core.methods.response.Log; import org.web3j.tx.TransactionManager; import java.math.BigInteger; import java.util.Optional; +import java.util.function.BiFunction; +import java.util.stream.Stream; import static com.iexec.commons.poco.utils.TestUtils.CHAIN_TASK_ID; +import static com.iexec.commons.poco.utils.TestUtils.WORKER_ADDRESS; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; class IexecHubServiceTests { + private static final String TRANSACTION_HASH = "transactionHash"; + @Mock private CredentialsService credentialsService; @@ -72,4 +83,162 @@ void shouldTaskNotBeInCompletedStatusOnChain() { assertThat(iexecHubService.isTaskInCompletedStatusOnChain(CHAIN_TASK_ID)).isFalse(); } + + // region Get event blocks + @Test + void shouldGetContributionBlock() { + final int fromBlock = 0; + final long latestBlock = 1; + when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); + + final IexecHubContract hubContract = mock(IexecHubContract.class); + doReturn(hubContract).when(iexecHubService).getHubContract(); + + final IexecHubContract.TaskContributeEventResponse taskContributeEventResponse = getTaskContributeEventResponse(latestBlock); + when(hubContract.taskContributeEventFlowable(any())) + .thenReturn(Flowable.fromArray(taskContributeEventResponse)); + + final ChainReceipt chainReceipt = iexecHubService.getContributionBlock(CHAIN_TASK_ID, WORKER_ADDRESS, fromBlock); + + assertThat(chainReceipt) + .usingRecursiveComparison() + .isEqualTo(ChainReceipt.builder() + .blockNumber(latestBlock) + .txHash(TRANSACTION_HASH) + .build()); + } + + private static IexecHubContract.TaskContributeEventResponse getTaskContributeEventResponse(long latestBlock) { + final IexecHubContract.TaskContributeEventResponse taskContributeEventResponse = + new IexecHubContract.TaskContributeEventResponse(); + taskContributeEventResponse.taskid = BytesUtils.stringToBytes(CHAIN_TASK_ID); + taskContributeEventResponse.worker = WORKER_ADDRESS; + taskContributeEventResponse.log = new Log(); + taskContributeEventResponse.log.setBlockNumber(String.valueOf(latestBlock)); + taskContributeEventResponse.log.setTransactionHash(TRANSACTION_HASH); + return taskContributeEventResponse; + } + + @Test + void shouldGetConsensusBlock() { + final int fromBlock = 0; + final long latestBlock = 1; + when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); + + final IexecHubContract hubContract = mock(IexecHubContract.class); + doReturn(hubContract).when(iexecHubService).getHubContract(); + + final IexecHubContract.TaskConsensusEventResponse taskConsensusEventResponse = getTaskConsensusEventResponse(latestBlock); + when(hubContract.taskConsensusEventFlowable(any())) + .thenReturn(Flowable.fromArray(taskConsensusEventResponse)); + + final ChainReceipt chainReceipt = iexecHubService.getConsensusBlock(CHAIN_TASK_ID, fromBlock); + + assertThat(chainReceipt) + .usingRecursiveComparison() + .isEqualTo(ChainReceipt.builder() + .blockNumber(latestBlock) + .txHash(TRANSACTION_HASH) + .build()); + } + + private static IexecHubContract.TaskConsensusEventResponse getTaskConsensusEventResponse(long latestBlock) { + final IexecHubContract.TaskConsensusEventResponse taskContributeEventResponse = + new IexecHubContract.TaskConsensusEventResponse(); + taskContributeEventResponse.taskid = BytesUtils.stringToBytes(CHAIN_TASK_ID); + taskContributeEventResponse.log = new Log(); + taskContributeEventResponse.log.setBlockNumber(String.valueOf(latestBlock)); + taskContributeEventResponse.log.setTransactionHash(TRANSACTION_HASH); + return taskContributeEventResponse; + } + + @Test + void shouldGetRevealBlock() { + final int fromBlock = 0; + final long latestBlock = 1; + when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); + + final IexecHubContract hubContract = mock(IexecHubContract.class); + doReturn(hubContract).when(iexecHubService).getHubContract(); + + final IexecHubContract.TaskRevealEventResponse taskRevealEventResponse = getTaskRevealEventResponse(latestBlock); + when(hubContract.taskRevealEventFlowable(any())) + .thenReturn(Flowable.fromArray(taskRevealEventResponse)); + + final ChainReceipt chainReceipt = iexecHubService.getRevealBlock(CHAIN_TASK_ID, WORKER_ADDRESS, fromBlock); + + assertThat(chainReceipt) + .usingRecursiveComparison() + .isEqualTo(ChainReceipt.builder() + .blockNumber(latestBlock) + .txHash(TRANSACTION_HASH) + .build()); + } + + private static IexecHubContract.TaskRevealEventResponse getTaskRevealEventResponse(long latestBlock) { + final IexecHubContract.TaskRevealEventResponse taskContributeEventResponse = + new IexecHubContract.TaskRevealEventResponse(); + taskContributeEventResponse.taskid = BytesUtils.stringToBytes(CHAIN_TASK_ID); + taskContributeEventResponse.worker = WORKER_ADDRESS; + taskContributeEventResponse.log = new Log(); + taskContributeEventResponse.log.setBlockNumber(String.valueOf(latestBlock)); + taskContributeEventResponse.log.setTransactionHash(TRANSACTION_HASH); + return taskContributeEventResponse; + } + + @Test + void shouldGetFinalizeBlock() { + final int fromBlock = 0; + final long latestBlock = 1; + when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); + + final IexecHubContract hubContract = mock(IexecHubContract.class); + doReturn(hubContract).when(iexecHubService).getHubContract(); + + final IexecHubContract.TaskFinalizeEventResponse taskFinalizeEventResponse = getTaskFinalizeEventResponse(latestBlock); + when(hubContract.taskFinalizeEventFlowable(any())) + .thenReturn(Flowable.fromArray(taskFinalizeEventResponse)); + + final ChainReceipt chainReceipt = iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, fromBlock); + + assertThat(chainReceipt) + .usingRecursiveComparison() + .isEqualTo(ChainReceipt.builder() + .blockNumber(latestBlock) + .txHash(TRANSACTION_HASH) + .build()); + } + + private static IexecHubContract.TaskFinalizeEventResponse getTaskFinalizeEventResponse(long latestBlock) { + final IexecHubContract.TaskFinalizeEventResponse taskContributeEventResponse = + new IexecHubContract.TaskFinalizeEventResponse(); + taskContributeEventResponse.taskid = BytesUtils.stringToBytes(CHAIN_TASK_ID); + taskContributeEventResponse.log = new Log(); + taskContributeEventResponse.log.setBlockNumber(String.valueOf(latestBlock)); + taskContributeEventResponse.log.setTransactionHash(TRANSACTION_HASH); + return taskContributeEventResponse; + } + + static Stream> eventBlockGetters() { + return Stream.of( + (iexecHubService, fromBlock) -> iexecHubService.getContributionBlock(CHAIN_TASK_ID, WORKER_ADDRESS, fromBlock), + (iexecHubService, fromBlock) -> iexecHubService.getConsensusBlock(CHAIN_TASK_ID, fromBlock), + (iexecHubService, fromBlock) -> iexecHubService.getRevealBlock(CHAIN_TASK_ID, WORKER_ADDRESS, fromBlock), + (iexecHubService, fromBlock) -> iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, fromBlock) + ); + } + + @ParameterizedTest + @MethodSource("eventBlockGetters") + void shouldNotGetEventBlockWhenFromBlockInFuture(BiFunction eventBlockGetter) { + final long fromBlock = 2; + final long latestBlock = 1; + when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); + + final ChainReceipt chainReceipt = eventBlockGetter.apply(iexecHubService, fromBlock); + assertThat(chainReceipt) + .usingRecursiveComparison() + .isEqualTo(ChainReceipt.builder().build()); + } + // endregion } From 4dfbe6b86817c49346bc3cd9da57e590a47f90ce Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 25 May 2023 17:00:35 +0200 Subject: [PATCH 57/77] Remove `.usingRecursiveComparison` --- src/test/java/com/iexec/core/chain/IexecHubServiceTests.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java index d116f7ef7..9f42a67f4 100644 --- a/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java +++ b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java @@ -101,7 +101,6 @@ void shouldGetContributionBlock() { final ChainReceipt chainReceipt = iexecHubService.getContributionBlock(CHAIN_TASK_ID, WORKER_ADDRESS, fromBlock); assertThat(chainReceipt) - .usingRecursiveComparison() .isEqualTo(ChainReceipt.builder() .blockNumber(latestBlock) .txHash(TRANSACTION_HASH) @@ -135,7 +134,6 @@ void shouldGetConsensusBlock() { final ChainReceipt chainReceipt = iexecHubService.getConsensusBlock(CHAIN_TASK_ID, fromBlock); assertThat(chainReceipt) - .usingRecursiveComparison() .isEqualTo(ChainReceipt.builder() .blockNumber(latestBlock) .txHash(TRANSACTION_HASH) @@ -168,7 +166,6 @@ void shouldGetRevealBlock() { final ChainReceipt chainReceipt = iexecHubService.getRevealBlock(CHAIN_TASK_ID, WORKER_ADDRESS, fromBlock); assertThat(chainReceipt) - .usingRecursiveComparison() .isEqualTo(ChainReceipt.builder() .blockNumber(latestBlock) .txHash(TRANSACTION_HASH) @@ -202,7 +199,6 @@ void shouldGetFinalizeBlock() { final ChainReceipt chainReceipt = iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, fromBlock); assertThat(chainReceipt) - .usingRecursiveComparison() .isEqualTo(ChainReceipt.builder() .blockNumber(latestBlock) .txHash(TRANSACTION_HASH) @@ -237,7 +233,6 @@ void shouldNotGetEventBlockWhenFromBlockInFuture(BiFunction Date: Thu, 25 May 2023 13:25:00 +0200 Subject: [PATCH 58/77] Add `ContributionAndFinalizationUnnotifiedDetector` --- CHANGELOG.md | 1 + .../core/configuration/CronConfiguration.java | 3 + ...tionAndFinalizationUnnotifiedDetector.java | 54 +++++ .../replicate/UnnotifiedAbstractDetector.java | 21 +- src/main/resources/application.yml | 19 +- ...ndFinalizationUnnotifiedDetectorTests.java | 205 ++++++++++++++++++ 6 files changed, 285 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetector.java create mode 100644 src/test/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetectorTests.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 758ffbe6e..ae2690756 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - Add `running2Finalized2Completed` in `TaskUpdateManager`. (#577 #578) - Disable `contributeAndFinalize` with CallBack. (#579 #581) - Add purge cached task descriptions ability. (#587) +- Add `ContributionAndFinalizationUnnotifiedDetector`. (#590) ### Bug Fixes - Prevent race condition on replicate update. (#568) - Use builders in test classes. (#589) diff --git a/src/main/java/com/iexec/core/configuration/CronConfiguration.java b/src/main/java/com/iexec/core/configuration/CronConfiguration.java index 58a0a0be0..3dd5656f8 100644 --- a/src/main/java/com/iexec/core/configuration/CronConfiguration.java +++ b/src/main/java/com/iexec/core/configuration/CronConfiguration.java @@ -26,6 +26,9 @@ public class CronConfiguration { @Value("${cron.detector.chain.reveal}") private int reveal; + @Value("${cron.detector.chain.contribute-and-finalize}") + private int contributeAndFinalize; + @Value("${cron.detector.chain.finalize}") private int finalize; diff --git a/src/main/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetector.java b/src/main/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetector.java new file mode 100644 index 000000000..d4eabe5dc --- /dev/null +++ b/src/main/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetector.java @@ -0,0 +1,54 @@ +/* + * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.iexec.core.detector.replicate; + +import com.iexec.common.replicate.ReplicateStatus; +import com.iexec.commons.poco.chain.ChainContributionStatus; +import com.iexec.core.chain.IexecHubService; +import com.iexec.core.configuration.CronConfiguration; +import com.iexec.core.replicate.ReplicatesService; +import com.iexec.core.task.TaskService; +import com.iexec.core.task.TaskStatus; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class ContributionAndFinalizationUnnotifiedDetector extends UnnotifiedAbstractDetector { + + public ContributionAndFinalizationUnnotifiedDetector(TaskService taskService, + ReplicatesService replicatesService, + IexecHubService iexecHubService, + CronConfiguration cronConfiguration) { + super( + taskService, + replicatesService, + iexecHubService, + TaskStatus.getWaitingContributionStatuses(), + ReplicateStatus.CONTRIBUTE_AND_FINALIZE_ONGOING, + ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE, + ChainContributionStatus.REVEALED, + cronConfiguration.getContributeAndFinalize()); + } + + @Override + @Scheduled(fixedRateString = "#{@cronConfiguration.getContributeAndFinalize()}") + public void detectOnChainChanges() { + super.detectOnChainChanges(); + } +} diff --git a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java index 0b5b5da68..bca1fb376 100644 --- a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java @@ -149,7 +149,7 @@ public void detectOnchainCompleted() { } /* - * This method should stay private. We need to insure that + * This method should stay private. We need to ensure that * it is only called by the POOL_MANAGER. * The POOL_MANAGER has already verified the status onchain * in the caller method so this update can happen even if @@ -169,30 +169,33 @@ private void updateReplicateStatuses(Task task, Replicate replicate) { for (ReplicateStatus statusToUpdate : statusesToUpdate) { // add details to the update if needed + ReplicateStatusDetails details = null; switch (statusToUpdate) { case CONTRIBUTED: // retrieve the contribution block for that wallet final ChainReceipt contributedBlock = iexecHubService.getContributionBlock(chainTaskId, wallet, initBlockNumber); final long contributedBlockNumber = contributedBlock != null ? contributedBlock.getBlockNumber() : 0; - replicatesService.updateReplicateStatus(chainTaskId, wallet, - statusToUpdate, new ReplicateStatusDetails(contributedBlockNumber)); + details = new ReplicateStatusDetails(contributedBlockNumber); break; case REVEALED: // retrieve the reveal block for that wallet final ChainReceipt revealedBlock = iexecHubService.getRevealBlock(chainTaskId, wallet, initBlockNumber); final long revealedBlockNumber = revealedBlock != null ? revealedBlock.getBlockNumber() : 0; - replicatesService.updateReplicateStatus(chainTaskId, wallet, - statusToUpdate, new ReplicateStatusDetails(revealedBlockNumber)); + details = new ReplicateStatusDetails(revealedBlockNumber); + break; + case CONTRIBUTE_AND_FINALIZE_DONE: + // retrieve the finalize block + final ChainReceipt finalizeBlock = iexecHubService.getFinalizeBlock(chainTaskId, initBlockNumber); + final long finalizeBlockNumber = finalizeBlock != null ? finalizeBlock.getBlockNumber() : 0; + details = new ReplicateStatusDetails(finalizeBlockNumber); break; default: // by default, no need to retrieve anything - replicatesService.updateReplicateStatus(chainTaskId, wallet, statusToUpdate); - + break; } - - + replicatesService.updateReplicateStatus(chainTaskId, wallet, statusToUpdate, details); } } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8aa0c0724..851d395f4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -21,18 +21,19 @@ cron: # all in milliseconds deal.replay: 60000 # 1m detector: - worker-lost: 30000 # 30s + worker-lost: 30000 # 30s chain: - unstarted-tx: 300000 # 5m - initialize: 30000 # 30s - contribute: 30000 # 30s - reveal: 30000 # 30s - finalize: 30000 # 30s - final-deadline: 30000 # 30s + unstarted-tx: 300000 # 5m + initialize: 30000 # 30s + contribute: 30000 # 30s + reveal: 30000 # 30s + contribute-and-finalize: 30000 # 30s + finalize: 30000 # 30s + final-deadline: 30000 # 30s timeout: - contribute: 120000 # 2m + contribute: 120000 # 2m reveal: ${REVEAL_TIMEOUT_PERIOD:120000} # 2m - result-upload: 30000 # 30s + result-upload: 30000 # 30s workers: askForReplicatePeriod: ${IEXEC_ASK_REPLICATE_PERIOD:5000} diff --git a/src/test/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetectorTests.java b/src/test/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetectorTests.java new file mode 100644 index 000000000..53c58a39b --- /dev/null +++ b/src/test/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetectorTests.java @@ -0,0 +1,205 @@ +package com.iexec.core.detector.replicate; + +import com.iexec.common.replicate.ReplicateStatusDetails; +import com.iexec.common.replicate.ReplicateStatusUpdate; +import com.iexec.commons.poco.chain.ChainContributionStatus; +import com.iexec.commons.poco.chain.ChainReceipt; +import com.iexec.core.chain.IexecHubService; +import com.iexec.core.chain.Web3jService; +import com.iexec.core.configuration.CronConfiguration; +import com.iexec.core.replicate.Replicate; +import com.iexec.core.replicate.ReplicatesService; +import com.iexec.core.task.Task; +import com.iexec.core.task.TaskService; +import com.iexec.core.task.TaskStatus; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.*; + +import java.util.Arrays; +import java.util.Collections; + +import static com.iexec.common.replicate.ReplicateStatus.*; +import static com.iexec.common.replicate.ReplicateStatusModifier.WORKER; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +class ContributionAndFinalizationUnnotifiedDetectorTests { + private final static String CHAIN_TASK_ID = "chainTaskId"; + private final static String WALLET_ADDRESS = "0x1"; + + @Mock + private TaskService taskService; + + @Mock + private ReplicatesService replicatesService; + + @Mock + public IexecHubService iexecHubService; + + @Mock + private CronConfiguration cronConfiguration; + + @Mock + private Web3jService web3jService; + + @Spy + @InjectMocks + private ContributionAndFinalizationUnnotifiedDetector detector; + + @BeforeEach + void init() { + MockitoAnnotations.openMocks(this); + } + + // Detector aggregator + @Test + void shouldDetectBothChangesOnChain() { + Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); + when(taskService.findByCurrentStatus(TaskStatus.getWaitingContributionStatuses())).thenReturn(Collections.singletonList(task)); + + Replicate replicate = new Replicate(WALLET_ADDRESS, CHAIN_TASK_ID); + ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder().status(CONTRIBUTE_AND_FINALIZE_ONGOING).modifier(WORKER).build(); + replicate.setStatusUpdateList(Collections.singletonList(statusUpdate)); + + when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate)); + when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true); + when(web3jService.getLatestBlockNumber()).thenReturn(11L); + when(iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, 0)) + .thenReturn(ChainReceipt.builder() + .blockNumber(10L) + .txHash("0xabcef") + .build() + ); + + for (int i = 0; i < 10; i++) { + detector.detectOnChainChanges(); + } + + Mockito.verify(replicatesService, Mockito.times(11)) // 10 detectors #1 & 1 detector #2 + .updateReplicateStatus( + eq(CHAIN_TASK_ID), + eq(WALLET_ADDRESS), + eq(CONTRIBUTE_AND_FINALIZE_DONE), + any(ReplicateStatusDetails.class) + ); + } + + + //Detector#1 after ContributeAndFinalize ongoing + + @Test + void shouldDetectUnNotifiedContributeAndFinalizeDoneAfterContributeAndFinalizeOngoing() { + Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); + when(taskService.findByCurrentStatus(Arrays.asList(TaskStatus.INITIALIZED, TaskStatus.RUNNING))).thenReturn(Collections.singletonList(task)); + + Replicate replicate = new Replicate(WALLET_ADDRESS, CHAIN_TASK_ID); + ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder().status(CONTRIBUTE_AND_FINALIZE_ONGOING).build(); + replicate.setStatusUpdateList(Collections.singletonList(statusUpdate)); + + when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate)); + when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true); + when(web3jService.getLatestBlockNumber()).thenReturn(11L); + when(iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, 0)) + .thenReturn(ChainReceipt.builder() + .blockNumber(10L) + .txHash("0xabcef") + .build() + ); + + detector.detectOnchainCompletedWhenOffchainCompleting(); + + Mockito.verify(replicatesService, Mockito.times(1)) // Missed CONTRIBUTE_AND_FINALIZE_DONE + .updateReplicateStatus( + eq(CHAIN_TASK_ID), + eq(WALLET_ADDRESS), + eq(CONTRIBUTE_AND_FINALIZE_DONE), + any(ReplicateStatusDetails.class) + ); + } + + @Test + void shouldDetectUnNotifiedContributeAndFinalizeDoneSinceBeforeContributeAndFinalizeOngoing() { + Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); + when(taskService.findByCurrentStatus(Arrays.asList(TaskStatus.INITIALIZED, TaskStatus.RUNNING))).thenReturn(Collections.singletonList(task)); + + Replicate replicate = new Replicate(WALLET_ADDRESS, CHAIN_TASK_ID); + ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder().status(COMPUTED).build(); + replicate.setStatusUpdateList(Collections.singletonList(statusUpdate)); + + when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate)); + when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true); + + detector.detectOnchainCompletedWhenOffchainCompleting(); + + Mockito.verify(replicatesService, Mockito.times(0)) + .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); + } + + @Test + void shouldNotDetectUnNotifiedContributeAndFinalizeDoneSinceNotFinalizedOnChain() { + Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); + when(taskService.findByCurrentStatus(Arrays.asList(TaskStatus.INITIALIZED, TaskStatus.RUNNING))).thenReturn(Collections.singletonList(task)); + + Replicate replicate = new Replicate(WALLET_ADDRESS, CHAIN_TASK_ID); + ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder().status(CONTRIBUTE_AND_FINALIZE_ONGOING).build(); + replicate.setStatusUpdateList(Collections.singletonList(statusUpdate)); + + when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate)); + when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(false); + detector.detectOnchainCompletedWhenOffchainCompleting(); + + Mockito.verify(replicatesService, Mockito.times(0)) + .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); + } + + + //Detector#2 + + @Test + void shouldDetectUnNotifiedContributeAndFinalizeOngoing() { + Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); + when(taskService.findByCurrentStatus(Arrays.asList(TaskStatus.INITIALIZED, TaskStatus.RUNNING))).thenReturn(Collections.singletonList(task)); + + Replicate replicate = new Replicate(WALLET_ADDRESS, CHAIN_TASK_ID); + ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder().status(CONTRIBUTE_AND_FINALIZE_ONGOING).build(); + replicate.setStatusUpdateList(Collections.singletonList(statusUpdate)); + + when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate)); + when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true); + when(web3jService.getLatestBlockNumber()).thenReturn(11L); + when(iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, 0)).thenReturn(ChainReceipt.builder() + .blockNumber(10L) + .txHash("0xabcef") + .build()); + + detector.detectOnchainCompleted(); + + Mockito.verify(replicatesService, Mockito.times(1)) // Missed CONTRIBUTE_AND_FINALIZE_DONE + .updateReplicateStatus( + eq(CHAIN_TASK_ID), + eq(WALLET_ADDRESS), + eq(CONTRIBUTE_AND_FINALIZE_DONE), + any(ReplicateStatusDetails.class) + ); + } + + @Test + void shouldNotDetectUnNotifiedContributedSinceContributeAndFinalizeDone() { + Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); + when(taskService.findByCurrentStatus(Arrays.asList(TaskStatus.INITIALIZED, TaskStatus.RUNNING))).thenReturn(Collections.singletonList(task)); + + Replicate replicate = new Replicate(WALLET_ADDRESS, CHAIN_TASK_ID); + ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder().status(CONTRIBUTE_AND_FINALIZE_DONE).build(); + replicate.setStatusUpdateList(Collections.singletonList(statusUpdate)); + + when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate)); + when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true); + detector.detectOnchainCompleted(); + + Mockito.verify(replicatesService, Mockito.times(0)) + .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); + } + +} From c9584e7b0d81ff3428020d0972bffb2537db03e0 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Tue, 30 May 2023 15:53:35 +0200 Subject: [PATCH 59/77] Update `IexecHubService` and `Web3jService` --- .../com/iexec/core/chain/IexecHubService.java | 19 ++++++++----------- .../com/iexec/core/chain/Web3jService.java | 11 ++++++++--- .../core/chain/IexecHubServiceTests.java | 9 +++++---- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/iexec/core/chain/IexecHubService.java b/src/main/java/com/iexec/core/chain/IexecHubService.java index 80fc4182c..cabb3bb98 100644 --- a/src/main/java/com/iexec/core/chain/IexecHubService.java +++ b/src/main/java/com/iexec/core/chain/IexecHubService.java @@ -217,13 +217,13 @@ public Optional reOpen(String chainTaskId) { private Optional sendReopenTransaction(String chainTaskId) { TransactionReceipt receipt; try { - receipt = getHubContract(web3jService.getWritingContractGasProvider()).reopen(stringToBytes(chainTaskId)).send(); + receipt = iexecHubContract.reopen(stringToBytes(chainTaskId)).send(); } catch (Exception e) { log.error("Failed reopen [chainTaskId:{}, error:{}]", chainTaskId, e.getMessage()); return Optional.empty(); } - List eventsList = getHubContract().getTaskReopenEvents(receipt); + List eventsList = IexecHubContract.getTaskReopenEvents(receipt); if (eventsList.isEmpty()) { log.error("Failed to get reopen event [chainTaskId:{}]", chainTaskId); return Optional.empty(); @@ -240,7 +240,7 @@ private long getWaitingTransactionCount() { } Flowable getDealEventObservable(EthFilter filter) { - return getHubContract().schedulerNoticeEventFlowable(filter); + return iexecHubContract.schedulerNoticeEventFlowable(filter); } public boolean hasEnoughGas() { @@ -264,12 +264,11 @@ public ChainReceipt getContributionBlock(String chainTaskId, return ChainReceipt.builder().build(); } - IexecHubContract iexecHub = getHubContract(); EthFilter ethFilter = createContributeEthFilter(fromBlock, latestBlock); // filter only taskContribute events for the chainTaskId and the worker's wallet // and retrieve the block number of the event - return iexecHub.taskContributeEventFlowable(ethFilter) + return iexecHubContract.taskContributeEventFlowable(ethFilter) .filter(eventResponse -> chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid)) && workerWallet.equals(eventResponse.worker) @@ -286,12 +285,12 @@ public ChainReceipt getConsensusBlock(String chainTaskId, long fromBlock) { if (fromBlock > latestBlock) { return ChainReceipt.builder().build(); } - IexecHubContract iexecHub = getHubContract(); + EthFilter ethFilter = createConsensusEthFilter(fromBlock, latestBlock); // filter only taskConsensus events for the chainTaskId (there should be only one) // and retrieve the block number of the event - return iexecHub.taskConsensusEventFlowable(ethFilter) + return iexecHubContract.taskConsensusEventFlowable(ethFilter) .filter(eventResponse -> chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid))) .map(eventResponse -> ChainReceipt.builder() .blockNumber(eventResponse.log.getBlockNumber().longValue()) @@ -308,12 +307,11 @@ public ChainReceipt getRevealBlock(String chainTaskId, return ChainReceipt.builder().build(); } - IexecHubContract iexecHub = getHubContract(); EthFilter ethFilter = createRevealEthFilter(fromBlock, latestBlock); // filter only taskReveal events for the chainTaskId and the worker's wallet // and retrieve the block number of the event - return iexecHub.taskRevealEventFlowable(ethFilter) + return iexecHubContract.taskRevealEventFlowable(ethFilter) .filter(eventResponse -> chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid)) && workerWallet.equals(eventResponse.worker) @@ -331,12 +329,11 @@ public ChainReceipt getFinalizeBlock(String chainTaskId, long fromBlock) { return ChainReceipt.builder().build(); } - IexecHubContract iexecHub = getHubContract(); EthFilter ethFilter = createFinalizeEthFilter(fromBlock, latestBlock); // filter only taskFinalize events for the chainTaskId (there should be only one) // and retrieve the block number of the event - return iexecHub.taskFinalizeEventFlowable(ethFilter) + return iexecHubContract.taskFinalizeEventFlowable(ethFilter) .filter(eventResponse -> chainTaskId.equals(BytesUtils.bytesToString(eventResponse.taskid)) ) diff --git a/src/main/java/com/iexec/core/chain/Web3jService.java b/src/main/java/com/iexec/core/chain/Web3jService.java index cc9af84bd..3c99fd18f 100644 --- a/src/main/java/com/iexec/core/chain/Web3jService.java +++ b/src/main/java/com/iexec/core/chain/Web3jService.java @@ -23,8 +23,13 @@ public class Web3jService extends Web3jAbstractService { public Web3jService(ChainConfig chainConfig) { - super(chainConfig.getPrivateChainAddress(), chainConfig.getGasPriceMultiplier(), chainConfig.getGasPriceCap(), - chainConfig.isSidechain()); + super( + chainConfig.getChainId(), + chainConfig.getPrivateChainAddress(), + chainConfig.getGasPriceMultiplier(), + chainConfig.getGasPriceCap(), + chainConfig.isSidechain() + ); } -} \ No newline at end of file +} diff --git a/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java index 9f42a67f4..9f0268e6a 100644 --- a/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java +++ b/src/test/java/com/iexec/core/chain/IexecHubServiceTests.java @@ -14,6 +14,7 @@ import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.springframework.test.util.ReflectionTestUtils; import org.web3j.crypto.Credentials; import org.web3j.crypto.Keys; import org.web3j.protocol.core.RemoteFunctionCall; @@ -92,7 +93,7 @@ void shouldGetContributionBlock() { when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); final IexecHubContract hubContract = mock(IexecHubContract.class); - doReturn(hubContract).when(iexecHubService).getHubContract(); + ReflectionTestUtils.setField(iexecHubService, "iexecHubContract", hubContract); final IexecHubContract.TaskContributeEventResponse taskContributeEventResponse = getTaskContributeEventResponse(latestBlock); when(hubContract.taskContributeEventFlowable(any())) @@ -125,7 +126,7 @@ void shouldGetConsensusBlock() { when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); final IexecHubContract hubContract = mock(IexecHubContract.class); - doReturn(hubContract).when(iexecHubService).getHubContract(); + ReflectionTestUtils.setField(iexecHubService, "iexecHubContract", hubContract); final IexecHubContract.TaskConsensusEventResponse taskConsensusEventResponse = getTaskConsensusEventResponse(latestBlock); when(hubContract.taskConsensusEventFlowable(any())) @@ -157,7 +158,7 @@ void shouldGetRevealBlock() { when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); final IexecHubContract hubContract = mock(IexecHubContract.class); - doReturn(hubContract).when(iexecHubService).getHubContract(); + ReflectionTestUtils.setField(iexecHubService, "iexecHubContract", hubContract); final IexecHubContract.TaskRevealEventResponse taskRevealEventResponse = getTaskRevealEventResponse(latestBlock); when(hubContract.taskRevealEventFlowable(any())) @@ -190,7 +191,7 @@ void shouldGetFinalizeBlock() { when(web3jService.getLatestBlockNumber()).thenReturn(latestBlock); final IexecHubContract hubContract = mock(IexecHubContract.class); - doReturn(hubContract).when(iexecHubService).getHubContract(); + ReflectionTestUtils.setField(iexecHubService, "iexecHubContract", hubContract); final IexecHubContract.TaskFinalizeEventResponse taskFinalizeEventResponse = getTaskFinalizeEventResponse(latestBlock); when(hubContract.taskFinalizeEventFlowable(any())) From 64033947dcd500a133fa487c780ea923868615df Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Tue, 30 May 2023 16:23:23 +0200 Subject: [PATCH 60/77] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae2690756..1c56a9c19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ All notable changes to this project will be documented in this file. - Move methods to get event blocks from `iexec-commons-poco`. (#588) ### Dependency Upgrades - Upgrade to `iexec-common` 8.1.0-NEXT-SNAPSHOT. (#571 #575 #586) -- Add new `iexec-commons-poco` 2.0.1-NEXT-SNAPSHOT dependency. (#571 #574 #586 #587 #588) +- Add new `iexec-commons-poco` 2.0.1-NEXT-SNAPSHOT dependency. (#571 #574 #586 #587 #588 #592) ## [[8.0.1]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.0.1) 2023-03-20 From 0854d3d2c00c558e88935c6c8fdd31cd3449fb7f Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Tue, 30 May 2023 15:26:35 +0200 Subject: [PATCH 61/77] Rename detectors' methods and fields to match Ongoing/Done standard --- CHANGELOG.md | 1 + .../replicate/UnnotifiedAbstractDetector.java | 56 +++++++++---------- .../task/listener/ReplicateListeners.java | 2 +- ...ndFinalizationUnnotifiedDetectorTests.java | 34 ++++++----- .../ContributionUnnotifiedDetectorTests.java | 37 +++++++----- .../RevealUnnotifiedDetectorTests.java | 36 +++++++----- .../replicate/ReplicateListenersTests.java | 6 +- 7 files changed, 98 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c56a9c19..a5a750683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file. - Use `==` or `!=` operators to test the equality of enums. (#584) - Rearrange checks order to avoid call to database. (#585) - Move methods to get event blocks from `iexec-commons-poco`. (#588) +- Rename detectors' methods and fields to match Ongoing/Done standard. (#591) ### Dependency Upgrades - Upgrade to `iexec-common` 8.1.0-NEXT-SNAPSHOT. (#571 #575 #586) - Add new `iexec-commons-poco` 2.0.1-NEXT-SNAPSHOT dependency. (#571 #574 #586 #587 #588 #592) diff --git a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java index bca1fb376..1340d70ad 100644 --- a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java @@ -42,9 +42,9 @@ public abstract class UnnotifiedAbstractDetector { private final IexecHubService iexecHubService; private final List detectWhenOffChainTaskStatuses; - private final ReplicateStatus offchainCompleting; - private final ReplicateStatus offchainCompleted; - private final ChainContributionStatus onchainCompleted; + private final ReplicateStatus offchainOngoing; + private final ReplicateStatus offchainDone; + private final ChainContributionStatus onchainOngoing; private final int detectorRate; private int detectorOccurrence = 0; @@ -53,63 +53,63 @@ protected UnnotifiedAbstractDetector(TaskService taskService, ReplicatesService replicatesService, IexecHubService iexecHubService, List detectWhenOffChainTaskStatuses, - ReplicateStatus offchainCompleting, - ReplicateStatus offchainCompleted, - ChainContributionStatus onchainCompleted, + ReplicateStatus offchainOngoing, + ReplicateStatus offchainDone, + ChainContributionStatus onchainOngoing, int detectorRate) { this.taskService = taskService; this.replicatesService = replicatesService; this.iexecHubService = iexecHubService; this.detectWhenOffChainTaskStatuses = detectWhenOffChainTaskStatuses; - this.offchainCompleting = offchainCompleting; - this.offchainCompleted = offchainCompleted; - this.onchainCompleted = onchainCompleted; + this.offchainOngoing = offchainOngoing; + this.offchainDone = offchainDone; + this.onchainOngoing = onchainOngoing; this.detectorRate = detectorRate; } /** * Detects the following issues: *
      - *
    • `onchainCompleted` status only if replicates are in `offchainCompleting` status;
    • - *
    • `onchainCompleted` if replicates are not in `offchainCompleted` status.
    • + *
    • `onchainDone` status only if replicates are in `offchainOngoing` status;
    • + *
    • `onchainDone` if replicates are not in `offchainDone` status.
    • *
* The second detection is not always ran, depending on the detector run occurrences. */ void detectOnChainChanges() { - detectOnchainCompletedWhenOffchainCompleting(); + detectOnchainDoneWhenOffchainOngoing(); detectorOccurrence++; if (detectorOccurrence % LESS_OFTEN_DETECTOR_FREQUENCY == 0) { - detectOnchainCompleted(); + detectOnchainDone(); } } /** - * Detecting onchain `offchainCompleted` status only if replicates are offchain `offchainCompleting` - * (worker didn't notify last offchain `offchainCompleted` status) + * Detecting onchain `offchainDone` status only if replicates are offchain `offchainOngoing` + * (worker didn't notify last offchain `offchainDone` status) * We want to detect them very often since it's highly probable */ - void detectOnchainCompletedWhenOffchainCompleting() { + void detectOnchainDoneWhenOffchainOngoing() { log.debug("Detect onchain {} (when offchain {}) [retryIn:{}]", - this.offchainCompleted, this.offchainCompleting, this.detectorRate); + this.offchainDone, this.offchainOngoing, this.detectorRate); for (Task task : taskService.findByCurrentStatus(detectWhenOffChainTaskStatuses)) { for (Replicate replicate : replicatesService.getReplicates(task.getChainTaskId())) { final ReplicateStatus lastRelevantStatus = replicate.getLastRelevantStatus(); - if (lastRelevantStatus != offchainCompleting) { + if (lastRelevantStatus != offchainOngoing) { continue; } final boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain( task.getChainTaskId(), replicate.getWalletAddress(), - onchainCompleted + onchainOngoing ); if (statusTrueOnChain) { log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]", - lastRelevantStatus, onchainCompleted, task.getChainTaskId()); + lastRelevantStatus, onchainOngoing, task.getChainTaskId()); updateReplicateStatuses(task, replicate); } } @@ -117,31 +117,31 @@ void detectOnchainCompletedWhenOffchainCompleting() { } /** - * Detecting `onchainCompleted` if replicates are not in `offchainCompleted` status + * Detecting `onchainDone` if replicates are not in `offchainDone` status * (worker didn't notify any status) * We want to detect them: * - Frequently but no so often since it's eth node resource consuming and less probable - * - When we receive a "can't do " relative to the `onchainCompleted` status (e.g.: `CANNOT_REVEAL`) + * - When we receive a "can't do " relative to the `onchainDone` status (e.g.: `CANNOT_REVEAL`) */ - public void detectOnchainCompleted() { - log.debug("Detect onchain {} [retryIn:{}]", onchainCompleted, this.detectorRate * LESS_OFTEN_DETECTOR_FREQUENCY); + public void detectOnchainDone() { + log.debug("Detect onchain {} [retryIn:{}]", onchainOngoing, this.detectorRate * LESS_OFTEN_DETECTOR_FREQUENCY); for (Task task : taskService.findByCurrentStatus(detectWhenOffChainTaskStatuses)) { for (Replicate replicate : replicatesService.getReplicates(task.getChainTaskId())) { final ReplicateStatus lastRelevantStatus = replicate.getLastRelevantStatus(); - if (lastRelevantStatus == offchainCompleted) { + if (lastRelevantStatus == offchainDone) { continue; } final boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain( task.getChainTaskId(), replicate.getWalletAddress(), - onchainCompleted + onchainOngoing ); if (statusTrueOnChain) { log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]", - lastRelevantStatus, onchainCompleted, task.getChainTaskId()); + lastRelevantStatus, onchainOngoing, task.getChainTaskId()); updateReplicateStatuses(task, replicate); } } @@ -163,7 +163,7 @@ private void updateReplicateStatuses(Task task, Replicate replicate) { final ReplicateStatus retrieveFrom = replicate.getCurrentStatus().equals(WORKER_LOST) ? replicate.getLastButOneStatus() : replicate.getCurrentStatus(); - final List statusesToUpdate = getMissingStatuses(retrieveFrom, offchainCompleted); + final List statusesToUpdate = getMissingStatuses(retrieveFrom, offchainDone); final String wallet = replicate.getWalletAddress(); diff --git a/src/main/java/com/iexec/core/task/listener/ReplicateListeners.java b/src/main/java/com/iexec/core/task/listener/ReplicateListeners.java index 47449f9da..53e86f68c 100644 --- a/src/main/java/com/iexec/core/task/listener/ReplicateListeners.java +++ b/src/main/java/com/iexec/core/task/listener/ReplicateListeners.java @@ -78,7 +78,7 @@ public void onReplicateUpdatedEvent(ReplicateUpdatedEvent event) { * task to consensus_reached */ if (cause != null && cause.equals(TASK_NOT_ACTIVE)) { - contributionUnnotifiedDetector.detectOnchainCompleted(); + contributionUnnotifiedDetector.detectOnchainDone(); } /* diff --git a/src/test/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetectorTests.java b/src/test/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetectorTests.java index 53c58a39b..f429d42ba 100644 --- a/src/test/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetectorTests.java @@ -1,5 +1,6 @@ package com.iexec.core.detector.replicate; +import com.iexec.common.replicate.ReplicateStatus; import com.iexec.common.replicate.ReplicateStatusDetails; import com.iexec.common.replicate.ReplicateStatusUpdate; import com.iexec.commons.poco.chain.ChainContributionStatus; @@ -53,7 +54,15 @@ void init() { MockitoAnnotations.openMocks(this); } - // Detector aggregator + // region Detector aggregator + /** + * When running {@link ContributionAndFinalizationUnnotifiedDetector#detectOnChainChanges} 10 times, + * {@link ReplicatesService#updateReplicateStatus(String, String, ReplicateStatus, ReplicateStatusDetails)} should be called 11 times: + *
    + *
  1. 10 times from {@link ContributionAndFinalizationUnnotifiedDetector#detectOnchainDoneWhenOffchainOngoing()};
  2. + *
  3. 1 time from {@link ContributionAndFinalizationUnnotifiedDetector#detectOnchainDone()}
  4. + *
+ */ @Test void shouldDetectBothChangesOnChain() { Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); @@ -77,7 +86,7 @@ void shouldDetectBothChangesOnChain() { detector.detectOnChainChanges(); } - Mockito.verify(replicatesService, Mockito.times(11)) // 10 detectors #1 & 1 detector #2 + Mockito.verify(replicatesService, Mockito.times(11)) .updateReplicateStatus( eq(CHAIN_TASK_ID), eq(WALLET_ADDRESS), @@ -85,10 +94,9 @@ void shouldDetectBothChangesOnChain() { any(ReplicateStatusDetails.class) ); } + // endregion - - //Detector#1 after ContributeAndFinalize ongoing - + //region detectOnchainDoneWhenOffchainOngoing (ContributeAndFinalizeOngoing) @Test void shouldDetectUnNotifiedContributeAndFinalizeDoneAfterContributeAndFinalizeOngoing() { Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); @@ -108,7 +116,7 @@ void shouldDetectUnNotifiedContributeAndFinalizeDoneAfterContributeAndFinalizeOn .build() ); - detector.detectOnchainCompletedWhenOffchainCompleting(); + detector.detectOnchainDoneWhenOffchainOngoing(); Mockito.verify(replicatesService, Mockito.times(1)) // Missed CONTRIBUTE_AND_FINALIZE_DONE .updateReplicateStatus( @@ -131,7 +139,7 @@ void shouldDetectUnNotifiedContributeAndFinalizeDoneSinceBeforeContributeAndFina when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true); - detector.detectOnchainCompletedWhenOffchainCompleting(); + detector.detectOnchainDoneWhenOffchainOngoing(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -148,15 +156,14 @@ void shouldNotDetectUnNotifiedContributeAndFinalizeDoneSinceNotFinalizedOnChain( when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(false); - detector.detectOnchainCompletedWhenOffchainCompleting(); + detector.detectOnchainDoneWhenOffchainOngoing(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); } + // endregion - - //Detector#2 - + //region detectOnchainDone (REVEALED) @Test void shouldDetectUnNotifiedContributeAndFinalizeOngoing() { Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); @@ -174,7 +181,7 @@ void shouldDetectUnNotifiedContributeAndFinalizeOngoing() { .txHash("0xabcef") .build()); - detector.detectOnchainCompleted(); + detector.detectOnchainDone(); Mockito.verify(replicatesService, Mockito.times(1)) // Missed CONTRIBUTE_AND_FINALIZE_DONE .updateReplicateStatus( @@ -196,10 +203,11 @@ void shouldNotDetectUnNotifiedContributedSinceContributeAndFinalizeDone() { when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true); - detector.detectOnchainCompleted(); + detector.detectOnchainDone(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); } + // endregion } diff --git a/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java b/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java index d8305c65f..26d99fcdc 100644 --- a/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java @@ -16,6 +16,7 @@ package com.iexec.core.detector.replicate; +import com.iexec.common.replicate.ReplicateStatus; import com.iexec.common.replicate.ReplicateStatusDetails; import com.iexec.common.replicate.ReplicateStatusUpdate; import com.iexec.commons.poco.chain.ChainReceipt; @@ -69,7 +70,15 @@ void init() { MockitoAnnotations.openMocks(this); } - // Detector aggregator + // region Detector aggregator + /** + * When running {@link ContributionUnnotifiedDetector#detectOnChainChanges} 10 times, + * {@link ReplicatesService#updateReplicateStatus(String, String, ReplicateStatus, ReplicateStatusDetails)} should be called 11 times: + *
    + *
  1. 10 times from {@link ContributionUnnotifiedDetector#detectOnchainDoneWhenOffchainOngoing()};
  2. + *
  3. 1 time from {@link ContributionUnnotifiedDetector#detectOnchainDone()}
  4. + *
+ */ @Test void shouldDetectBothChangesOnChain() { Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); @@ -91,13 +100,12 @@ void shouldDetectBothChangesOnChain() { contributionDetector.detectOnChainChanges(); } - Mockito.verify(replicatesService, Mockito.times(11)) // 10 detectors #1 & 1 detector #2 + Mockito.verify(replicatesService, Mockito.times(11)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); } + // endregion - - //Detector#1 after contributing - + //region detectOnchainDoneWhenOffchainOngoing (CONTRIBUTING) @Test void shouldDetectUnNotifiedContributedAfterContributing() { Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); @@ -114,7 +122,7 @@ void shouldDetectUnNotifiedContributedAfterContributing() { when(iexecHubService.getContributionBlock(anyString(), anyString(), anyLong())) .thenReturn(ChainReceipt.builder().blockNumber(10L).txHash("0xabcef").build()); - contributionDetector.detectOnchainCompletedWhenOffchainCompleting(); + contributionDetector.detectOnchainDoneWhenOffchainOngoing(); Mockito.verify(replicatesService, Mockito.times(1)) // Missed CONTRIBUTED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -133,7 +141,7 @@ void shouldDetectUnNotifiedContributedAfterContributingSinceBeforeContributing() when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true); - contributionDetector.detectOnchainCompletedWhenOffchainCompleting(); + contributionDetector.detectOnchainDoneWhenOffchainOngoing(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -151,15 +159,14 @@ void shouldNotDetectUnNotifiedContributedAfterContributingSinceNotContributedOnC // when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD); when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(false); - contributionDetector.detectOnchainCompletedWhenOffchainCompleting(); + contributionDetector.detectOnchainDoneWhenOffchainOngoing(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); } + // endregion - - //Detector#2 - + // region detectOnchainDone (CONTRIBUTED) @Test void shouldDetectUnNotifiedContributed1() { Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); @@ -178,7 +185,7 @@ void shouldDetectUnNotifiedContributed1() { .txHash("0xabcef") .build()); - contributionDetector.detectOnchainCompleted(); + contributionDetector.detectOnchainDone(); Mockito.verify(replicatesService, Mockito.times(1))//Missed CONTRIBUTED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -202,7 +209,7 @@ void shouldDetectUnNotifiedContributed2() { .txHash("0xabcef") .build()); - contributionDetector.detectOnchainCompleted(); + contributionDetector.detectOnchainDone(); Mockito.verify(replicatesService, Mockito.times(1))//Missed CONTRIBUTING & CONTRIBUTED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -220,10 +227,10 @@ void shouldNotDetectUnNotifiedContributedSinceContributed() { when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD); when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true); - contributionDetector.detectOnchainCompleted(); + contributionDetector.detectOnchainDone(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); } - + // endregion } diff --git a/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java b/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java index 99b8b8266..cfe6a05bf 100644 --- a/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/replicate/RevealUnnotifiedDetectorTests.java @@ -16,6 +16,7 @@ package com.iexec.core.detector.replicate; +import com.iexec.common.replicate.ReplicateStatus; import com.iexec.common.replicate.ReplicateStatusDetails; import com.iexec.common.replicate.ReplicateStatusUpdate; import com.iexec.commons.poco.chain.ChainReceipt; @@ -68,7 +69,15 @@ void init() { MockitoAnnotations.openMocks(this); } - // Detector aggregator + // region Detector aggregator + /** + * When running {@link RevealUnnotifiedDetector#detectOnChainChanges} 10 times, + * {@link ReplicatesService#updateReplicateStatus(String, String, ReplicateStatus, ReplicateStatusDetails)} should be called 11 times: + *
    + *
  1. 10 times from {@link RevealUnnotifiedDetector#detectOnchainDoneWhenOffchainOngoing()};
  2. + *
  3. 1 time from {@link RevealUnnotifiedDetector#detectOnchainDone()}
  4. + *
+ */ @Test void shouldDetectBothChangesOnChain() { Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); @@ -90,13 +99,12 @@ void shouldDetectBothChangesOnChain() { revealDetector.detectOnChainChanges(); } - Mockito.verify(replicatesService, Mockito.times(11)) // 10 detectors #1 & 1 detector #2 + Mockito.verify(replicatesService, Mockito.times(11)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); } + // endregion - - //Detector#1 after contributing - + //region detectOnchainDoneWhenOffchainOngoing (REVEALING) @Test void shouldDetectUnNotifiedRevealedAfterRevealing() { Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); @@ -115,7 +123,7 @@ void shouldDetectUnNotifiedRevealedAfterRevealing() { .txHash("0xabcef") .build()); - revealDetector.detectOnchainCompletedWhenOffchainCompleting(); + revealDetector.detectOnchainDoneWhenOffchainOngoing(); Mockito.verify(replicatesService, Mockito.times(1))//Missed REVEALED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -133,7 +141,7 @@ void shouldDetectUnNotifiedRevealedAfterRevealingSinceBeforeRevealing() { when(cronConfiguration.getReveal()).thenReturn(DETECTOR_PERIOD); when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true); - revealDetector.detectOnchainCompletedWhenOffchainCompleting(); + revealDetector.detectOnchainDoneWhenOffchainOngoing(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -150,15 +158,14 @@ void shouldNotDetectUnNotifiedRevealedAfterRevealingSinceNotRevealedOnChain() { when(cronConfiguration.getReveal()).thenReturn(DETECTOR_PERIOD); when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(false); - revealDetector.detectOnchainCompletedWhenOffchainCompleting(); + revealDetector.detectOnchainDoneWhenOffchainOngoing(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); } + // endregion - - //Detector#2 - + // region detectOnchainDone (REVEALED) @Test void shouldDetectUnNotifiedRevealed1() { Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build(); @@ -177,7 +184,7 @@ void shouldDetectUnNotifiedRevealed1() { .txHash("0xabcef") .build()); - revealDetector.detectOnchainCompleted(); + revealDetector.detectOnchainDone(); Mockito.verify(replicatesService, Mockito.times(1))//Missed REVEALED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -206,7 +213,7 @@ void shouldDetectUnNotifiedRevealed2() { .txHash("0xabcef") .build()); - revealDetector.detectOnchainCompleted(); + revealDetector.detectOnchainDone(); Mockito.verify(replicatesService, Mockito.times(1))//Missed REVEALING & REVEALED .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); @@ -224,9 +231,10 @@ void shouldNotDetectUnNotifiedRevealedSinceRevealed() { when(cronConfiguration.getReveal()).thenReturn(DETECTOR_PERIOD); when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate)); when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true); - revealDetector.detectOnchainCompleted(); + revealDetector.detectOnchainDone(); Mockito.verify(replicatesService, Mockito.times(0)) .updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class)); } + // endregion } diff --git a/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java b/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java index c250bc7c4..a457f154d 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateListenersTests.java @@ -118,7 +118,7 @@ void shouldTriggerDetectOnchainContributedSinceTaskNotActive() { replicateListeners.onReplicateUpdatedEvent(replicateUpdatedEvent); - Mockito.verify(contributionUnnotifiedDetector, Mockito.times(1)).detectOnchainCompleted(); + Mockito.verify(contributionUnnotifiedDetector, Mockito.times(1)).detectOnchainDone(); } @Test @@ -132,7 +132,7 @@ void shouldNotTriggerDetectOnchain() { replicateListeners.onReplicateUpdatedEvent(replicateUpdatedEvent); } - Mockito.verify(contributionUnnotifiedDetector, Mockito.times(0)).detectOnchainCompleted(); + Mockito.verify(contributionUnnotifiedDetector, Mockito.times(0)).detectOnchainDone(); } @Test @@ -145,7 +145,7 @@ void shouldNotTriggerDetectOnchainContributedSinceCauseIsNull() { replicateListeners.onReplicateUpdatedEvent(replicateUpdatedEvent); - Mockito.verify(contributionUnnotifiedDetector, Mockito.times(0)).detectOnchainCompleted(); + Mockito.verify(contributionUnnotifiedDetector, Mockito.times(0)).detectOnchainDone(); } static Stream getUncompletableStatuses() { From b9875c736d53b7af1a57a1945a89f9cc8cb497bc Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Tue, 30 May 2023 17:26:54 +0200 Subject: [PATCH 62/77] Fix `onchainOngoing`/`onchainDone` issue --- .../replicate/UnnotifiedAbstractDetector.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java index 1340d70ad..5f9d03263 100644 --- a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java @@ -44,7 +44,7 @@ public abstract class UnnotifiedAbstractDetector { private final List detectWhenOffChainTaskStatuses; private final ReplicateStatus offchainOngoing; private final ReplicateStatus offchainDone; - private final ChainContributionStatus onchainOngoing; + private final ChainContributionStatus onchainDone; private final int detectorRate; private int detectorOccurrence = 0; @@ -55,7 +55,7 @@ protected UnnotifiedAbstractDetector(TaskService taskService, List detectWhenOffChainTaskStatuses, ReplicateStatus offchainOngoing, ReplicateStatus offchainDone, - ChainContributionStatus onchainOngoing, + ChainContributionStatus onchainDone, int detectorRate) { this.taskService = taskService; this.replicatesService = replicatesService; @@ -64,7 +64,7 @@ protected UnnotifiedAbstractDetector(TaskService taskService, this.detectWhenOffChainTaskStatuses = detectWhenOffChainTaskStatuses; this.offchainOngoing = offchainOngoing; this.offchainDone = offchainDone; - this.onchainOngoing = onchainOngoing; + this.onchainDone = onchainDone; this.detectorRate = detectorRate; } @@ -92,7 +92,7 @@ void detectOnChainChanges() { */ void detectOnchainDoneWhenOffchainOngoing() { log.debug("Detect onchain {} (when offchain {}) [retryIn:{}]", - this.offchainDone, this.offchainOngoing, this.detectorRate); + this.onchainDone, this.offchainOngoing, this.detectorRate); for (Task task : taskService.findByCurrentStatus(detectWhenOffChainTaskStatuses)) { for (Replicate replicate : replicatesService.getReplicates(task.getChainTaskId())) { @@ -104,12 +104,12 @@ void detectOnchainDoneWhenOffchainOngoing() { final boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain( task.getChainTaskId(), replicate.getWalletAddress(), - onchainOngoing + onchainDone ); if (statusTrueOnChain) { log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]", - lastRelevantStatus, onchainOngoing, task.getChainTaskId()); + lastRelevantStatus, onchainDone, task.getChainTaskId()); updateReplicateStatuses(task, replicate); } } @@ -124,7 +124,7 @@ void detectOnchainDoneWhenOffchainOngoing() { * - When we receive a "can't do " relative to the `onchainDone` status (e.g.: `CANNOT_REVEAL`) */ public void detectOnchainDone() { - log.debug("Detect onchain {} [retryIn:{}]", onchainOngoing, this.detectorRate * LESS_OFTEN_DETECTOR_FREQUENCY); + log.debug("Detect onchain {} [retryIn:{}]", onchainDone, this.detectorRate * LESS_OFTEN_DETECTOR_FREQUENCY); for (Task task : taskService.findByCurrentStatus(detectWhenOffChainTaskStatuses)) { for (Replicate replicate : replicatesService.getReplicates(task.getChainTaskId())) { final ReplicateStatus lastRelevantStatus = replicate.getLastRelevantStatus(); @@ -136,12 +136,12 @@ public void detectOnchainDone() { final boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain( task.getChainTaskId(), replicate.getWalletAddress(), - onchainOngoing + onchainDone ); if (statusTrueOnChain) { log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]", - lastRelevantStatus, onchainOngoing, task.getChainTaskId()); + lastRelevantStatus, onchainDone, task.getChainTaskId()); updateReplicateStatuses(task, replicate); } } From 8049ccf7ba2eb58dac39fe57b5ad77be1cba4e63 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Tue, 30 May 2023 17:29:27 +0200 Subject: [PATCH 63/77] Fix comment --- .../core/detector/replicate/UnnotifiedAbstractDetector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java index 5f9d03263..202759f5d 100644 --- a/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java +++ b/src/main/java/com/iexec/core/detector/replicate/UnnotifiedAbstractDetector.java @@ -86,7 +86,7 @@ void detectOnChainChanges() { } /** - * Detecting onchain `offchainDone` status only if replicates are offchain `offchainOngoing` + * Detecting `onchainDone` status only if replicates are `offchainOngoing` * (worker didn't notify last offchain `offchainDone` status) * We want to detect them very often since it's highly probable */ From c1d5a40bd0617a5ce4f87b5375ef324bfc2f780c Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 1 Jun 2023 11:16:46 +0200 Subject: [PATCH 64/77] Add ContributeAndFinalize task detector --- CHANGELOG.md | 2 +- .../detector/task/FinalizedTaskDetector.java | 66 +++- .../task/FinalizedTaskDetectorTests.java | 281 ++++++++++++++++++ 3 files changed, 336 insertions(+), 13 deletions(-) create mode 100644 src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java diff --git a/CHANGELOG.md b/CHANGELOG.md index a5a750683..3bc65e817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file. - Add `running2Finalized2Completed` in `TaskUpdateManager`. (#577 #578) - Disable `contributeAndFinalize` with CallBack. (#579 #581) - Add purge cached task descriptions ability. (#587) -- Add `ContributionAndFinalizationUnnotifiedDetector`. (#590) +- Add detectors for ContributionAndFinalizeFlow. (#590 #593) ### Bug Fixes - Prevent race condition on replicate update. (#568) - Use builders in test classes. (#589) diff --git a/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java b/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java index e2558b21f..f90b7c1cb 100644 --- a/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java +++ b/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java @@ -16,10 +16,13 @@ package com.iexec.core.detector.task; +import com.iexec.common.replicate.ReplicateStatus; import com.iexec.commons.poco.chain.ChainTask; import com.iexec.commons.poco.chain.ChainTaskStatus; import com.iexec.core.chain.IexecHubService; import com.iexec.core.detector.Detector; +import com.iexec.core.replicate.Replicate; +import com.iexec.core.replicate.ReplicatesService; import com.iexec.core.task.Task; import com.iexec.core.task.TaskService; import com.iexec.core.task.TaskStatus; @@ -28,6 +31,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Optional; @Slf4j @@ -37,30 +41,68 @@ public class FinalizedTaskDetector implements Detector { private final TaskService taskService; private final TaskUpdateRequestManager taskUpdateRequestManager; private final IexecHubService iexecHubService; + private final ReplicatesService replicatesService; public FinalizedTaskDetector(TaskService taskService, TaskUpdateRequestManager taskUpdateRequestManager, - IexecHubService iexecHubService) { + IexecHubService iexecHubService, + ReplicatesService replicatesService) { this.taskService = taskService; this.taskUpdateRequestManager = taskUpdateRequestManager; this.iexecHubService = iexecHubService; + this.replicatesService = replicatesService; } - /** - * Detector to detect tasks that are finalizing but are not finalized yet. - */ @Scheduled(fixedRateString = "#{@cronConfiguration.getFinalize()}") @Override public void detect() { + detectFinalizedTasks(); + detectContributeAndFinalizeDoneTasks(); + } + + /** + * Detect tasks that are finalizing but are not finalized yet. + */ + void detectFinalizedTasks() { log.debug("Trying to detect finalized tasks"); - for (Task task : taskService.findByCurrentStatus(TaskStatus.FINALIZING)) { - Optional chainTask = iexecHubService.getChainTask(task.getChainTaskId()); - if (chainTask.isPresent() && chainTask.get().getStatus().equals(ChainTaskStatus.COMPLETED)) { - log.info("Detected confirmed missing update (task) [is:{}, should:{}, taskId:{}]", - task.getCurrentStatus(), TaskStatus.FINALIZED, task.getChainTaskId()); - taskUpdateRequestManager.publishRequest(task.getChainTaskId()); - } + taskService.findByCurrentStatus(TaskStatus.FINALIZING) + .stream() + .filter(this::isChainTaskCompleted) + .forEach(this::publishTaskUpdateRequest); + } + + /** + * Detect tasks that are contributed and finalized by worker + * but are not off-chain finalized yet. + */ + void detectContributeAndFinalizeDoneTasks() { + log.debug("Trying to detect contributed and finalized tasks"); + taskService.findByCurrentStatus(TaskStatus.RUNNING) + .stream() + .filter(this::isTaskContributeAndFinalizeDone) + .forEach(this::publishTaskUpdateRequest); + } + + boolean isChainTaskCompleted(Task task) { + final Optional chainTask = iexecHubService.getChainTask(task.getChainTaskId()); + return chainTask.isPresent() && chainTask.get().getStatus().equals(ChainTaskStatus.COMPLETED); + } + + boolean isTaskContributeAndFinalizeDone(Task task) { + // Only TEE tasks can follow ContributeAndFinalize workflow + if (!task.isTeeTask()) { + return false; } + + final List replicates = replicatesService.getReplicates(task.getChainTaskId()); + return replicates.size() == 1 + && replicates.get(0).containsStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE) + && isChainTaskCompleted(task); } -} + void publishTaskUpdateRequest(Task task) { + log.info("Detected confirmed missing update (task) [is:{}, should:{}, taskId:{}]", + task.getCurrentStatus(), TaskStatus.FINALIZED, task.getChainTaskId()); + taskUpdateRequestManager.publishRequest(task.getChainTaskId()); + } +} diff --git a/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java b/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java new file mode 100644 index 000000000..e2205e928 --- /dev/null +++ b/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java @@ -0,0 +1,281 @@ +package com.iexec.core.detector.task; + +import com.iexec.common.replicate.ReplicateStatus; +import com.iexec.common.replicate.ReplicateStatusModifier; +import com.iexec.commons.poco.chain.ChainTask; +import com.iexec.commons.poco.chain.ChainTaskStatus; +import com.iexec.core.chain.IexecHubService; +import com.iexec.core.replicate.Replicate; +import com.iexec.core.replicate.ReplicatesService; +import com.iexec.core.task.Task; +import com.iexec.core.task.TaskService; +import com.iexec.core.task.TaskStatus; +import com.iexec.core.task.update.TaskUpdateRequestManager; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.*; + +import java.util.List; +import java.util.Optional; + +import static com.iexec.core.task.TaskTestsUtils.*; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class FinalizedTaskDetectorTests { + @Mock + private TaskService taskService; + @Mock + private TaskUpdateRequestManager taskUpdateRequestManager; + @Mock + private IexecHubService iexecHubService; + @Mock + private ReplicatesService replicatesService; + + @Spy + @InjectMocks + private FinalizedTaskDetector detector; + + @BeforeEach + void init() { + MockitoAnnotations.openMocks(this); + } + + // region detect + @Test + void shouldDetectTasks() { +// final String completedChainTaskId = "0x65bc5e94ed1486b940bd6cc0013c418efad58a0a52a3d08cee89faaa21970426"; +// final Task completedTask = getOnchainCompletedTask(completedChainTaskId).build(); +// when(taskService.findByCurrentStatus(TaskStatus.FINALIZING)).thenReturn(List.of(completedTask)); + + final String contributedAndFinalizedChainTaskId = "0x75bc5e94ed1486b940bd6cc0013c418efad58a0a52a3d08cee89faaa21970426"; + final Task contributeAndFinalizeTask = getContributeAndFinalizeDoneTask(contributedAndFinalizedChainTaskId).build(); + when(taskService.findByCurrentStatus(TaskStatus.RUNNING)).thenReturn(List.of(contributeAndFinalizeTask)); + + detector.detect(); + +// verify(taskUpdateRequestManager).publishRequest(completedChainTaskId); + verify(taskUpdateRequestManager).publishRequest(contributedAndFinalizedChainTaskId); + } + // endregion + + // region detectFinalizedTasks + @Test + void shouldDetectFinalizedTask() { + final Task task = getOnchainCompletedTask(CHAIN_TASK_ID).build(); + + when(taskService.findByCurrentStatus(TaskStatus.FINALIZING)).thenReturn(List.of(task)); + + detector.detectFinalizedTasks(); + + verify(taskUpdateRequestManager).publishRequest(CHAIN_TASK_ID); + } + + @Test + void shouldDetectNoFinalizedTassAsTaskIsRevealing() { + final Task task = getOnchainRevealingTask(CHAIN_TASK_ID).build(); + + when(taskService.findByCurrentStatus(TaskStatus.FINALIZING)).thenReturn(List.of(task)); + + detector.detectFinalizedTasks(); + + verify(taskUpdateRequestManager, Mockito.never()).publishRequest(CHAIN_TASK_ID); + } + // endregion + + // region detectContributeAndFinalizeDoneTasks + @Test + void shouldDetectContributeAndFinalizeDoneTask() { + final Task task = getContributeAndFinalizeDoneTask(CHAIN_TASK_ID).build(); + + when(taskService.findByCurrentStatus(TaskStatus.RUNNING)).thenReturn(List.of(task)); + + detector.detectContributeAndFinalizeDoneTasks(); + + verify(taskUpdateRequestManager).publishRequest(CHAIN_TASK_ID); + } + + @Test + void shouldDetectNoContributeAndFinalizeDoneTaskAsTaskIsRevealing() { + final Task task = getOnchainRevealingTask(CHAIN_DEAL_ID).build(); + + when(taskService.findByCurrentStatus(TaskStatus.RUNNING)).thenReturn(List.of(task)); + + detector.detectContributeAndFinalizeDoneTasks(); + + verify(taskUpdateRequestManager, Mockito.never()).publishRequest(CHAIN_TASK_ID); + } + // endregion + + // region isChainTaskCompleted + @Test + void shouldChainTaskBeCompleted() { + final Task task = getOnchainCompletedTask(CHAIN_TASK_ID).build(); + + final boolean chainTaskCompleted = detector.isChainTaskCompleted(task); + + Assertions.assertThat(chainTaskCompleted).isTrue(); + } + + @Test + void shouldChainTaskNotBeCompletedAsChainTaskAbsent() { + final Task task = Task.builder() + .chainTaskId(CHAIN_TASK_ID) + .currentStatus(TaskStatus.FINALIZING) + .build(); + + when(iexecHubService.getChainTask(CHAIN_TASK_ID)).thenReturn(Optional.empty()); + + final boolean chainTaskCompleted = detector.isChainTaskCompleted(task); + + Assertions.assertThat(chainTaskCompleted).isFalse(); + } + + @Test + void shouldChainTaskNotBeCompletedAsChainTaskNotCompleted() { + final Task task = getOnchainRevealingTask(CHAIN_DEAL_ID).build(); + + final boolean chainTaskCompleted = detector.isChainTaskCompleted(task); + + Assertions.assertThat(chainTaskCompleted).isFalse(); + } + // endregion + + // region isTaskContributeAndFinalizeDone + @Test + void shouldTaskBeContributeAndFinalizeDone() { + final Task task = getContributeAndFinalizeDoneTask(CHAIN_TASK_ID).build(); + + final boolean taskContributeAndFinalizeDone = detector.isTaskContributeAndFinalizeDone(task); + + Assertions.assertThat(taskContributeAndFinalizeDone).isTrue(); + } + + @Test + void shouldTaskNotBeContributeAndFinalizeDoneAsNotTee() { + final Task task = Task.builder() + .chainTaskId(CHAIN_TASK_ID) + .currentStatus(TaskStatus.FINALIZING) + .tag(NO_TEE_TAG) + .build(); + + final boolean taskContributeAndFinalizeDone = detector.isTaskContributeAndFinalizeDone(task); + + Assertions.assertThat(taskContributeAndFinalizeDone).isFalse(); + } + + @Test + void shouldTaskNotBeContributeAndFinalizeDoneAsMultipleReplicates() { + final Task task = Task.builder() + .chainTaskId(CHAIN_TASK_ID) + .currentStatus(TaskStatus.FINALIZING) + .tag(TEE_TAG) + .build(); + final Replicate replicate1 = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); + final Replicate replicate2 = new Replicate(WALLET_WORKER_2, CHAIN_TASK_ID); + final ChainTask chainTask = ChainTask.builder() + .chainTaskId(CHAIN_TASK_ID) + .status(ChainTaskStatus.COMPLETED) + .build(); + + when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(List.of(replicate1, replicate2)); + when(iexecHubService.getChainTask(CHAIN_TASK_ID)).thenReturn(Optional.of(chainTask)); + + final boolean taskContributeAndFinalizeDone = detector.isTaskContributeAndFinalizeDone(task); + + Assertions.assertThat(taskContributeAndFinalizeDone).isFalse(); + } + + @Test + void shouldTaskNotBeContributeAndFinalizeDoneAsReplicateNotDone() { + final Task task = Task.builder() + .chainTaskId(CHAIN_TASK_ID) + .currentStatus(TaskStatus.FINALIZING) + .tag(TEE_TAG) + .build(); + final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); + replicate.updateStatus(ReplicateStatus.COMPUTING, ReplicateStatusModifier.WORKER); + + when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(List.of(replicate)); + + final boolean taskContributeAndFinalizeDone = detector.isTaskContributeAndFinalizeDone(task); + + Assertions.assertThat(taskContributeAndFinalizeDone).isFalse(); + } + + @Test + void shouldTaskNotBeContributeAndFinalizeDoneAsChainTaskNotCompleted() { + final Task task = Task.builder() + .chainTaskId(CHAIN_TASK_ID) + .currentStatus(TaskStatus.FINALIZING) + .tag(TEE_TAG) + .build(); + final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); + replicate.updateStatus(ReplicateStatus.COMPUTING, ReplicateStatusModifier.WORKER); + final ChainTask chainTask = ChainTask.builder() + .chainTaskId(CHAIN_TASK_ID) + .status(ChainTaskStatus.REVEALING) + .build(); + + when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(List.of(replicate)); + when(iexecHubService.getChainTask(CHAIN_TASK_ID)).thenReturn(Optional.of(chainTask)); + + final boolean taskContributeAndFinalizeDone = detector.isTaskContributeAndFinalizeDone(task); + + Assertions.assertThat(taskContributeAndFinalizeDone).isFalse(); + } + // endregion + + // region publishTaskUpdateRequest + @Test + void shouldPublishTaskUpdateRequest() { + final Task task = Task.builder() + .chainTaskId(CHAIN_TASK_ID) + .currentStatus(TaskStatus.FINALIZING) + .build(); + + detector.publishTaskUpdateRequest(task); + + verify(taskUpdateRequestManager).publishRequest(CHAIN_TASK_ID); + } + // endregion + + // region Utils + private Task.TaskBuilder getOnchainCompletedTask(String chainTaskId) { + final ChainTask chainTask = ChainTask.builder() + .chainTaskId(chainTaskId) + .status(ChainTaskStatus.COMPLETED) + .build(); + + when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.of(chainTask)); + + return Task.builder() + .chainTaskId(chainTaskId) + .currentStatus(TaskStatus.FINALIZING); + } + + private Task.TaskBuilder getOnchainRevealingTask(String chainTaskId) { + final ChainTask chainTask = ChainTask.builder() + .chainTaskId(chainTaskId) + .status(ChainTaskStatus.REVEALING) + .build(); + + when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.of(chainTask)); + + return Task.builder() + .chainTaskId(chainTaskId) + .currentStatus(TaskStatus.FINALIZING); + } + + private Task.TaskBuilder getContributeAndFinalizeDoneTask(String chainTaskId) { + final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); + replicate.updateStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE, ReplicateStatusModifier.WORKER); + + when(replicatesService.getReplicates(chainTaskId)).thenReturn(List.of(replicate)); + + return getOnchainCompletedTask(chainTaskId) + .tag(TEE_TAG); + } + // endregion +} From 31493c4b9fd23b2bc792a3ce6c26dd82d2989a04 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 1 Jun 2023 11:31:16 +0200 Subject: [PATCH 65/77] Fix test --- .../iexec/core/detector/task/FinalizedTaskDetectorTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java b/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java index e2205e928..34d799d28 100644 --- a/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java @@ -212,7 +212,7 @@ void shouldTaskNotBeContributeAndFinalizeDoneAsChainTaskNotCompleted() { .tag(TEE_TAG) .build(); final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID); - replicate.updateStatus(ReplicateStatus.COMPUTING, ReplicateStatusModifier.WORKER); + replicate.updateStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE, ReplicateStatusModifier.WORKER); final ChainTask chainTask = ChainTask.builder() .chainTaskId(CHAIN_TASK_ID) .status(ChainTaskStatus.REVEALING) From c790d83d48d36e457209c27a1013a8e9f878cb8a Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Thu, 1 Jun 2023 12:03:18 +0200 Subject: [PATCH 66/77] Uncomment test part --- .../core/detector/task/FinalizedTaskDetectorTests.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java b/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java index 34d799d28..94656577b 100644 --- a/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java @@ -45,9 +45,9 @@ void init() { // region detect @Test void shouldDetectTasks() { -// final String completedChainTaskId = "0x65bc5e94ed1486b940bd6cc0013c418efad58a0a52a3d08cee89faaa21970426"; -// final Task completedTask = getOnchainCompletedTask(completedChainTaskId).build(); -// when(taskService.findByCurrentStatus(TaskStatus.FINALIZING)).thenReturn(List.of(completedTask)); + final String completedChainTaskId = "0x65bc5e94ed1486b940bd6cc0013c418efad58a0a52a3d08cee89faaa21970426"; + final Task completedTask = getOnchainCompletedTask(completedChainTaskId).build(); + when(taskService.findByCurrentStatus(TaskStatus.FINALIZING)).thenReturn(List.of(completedTask)); final String contributedAndFinalizedChainTaskId = "0x75bc5e94ed1486b940bd6cc0013c418efad58a0a52a3d08cee89faaa21970426"; final Task contributeAndFinalizeTask = getContributeAndFinalizeDoneTask(contributedAndFinalizedChainTaskId).build(); @@ -55,7 +55,7 @@ void shouldDetectTasks() { detector.detect(); -// verify(taskUpdateRequestManager).publishRequest(completedChainTaskId); + verify(taskUpdateRequestManager).publishRequest(completedChainTaskId); verify(taskUpdateRequestManager).publishRequest(contributedAndFinalizedChainTaskId); } // endregion From e0dd0a5b92b17728d61bce9b67ae407c8a57def4 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton <87655102+mcornaton@users.noreply.github.com> Date: Fri, 2 Jun 2023 09:08:05 +0200 Subject: [PATCH 67/77] Replace `.equals` with `==` for enum members Co-authored-by: Jeremy Bernard --- .../com/iexec/core/detector/task/FinalizedTaskDetector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java b/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java index f90b7c1cb..fdd6456dc 100644 --- a/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java +++ b/src/main/java/com/iexec/core/detector/task/FinalizedTaskDetector.java @@ -85,7 +85,7 @@ void detectContributeAndFinalizeDoneTasks() { boolean isChainTaskCompleted(Task task) { final Optional chainTask = iexecHubService.getChainTask(task.getChainTaskId()); - return chainTask.isPresent() && chainTask.get().getStatus().equals(ChainTaskStatus.COMPLETED); + return chainTask.isPresent() && chainTask.get().getStatus() == ChainTaskStatus.COMPLETED; } boolean isTaskContributeAndFinalizeDone(Task task) { From 43f8782e8acade6649b8692176092feac2cf64f3 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Fri, 2 Jun 2023 09:10:07 +0200 Subject: [PATCH 68/77] Fix typo --- .../iexec/core/detector/task/FinalizedTaskDetectorTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java b/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java index 94656577b..cf14b1e1a 100644 --- a/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java @@ -73,7 +73,7 @@ void shouldDetectFinalizedTask() { } @Test - void shouldDetectNoFinalizedTassAsTaskIsRevealing() { + void shouldDetectNoFinalizedTaskAsTaskIsRevealing() { final Task task = getOnchainRevealingTask(CHAIN_TASK_ID).build(); when(taskService.findByCurrentStatus(TaskStatus.FINALIZING)).thenReturn(List.of(task)); From 3bad8936c58c733b1ff37b0d9f5a24255fc60c7c Mon Sep 17 00:00:00 2001 From: Maxence Cornaton Date: Fri, 2 Jun 2023 09:30:27 +0200 Subject: [PATCH 69/77] Add copyright --- .../task/FinalizedTaskDetectorTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java b/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java index cf14b1e1a..8b69f54c9 100644 --- a/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java +++ b/src/test/java/com/iexec/core/detector/task/FinalizedTaskDetectorTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023-2023 IEXEC BLOCKCHAIN TECH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.iexec.core.detector.task; import com.iexec.common.replicate.ReplicateStatus; From 0f1b7133b273d993c45620af8fbfc83d190fe534 Mon Sep 17 00:00:00 2001 From: Maxence Cornaton <87655102+mcornaton@users.noreply.github.com> Date: Fri, 2 Jun 2023 13:45:10 +0200 Subject: [PATCH 70/77] Update CHANGELOG.md Co-authored-by: Jeremy Bernard --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bc65e817..3b8642cf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file. - Add `running2Finalized2Completed` in `TaskUpdateManager`. (#577 #578) - Disable `contributeAndFinalize` with CallBack. (#579 #581) - Add purge cached task descriptions ability. (#587) -- Add detectors for ContributionAndFinalizeFlow. (#590 #593) +- Add detectors for `ContributeAndFinalize` flow. (#590 #593) ### Bug Fixes - Prevent race condition on replicate update. (#568) - Use builders in test classes. (#589) From 63983b8a0c2d8053d7e503bfd47f8eb760925797 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 8 Jun 2023 09:14:44 +0200 Subject: [PATCH 71/77] Use iexec-commons-poco@3.0.2 and iexec-commons@8.2.0 --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index c5ca6f7cb..269d5f0a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ version=8.0.1 -iexecCommonVersion=8.1.0-NEXT-SNAPSHOT -iexecCommonsPocoVersion=2.0.1-NEXT-SNAPSHOT +iexecCommonVersion=8.2.0 +iexecCommonsPocoVersion=3.0.2 iexecBlockchainAdapterVersion=8.0.1-NEXT-SNAPSHOT iexecResultVersion=8.0.0-NEXT-SNAPSHOT iexecSmsVersion=8.0.0-NEXT-SNAPSHOT From b3c01adc6458b2a2f367fb222fe39d6d7f14f0b4 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 8 Jun 2023 09:15:29 +0200 Subject: [PATCH 72/77] Use 8.1.0 feign libraries --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 269d5f0a6..e8f313346 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ version=8.0.1 iexecCommonVersion=8.2.0 iexecCommonsPocoVersion=3.0.2 -iexecBlockchainAdapterVersion=8.0.1-NEXT-SNAPSHOT -iexecResultVersion=8.0.0-NEXT-SNAPSHOT -iexecSmsVersion=8.0.0-NEXT-SNAPSHOT +iexecBlockchainAdapterVersion=8.1.0 +iexecResultVersion=8.1.0 +iexecSmsVersion=8.1.0 nexusUser nexusPassword From 0f1cd9e2a149f2a30abbfd9eae6c76eb2a5f6bd8 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 8 Jun 2023 09:20:11 +0200 Subject: [PATCH 73/77] Update `Web3jService` constructor --- src/main/java/com/iexec/core/chain/ChainConfig.java | 5 +++++ src/main/java/com/iexec/core/chain/Web3jService.java | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/com/iexec/core/chain/ChainConfig.java b/src/main/java/com/iexec/core/chain/ChainConfig.java index 918f24760..f2350b719 100644 --- a/src/main/java/com/iexec/core/chain/ChainConfig.java +++ b/src/main/java/com/iexec/core/chain/ChainConfig.java @@ -22,6 +22,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import java.time.Duration; + @Component @Getter @AllArgsConstructor @@ -37,6 +39,9 @@ public class ChainConfig { @Value("#{blockchainAdapterService.publicChainConfig.iexecHubContractAddress}") private String hubAddress; + @Value("#{blockchainAdapterService.publicChainConfig.blockTime}") + private Duration blockTime; + @Value("${chain.privateAddress}") private String privateChainAddress; diff --git a/src/main/java/com/iexec/core/chain/Web3jService.java b/src/main/java/com/iexec/core/chain/Web3jService.java index 3c99fd18f..9a83f9763 100644 --- a/src/main/java/com/iexec/core/chain/Web3jService.java +++ b/src/main/java/com/iexec/core/chain/Web3jService.java @@ -19,6 +19,8 @@ import com.iexec.commons.poco.chain.Web3jAbstractService; import org.springframework.stereotype.Service; +import java.time.Duration; + @Service public class Web3jService extends Web3jAbstractService { @@ -26,6 +28,7 @@ public Web3jService(ChainConfig chainConfig) { super( chainConfig.getChainId(), chainConfig.getPrivateChainAddress(), + chainConfig.getBlockTime(), chainConfig.getGasPriceMultiplier(), chainConfig.getGasPriceCap(), chainConfig.isSidechain() From c2f5e003106d69b6748623e5df7e11c40a22fc9a Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 8 Jun 2023 09:31:28 +0200 Subject: [PATCH 74/77] Fix `TaskDescription` usage in `ReplicateServiceTests` --- .../java/com/iexec/core/replicate/ReplicateServiceTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java index d8139c545..b0e2a0fdb 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java @@ -1030,7 +1030,7 @@ void shouldAuthorizeUpdateOnResultUploadFailed() { .build(); UpdateReplicateStatusArgs updateReplicateStatusArgs = UpdateReplicateStatusArgs .builder() - .taskDescription(new TaskDescription()) + .taskDescription(TaskDescription.builder().build()) .build(); assertThat(replicatesService.canUpdateReplicateStatus(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate, updateReplicateStatusArgs)) From d5fd1de798250530d8ee06ae04c25d1e3282df81 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 8 Jun 2023 09:44:38 +0200 Subject: [PATCH 75/77] Add `License` link in README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index efc103098..495477d96 100644 --- a/README.md +++ b/README.md @@ -71,3 +71,7 @@ No default strategy has been implemented in the [Dockerfile](Dockerfile) at the ``` ./gradlew build ``` + +## License + +This repository code is released under the [Apache License 2.0](LICENSE). From f60197b08400b28bf16130b5cbda782e7e47f8e6 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 8 Jun 2023 09:45:52 +0200 Subject: [PATCH 76/77] Update CHANGELOG.md --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b8642cf0..76c0a1065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,8 +24,11 @@ All notable changes to this project will be documented in this file. - Move methods to get event blocks from `iexec-commons-poco`. (#588) - Rename detectors' methods and fields to match Ongoing/Done standard. (#591) ### Dependency Upgrades -- Upgrade to `iexec-common` 8.1.0-NEXT-SNAPSHOT. (#571 #575 #586) -- Add new `iexec-commons-poco` 2.0.1-NEXT-SNAPSHOT dependency. (#571 #574 #586 #587 #588 #592) +- Upgrade to `iexec-common` 8.2.0. (#571 #575 #586 #594) +- Add new `iexec-commons-poco` 3.0.2 dependency. (#571 #574 #586 #587 #588 #592 #594) +- Upgrade to `iexec-blockchain-adapter-api-library` 8.1.0. (#594) +- Upgrade to `iexec-result-proxy-library` 8.1.0. (#594) +- Upgrade to `iexec-sms-library` 8.1.0. (#594) ## [[8.0.1]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.0.1) 2023-03-20 From b02a0c48ba7d718dd42a38ace372f2b34e280a19 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Fri, 9 Jun 2023 15:11:14 +0200 Subject: [PATCH 77/77] Release version 8.1.0 --- CHANGELOG.md | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76c0a1065..92256dbc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. -## [[NEXT]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/vNEXT) 2023 +## [[8.1.0]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.1.0) 2023-06-09 ### New Features - Add ContributeAndFinalize to `ReplicateWorkflow`. (#574) diff --git a/gradle.properties b/gradle.properties index e8f313346..a0065e61d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=8.0.1 +version=8.1.0 iexecCommonVersion=8.2.0 iexecCommonsPocoVersion=3.0.2 iexecBlockchainAdapterVersion=8.1.0