Skip to content

Commit bbbe309

Browse files
authored
Merge pull request #56 from iExecBlockchainComputing/release/3.1.0
Release 3.1.0
2 parents b9b143c + 8bf22a2 commit bbbe309

File tree

12 files changed

+149
-144
lines changed

12 files changed

+149
-144
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [[3.1.0]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v3.1.0) 2023-09-25
6+
7+
### New Features
8+
- Add `isEligibleToContributeAndFinalize` method to `TaskDescription`. (#53)
9+
- Use `RawTransactionManager` instance to create App, Dataset and Workerpool on-chain in one block. (#54)
10+
### Quality
11+
- Do not run tests in `itest` task to avoid executing them twice. (#47)
12+
- Upgrade to Gradle 8.2.1 with up-to-date plugins. (#49)
13+
- Fetch contribution deadline ratio during `@PostConstruct` execution in `IexecHubAbstractService`. (#51)
14+
- Remove dead code in `IexecHubAbstractService` and `Web3jAbstractService`. (#54 #55)
15+
### Dependency Upgrades
16+
- Upgrade to Spring Boot 2.7.14. (#48)
17+
- Upgrade to `testcontainers` 1.19.0. (#50)
18+
- Upgrade to `jenkins-library` 2.7.3. (#52)
19+
520
## [[3.0.5]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v3.0.5) 2023-06-26
621

722
### Bug Fixes

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@Library('global-jenkins-library@2.5.0') _
1+
@Library('global-jenkins-library@2.7.3') _
22
buildJavaProject(
33
buildInfo: getBuildInfo(),
44
integrationTestsEnvVars: [],

build.gradle

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
plugins {
22
id 'java-library'
33
id 'jacoco'
4-
id 'org.sonarqube' version '3.3'
4+
id 'org.sonarqube' version '4.2.1.3168'
55
id 'maven-publish'
6-
id 'io.freefair.lombok' version '6.6.1'
6+
id 'io.freefair.lombok' version '8.2.2'
77
}
88

99
group = 'com.iexec.commons'
1010

11+
ext {
12+
testContainersVersion = '1.19.0'
13+
}
14+
1115
if (!project.hasProperty('gitBranch')) {
1216
ext.gitBranch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()
1317
}
@@ -30,7 +34,7 @@ repositories {
3034
}
3135

3236
dependencies {
33-
implementation platform('org.springframework.boot:spring-boot-dependencies:2.6.14')
37+
implementation platform('org.springframework.boot:spring-boot-dependencies:2.7.14')
3438

3539
// web3j
3640
api 'org.web3j:core:4.9.7'
@@ -54,9 +58,10 @@ dependencies {
5458

5559
// tests
5660
testImplementation 'org.junit.jupiter:junit-jupiter'
61+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
5762
testImplementation 'org.mockito:mockito-junit-jupiter'
5863
testImplementation 'org.assertj:assertj-core'
59-
testImplementation 'org.testcontainers:junit-jupiter:1.17.2'
64+
testImplementation "org.testcontainers:junit-jupiter:$testContainersVersion"
6065

6166
// spring-test for ReflectionTestUtils
6267
testImplementation 'org.springframework:spring-test'
@@ -90,14 +95,11 @@ test {
9095
}
9196
}
9297

93-
tasks.register('itest', Test) {
98+
tasks.register('itest') {
9499
group 'Verification'
95100
description 'Runs the integration tests.'
96101
}
97102

98-
jacoco {
99-
toolVersion = '0.8.7'
100-
}
101103
// sonarqube code coverage requires jacoco XML report
102104
jacocoTestReport {
103105
reports {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=3.0.5
1+
version=3.1.0
22

33
nexusUser
44
nexusPassword

gradle/wrapper/gradle-wrapper.jar

1.76 KB
Binary file not shown.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
44
networkTimeout=10000
5+
validateDistributionUrl=true
56
zipStoreBase=GRADLE_USER_HOME
67
zipStorePath=wrapper/dists

gradlew

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ done
8585
APP_BASE_NAME=${0##*/}
8686
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
8787

88-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90-
9188
# Use the maximum available, or set MAX_FD != -1 to use that value.
9289
MAX_FD=maximum
9390

@@ -133,26 +130,29 @@ location of your Java installation."
133130
fi
134131
else
135132
JAVACMD=java
136-
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
133+
if ! command -v java >/dev/null 2>&1
134+
then
135+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137136
138137
Please set the JAVA_HOME variable in your environment to match the
139138
location of your Java installation."
139+
fi
140140
fi
141141

142142
# Increase the maximum file descriptors if we can.
143143
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144144
case $MAX_FD in #(
145145
max*)
146146
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147-
# shellcheck disable=SC3045
147+
# shellcheck disable=SC3045
148148
MAX_FD=$( ulimit -H -n ) ||
149149
warn "Could not query maximum file descriptor limit"
150150
esac
151151
case $MAX_FD in #(
152152
'' | soft) :;; #(
153153
*)
154154
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155-
# shellcheck disable=SC3045
155+
# shellcheck disable=SC3045
156156
ulimit -n "$MAX_FD" ||
157157
warn "Could not set maximum file descriptor limit to $MAX_FD"
158158
esac
@@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
197197
done
198198
fi
199199

200+
201+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
202+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
203+
200204
# Collect all arguments for the java command;
201205
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
202206
# shell script including quotes and variable substitutions, so put them in

src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java

Lines changed: 24 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ public abstract class IexecHubAbstractService {
6767

6868
protected final Credentials credentials;
6969
private final String iexecHubAddress;
70+
private final RawTransactionManager txManager;
7071
protected IexecHubContract iexecHubContract;
7172
private final Web3jAbstractService web3jAbstractService;
72-
private long maxNbOfPeriodsForConsensus;
73+
private long maxNbOfPeriodsForConsensus = -1;
7374
private final int nbBlocksToWaitPerRetry;
7475
private final long retryDelay;// ms
7576
private final int maxRetries;
@@ -103,15 +104,18 @@ protected IexecHubAbstractService(
103104
this.retryDelay = nbBlocksToWaitPerRetry * this.web3jAbstractService.getBlockTime().toMillis();
104105
this.maxRetries = maxRetries;
105106

106-
iexecHubContract = getHubContract(
107-
this.web3jAbstractService.getContractGasProvider(),
108-
this.web3jAbstractService.getChainId(),
107+
txManager = new RawTransactionManager(
108+
web3jAbstractService.getWeb3j(),
109+
credentials,
110+
web3jAbstractService.getChainId(),
109111
DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH,
110-
this.web3jAbstractService.getBlockTime().toMillis()
112+
web3jAbstractService.getBlockTime().toMillis()
111113
);
114+
115+
iexecHubContract = getHubContract(web3jAbstractService.getContractGasProvider());
116+
112117
log.info("Abstract IexecHubService initialized (iexec proxy address) [hubAddress:{}]",
113118
iexecHubContract.getContractAddress());
114-
setMaxNbOfPeriodsForConsensus();
115119
}
116120

117121
@PostConstruct
@@ -121,6 +125,7 @@ private void validateRemoteIexecHubSmartContract() {
121125
"IexecHub smart contract validation failed."
122126
);
123127
}
128+
setMaxNbOfPeriodsForConsensus();
124129
}
125130

126131

@@ -132,15 +137,9 @@ private static int scoreToWeight(int workerScore) {
132137
* Get an IexecHubContract instance.
133138
*
134139
* @param contractGasProvider gas provider, useful for sending txs
135-
* @param chainId chain ID for EIP155 protection
136-
* @param watchAttempts number of attempts to get tx receipt
137-
* @param sleepDuration sleep duration in ms between 2 consecutive attempts
138140
* @return an IexecHubContract instance
139141
*/
140-
private IexecHubContract getHubContract(ContractGasProvider contractGasProvider,
141-
long chainId,
142-
int watchAttempts,
143-
long sleepDuration) {
142+
private IexecHubContract getHubContract(ContractGasProvider contractGasProvider) {
144143
ExceptionInInitializerError exceptionInInitializerError =
145144
new ExceptionInInitializerError("Failed to load IexecHub " +
146145
"contract from address " + iexecHubAddress);
@@ -149,12 +148,7 @@ private IexecHubContract getHubContract(ContractGasProvider contractGasProvider,
149148
try {
150149
return IexecHubContract.load(iexecHubAddress,
151150
web3jAbstractService.getWeb3j(),
152-
new RawTransactionManager(
153-
web3jAbstractService.getWeb3j(),
154-
credentials,
155-
chainId,
156-
watchAttempts,
157-
sleepDuration),
151+
txManager,
158152
contractGasProvider);
159153
} catch (EnsResolutionException e) {
160154
throw exceptionInInitializerError;
@@ -205,9 +199,10 @@ public WorkerpoolRegistry getWorkerpoolRegistryContract(ContractGasProvider cont
205199
if (workerpoolRegistryAddress == null || workerpoolRegistryAddress.isEmpty()) {
206200
throw exceptionInInitializerError;
207201
}
208-
return WorkerpoolRegistry.load(workerpoolRegistryAddress,
202+
return WorkerpoolRegistry.load(
203+
workerpoolRegistryAddress,
209204
web3jAbstractService.getWeb3j(),
210-
credentials,
205+
txManager,
211206
contractGasProvider);
212207
} catch (Exception e) {
213208
log.error("Failed to load WorkerpoolRegistry contract [address:{}]",
@@ -372,9 +367,10 @@ public AppRegistry getAppRegistryContract(ContractGasProvider contractGasProvide
372367
if (appRegistryAddress == null || appRegistryAddress.isEmpty()) {
373368
throw exceptionInInitializerError;
374369
}
375-
return AppRegistry.load(appRegistryAddress,
370+
return AppRegistry.load(
371+
appRegistryAddress,
376372
web3jAbstractService.getWeb3j(),
377-
credentials,
373+
txManager,
378374
contractGasProvider);
379375
} catch (Exception e) {
380376
log.error("Failed to load AppRegistry contract [address:{}]",
@@ -562,9 +558,10 @@ public DatasetRegistry getDatasetRegistryContract(ContractGasProvider contractGa
562558
if (datasetRegistryAddress == null || datasetRegistryAddress.isEmpty()) {
563559
throw exceptionInInitializerError;
564560
}
565-
return DatasetRegistry.load(datasetRegistryAddress,
561+
return DatasetRegistry.load(
562+
datasetRegistryAddress,
566563
web3jAbstractService.getWeb3j(),
567-
credentials,
564+
txManager,
568565
contractGasProvider);
569566
} catch (Exception e) {
570567
log.error("Failed to load DatasetRegistry contract [address:{}]",
@@ -718,37 +715,6 @@ public String predictDataset(String owner, String name, String multiAddress,
718715
return address;
719716
}
720717

721-
public Optional<String> getTaskBeneficiary(String chainTaskId, Integer chainId) {
722-
Optional<ChainTask> chainTask = getChainTask(chainTaskId);
723-
if (chainTask.isEmpty()) {
724-
log.error("Failed to get Task Beneficiary as ChainTask not found" +
725-
" [chainTaskId:{}]", chainTaskId);
726-
return Optional.empty();
727-
}
728-
Optional<ChainDeal> optionalChainDeal = getChainDeal(chainTask.get().getDealid());
729-
return optionalChainDeal.map(chainDeal -> chainDeal.getBeneficiary().toLowerCase());
730-
}
731-
732-
public boolean isPublicResult(String chainTaskId, Integer chainId) {
733-
Optional<String> beneficiary = getTaskBeneficiary(chainTaskId, chainId);
734-
if (beneficiary.isEmpty()) {
735-
log.error("Failed to get beneficiary for isPublicResult() method" +
736-
" [chainTaskId:{}]", chainTaskId);
737-
return false;
738-
}
739-
return beneficiary.get().equals(BytesUtils.EMPTY_ADDRESS);
740-
}
741-
742-
public String getTaskResults(String chainTaskId, Integer chainId) {
743-
Optional<ChainTask> chainTask = getChainTask(chainTaskId);
744-
if (chainTask.isEmpty()) {
745-
log.error("Failed to get Task Results as ChainTask not found" +
746-
" [chainTaskId:{}]", chainTaskId);
747-
return "";
748-
}
749-
return chainTask.get().getResults();
750-
}
751-
752718
/**
753719
* Retrieves on-chain deal with a retryer
754720
*
@@ -1058,47 +1024,17 @@ public long getMaxNbOfPeriodsForConsensus() {
10581024

10591025
private void setMaxNbOfPeriodsForConsensus() {
10601026
try {
1061-
this.maxNbOfPeriodsForConsensus = iexecHubContract
1062-
.contribution_deadline_ratio().send().longValue();
1027+
maxNbOfPeriodsForConsensus = iexecHubContract.contribution_deadline_ratio().send().longValue();
10631028
} catch (Exception e) {
10641029
log.error("Failed to get maxNbOfPeriodsForConsensus from the chain", e);
1065-
this.maxNbOfPeriodsForConsensus = -1;
1030+
maxNbOfPeriodsForConsensus = -1;
10661031
}
10671032
}
10681033

10691034
public boolean hasEnoughGas(String address) {
10701035
return web3jAbstractService.hasEnoughGas(address);
10711036
}
10721037

1073-
1074-
protected boolean isStatusValidOnChainAfterPendingReceipt(String chainTaskId,
1075-
ChainStatus onchainStatus,
1076-
BiFunction<String, ChainStatus, Boolean> isStatusValidOnChainFunction) {
1077-
long maxWaitingTime = web3jAbstractService.getMaxWaitingTimeWhenPendingReceipt();
1078-
log.info("Waiting for on-chain status after pending receipt " +
1079-
"[chainTaskId:{}, status:{}, maxWaitingTime:{}]",
1080-
chainTaskId, onchainStatus, maxWaitingTime);
1081-
1082-
final long startTime = System.currentTimeMillis();
1083-
long duration = 0;
1084-
while (duration < maxWaitingTime) {
1085-
try {
1086-
if (isStatusValidOnChainFunction.apply(chainTaskId, onchainStatus)) {
1087-
return true;
1088-
}
1089-
Thread.sleep(500);
1090-
} catch (InterruptedException e) {
1091-
log.error("Error in checking the latest block number", e);
1092-
}
1093-
duration = System.currentTimeMillis() - startTime;
1094-
}
1095-
1096-
log.error("Timeout reached after waiting for on-chain status " +
1097-
"[chainTaskId:{}, maxWaitingTime:{}]",
1098-
chainTaskId, maxWaitingTime);
1099-
return false;
1100-
}
1101-
11021038
/*
11031039
* Behaves as a cache to avoid always calling blockchain to retrieve task description
11041040
*

0 commit comments

Comments
 (0)