Skip to content

Commit 06c45e3

Browse files
Merge pull request #290 from iExecBlockchainComputing/release/4.0.1
Release/4.0.1
2 parents c3e91d2 + 0d75ee9 commit 06c45e3

File tree

8 files changed

+57
-24
lines changed

8 files changed

+57
-24
lines changed

Jenkinsfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ pipeline {
2525

2626
stage('Upload Jars') {
2727
when {
28-
branch 'master'
28+
anyOf{
29+
branch 'master'
30+
branch 'develop'
31+
}
2932
}
3033
steps {
3134
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'nexus', usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASSWORD']]) {
@@ -36,7 +39,10 @@ pipeline {
3639

3740
stage('Build/Upload Docker image') {
3841
when {
39-
branch 'master'
42+
anyOf{
43+
branch 'master'
44+
branch 'develop'
45+
}
4046
}
4147
steps {
4248
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'nexus', usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASSWORD']]) {

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ compileJava.dependsOn createVersion
117117

118118
def gitBranch = 'git name-rev --name-only HEAD'.execute().text.trim()
119119
def isMasterBranch = gitBranch == "master"
120-
def canUploadArchives = isMasterBranch && project.hasProperty("nexusUser") && project.hasProperty("nexusPassword")
120+
def isDevelopBranch = gitBranch == "develop"
121+
def canUploadArchives = (isMasterBranch || isDevelopBranch ) && project.hasProperty("nexusUser") && project.hasProperty("nexusPassword")
121122
def gitShortCommit = 'git rev-parse --short HEAD'.execute().text.trim()
122123
def isSnapshotVersion = project.version.contains("SNAPSHOT")
123124

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
iexecCommonVersion=4.1.0-SNAPSHOT
1+
iexecCommonVersion=4.0.1
22
nexusUser=fake
33
nexusPassword=fake
4-
version=4.1.0-SNAPSHOT
4+
version=4.0.1

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import com.iexec.common.security.Signature;
77
import com.iexec.common.task.TaskDescription;
88
import com.iexec.common.utils.BytesUtils;
9+
import com.iexec.common.utils.WaitUtils;
910
import com.iexec.worker.config.PublicConfigurationService;
1011
import lombok.extern.slf4j.Slf4j;
1112
import org.springframework.beans.factory.annotation.Autowired;
1213
import org.springframework.stereotype.Service;
1314
import org.web3j.protocol.core.RemoteCall;
15+
import org.web3j.protocol.core.methods.response.BaseEventResponse;
1416
import org.web3j.protocol.core.methods.response.TransactionReceipt;
1517

1618
import java.util.HashMap;
@@ -97,8 +99,7 @@ private IexecHubABILegacy.TaskContributeEventResponse sendContributeTransaction(
9799
contributeEvent = contributeEvents.get(0);
98100
}
99101

100-
if (contributeEvent != null && contributeEvent.log != null &&
101-
isStatusValidOnChainAfterPendingReceipt(chainTaskId, CONTRIBUTED, this::isContributionStatusValidOnChain)) {
102+
if (isSuccessTx(chainTaskId, contributeEvent, CONTRIBUTED)) {
102103
log.info("Contributed [chainTaskId:{}, resultHash:{}, gasUsed:{}, log:{}]",
103104
chainTaskId, resultHash, contributeReceipt.getGasUsed(), contributeEvent.log);
104105
return contributeEvent;
@@ -108,6 +109,18 @@ private IexecHubABILegacy.TaskContributeEventResponse sendContributeTransaction(
108109
return null;
109110
}
110111

112+
private boolean isSuccessTx(String chainTaskId, BaseEventResponse txEvent, ChainContributionStatus pretendedStatus) {
113+
if (txEvent == null || txEvent.log == null) {
114+
return false;
115+
}
116+
117+
if (txEvent.log.getType() == null || txEvent.log.getType().equals(PENDING_RECEIPT_STATUS)) {
118+
return isStatusValidOnChainAfterPendingReceipt(chainTaskId, pretendedStatus, this::isContributionStatusValidOnChain);
119+
}
120+
121+
return true;
122+
}
123+
111124
IexecHubABILegacy.TaskRevealEventResponse reveal(String chainTaskId, String resultDigest) {
112125
try {
113126
return CompletableFuture.supplyAsync(() -> {
@@ -142,8 +155,7 @@ private IexecHubABILegacy.TaskRevealEventResponse sendRevealTransaction(String c
142155
revealEvent = revealEvents.get(0);
143156
}
144157

145-
if (revealEvent != null && revealEvent.log != null &&
146-
isStatusValidOnChainAfterPendingReceipt(chainTaskId, REVEALED, this::isContributionStatusValidOnChain)) {
158+
if (isSuccessTx(chainTaskId, revealEvent, REVEALED)) {
147159
log.info("Revealed [chainTaskId:{}, resultDigest:{}, gasUsed:{}, log:{}]",
148160
chainTaskId, resultDigest, revealReceipt.getGasUsed(), revealEvent.log);
149161
return revealEvent;
@@ -189,7 +201,7 @@ private boolean isBlockchainReadTrueWhenNodeNotSync(String chainTaskId, Function
189201
long maxWaitingTime = web3jService.getMaxWaitingTimeWhenPendingReceipt();
190202
long startTime = System.currentTimeMillis();
191203

192-
for(long duration = 0L; duration < maxWaitingTime; duration = System.currentTimeMillis() - startTime) {
204+
for (long duration = 0L; duration < maxWaitingTime; duration = System.currentTimeMillis() - startTime) {
193205
try {
194206
if (booleanBlockchainReadFunction.apply(chainTaskId)) {
195207
return true;
@@ -205,16 +217,16 @@ private boolean isBlockchainReadTrueWhenNodeNotSync(String chainTaskId, Function
205217
return false;
206218
}
207219

208-
Boolean isChainTaskActive(String chainTaskId){
220+
Boolean isChainTaskActive(String chainTaskId) {
209221
Optional<ChainTask> chainTask = getChainTask(chainTaskId);
210-
if (chainTask.isPresent()){
211-
switch (chainTask.get().getStatus()){
222+
if (chainTask.isPresent()) {
223+
switch (chainTask.get().getStatus()) {
212224
case UNSET:
213225
break;//Could happen if node not synchronized. Should wait.
214226
case ACTIVE:
215227
return true;
216228
case REVEALING:
217-
return false;
229+
return false;
218230
case COMPLETED:
219231
return false;
220232
case FAILLED:
@@ -224,16 +236,16 @@ Boolean isChainTaskActive(String chainTaskId){
224236
return false;
225237
}
226238

227-
public Boolean isChainTaskRevealing(String chainTaskId){
239+
public Boolean isChainTaskRevealing(String chainTaskId) {
228240
Optional<ChainTask> chainTask = getChainTask(chainTaskId);
229-
if (chainTask.isPresent()){
230-
switch (chainTask.get().getStatus()){
241+
if (chainTask.isPresent()) {
242+
switch (chainTask.get().getStatus()) {
231243
case UNSET:
232244
break;//Should not happen
233245
case ACTIVE:
234246
break;//Could happen if node not synchronized. Should wait.
235247
case REVEALING:
236-
return true;
248+
return true;
237249
case COMPLETED:
238250
return false;
239251
case FAILLED:
@@ -248,15 +260,15 @@ public Boolean isChainTaskRevealing(String chainTaskId){
248260
*
249261
*/
250262
public void putTaskDescription(TaskDescription taskDescription) {
251-
if (taskDescription != null && taskDescription.getChainTaskId() != null){
263+
if (taskDescription != null && taskDescription.getChainTaskId() != null) {
252264
taskDescriptions.putIfAbsent(taskDescription.getChainTaskId(), taskDescription);
253265
return;
254266
}
255267
log.error("Cant putTaskDescription [taskDescription:{}]", taskDescription);
256268
}
257269

258270
public TaskDescription getTaskDescription(String chainTaskId) {
259-
if (taskDescriptions.get(chainTaskId) == null){
271+
if (taskDescriptions.get(chainTaskId) == null) {
260272
Optional<TaskDescription> taskDescriptionFromChain = this.getTaskDescriptionFromChain(chainTaskId);
261273
taskDescriptionFromChain.ifPresent(this::putTaskDescription);
262274
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,17 @@ public RevealService(IexecHubService iexecHubService,
2525
this.web3jService = web3jService;
2626
}
2727

28-
public boolean canReveal(String chainTaskId, String determinismHash) {
28+
public boolean repeatCanReveal(String chainTaskId, String determinismHash) {
29+
return web3jService.repeatCheck(6, 3, "canReveal",
30+
this::canReveal, chainTaskId, determinismHash);
31+
}
32+
33+
/*
34+
* params: String chainTaskId, String determinismHash
35+
* */
36+
public boolean canReveal(String... args) {
37+
String chainTaskId = args[0];
38+
String determinismHash = args[1];
2939

3040
Optional<ChainTask> optionalChainTask = iexecHubService.getChainTask(chainTaskId);
3141
if (!optionalChainTask.isPresent()) {
@@ -49,7 +59,7 @@ public boolean canReveal(String chainTaskId, String determinismHash) {
4959
boolean isContributionResultHashCorrect = false;
5060
boolean isContributionResultSealCorrect = false;
5161

52-
if (!determinismHash.isEmpty()) {
62+
if (!determinismHash.isEmpty()) {//TODO
5363
isContributionResultHashCorrect = chainContribution.getResultHash().equals(HashUtils.concatenateAndHash(chainTaskId, determinismHash));
5464

5565
String walletAddress = credentialsService.getCredentials().getAddress();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.iexec.worker.chain;
22

33
import com.iexec.common.chain.Web3jAbstractService;
4+
import com.iexec.common.utils.WaitUtils;
45
import com.iexec.worker.config.PublicConfigurationService;
56
import com.iexec.worker.config.WorkerConfigurationService;
67
import lombok.extern.slf4j.Slf4j;
78
import org.springframework.stereotype.Service;
89

10+
import java.util.function.Function;
11+
912
@Slf4j
1013
@Service
1114
public class Web3jService extends Web3jAbstractService {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ ReplicateActionResponse reveal(String chainTaskId, TaskNotificationExtra extra)
272272
return ReplicateActionResponse.failure(BLOCK_NOT_REACHED);
273273
}
274274

275-
boolean canReveal = revealService.canReveal(chainTaskId, determinismHash);
275+
boolean canReveal = revealService.repeatCanReveal(chainTaskId, determinismHash);
276+
276277
if (!canReveal) {
277278
log.error("Cannot reveal, one or more conditions are not satisfied [chainTaskId:{}]", chainTaskId);
278279
return ReplicateActionResponse.failure(CANNOT_REVEAL);

src/test/java/com/iexec/worker/executor/TaskManagerServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void shouldReveal() {
184184

185185
when(resultService.getTaskDeterminismHash(CHAIN_TASK_ID)).thenReturn(hash);
186186
when(revealService.isConsensusBlockReached(CHAIN_TASK_ID, consensusBlock)).thenReturn(true);
187-
when(revealService.canReveal(CHAIN_TASK_ID, hash)).thenReturn(true);
187+
when(revealService.repeatCanReveal(CHAIN_TASK_ID, hash)).thenReturn(true);
188188
when(iexecHubService.hasEnoughGas()).thenReturn(true);
189189

190190
taskManagerService.reveal(CHAIN_TASK_ID, TaskNotificationExtra.builder().blockNumber(consensusBlock).build());

0 commit comments

Comments
 (0)