Skip to content

Commit 003929d

Browse files
authored
Remove code related to reopen PoCo feature in IexecHubService and TaskUpdateManager (#743)
1 parent 036b456 commit 003929d

File tree

9 files changed

+29
-250
lines changed

9 files changed

+29
-250
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
1515
- Remove redundant blockchain calls to diminish pressure on Ethereum JSON-RPC API. (#734)
1616
- Compute alive workers metrics in `WorkerService#updateMetrics` scheduled job. (#739)
1717
- Fix Spring Security deprecations after Spring Boot 3.3.8 upgrade. (#740)
18+
- Remove code related to reopen PoCo feature in `IexecHubService` and `TaskUpdateManager`. (#743)
1819

1920
### Breaking API changes
2021

src/main/java/com/iexec/core/chain/DealWatcherService.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 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.
@@ -180,10 +180,9 @@ private void onDealEvent(DealEvent dealEvent, String watcher) {
180180
}
181181

182182
/**
183-
* Handle new onchain deals and add its tasks
184-
* to db.
183+
* Handle new on-chain deals and add its tasks to MongoDB ask collection.
185184
*
186-
* @param dealEvent
185+
* @param dealEvent Object representing PoCo SchedulerNoticeEvent
187186
*/
188187
private void handleDeal(DealEvent dealEvent) {
189188
String chainDealId = dealEvent.getChainDealId();
@@ -203,7 +202,7 @@ private void handleDeal(DealEvent dealEvent) {
203202
chainDealId,
204203
taskIndex,
205204
dealEvent.getBlockNumber().longValue(),
206-
BytesUtils.hexStringToAscii(chainDeal.getChainApp().getUri()),
205+
chainDeal.getChainApp().getMultiaddr(),
207206
chainDeal.getParams().getIexecArgs(),
208207
chainDeal.getTrust().intValue(),
209208
chainDeal.getChainCategory().getMaxExecutionTime(),

src/main/java/com/iexec/core/chain/IexecHubService.java

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,18 @@
2828
import org.web3j.abi.datatypes.Event;
2929
import org.web3j.protocol.core.DefaultBlockParameter;
3030
import org.web3j.protocol.core.methods.request.EthFilter;
31-
import org.web3j.protocol.core.methods.response.TransactionReceipt;
3231

3332
import java.math.BigInteger;
34-
import java.time.Instant;
3533
import java.util.Date;
36-
import java.util.List;
37-
import java.util.Optional;
38-
import java.util.concurrent.CompletableFuture;
39-
import java.util.concurrent.ExecutionException;
40-
import java.util.concurrent.Executors;
41-
import java.util.concurrent.ThreadPoolExecutor;
4234

4335
import static com.iexec.commons.poco.chain.ChainContributionStatus.CONTRIBUTED;
4436
import static com.iexec.commons.poco.chain.ChainContributionStatus.REVEALED;
4537
import static com.iexec.commons.poco.contract.generated.IexecHubContract.*;
46-
import static com.iexec.commons.poco.utils.BytesUtils.stringToBytes;
4738

4839
@Slf4j
4940
@Service
5041
public class IexecHubService extends IexecHubAbstractService implements Purgeable {
5142

52-
private final ThreadPoolExecutor executor;
5343
private final SignerService signerService;
5444
private final Web3jService web3jService;
5545

@@ -62,7 +52,6 @@ public IexecHubService(SignerService signerService,
6252
chainConfig.getHubAddress());
6353
this.signerService = signerService;
6454
this.web3jService = web3jService;
65-
this.executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
6655
if (!hasEnoughGas()) {
6756
System.exit(0);
6857
}
@@ -130,67 +119,6 @@ public Date getChainDealFinalDeadline(ChainDeal chainDeal) {
130119
return new Date(startTime + maxTime * 10);
131120
}
132121

133-
public boolean canReopen(String chainTaskId) {
134-
final ChainTask chainTask = getChainTask(chainTaskId).orElse(null);
135-
if (chainTask == null) {
136-
return false;
137-
}
138-
139-
boolean isChainTaskStatusRevealing = chainTask.getStatus() == ChainTaskStatus.REVEALING;
140-
boolean isBeforeFinalDeadline = Instant.now().toEpochMilli() < chainTask.getFinalDeadline();
141-
boolean isAfterRevealDeadline = chainTask.getRevealDeadline() <= Instant.now().toEpochMilli();
142-
boolean revealCounterEqualsZero = chainTask.getRevealCounter() == 0;
143-
144-
boolean check = isChainTaskStatusRevealing && isBeforeFinalDeadline && isAfterRevealDeadline
145-
&& revealCounterEqualsZero;
146-
if (check) {
147-
log.info("Reopenable onchain [chainTaskId:{}]", chainTaskId);
148-
} else {
149-
log.warn("Can't reopen [chainTaskId:{}, " +
150-
"isChainTaskStatusRevealing:{}, isBeforeFinalDeadline:{}, " +
151-
"isAfterRevealDeadline:{}, revealCounterEqualsZero:{}]", chainTaskId,
152-
isChainTaskStatusRevealing, isBeforeFinalDeadline, isAfterRevealDeadline, revealCounterEqualsZero);
153-
}
154-
return check;
155-
}
156-
157-
public Optional<ChainReceipt> reOpen(String chainTaskId) {
158-
log.info("Requested reopen [chainTaskId:{}, waitingTxCount:{}]", chainTaskId, getWaitingTransactionCount());
159-
try {
160-
return CompletableFuture.supplyAsync(() -> sendReopenTransaction(chainTaskId), executor).get();
161-
} catch (InterruptedException e) {
162-
Thread.currentThread().interrupt();
163-
} catch (ExecutionException e) {
164-
log.error("reOpen asynchronous execution did not complete", e);
165-
}
166-
return Optional.empty();
167-
}
168-
169-
private Optional<ChainReceipt> sendReopenTransaction(String chainTaskId) {
170-
TransactionReceipt receipt;
171-
try {
172-
receipt = iexecHubContract.reopen(stringToBytes(chainTaskId)).send();
173-
} catch (Exception e) {
174-
log.error("Failed reopen [chainTaskId:{}, error:{}]", chainTaskId, e.getMessage());
175-
return Optional.empty();
176-
}
177-
178-
List<IexecHubContract.TaskReopenEventResponse> eventsList = IexecHubContract.getTaskReopenEvents(receipt);
179-
if (eventsList.isEmpty()) {
180-
log.error("Failed to get reopen event [chainTaskId:{}]", chainTaskId);
181-
return Optional.empty();
182-
}
183-
184-
ChainReceipt chainReceipt = buildChainReceipt(receipt);
185-
log.info("Reopened [chainTaskId:{}, gasUsed:{}, block:{}]",
186-
chainTaskId, receipt.getGasUsed(), chainReceipt.getBlockNumber());
187-
return Optional.of(chainReceipt);
188-
}
189-
190-
private long getWaitingTransactionCount() {
191-
return executor.getTaskCount() - executor.getCompletedTaskCount();
192-
}
193-
194122
Flowable<IexecHubContract.SchedulerNoticeEventResponse> getDealEventObservable(EthFilter filter) {
195123
return iexecHubContract.schedulerNoticeEventFlowable(filter);
196124
}
@@ -201,14 +129,6 @@ public boolean hasEnoughGas() {
201129
return hasEnoughGas;
202130
}
203131

204-
private ChainReceipt buildChainReceipt(TransactionReceipt receipt) {
205-
return ChainReceipt.builder()
206-
.txHash(receipt.getTransactionHash())
207-
.blockNumber(receipt.getBlockNumber() != null ?
208-
receipt.getBlockNumber().longValue() : 0)
209-
.build();
210-
}
211-
212132
// region check contribution status
213133
public boolean repeatIsContributedTrue(String chainTaskId, String walletAddress) {
214134
return web3jService.repeatCheck(NB_BLOCKS_TO_WAIT_PER_RETRY, MAX_RETRIES,

src/main/java/com/iexec/core/detector/replicate/RevealTimeoutDetector.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 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.
@@ -37,11 +37,11 @@
3737
@Service
3838
public class RevealTimeoutDetector implements Detector {
3939

40-
private TaskService taskService;
41-
private ReplicatesService replicatesService;
40+
private final TaskService taskService;
41+
private final ReplicatesService replicatesService;
4242

43-
public RevealTimeoutDetector(TaskService taskService,
44-
ReplicatesService replicatesService) {
43+
public RevealTimeoutDetector(final TaskService taskService,
44+
final ReplicatesService replicatesService) {
4545
this.taskService = taskService;
4646
this.replicatesService = replicatesService;
4747
}
@@ -50,10 +50,8 @@ public RevealTimeoutDetector(TaskService taskService,
5050
@Override
5151
public void detect() {
5252
log.debug("Trying to detect reveal timeout");
53-
54-
detectTaskAfterRevealDealLineWithZeroReveal();//finalizable
55-
56-
detectTaskAfterRevealDealLineWithAtLeastOneReveal();//reopenable
53+
detectTaskAfterRevealDealLineWithZeroReveal(); // can be reopened
54+
detectTaskAfterRevealDealLineWithAtLeastOneReveal(); // can be finalized
5755
}
5856

5957
private void detectTaskAfterRevealDealLineWithAtLeastOneReveal() {

src/main/java/com/iexec/core/task/update/TaskUpdateManager.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -525,28 +525,21 @@ void consensusReached2AtLeastOneReveal2ResultUploading(Task task) {
525525
}
526526
}
527527

528-
void consensusReached2Reopening(Task task) {
528+
void consensusReached2Reopening(final Task task) {
529529
log.debug("consensusReached2Reopening [chainTaskId:{}]", task.getChainTaskId());
530-
Date now = new Date();
530+
final Date now = new Date();
531531

532-
boolean isConsensusReachedStatus = task.getCurrentStatus() == CONSENSUS_REACHED;
533-
boolean isAfterRevealDeadline = task.getRevealDeadline() != null && now.after(task.getRevealDeadline());
534-
boolean hasAtLeastOneReveal = replicatesService.getNbReplicatesWithCurrentStatus(task.getChainTaskId(), ReplicateStatus.REVEALED) > 0;
532+
final boolean isConsensusReachedStatus = task.getCurrentStatus() == CONSENSUS_REACHED;
533+
final boolean isAfterRevealDeadline = task.getRevealDeadline() != null && now.after(task.getRevealDeadline());
534+
final boolean hasAtLeastOneReveal = replicatesService.getNbReplicatesWithCurrentStatus(task.getChainTaskId(), ReplicateStatus.REVEALED) > 0;
535535

536536
if (!isConsensusReachedStatus || !isAfterRevealDeadline || hasAtLeastOneReveal) {
537537
return;
538538
}
539539

540-
boolean canReopen = iexecHubService.canReopen(task.getChainTaskId());
541-
boolean hasEnoughGas = iexecHubService.hasEnoughGas();
542-
543-
if (!canReopen || !hasEnoughGas) {
544-
return;
545-
}
546-
547540
updateTaskStatusAndSave(task, REOPENING);
548541
//TODO Update reopen call
549-
Optional<ChainReceipt> optionalChainReceipt = Optional.empty(); //iexecHubService.reOpen(task.getChainTaskId());
542+
Optional<ChainReceipt> optionalChainReceipt = Optional.empty();
550543

551544
if (optionalChainReceipt.isEmpty()) {
552545
log.error("Reopen failed [chainTaskId:{}]", task.getChainTaskId());
@@ -558,12 +551,11 @@ void consensusReached2Reopening(Task task) {
558551
reopening2Reopened(task, optionalChainReceipt.get());
559552
}
560553

561-
void reopening2Reopened(Task task) {
562-
log.debug("reopening2Reopened [chainTaskId:{}]", task.getChainTaskId());
554+
void reopening2Reopened(final Task task) {
563555
reopening2Reopened(task, null);
564556
}
565557

566-
void reopening2Reopened(Task task, ChainReceipt chainReceipt) {
558+
void reopening2Reopened(final Task task, final ChainReceipt chainReceipt) {
567559
log.debug("reopening2Reopened [chainTaskId:{}]", task.getChainTaskId());
568560
Optional<ChainTask> oChainTask = iexecHubService.getChainTask(task.getChainTaskId());
569561
if (oChainTask.isEmpty()) {

src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 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.
@@ -164,7 +164,7 @@ void shouldUpdateLastSeenBlockWhenOneDeal() {
164164
@Test
165165
void shouldUpdateLastSeenBlockWhenOneDealAndCreateTask() {
166166
ChainApp chainApp = ChainApp.builder()
167-
.uri("0x00").build();
167+
.multiaddr("0x00").build();
168168

169169
ChainCategory chainCategory = ChainCategory.builder().build();
170170

@@ -206,7 +206,7 @@ void shouldUpdateLastSeenBlockWhenOneDealAndNotCreateTaskSinceDealIsExpired() {
206206
ChainDeal chainDeal = ChainDeal.builder()
207207
.botFirst(BigInteger.valueOf(0))
208208
.botSize(BigInteger.valueOf(1))
209-
.chainApp(ChainApp.builder().uri("0x00").build())
209+
.chainApp(ChainApp.builder().multiaddr("0x00").build())
210210
.chainCategory(ChainCategory.builder().build())
211211
.params(DealParams.builder().iexecArgs("args").build())
212212
.trust(BigInteger.valueOf(3))

src/test/java/com/iexec/core/chain/IexecHubServiceTests.java

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import org.web3j.crypto.Keys;
3434
import org.web3j.protocol.core.methods.response.Log;
3535

36-
import java.time.Instant;
37-
import java.time.temporal.ChronoUnit;
3836
import java.util.Optional;
3937
import java.util.function.BiFunction;
4038
import java.util.stream.Stream;
@@ -49,7 +47,6 @@
4947
class IexecHubServiceTests {
5048

5149
private static final String TRANSACTION_HASH = "transactionHash";
52-
private static final long TIME_INTERVAL_IN_MS = 100L;
5350

5451
@Mock
5552
private SignerService signerService;
@@ -91,67 +88,6 @@ void shouldTaskNotBeInCompletedStatusOnChain() {
9188
}
9289
// endregion
9390

94-
// region canReopen
95-
@Test
96-
void canNotRepoenWhenChainTaskNotFound() {
97-
when(iexecHubService.getChainTask(CHAIN_TASK_ID)).thenReturn(Optional.empty());
98-
assertThat(iexecHubService.canReopen(CHAIN_TASK_ID)).isFalse();
99-
}
100-
101-
@Test
102-
void canNotReopenWhenNotRevealing() {
103-
final ChainTask chainTask = ChainTask.builder()
104-
.status(ChainTaskStatus.ACTIVE)
105-
.finalDeadline(Instant.now().plus(TIME_INTERVAL_IN_MS, ChronoUnit.MILLIS).toEpochMilli())
106-
.build();
107-
when(iexecHubService.getChainTask(CHAIN_TASK_ID)).thenReturn(Optional.of(chainTask));
108-
assertThat(iexecHubService.canReopen(CHAIN_TASK_ID)).isFalse();
109-
}
110-
111-
@Test
112-
void canNotReopenWhenFinalDeadlineReached() {
113-
final ChainTask chainTask = ChainTask.builder()
114-
.status(ChainTaskStatus.REVEALING)
115-
.finalDeadline(Instant.now().minus(TIME_INTERVAL_IN_MS, ChronoUnit.MILLIS).toEpochMilli())
116-
.build();
117-
when(iexecHubService.getChainTask(CHAIN_TASK_ID)).thenReturn(Optional.of(chainTask));
118-
assertThat(iexecHubService.canReopen(CHAIN_TASK_ID)).isFalse();
119-
}
120-
121-
@Test
122-
void canNotReopenWhenBeforeRevealDeadline() {
123-
final ChainTask chainTask = ChainTask.builder()
124-
.status(ChainTaskStatus.REVEALING)
125-
.revealDeadline(Instant.now().plus(TIME_INTERVAL_IN_MS, ChronoUnit.MILLIS).toEpochMilli())
126-
.finalDeadline(Instant.now().plus(TIME_INTERVAL_IN_MS, ChronoUnit.MILLIS).toEpochMilli())
127-
.build();
128-
when(iexecHubService.getChainTask(CHAIN_TASK_ID)).thenReturn(Optional.of(chainTask));
129-
assertThat(iexecHubService.canReopen(CHAIN_TASK_ID)).isFalse();
130-
}
131-
132-
@Test
133-
void canNotReopenWhenSomeWinnersRevealed() {
134-
final ChainTask chainTask = ChainTask.builder()
135-
.status(ChainTaskStatus.REVEALING)
136-
.revealCounter(1)
137-
.finalDeadline(Instant.now().minus(TIME_INTERVAL_IN_MS, ChronoUnit.MILLIS).toEpochMilli())
138-
.build();
139-
when(iexecHubService.getChainTask(CHAIN_TASK_ID)).thenReturn(Optional.of(chainTask));
140-
assertThat(iexecHubService.canReopen(CHAIN_TASK_ID)).isFalse();
141-
}
142-
143-
@Test
144-
void canReopenWhenRevealDeadlineReachedAndNoReveal() {
145-
final ChainTask chainTask = ChainTask.builder()
146-
.status(ChainTaskStatus.REVEALING)
147-
.revealDeadline(Instant.now().minus(TIME_INTERVAL_IN_MS, ChronoUnit.MILLIS).toEpochMilli())
148-
.finalDeadline(Instant.now().plus(TIME_INTERVAL_IN_MS, ChronoUnit.MILLIS).toEpochMilli())
149-
.build();
150-
when(iexecHubService.getChainTask(CHAIN_TASK_ID)).thenReturn(Optional.of(chainTask));
151-
assertThat(iexecHubService.canReopen(CHAIN_TASK_ID)).isTrue();
152-
}
153-
// endregion
154-
15591
// region isContributed
15692
@ParameterizedTest
15793
@EnumSource(value = ChainContributionStatus.class, mode = EnumSource.Mode.INCLUDE, names = {"CONTRIBUTED", "REVEALED"})

0 commit comments

Comments
 (0)