Skip to content

Commit 3a28542

Browse files
authored
feat: replace deprecated isTeeTask usages with requiresSgx (#665)
1 parent 05aa321 commit 3a28542

File tree

12 files changed

+155
-154
lines changed

12 files changed

+155
-154
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# x-release-please-start-version
22
version=9.1.0
33
# x-release-please-end
4-
iexecCommonsPocoVersion=5.1.0
5-
iexecCommonVersion=9.1.0
4+
iexecCommonsPocoVersion=5.3.1
5+
iexecCommonVersion=9.2.0
66
iexecCommonsContainersVersion=2.0.0
77
iexecResultVersion=9.0.0
88
iexecSmsVersion=9.0.0

src/main/java/com/iexec/worker/chain/ContributionService.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,13 @@ public Contribution getContribution(ComputedFile computedFile) {
169169
String enclaveChallenge = workerpoolAuthorization.getEnclaveChallenge();
170170
String enclaveSignature = computedFile.getEnclaveSignature();
171171

172-
boolean isTeeTask = iexecHubService.isTeeTask(chainTaskId);
173-
if (isTeeTask) {
174-
if (!enclaveAuthorizationService.isVerifiedEnclaveSignature(chainTaskId,
175-
resultHash, resultSeal, enclaveSignature, enclaveChallenge)) {
172+
if (iexecHubService.getTaskDescription(chainTaskId).requiresSgx()) {
173+
if (!enclaveAuthorizationService.isVerifiedEnclaveSignature(
174+
chainTaskId, resultHash, resultSeal, enclaveSignature, enclaveChallenge)) {
176175
log.error("Cannot get contribution with invalid enclave " +
177176
"signature [chainTaskId:{}, resultHash:{}, " +
178-
"resultSeal:{}, enclaveSignature:{}, " +
179-
"enclaveChallenge:{}]", chainTaskId, resultHash,
180-
resultSeal, enclaveSignature, enclaveChallenge);
177+
"resultSeal:{}, enclaveSignature:{}, enclaveChallenge:{}]",
178+
chainTaskId, resultHash, resultSeal, enclaveSignature, enclaveChallenge);
181179
return null;
182180
}
183181
} else {

src/main/java/com/iexec/worker/compute/ComputeManagerService.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ public boolean isAppDownloaded(String imageUri) {
160160
* @see PreComputeService#runTeePreCompute(TaskDescription)
161161
*/
162162
public PreComputeResponse runPreCompute(final TaskDescription taskDescription) {
163-
log.info("Running pre-compute [chainTaskId:{}, isTee:{}]",
164-
taskDescription.getChainTaskId(), taskDescription.isTeeTask());
163+
log.info("Running pre-compute [chainTaskId:{}, requiresSgx:{}]",
164+
taskDescription.getChainTaskId(), taskDescription.requiresSgx());
165165

166-
if (taskDescription.isTeeTask()) {
166+
if (taskDescription.requiresSgx()) {
167167
return preComputeService.runTeePreCompute(taskDescription);
168168
}
169169
return PreComputeResponse.builder().build();
@@ -178,8 +178,8 @@ public PreComputeResponse runPreCompute(final TaskDescription taskDescription) {
178178
*/
179179
public AppComputeResponse runCompute(final TaskDescription taskDescription) {
180180
final String chainTaskId = taskDescription.getChainTaskId();
181-
log.info("Running compute [chainTaskId:{}, isTee:{}]",
182-
chainTaskId, taskDescription.isTeeTask());
181+
log.info("Running compute [chainTaskId:{}, requiresSgx:{}]",
182+
chainTaskId, taskDescription.requiresSgx());
183183

184184
final AppComputeResponse appComputeResponse = appComputeService.runCompute(taskDescription);
185185

@@ -211,11 +211,11 @@ private void writeLogs(String chainTaskId, String filename, String logs) {
211211
*/
212212
public PostComputeResponse runPostCompute(final TaskDescription taskDescription) {
213213
final String chainTaskId = taskDescription.getChainTaskId();
214-
log.info("Running post-compute [chainTaskId:{}, isTee:{}]",
215-
chainTaskId, taskDescription.isTeeTask());
214+
log.info("Running post-compute [chainTaskId:{}, requiresSgx:{}]",
215+
chainTaskId, taskDescription.requiresSgx());
216216

217217
final PostComputeResponse postComputeResponse;
218-
if (!taskDescription.isTeeTask()) {
218+
if (!taskDescription.requiresSgx()) {
219219
postComputeResponse = postComputeService.runStandardPostCompute(taskDescription);
220220
} else {
221221
postComputeResponse = postComputeService.runTeePostCompute(taskDescription);

src/main/java/com/iexec/worker/compute/app/AppComputeService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public AppComputeResponse runCompute(final TaskDescription taskDescription) {
6969

7070
final SgxDriverMode sgxDriverMode;
7171
final List<String> env;
72-
if (taskDescription.isTeeTask()) {
72+
if (taskDescription.requiresSgx()) {
7373
final TeeService teeService = teeServicesManager.getTeeService(taskDescription.getTeeFramework());
7474
env = teeService.buildComputeDockerEnv(taskDescription);
7575
binds.addAll(teeService.getAdditionalBindings().stream().map(Bind::parse).toList());
@@ -83,7 +83,7 @@ public AppComputeResponse runCompute(final TaskDescription taskDescription) {
8383
.withBinds(binds)
8484
.withDevices(sgxService.getSgxDevices());
8585
// Enclave should be able to connect to the LAS
86-
if (taskDescription.isTeeTask()) {
86+
if (taskDescription.requiresSgx()) {
8787
hostConfig.withNetworkMode(workerConfigService.getDockerNetworkName());
8888
}
8989
final DockerRunRequest runRequest = DockerRunRequest.builder()

src/main/java/com/iexec/worker/result/ResultService.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ public ResultModel getResultModelWithZip(final String chainTaskId) {
143143

144144
return ResultModel.builder()
145145
.chainTaskId(chainTaskId)
146-
.image(resultInfo.getImage())
147-
.cmd(resultInfo.getCmd())
148146
.zip(zipResultAsBytes)
149147
.deterministHash(resultInfo.getDeterministHash())
150148
.build();
@@ -193,7 +191,7 @@ public String uploadResultAndGetLink(final WorkerpoolAuthorization workerpoolAut
193191
}
194192

195193
// Cloud computing - tee
196-
if (task.isTeeTask()) {
194+
if (task.requiresSgx()) {
197195
log.info("Web2 storage, already uploaded (with tee) [chainTaskId:{}]", chainTaskId);
198196
return getWeb2ResultLink(task);
199197
}
@@ -351,7 +349,7 @@ public boolean writeComputedFile(final ComputedFile computedFile) {
351349
return false;
352350
}
353351
final ChainDeal chainDeal = iexecHubService.getChainDeal(chainTask.getDealid()).orElse(null);
354-
if (chainDeal == null || !TeeUtils.isTeeTag(chainDeal.getTag())) {
352+
if (chainDeal == null || TeeUtils.getTeeFramework(chainDeal.getTag()) == null) {
355353
log.error("Cannot write computed file if task is not of TEE type [chainTaskId:{}, computedFile:{}]",
356354
chainTaskId, computedFile);
357355
return false;

src/main/java/com/iexec/worker/task/TaskManagerService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ ReplicateActionResponse start(final TaskDescription taskDescription) {
106106
}
107107

108108
// result encryption is not supported for standard tasks
109-
if (!taskDescription.isTeeTask() && taskDescription.getDealParams().isIexecResultEncryption()) {
109+
if (!taskDescription.requiresSgx() && taskDescription.getDealParams().isIexecResultEncryption()) {
110110
return getFailureResponseAndPrintErrors(
111111
List.of(new WorkflowError(TASK_DESCRIPTION_INVALID)), context, chainTaskId);
112112
}
113113

114-
if (taskDescription.isTeeTask()) {
114+
if (taskDescription.requiresSgx()) {
115115
// If any TEE prerequisite is not met,
116116
// then we won't be able to run the task.
117117
// So it should be aborted right now.
@@ -194,7 +194,7 @@ ReplicateActionResponse downloadData(final TaskDescription taskDescription) {
194194
requireNonNull(taskDescription, "task description must not be null");
195195
final String chainTaskId = taskDescription.getChainTaskId();
196196
// Return early if TEE task
197-
if (taskDescription.isTeeTask()) {
197+
if (taskDescription.requiresSgx()) {
198198
log.info("Dataset and input files will be downloaded by the pre-compute enclave [chainTaskId:{}]", chainTaskId);
199199
return ReplicateActionResponse.success();
200200
}
@@ -255,7 +255,7 @@ ReplicateActionResponse compute(final TaskDescription taskDescription) {
255255
List.of(new WorkflowError(APP_NOT_FOUND_LOCALLY)), context, chainTaskId);
256256
}
257257

258-
if (taskDescription.isTeeTask()) {
258+
if (taskDescription.requiresSgx()) {
259259
final TeeService teeService = teeServicesManager.getTeeService(taskDescription.getTeeFramework());
260260
if (!teeService.prepareTeeForTask(chainTaskId)) {
261261
return getFailureResponseAndPrintErrors(

src/test/java/com/iexec/worker/chain/ContributionServiceTests.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
import com.iexec.common.result.ComputedFile;
2020
import com.iexec.commons.poco.chain.*;
21+
import com.iexec.commons.poco.order.OrderTag;
2122
import com.iexec.commons.poco.security.Signature;
2223
import com.iexec.commons.poco.task.TaskDescription;
24+
import com.iexec.commons.poco.tee.TeeUtils;
2325
import com.iexec.commons.poco.utils.BytesUtils;
2426
import com.iexec.commons.poco.utils.HashUtils;
2527
import com.iexec.commons.poco.utils.SignatureUtils;
@@ -71,10 +73,13 @@ class ContributionServiceTests {
7173
.contributors(List.of())
7274
.build();
7375

74-
private final TaskDescription taskDescription = TaskDescription.builder()
75-
.chainTaskId(chainTask.getChainTaskId())
76-
.trust(BigInteger.ONE)
77-
.build();
76+
TaskDescription getTaskDescription(final OrderTag tag) {
77+
return TaskDescription.builder()
78+
.chainTaskId(chainTask.getChainTaskId())
79+
.trust(BigInteger.ONE)
80+
.teeFramework(TeeUtils.getTeeFramework(tag.getValue()))
81+
.build();
82+
}
7883

7984
@BeforeEach
8085
void beforeEach() {
@@ -101,14 +106,9 @@ void shouldChainTaskNotBeInitialized() {
101106
@Test
102107
void getCannotContributeStatusCauseShouldReturnWorkerpoolAuthorizationNotFound() {
103108
final String chainTaskId = chainTask.getChainTaskId();
104-
final TaskDescription contributeAndFinalizeTaskDescription = TaskDescription.builder()
105-
.chainTaskId(chainTaskId)
106-
.trust(BigInteger.ONE)
107-
.isTeeTask(true)
108-
.build();
109109

110110
when(workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId)).thenReturn(null);
111-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(contributeAndFinalizeTaskDescription);
111+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.TEE_SCONE));
112112
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.of(chainTask));
113113

114114
assertThat(contributionService.getCannotContributeStatusCause(chainTaskId))
@@ -122,7 +122,7 @@ void getCannotContributeStatusShouldReturnChainUnreachable() {
122122
final String chainTaskId = "chainTaskId";
123123
when(workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId))
124124
.thenReturn(getTeeWorkerpoolAuth());
125-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(taskDescription);
125+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
126126
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.empty());
127127

128128
assertThat(contributionService.getCannotContributeStatusCause(chainTaskId))
@@ -137,7 +137,7 @@ void getCannotContributeStatusShouldReturnStakeTooLow() {
137137

138138
when(workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId))
139139
.thenReturn(getTeeWorkerpoolAuth());
140-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(taskDescription);
140+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
141141
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.of(chainTask));
142142
when(iexecHubService.getChainAccount()).thenReturn(Optional.of(ChainAccount.builder().deposit(0).build()));
143143
when(iexecHubService.getChainDeal(CHAIN_DEAL_ID)).thenReturn(Optional.of(ChainDeal.builder().workerStake(BigInteger.valueOf(5)).build()));
@@ -163,7 +163,7 @@ void getCannotContributeStatusShouldReturnTaskNotActive() {
163163

164164
when(workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId))
165165
.thenReturn(getTeeWorkerpoolAuth());
166-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(taskDescription);
166+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
167167
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.of(inactiveTask));
168168
when(iexecHubService.getChainAccount()).thenReturn(Optional.of(ChainAccount.builder().deposit(1000).build()));
169169
when(iexecHubService.getChainDeal(CHAIN_DEAL_ID)).thenReturn(Optional.of(ChainDeal.builder().workerStake(BigInteger.valueOf(5)).build()));
@@ -188,7 +188,7 @@ void getCannotContributeStatusShouldReturnAfterDeadline() {
188188

189189
when(workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId))
190190
.thenReturn(getTeeWorkerpoolAuth());
191-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(taskDescription);
191+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
192192
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.of(timedOutChainTask));
193193
when(iexecHubService.getChainAccount())
194194
.thenReturn(Optional.of(ChainAccount.builder().deposit(1000).build()));
@@ -216,7 +216,7 @@ void getCannotContributeStatusShouldReturnContributionAlreadySet() {
216216

217217
when(workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId))
218218
.thenReturn(getTeeWorkerpoolAuth());
219-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(taskDescription);
219+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
220220
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.of(alreadyContributedChainTask));
221221
when(iexecHubService.getChainAccount())
222222
.thenReturn(Optional.of(ChainAccount.builder().deposit(1000).build()));
@@ -237,7 +237,7 @@ void getCannotContributeStatusCauseShouldReturnEmpty() {
237237

238238
when(workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId))
239239
.thenReturn(getTeeWorkerpoolAuth());
240-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(taskDescription);
240+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
241241
when(iexecHubService.getChainTask(chainTaskId))
242242
.thenReturn(Optional.of(chainTask));
243243
when(iexecHubService.getChainAccount())
@@ -256,14 +256,10 @@ void getCannotContributeStatusCauseShouldReturnEmpty() {
256256
@Test
257257
void getCannotContributeStatusShouldReturnEmptyForContributeAndFinalizeFlow() {
258258
final String chainTaskId = chainTask.getChainTaskId();
259-
final TaskDescription contributeAndFinalizeTaskDescription = TaskDescription.builder()
260-
.trust(BigInteger.ONE)
261-
.isTeeTask(true)
262-
.build();
263259

264260
when(workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId))
265261
.thenReturn(getTeeWorkerpoolAuth());
266-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(contributeAndFinalizeTaskDescription);
262+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.TEE_SCONE));
267263
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.of(chainTask));
268264

269265
assertThat(contributionService.getCannotContributeStatusCause(chainTaskId)).isEmpty();
@@ -286,7 +282,7 @@ void getCannotContributeStatusShouldReturnMultipleErrors() {
286282

287283
when(workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId))
288284
.thenReturn(getTeeWorkerpoolAuth());
289-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(taskDescription);
285+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
290286
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.of(problematicChainTask));
291287
when(iexecHubService.getChainAccount())
292288
.thenReturn(Optional.of(ChainAccount.builder().deposit(0).build())); // Also stake too low
@@ -310,7 +306,7 @@ void getCannotContributeStatusShouldReturnAuthAndChainUnreachableErrors() {
310306
final String chainTaskId = chainTask.getChainTaskId();
311307

312308
when(workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId)).thenReturn(null);
313-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(taskDescription);
309+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
314310
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.empty());
315311

316312
assertThat(contributionService.getCannotContributeStatusCause(chainTaskId))
@@ -342,7 +338,7 @@ void getCannotContributeAndFinalizeStatusCauseShouldReturnTrustNotOne() {
342338
void getCannotContributeAndFinalizeStatusCauseShouldReturnChainUnreachable() {
343339
final String chainTaskId = chainTask.getChainTaskId();
344340

345-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(taskDescription);
341+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
346342
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.empty());
347343

348344
assertThat(contributionService.getCannotContributeAndFinalizeStatusCause(chainTaskId))
@@ -362,7 +358,7 @@ void getCannotContributeAndFinalizeStatusCauseShouldReturnTaskAlreadyContributed
362358

363359
final String chainTaskId = chainTaskWithContribution.getChainTaskId();
364360

365-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(taskDescription);
361+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
366362
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.of(chainTaskWithContribution));
367363

368364
assertThat(contributionService.getCannotContributeAndFinalizeStatusCause(chainTaskId))
@@ -373,7 +369,7 @@ void getCannotContributeAndFinalizeStatusCauseShouldReturnTaskAlreadyContributed
373369
void getCannotContributeAndFinalizeStatusCauseShouldReturnEmpty() {
374370
final String chainTaskId = chainTask.getChainTaskId();
375371

376-
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(taskDescription);
372+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
377373
when(iexecHubService.getChainTask(chainTaskId)).thenReturn(Optional.of(chainTask));
378374

379375
assertThat(contributionService.getCannotContributeAndFinalizeStatusCause(chainTaskId)).isEmpty();
@@ -433,7 +429,7 @@ void getContribution() {
433429

434430
final WorkerpoolAuthorization teeWorkerpoolAuth = getTeeWorkerpoolAuth();
435431
when(workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId)).thenReturn(teeWorkerpoolAuth);
436-
when(iexecHubService.isTeeTask(chainTaskId)).thenReturn(false);
432+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.STANDARD));
437433

438434
final ComputedFile computedFile = ComputedFile.builder()
439435
.taskId(chainTaskId)
@@ -469,7 +465,7 @@ void getContributionWithTee() {
469465
when(enclaveAuthorizationService.
470466
isVerifiedEnclaveSignature(anyString(), anyString(), anyString(), anyString(), anyString()))
471467
.thenReturn(true);
472-
when(iexecHubService.isTeeTask(chainTaskId)).thenReturn(true);
468+
when(iexecHubService.getTaskDescription(chainTaskId)).thenReturn(getTaskDescription(OrderTag.TEE_SCONE));
473469

474470
final ComputedFile computedFile = ComputedFile.builder()
475471
.taskId(chainTaskId)

0 commit comments

Comments
 (0)