Skip to content

Commit d79c7ba

Browse files
authored
Save contribution and result updload replicate data when CONTRIBUTE_AND_FINALIZE_DONE (#651)
1 parent a5d4eed commit d79c7ba

File tree

3 files changed

+60
-30
lines changed

3 files changed

+60
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ All notable changes to this project will be documented in this file.
3030
- Expose `TaskLogsModel` on `TaskController` instead of `TaskLogs`. (#631)
3131
- Remove duplicated MongoDB read on `ReplicatesList` during replicate status update. (#647)
3232
- Use less MongoDB calls when updating a task to a final status. (#649)
33+
- Save contribution and result updload replicate data when `CONTRIBUTE_AND_FINALIZE_DONE`. (#651)
3334

3435
### Dependency Upgrades
3536

src/main/java/com/iexec/core/replicate/ReplicatesService.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -235,27 +235,19 @@ public UpdateReplicateStatusArgs computeUpdateReplicateStatusArgs(String chainTa
235235
ChainContribution chainContribution = null;
236236
String resultLink = null;
237237
String chainCallbackData = null;
238-
TaskDescription taskDescription = null;
238+
final TaskDescription taskDescription = iexecHubService.getTaskDescription(chainTaskId);
239239

240-
switch (statusUpdate.getStatus()) {
241-
case CONTRIBUTED:
242-
workerWeight = iexecHubService.getWorkerWeight(walletAddress);
243-
chainContribution = iexecHubService.getChainContribution(chainTaskId, walletAddress).orElse(null);
244-
break;
245-
case RESULT_UPLOADED:
246-
ReplicateStatusDetails details = statusUpdate.getDetails();
247-
if (details != null) {
248-
resultLink = details.getResultLink();
249-
chainCallbackData = details.getChainCallbackData();
250-
}
251-
taskDescription = iexecHubService.getTaskDescription(chainTaskId);
252-
break;
253-
case COMPUTED:
254-
case RESULT_UPLOAD_FAILED:
255-
taskDescription = iexecHubService.getTaskDescription(chainTaskId);
256-
break;
257-
default:
258-
break;
240+
if (statusUpdate.getStatus() == CONTRIBUTED || statusUpdate.getStatus() == CONTRIBUTE_AND_FINALIZE_DONE) {
241+
workerWeight = iexecHubService.getWorkerWeight(walletAddress);
242+
chainContribution = iexecHubService.getChainContribution(chainTaskId, walletAddress).orElse(null);
243+
}
244+
245+
if (statusUpdate.getStatus() == RESULT_UPLOADED || statusUpdate.getStatus() == CONTRIBUTE_AND_FINALIZE_DONE) {
246+
final ReplicateStatusDetails details = statusUpdate.getDetails();
247+
if (details != null) {
248+
resultLink = details.getResultLink();
249+
chainCallbackData = details.getChainCallbackData();
250+
}
259251
}
260252

261253
return UpdateReplicateStatusArgs.builder()
@@ -427,12 +419,12 @@ Either<ReplicateStatusUpdateError, TaskNotificationType> updateReplicateStatusWi
427419
return Either.left(error);
428420
}
429421

430-
if (newStatus == CONTRIBUTED) {
422+
if (newStatus == CONTRIBUTED || newStatus == CONTRIBUTE_AND_FINALIZE_DONE) {
431423
replicate.setContributionHash(updateReplicateStatusArgs.getChainContribution().getResultHash());
432424
replicate.setWorkerWeight(updateReplicateStatusArgs.getWorkerWeight());
433425
}
434426

435-
if (newStatus == RESULT_UPLOADED) {
427+
if (newStatus == RESULT_UPLOADED || newStatus == CONTRIBUTE_AND_FINALIZE_DONE) {
436428
replicate.setResultLink(updateReplicateStatusArgs.getResultLink());
437429
replicate.setChainCallbackData(updateReplicateStatusArgs.getChainCallbackData());
438430
}

src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ void shouldGetCorrectNbReplicatesContainingMultipleStatus() {
336336
assertThat(shouldBe0).isZero();
337337
}
338338

339+
// region getRandomReplicateWithRevealStatus
339340
@Test
340341
void shouldGetReplicateWithRevealStatus() {
341342
Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID);
@@ -384,7 +385,9 @@ void shouldNotGetReplicateWithRevealStatusWithNonEmptyList() {
384385
Optional<Replicate> optional = replicatesService.getRandomReplicateWithRevealStatus(CHAIN_TASK_ID);
385386
assertThat(optional).isEmpty();
386387
}
388+
//endregion
387389

390+
//region updateReplicateStatus
388391
@Test
389392
void shouldUpdateReplicateStatusWithoutStdout() {
390393
Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID);
@@ -765,8 +768,9 @@ void shouldUpdateToResultUploaded() {
765768
assertThat(capturedEvent.getWalletAddress()).isEqualTo(WALLET_WORKER_1);
766769
assertThat(capturedEvent.getReplicateStatusUpdate().getStatus()).isEqualTo(RESULT_UPLOADED);
767770
}
771+
// endregion
768772

769-
// getReplicateWithResultUploadedStatus
773+
// region getReplicateWithResultUploadedStatus
770774

771775
@Test
772776
void should() {
@@ -786,8 +790,9 @@ void should() {
786790
.getWalletAddress())
787791
.isEqualTo(WALLET_WORKER_2);
788792
}
793+
// endregion
789794

790-
// isResultUploaded
795+
// region isResultUploaded
791796

792797
@Test
793798
void shouldCheckResultServiceAndReturnTrue() {
@@ -860,6 +865,7 @@ void shouldReturnTrueForTeeTask() {
860865
assertThat(isResultUploaded).isTrue();
861866
verify(resultService, never()).isResultUploaded(CHAIN_TASK_ID);
862867
}
868+
// endregion
863869

864870
// didReplicateContributeOnchain
865871

@@ -1343,7 +1349,7 @@ void computeUpdateReplicateStatusArgsContributed() {
13431349

13441350
when(iexecHubService.getWorkerWeight(WALLET_WORKER_1)).thenReturn(expectedWorkerWeight);
13451351
when(iexecHubService.getChainContribution(CHAIN_TASK_ID, WALLET_WORKER_1))
1346-
.thenReturn(Optional.of(ChainContribution.builder().build()));
1352+
.thenReturn(Optional.of(expectedChainContribution));
13471353

13481354
assertThat(replicatesService.computeUpdateReplicateStatusArgs(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate))
13491355
.isEqualTo(UpdateReplicateStatusArgs.builder()
@@ -1354,8 +1360,6 @@ void computeUpdateReplicateStatusArgsContributed() {
13541360

13551361
@Test
13561362
void computeUpdateReplicateStatusArgsResultUploaded() {
1357-
final int unexpectedWorkerWeight = 1;
1358-
final ChainContribution unexpectedChainContribution = ChainContribution.builder().build();
13591363
final String expectedResultLink = "resultLink";
13601364
final String expectedChainCallbackData = "chainCallbackData";
13611365
final TaskDescription expectedTaskDescription = TaskDescription.builder().build();
@@ -1370,9 +1374,6 @@ void computeUpdateReplicateStatusArgsResultUploaded() {
13701374
.details(details)
13711375
.build();
13721376

1373-
when(iexecHubService.getWorkerWeight(WALLET_WORKER_1)).thenReturn(unexpectedWorkerWeight);
1374-
when(iexecHubService.getChainContribution(CHAIN_TASK_ID, WALLET_WORKER_1))
1375-
.thenReturn(Optional.of(unexpectedChainContribution));
13761377
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID))
13771378
.thenReturn(expectedTaskDescription);
13781379

@@ -1384,6 +1385,42 @@ void computeUpdateReplicateStatusArgsResultUploaded() {
13841385
.chainCallbackData(expectedChainCallbackData)
13851386
.taskDescription(expectedTaskDescription)
13861387
.build());
1388+
1389+
verify(iexecHubService, never()).getWorkerWeight(WALLET_WORKER_1);
1390+
verify(iexecHubService, never()).getChainContribution(CHAIN_TASK_ID, WALLET_WORKER_1);
1391+
}
1392+
1393+
@Test
1394+
void computeUpdateReplicateStatusArgsContributeAndFinalizeDone() {
1395+
final int expectedWorkerWeight = 1;
1396+
final ChainContribution expectedChainContribution = ChainContribution.builder().build();
1397+
final String expectedResultLink = "resultLink";
1398+
final String expectedChainCallbackData = "chainCallbackData";
1399+
final TaskDescription expectedTaskDescription = TaskDescription.builder().build();
1400+
1401+
final ReplicateStatusDetails details = ReplicateStatusDetails.builder()
1402+
.resultLink(expectedResultLink)
1403+
.chainCallbackData(expectedChainCallbackData)
1404+
.build();
1405+
final ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder()
1406+
.modifier(WORKER)
1407+
.status(CONTRIBUTE_AND_FINALIZE_DONE)
1408+
.details(details)
1409+
.build();
1410+
1411+
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)).thenReturn(expectedTaskDescription);
1412+
when(iexecHubService.getWorkerWeight(WALLET_WORKER_1)).thenReturn(expectedWorkerWeight);
1413+
when(iexecHubService.getChainContribution(CHAIN_TASK_ID, WALLET_WORKER_1))
1414+
.thenReturn(Optional.of(expectedChainContribution));
1415+
1416+
assertThat(replicatesService.computeUpdateReplicateStatusArgs(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate))
1417+
.isEqualTo(UpdateReplicateStatusArgs.builder()
1418+
.workerWeight(expectedWorkerWeight)
1419+
.chainContribution(expectedChainContribution)
1420+
.resultLink(expectedResultLink)
1421+
.chainCallbackData(expectedChainCallbackData)
1422+
.taskDescription(expectedTaskDescription)
1423+
.build());
13871424
}
13881425

13891426
@Test

0 commit comments

Comments
 (0)