Skip to content

Commit 2a089a3

Browse files
authored
1 parent d3eaf01 commit 2a089a3

File tree

9 files changed

+77
-59
lines changed

9 files changed

+77
-59
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ All notable changes to this project will be documented in this file.
3636
- Upgrade to Spring Dependency Management Plugin 1.1.4. (#634)
3737
- Upgrade to Spring Doc Openapi 1.7.0. (#637)
3838
- Upgrade to `jenkins-library` 2.7.4. (#630)
39+
- Upgrade to `iexec-commons-poco` 3.2.0. (#648)
40+
- Upgrade to `iexec-common` 8.3.1. (#648)
3941

4042
## [[8.2.3]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.2.3) 2023-12-14
4143

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version=8.2.3
2-
iexecCommonVersion=8.3.0
3-
iexecCommonsPocoVersion=3.1.0
2+
iexecCommonVersion=8.3.1
3+
iexecCommonsPocoVersion=3.2.0
44
iexecBlockchainAdapterVersion=8.2.0-NEXT-SNAPSHOT
55
iexecResultVersion=8.2.0
66
iexecSmsVersion=8.3.0

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public boolean isBeforeContributionDeadline(ChainDeal chainDeal) {
125125
* <li> maxCategoryTime: duration of the deal's category.
126126
* <li> nbOfCategoryUnits: number of category units dedicated
127127
* for the contribution phase.
128+
* </ul>
128129
*
129130
* @param chainDeal
130131
* @return
@@ -147,6 +148,7 @@ public Date getChainDealContributionDeadline(ChainDeal chainDeal) {
147148
* <li> maxCategoryTime: duration of the deal's category.
148149
* <li> 10: number of category units dedicated
149150
* for the hole execution.
151+
* </ul>
150152
*
151153
* @param chainDeal
152154
* @return
@@ -267,14 +269,14 @@ public boolean repeatIsRevealedTrue(String chainTaskId, String walletAddress) {
267269
"isRevealedTrue", this::isRevealed, chainTaskId, walletAddress);
268270
}
269271

270-
boolean isContributed(String... args) {
272+
public boolean isContributed(String... args) {
271273
return getChainContribution(args[0], args[1])
272274
.map(ChainContribution::getStatus)
273275
.filter(chainStatus -> chainStatus == CONTRIBUTED || chainStatus == REVEALED)
274276
.isPresent();
275277
}
276278

277-
boolean isRevealed(String... args) {
279+
public boolean isRevealed(String... args) {
278280
return getChainContribution(args[0], args[1])
279281
.map(ChainContribution::getStatus)
280282
.filter(chainStatus -> chainStatus == REVEALED)

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ protected UnnotifiedAbstractDetector(TaskService taskService,
7171
/**
7272
* Detects the following issues:
7373
* <ul>
74-
* <li>`onchainDone` status only if replicates are in `offchainOngoing` status;</li>
75-
* <li>`onchainDone` if replicates are not in `offchainDone` status.</li>
76-
* </ul></ul>
74+
* <li>`onchainDone` status only if replicates are in `offchainOngoing` status
75+
* <li>`onchainDone` if replicates are not in `offchainDone` status
76+
* </ul>
7777
* The second detection is not always ran, depending on the detector run occurrences.
7878
*/
7979
void detectOnChainChanges() {
@@ -101,11 +101,8 @@ void detectOnchainDoneWhenOffchainOngoing() {
101101
continue;
102102
}
103103

104-
final boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain(
105-
task.getChainTaskId(),
106-
replicate.getWalletAddress(),
107-
onchainDone
108-
);
104+
final boolean statusTrueOnChain = detectStatusReachedOnChain(
105+
task.getChainTaskId(), replicate.getWalletAddress());
109106

110107
if (statusTrueOnChain) {
111108
log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]",
@@ -121,7 +118,7 @@ void detectOnchainDoneWhenOffchainOngoing() {
121118
* (worker didn't notify any status)
122119
* We want to detect them:
123120
* - Frequently but no so often since it's eth node resource consuming and less probable
124-
* - When we receive a "can't do <action>" relative to the `onchainDone` status (e.g.: `CANNOT_REVEAL`)
121+
* - When we receive a "can't do &lt;action&gt;" relative to the `onchainDone` status (e.g.: `CANNOT_REVEAL`)
125122
*/
126123
public void detectOnchainDone() {
127124
log.debug("Detect onchain {} [retryIn:{}]", onchainDone, this.detectorRate * LESS_OFTEN_DETECTOR_FREQUENCY);
@@ -133,11 +130,8 @@ public void detectOnchainDone() {
133130
continue;
134131
}
135132

136-
final boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain(
137-
task.getChainTaskId(),
138-
replicate.getWalletAddress(),
139-
onchainDone
140-
);
133+
final boolean statusTrueOnChain = detectStatusReachedOnChain(
134+
task.getChainTaskId(), replicate.getWalletAddress());
141135

142136
if (statusTrueOnChain) {
143137
log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]",
@@ -148,6 +142,24 @@ public void detectOnchainDone() {
148142
}
149143
}
150144

145+
/**
146+
* Checks if {@code onchainDone} status has been reached on blockchain network.
147+
*
148+
* @param chainTaskId ID of on-chain task
149+
* @param walletAddress Address of a worker working on the current task.
150+
* @return
151+
*/
152+
private boolean detectStatusReachedOnChain(String chainTaskId, String walletAddress) {
153+
switch (onchainDone) {
154+
case CONTRIBUTED:
155+
return iexecHubService.isContributed(chainTaskId, walletAddress);
156+
case REVEALED:
157+
return iexecHubService.isRevealed(chainTaskId, walletAddress);
158+
default:
159+
return false;
160+
}
161+
}
162+
151163
/*
152164
* This method should stay private. We need to ensure that
153165
* it is only called by the POOL_MANAGER.

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,11 @@ public boolean isResultUploaded(TaskDescription task) {
618618
}
619619

620620
public boolean didReplicateContributeOnchain(String chainTaskId, String walletAddress) {
621-
return iexecHubService.isStatusTrueOnChain(
622-
chainTaskId, walletAddress, getChainStatus(ReplicateStatus.CONTRIBUTED));
621+
return iexecHubService.isContributed(chainTaskId, walletAddress);
623622
}
624623

625624
public boolean didReplicateRevealOnchain(String chainTaskId, String walletAddress) {
626-
return iexecHubService.isStatusTrueOnChain(
627-
chainTaskId, walletAddress, getChainStatus(ReplicateStatus.REVEALED));
625+
return iexecHubService.isRevealed(chainTaskId, walletAddress);
628626
}
629627

630628
public void setRevealTimeoutStatusIfNeeded(String chainTaskId, Replicate replicate) {

src/test/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetectorTests.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.iexec.common.replicate.ReplicateStatus;
44
import com.iexec.common.replicate.ReplicateStatusDetails;
55
import com.iexec.common.replicate.ReplicateStatusUpdate;
6-
import com.iexec.commons.poco.chain.ChainContributionStatus;
76
import com.iexec.commons.poco.chain.ChainReceipt;
87
import com.iexec.core.chain.IexecHubService;
98
import com.iexec.core.chain.Web3jService;
@@ -55,6 +54,7 @@ void init() {
5554
}
5655

5756
// region Detector aggregator
57+
5858
/**
5959
* When running {@link ContributionAndFinalizationUnnotifiedDetector#detectOnChainChanges} 10 times,
6060
* {@link ReplicatesService#updateReplicateStatus(String, String, ReplicateStatus, ReplicateStatusDetails)} should be called 11 times:
@@ -73,7 +73,7 @@ void shouldDetectBothChangesOnChain() {
7373
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));
7474

7575
when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
76-
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true);
76+
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(true);
7777
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
7878
when(iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, 0))
7979
.thenReturn(ChainReceipt.builder()
@@ -94,9 +94,11 @@ void shouldDetectBothChangesOnChain() {
9494
any(ReplicateStatusDetails.class)
9595
);
9696
}
97+
9798
// endregion
9899

99100
//region detectOnchainDoneWhenOffchainOngoing (ContributeAndFinalizeOngoing)
101+
100102
@Test
101103
void shouldDetectUnNotifiedContributeAndFinalizeDoneAfterContributeAndFinalizeOngoing() {
102104
Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
@@ -107,7 +109,7 @@ void shouldDetectUnNotifiedContributeAndFinalizeDoneAfterContributeAndFinalizeOn
107109
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));
108110

109111
when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
110-
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true);
112+
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(true);
111113
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
112114
when(iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, 0))
113115
.thenReturn(ChainReceipt.builder()
@@ -137,7 +139,7 @@ void shouldDetectUnNotifiedContributeAndFinalizeDoneSinceBeforeContributeAndFina
137139
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));
138140

139141
when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
140-
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true);
142+
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(true);
141143

142144
detector.detectOnchainDoneWhenOffchainOngoing();
143145

@@ -155,15 +157,17 @@ void shouldNotDetectUnNotifiedContributeAndFinalizeDoneSinceNotFinalizedOnChain(
155157
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));
156158

157159
when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
158-
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(false);
160+
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(false);
159161
detector.detectOnchainDoneWhenOffchainOngoing();
160162

161163
Mockito.verify(replicatesService, Mockito.times(0))
162164
.updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class));
163165
}
166+
164167
// endregion
165168

166169
//region detectOnchainDone (REVEALED)
170+
167171
@Test
168172
void shouldDetectUnNotifiedContributeAndFinalizeOngoing() {
169173
Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
@@ -174,7 +178,7 @@ void shouldDetectUnNotifiedContributeAndFinalizeOngoing() {
174178
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));
175179

176180
when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
177-
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true);
181+
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(true);
178182
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
179183
when(iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, 0)).thenReturn(ChainReceipt.builder()
180184
.blockNumber(10L)
@@ -202,12 +206,13 @@ void shouldNotDetectUnNotifiedContributedSinceContributeAndFinalizeDone() {
202206
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));
203207

204208
when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
205-
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true);
209+
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(true);
206210
detector.detectOnchainDone();
207211

208212
Mockito.verify(replicatesService, Mockito.times(0))
209213
.updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class));
210214
}
215+
211216
// endregion
212217

213218
}

src/test/java/com/iexec/core/detector/replicate/ContributionUnnotifiedDetectorTests.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void init() {
7171
}
7272

7373
// region Detector aggregator
74+
7475
/**
7576
* When running {@link ContributionUnnotifiedDetector#detectOnChainChanges} 10 times,
7677
* {@link ReplicatesService#updateReplicateStatus(String, String, ReplicateStatus, ReplicateStatusDetails)} should be called 11 times:
@@ -89,7 +90,7 @@ void shouldDetectBothChangesOnChain() {
8990
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));
9091

9192
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
92-
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
93+
when(iexecHubService.isContributed(any(), any())).thenReturn(true);
9394
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
9495
when(iexecHubService.getContributionBlock(anyString(), anyString(), anyLong())).thenReturn(ChainReceipt.builder()
9596
.blockNumber(10L)
@@ -103,9 +104,11 @@ void shouldDetectBothChangesOnChain() {
103104
Mockito.verify(replicatesService, Mockito.times(11))
104105
.updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class));
105106
}
107+
106108
// endregion
107109

108110
//region detectOnchainDoneWhenOffchainOngoing (CONTRIBUTING)
111+
109112
@Test
110113
void shouldDetectUnNotifiedContributedAfterContributing() {
111114
Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
@@ -117,7 +120,7 @@ void shouldDetectUnNotifiedContributedAfterContributing() {
117120

118121
when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
119122
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
120-
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
123+
when(iexecHubService.isContributed(any(), any())).thenReturn(true);
121124
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
122125
when(iexecHubService.getContributionBlock(anyString(), anyString(), anyLong()))
123126
.thenReturn(ChainReceipt.builder().blockNumber(10L).txHash("0xabcef").build());
@@ -139,7 +142,7 @@ void shouldDetectUnNotifiedContributedAfterContributingSinceBeforeContributing()
139142

140143
when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
141144
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
142-
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
145+
when(iexecHubService.isContributed(any(), any())).thenReturn(true);
143146

144147
contributionDetector.detectOnchainDoneWhenOffchainOngoing();
145148

@@ -158,15 +161,17 @@ void shouldNotDetectUnNotifiedContributedAfterContributingSinceNotContributedOnC
158161

159162
// when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
160163
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
161-
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(false);
164+
when(iexecHubService.isContributed(any(), any())).thenReturn(false);
162165
contributionDetector.detectOnchainDoneWhenOffchainOngoing();
163166

164167
Mockito.verify(replicatesService, Mockito.times(0))
165168
.updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class));
166169
}
170+
167171
// endregion
168172

169173
// region detectOnchainDone (CONTRIBUTED)
174+
170175
@Test
171176
void shouldDetectUnNotifiedContributed1() {
172177
Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
@@ -178,7 +183,7 @@ void shouldDetectUnNotifiedContributed1() {
178183

179184
when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
180185
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
181-
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
186+
when(iexecHubService.isContributed(any(), any())).thenReturn(true);
182187
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
183188
when(iexecHubService.getContributionBlock(anyString(), anyString(), anyLong())).thenReturn(ChainReceipt.builder()
184189
.blockNumber(10L)
@@ -202,7 +207,7 @@ void shouldDetectUnNotifiedContributed2() {
202207

203208
when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
204209
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
205-
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
210+
when(iexecHubService.isContributed(any(), any())).thenReturn(true);
206211
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
207212
when(iexecHubService.getContributionBlock(anyString(), anyString(), anyLong())).thenReturn(ChainReceipt.builder()
208213
.blockNumber(10L)
@@ -226,11 +231,12 @@ void shouldNotDetectUnNotifiedContributedSinceContributed() {
226231

227232
when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
228233
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
229-
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
234+
when(iexecHubService.isContributed(any(), any())).thenReturn(true);
230235
contributionDetector.detectOnchainDone();
231236

232237
Mockito.verify(replicatesService, Mockito.times(0))
233238
.updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class));
234239
}
240+
235241
// endregion
236242
}

0 commit comments

Comments
 (0)