Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Check result has been uploaded for TEE tasks #672

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Bug Fixes

- Keep a single `updateReplicateStatus` method in `ReplicatesService`. (#670)
- Check result has been uploaded for TEE tasks. (#672)

### Quality

Expand Down
14 changes: 6 additions & 8 deletions src/main/java/com/iexec/core/replicate/ReplicatesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import static com.iexec.common.replicate.ReplicateStatus.*;
import static com.iexec.common.replicate.ReplicateStatusCause.REVEAL_TIMEOUT;
import static com.iexec.commons.poco.chain.DealParams.IPFS_RESULT_STORAGE_PROVIDER;

@Slf4j
@Service
Expand Down Expand Up @@ -551,17 +552,14 @@ public boolean isResultUploaded(String chainTaskId) {
}

public boolean isResultUploaded(TaskDescription task) {
// Offchain computing - basic & tee
if (task.containsCallback()) {
return true;
}
final boolean hasIpfsStorageProvider = IPFS_RESULT_STORAGE_PROVIDER.equals(task.getResultStorageProvider());

// Cloud computing - tee
if (task.isTeeTask()) {
return true; // pushed from enclave
// Offchain computing or TEE task with private storage
if (task.containsCallback() || (task.isTeeTask() && !hasIpfsStorageProvider)) {
return true;
}

// Cloud computing - basic
// Cloud computing, upload to IPFS - basic & TEE
return resultService.isResultUploaded(task.getChainTaskId());
}

Expand Down
59 changes: 28 additions & 31 deletions src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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.ValueSource;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
Expand All @@ -52,6 +54,8 @@

import static com.iexec.common.replicate.ReplicateStatus.*;
import static com.iexec.common.replicate.ReplicateStatusModifier.WORKER;
import static com.iexec.commons.poco.chain.DealParams.DROPBOX_RESULT_STORAGE_PROVIDER;
import static com.iexec.commons.poco.chain.DealParams.IPFS_RESULT_STORAGE_PROVIDER;
import static com.iexec.commons.poco.utils.TestUtils.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -796,12 +800,14 @@ void shouldGetReplicateWithResultUploadedStatus() {

// region isResultUploaded

@Test
void shouldCheckResultServiceAndReturnTrue() {
@ParameterizedTest
@ValueSource(booleans = {true, false})
void shouldCheckResultServiceAndReturnTrue(boolean isTeeTask) {
TaskDescription taskDescription = TaskDescription.builder()
.chainTaskId(CHAIN_TASK_ID)
.callback(BytesUtils.EMPTY_ADDRESS)
.isTeeTask(false)
.isTeeTask(isTeeTask)
.resultStorageProvider(IPFS_RESULT_STORAGE_PROVIDER)
.build();
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID))
.thenReturn(taskDescription);
Expand All @@ -812,12 +818,14 @@ void shouldCheckResultServiceAndReturnTrue() {
verify(resultService).isResultUploaded(CHAIN_TASK_ID);
}

@Test
void shouldCheckResultServiceAndReturnFalse() {
@ParameterizedTest
@ValueSource(booleans = {true, false})
void shouldCheckResultServiceAndReturnFalse(boolean isTeeTask) {
TaskDescription taskDescription = TaskDescription.builder()
.chainTaskId(CHAIN_TASK_ID)
.callback(BytesUtils.EMPTY_ADDRESS)
.isTeeTask(false)
.isTeeTask(isTeeTask)
.resultStorageProvider(IPFS_RESULT_STORAGE_PROVIDER)
.build();
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID))
.thenReturn(taskDescription);
Expand All @@ -838,12 +846,13 @@ void shouldReturnFalseSinceTaskNotFound() {
verify(resultService, never()).isResultUploaded(CHAIN_TASK_ID);
}

@Test
void shouldReturnTrueForCallbackTask() {
@ParameterizedTest
@ValueSource(booleans = {true, false})
void shouldReturnTrueForCallbackTask(boolean isTeeTask) {
TaskDescription taskDescription = TaskDescription.builder()
.chainTaskId(CHAIN_TASK_ID)
.callback("callback")
.isTeeTask(false)
.isTeeTask(isTeeTask)
.build();
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID))
.thenReturn(taskDescription);
Expand All @@ -854,18 +863,19 @@ void shouldReturnTrueForCallbackTask() {
}

@Test
void shouldReturnTrueForTeeTask() {
void shouldReturnTrueIfPrivateStorageForTeeTask() {
TaskDescription taskDescription = TaskDescription.builder()
.chainTaskId(CHAIN_TASK_ID)
.callback(BytesUtils.EMPTY_ADDRESS)
.isTeeTask(true)
.resultStorageProvider(DROPBOX_RESULT_STORAGE_PROVIDER)
.build();
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID))
.thenReturn(taskDescription);

boolean isResultUploaded = replicatesService.isResultUploaded(CHAIN_TASK_ID);
assertThat(isResultUploaded).isTrue();
verify(resultService, never()).isResultUploaded(CHAIN_TASK_ID);
verify(resultService, never()).isResultUploaded(any());
}
// endregion

Expand Down Expand Up @@ -992,7 +1002,7 @@ void shouldAuthorizeUpdateOnResultUploadFailed() {
.build();
UpdateReplicateStatusArgs updateReplicateStatusArgs = UpdateReplicateStatusArgs
.builder()
.taskDescription(TaskDescription.builder().build())
.taskDescription(TaskDescription.builder().resultStorageProvider(IPFS_RESULT_STORAGE_PROVIDER).build())
.build();

assertThat(replicatesService.canUpdateReplicateStatus(replicate, statusUpdate, updateReplicateStatusArgs))
Expand All @@ -1017,24 +1027,6 @@ void shouldNotAuthorizeUpdateOnResultUploadFailedSinceResultUploadedWithCallback
.isEqualTo(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE);
}

@Test
void shouldNotAuthorizeUpdateOnResultUploadFailedSinceResultUploadedWithTee() {
Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID);
replicate.updateStatus(RESULT_UPLOADING, ReplicateStatusModifier.WORKER);

ReplicateStatusUpdate statusUpdate = ReplicateStatusUpdate.builder()
.modifier(WORKER)
.status(RESULT_UPLOAD_FAILED)
.build();
UpdateReplicateStatusArgs updateReplicateStatusArgs = UpdateReplicateStatusArgs
.builder()
.taskDescription(TaskDescription.builder().isTeeTask(true).build())
.build();

assertThat(replicatesService.canUpdateReplicateStatus(replicate, statusUpdate, updateReplicateStatusArgs))
.isEqualTo(ReplicateStatusUpdateError.GENERIC_CANT_UPDATE);
}

@Test
void shouldNotAuthorizeUpdateOnContributedSinceNoBlockAvailable() {
final Replicate replicate = new Replicate(WALLET_WORKER_1, CHAIN_TASK_ID);
Expand Down Expand Up @@ -1229,6 +1221,7 @@ void shouldAuthorizeUpdateOnContributeAndFinalizeDone() {
.thenReturn(true);
when(iexecHubService.getTaskDescription(CHAIN_TASK_ID)).thenReturn(task);
when(iexecHubService.isTaskInCompletedStatusOnChain(CHAIN_TASK_ID)).thenReturn(true);
when(resultService.isResultUploaded(CHAIN_TASK_ID)).thenReturn(true);

assertThat(replicatesService.canUpdateReplicateStatus(replicate, statusUpdate, null))
.isEqualTo(ReplicateStatusUpdateError.NO_ERROR);
Expand Down Expand Up @@ -1261,7 +1254,11 @@ void shouldNotAuthorizeUpdateOnContributeAndFinalizeDoneWhenNotUploaded() {
.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)
.resultStorageProvider(IPFS_RESULT_STORAGE_PROVIDER)
.build();

when(iexecHubService.repeatIsRevealedTrue(CHAIN_TASK_ID, WALLET_WORKER_1))
.thenReturn(true);
Expand Down