Skip to content

Commit 7c19751

Browse files
authored
Do not supply replicates past their contribution deadlines to workers (#702)
1 parent 58f3e61 commit 7c19751

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## [[NEXT]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/vNEXT) 2024
66

7+
### Deprecation Notices
8+
9+
- Deprecate legacy task feedback API endpoints. (#701)
10+
711
### New Features
812

913
- Create `iexec-task-api` to access task feedback API. (#695)
@@ -15,7 +19,7 @@ All notable changes to this project will be documented in this file.
1519

1620
- Always use `WorkerpoolAuthorization` to retrieve JWT and check result upload on Result Proxy. (#690)
1721
- Use correct `Signature` import in `SchedulerClient`. (#697)
18-
- Deprecate legacy task feedback API endpoints. (#701)
22+
- Do not supply replicates past their contribution deadline to workers. (#702)
1923

2024
### Quality
2125

src/main/java/com/iexec/core/task/TaskRepository.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,23 @@ public interface TaskRepository extends MongoRepository<Task, String> {
3939
/**
4040
* Retrieves the prioritized task matching with given criteria:
4141
* <ul>
42-
* <li>Task is in one of given {@code statuses};</li>
43-
* <li>Task has not given {@code excludedTag}
44-
* - this is mainly used to exclude TEE tasks;
45-
* </li>
46-
* <li>Chain task ID is not one of the given {@code excludedChainTaskIds};</li>
47-
* <li>Tasks are prioritized according to the {@code sort} parameter.</li>
42+
* <li>Task is in one of given {@code statuses}
43+
* <li>Task contribution deadline is after a provided {@code timestamp}
44+
* <li>Task has not given {@code excludedTags}, this is mainly used to exclude TEE tasks
45+
* <li>Chain task ID is not one of the given {@code excludedChainTaskIds}
46+
* <li>Tasks are prioritized according to the {@code sort} parameter
4847
* </ul>
4948
*
5049
* @param statuses The task status should be one of this list.
50+
* @param timestamp The task contribution deadline should be after the provided timestamp.
5151
* @param excludedTags The task tag should not be one this tag list
5252
* - use {@literal null} if no tag should be excluded.
5353
* @param excludedChainTaskIds The chain task ID should not be one of this list.
5454
* @param sort How to prioritize tasks.
5555
* @return The first task matching with the criteria, according to the {@code sort} parameter.
5656
*/
57-
Optional<Task> findFirstByCurrentStatusInAndTagNotInAndChainTaskIdNotIn(List<TaskStatus> statuses, List<String> excludedTags, List<String> excludedChainTaskIds, Sort sort);
57+
Optional<Task> findFirstByCurrentStatusInAndContributionDeadlineAfterAndTagNotInAndChainTaskIdNotIn(
58+
List<TaskStatus> statuses, Date timestamp, List<String> excludedTags, List<String> excludedChainTaskIds, Sort sort);
5859

5960
@Query(value = "{ finalDeadline: {$lt : ?0} }", fields = "{ chainTaskId: true }")
6061
List<Task> findChainTaskIdsByFinalDeadlineBefore(Date date);

src/main/java/com/iexec/core/task/TaskService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public Optional<Task> getPrioritizedInitializedOrRunningTask(
251251
}
252252

253253
/**
254-
* Shortcut for {@link TaskRepository#findFirstByCurrentStatusInAndTagNotInAndChainTaskIdNotIn}.
254+
* Shortcut for {@link TaskRepository#findFirstByCurrentStatusInAndContributionDeadlineAfterAndTagNotInAndChainTaskIdNotIn}.
255255
* Retrieves the prioritized task matching with given criteria:
256256
* <ul>
257257
* <li>Task is in one of given {@code statuses};</li>
@@ -273,8 +273,9 @@ private Optional<Task> findPrioritizedTask(List<TaskStatus> statuses,
273273
List<String> excludedTags,
274274
List<String> excludedChainTaskIds,
275275
Sort sort) {
276-
return taskRepository.findFirstByCurrentStatusInAndTagNotInAndChainTaskIdNotIn(
276+
return taskRepository.findFirstByCurrentStatusInAndContributionDeadlineAfterAndTagNotInAndChainTaskIdNotIn(
277277
statuses,
278+
new Date(),
278279
excludedTags,
279280
excludedChainTaskIds,
280281
sort

src/test/java/com/iexec/core/task/TaskServiceTests.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.junit.jupiter.api.extension.ExtendWith;
3333
import org.mockito.Mock;
3434
import org.mockito.Mockito;
35-
import org.mockito.MockitoAnnotations;
35+
import org.mockito.junit.jupiter.MockitoExtension;
3636
import org.springframework.beans.factory.annotation.Autowired;
3737
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
3838
import org.springframework.boot.test.system.CapturedOutput;
@@ -67,6 +67,7 @@
6767

6868
@DataMongoTest
6969
@Testcontainers
70+
@ExtendWith(MockitoExtension.class)
7071
@ExtendWith(OutputCaptureExtension.class)
7172
class TaskServiceTests {
7273
private final long maxExecutionTime = 60000;
@@ -101,7 +102,6 @@ static void initRegistry() {
101102

102103
@BeforeEach
103104
void init() {
104-
MockitoAnnotations.openMocks(this);
105105
taskRepository.deleteAll();
106106
taskService = new TaskService(mongoTemplate, taskRepository, iexecHubService, applicationEventPublisher);
107107
}
@@ -259,6 +259,7 @@ void shouldNotFindByCurrentStatusList() {
259259
}
260260
// endregion
261261

262+
// region getPrioritizedInitializedOrRunningTask
262263
@Test
263264
void shouldGetInitializedOrRunningTasks() {
264265
final Task task = getStubTask();
@@ -269,6 +270,17 @@ void shouldGetInitializedOrRunningTasks() {
269270
.isEqualTo(Optional.of(task));
270271
}
271272

273+
@Test
274+
void shouldNotGetTaskPastContributionDeadline() {
275+
final Task task = getStubTask();
276+
task.setContributionDeadline(Date.from(Instant.now().minus(1, ChronoUnit.MINUTES)));
277+
taskRepository.save(task);
278+
assertThat(taskService.getPrioritizedInitializedOrRunningTask(false, List.of()))
279+
.usingRecursiveComparison()
280+
.isEqualTo(Optional.empty());
281+
}
282+
// endregion
283+
272284
@Test
273285
void shouldGetChainTaskIdsOfTasksExpiredBefore() {
274286
Date date = new Date();

src/test/java/com/iexec/core/task/TaskTestsUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2021-2024 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@ public class TaskTestsUtils {
3838

3939
public static Task getStubTask() {
4040
final Task task = new Task(CHAIN_DEAL_ID, 0, DAPP_NAME, COMMAND_LINE, 1, 60000, NO_TEE_TAG);
41+
task.setContributionDeadline(Date.from(Instant.now().plus(1, ChronoUnit.MINUTES)));
4142
task.setFinalDeadline(Date.from(Instant.now().plus(1, ChronoUnit.MINUTES)));
4243
return task;
4344
}

0 commit comments

Comments
 (0)