Skip to content

Commit

Permalink
Merge pull request #112 from iExecBlockchainComputing/release/4.2.0
Browse files Browse the repository at this point in the history
Release/4.2.0
  • Loading branch information
jbern0rd authored Dec 18, 2024
2 parents af3cb8a + fd0e09b commit dae8024
Show file tree
Hide file tree
Showing 21 changed files with 524 additions and 276 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

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

## [[4.2.0]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v4.2.0) 2024-12-18

### New Features

- Add `getUserGasPrice` method to `Web3jAbstractService`. (#104)
- Make **TEE tasks** with callback eligible to `contributeAndFinalize` flow. (#109)
- Add accessors to read on-chain deployed PoCo Smart Contracts configurations:
`callbackgas`, `contribution_deadline_ratio` and `final_deadline_ratio`. (#111)

### Bug Fixes

- Prefer methods with ECKEyPair parameter when signing prefixed messages. (#107)

### Quality

- Use `poco-chain` with `poco v5.5.0` and `voucher v1.0.0` in tests. (#106)
- Manage deal parameters in a single field and add assets owner and assets price fields in `TaskDescription`. (#108)

### Dependency Upgrades

- Upgrade to Gradle 8.10.2. (#105)
- Upgrade to `testcontainers` 1.20.4. (#110)

## [[4.1.0]](https://github.com/iExecBlockchainComputing/iexec-commons-poco/releases/tag/v4.1.0) 2024-06-17

### New Features
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id 'java-library'
id 'io.freefair.lombok' version '8.6'
id 'io.freefair.lombok' version '8.10.2'
id 'jacoco'
id 'org.sonarqube' version '5.0.0.4638'
id 'org.sonarqube' version '5.1.0.4882'
id 'maven-publish'
}

group = 'com.iexec.commons'

ext {
testContainersVersion = '1.19.3'
testContainersVersion = '1.20.4'
}

if (!project.hasProperty('gitBranch')) {
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
poco-chain:
image: docker-regis.iex.ec/poco-chain:native-v5.4.2-5s
image: docker-regis.iex.ec/poco-chain:1.0.0-poco-v5.5.0-voucher-v1.0.0-nethermind
expose:
- "8545"
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version=4.1.0
version=4.2.0
nexusUser
nexusPassword
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
import org.awaitility.core.ConditionTimeoutException;
import org.web3j.crypto.Credentials;
import org.web3j.ens.EnsResolutionException;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tuples.generated.Tuple3;
import org.web3j.tx.RawTransactionManager;
import org.web3j.tx.gas.ContractGasProvider;
import org.web3j.tx.gas.DefaultGasProvider;
import org.web3j.utils.Numeric;

import java.io.IOException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
Expand All @@ -41,6 +44,7 @@
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

import static com.iexec.commons.poco.encoding.AccessorsEncoder.*;
import static com.iexec.commons.poco.encoding.AssetDataEncoder.getAssetAddressFromReceipt;
import static com.iexec.commons.poco.tee.TeeEnclaveConfiguration.buildEnclaveConfigurationFromJsonString;
import static com.iexec.commons.poco.utils.BytesUtils.isNonZeroedBytes32;
Expand Down Expand Up @@ -889,7 +893,7 @@ public long getMaxNbOfPeriodsForConsensus() {

private void setMaxNbOfPeriodsForConsensus() {
try {
maxNbOfPeriodsForConsensus = iexecHubContract.contribution_deadline_ratio().send().longValue();
maxNbOfPeriodsForConsensus = getContributionDeadlineRatio().longValue();
} catch (Exception e) {
log.error("Failed to get maxNbOfPeriodsForConsensus from the chain", e);
maxNbOfPeriodsForConsensus = -1;
Expand Down Expand Up @@ -951,6 +955,45 @@ public boolean isTeeTask(String chainTaskId) {
return taskDescription.isTeeTask();
}

// region accessors

/**
* Send call to callbackgas() PoCo method.
*
* @return callbackgas value
* @throws IOException if communication fails
*/
public BigInteger getCallbackGas() throws IOException {
return sendCallWithFunctionSelector(CALLBACKGAS_SELECTOR);
}

/**
* Send call to contribution_deadline_ratio() PoCo method.
*
* @return contribution_deadline_ratio value
* @throws IOException if communication fails
*/
public BigInteger getContributionDeadlineRatio() throws IOException {
return sendCallWithFunctionSelector(CONTRIBUTION_DEADLINE_RATIO_SELECTOR);
}

/**
* Send call to final_deadline_ratio() PoCo method.
*
* @return final_deadline_ratio value
* @throws IOException if communication fails
*/
public BigInteger getFinalDeadlineRatio() throws IOException {
return sendCallWithFunctionSelector(FINAL_DEADLINE_RATIO_SELECTOR);
}

private BigInteger sendCallWithFunctionSelector(final String functionSelector) throws IOException {
return Numeric.toBigInt(
txManager.sendCall(iexecHubAddress, functionSelector, DefaultBlockParameterName.LATEST));
}

// endregion

// region Purge

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.web3j.protocol.core.methods.response.Transaction;
import org.web3j.protocol.exceptions.JsonRpcError;
import org.web3j.tx.RawTransactionManager;
import org.web3j.utils.Numeric;

import java.io.IOException;
import java.math.BigInteger;
Expand Down Expand Up @@ -108,8 +107,7 @@ public BigInteger getNonce() {
* Signs messages with Ethereum prefix
*/
public Signature signMessageHash(String messageHash) {
String hexPrivateKey = Numeric.toHexStringWithPrefix(credentials.getEcKeyPair().getPrivateKey());
return SignatureUtils.signMessageHashAndGetSignature(messageHash, hexPrivateKey);
return SignatureUtils.signMessageHashAndGetSignature(messageHash, credentials.getEcKeyPair());
}

public String signEIP712Entity(EIP712Entity<?> eip712Entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public Optional<BigInteger> getBalance(String address) {
*/
public Optional<BigInteger> getNetworkGasPrice() {
try {
BigInteger gasPrice = web3j.ethGasPrice().send().getGasPrice();
final BigInteger gasPrice = web3j.ethGasPrice().send().getGasPrice();
if (gasPrice != null && gasPrice.signum() > 0) {
return Optional.of(gasPrice);
}
Expand All @@ -276,17 +276,28 @@ public Optional<BigInteger> getNetworkGasPrice() {
}

public BigInteger getUserGasPrice(float gasPriceMultiplier, long gasPriceCap) {
Optional<BigInteger> networkGasPrice = getNetworkGasPrice();
final Optional<BigInteger> networkGasPrice = getNetworkGasPrice();
if (networkGasPrice.isEmpty()) {
log.warn("Undefined network gas price (will use default) " +
"[userGasPriceCap:{}]", gasPriceCap);
return BigInteger.valueOf(gasPriceCap);
}
long wishedGasPrice = (long) (networkGasPrice.get().floatValue() * gasPriceMultiplier);
final long wishedGasPrice = (long) (networkGasPrice.get().floatValue() * gasPriceMultiplier);

return BigInteger.valueOf(Math.min(wishedGasPrice, gasPriceCap));
}

/**
* Returns gas price following current user parameters defined in the {@code Web3jAbstractService} instance.
* <p>
* The gas price will be Min(gasPriceCap, networkGasPrice * gasPriceMultiplier)
*
* @return The gas Price as a {@code BigInteger}
*/
public BigInteger getUserGasPrice() {
return getUserGasPrice(gasPriceMultiplier, gasPriceCap);
}

private ContractGasProvider getWritingContractGasProvider() {
return new ContractGasProvider() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2024 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.iexec.commons.poco.encoding;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
* Class containing Ethereum function selectors to read PoCo Smart Contracts configurations.
* <p>
* Current accessors allow to read callback gas, contribution deadline ratio and final deadline ratio.
*
* @see <a href="https://github.com/iExecBlockchainComputing/PoCo/blob/main/contracts/modules/interfaces/IexecAccessors.sol">PoCo accessors</a>
* @see <a href="https://docs.soliditylang.org/en/latest/abi-spec.html#function-selector">Ethereum Contract ABI Specification</a>
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class AccessorsEncoder {

/**
* keccak256(callbackgas())
*/
public static final String CALLBACKGAS_SELECTOR = "0xe63ec07d";

/**
* keccak256(contribution_deadline_ratio())
*/
public static final String CONTRIBUTION_DEADLINE_RATIO_SELECTOR = "0x74ed5244";

/**
* keccak256(final_deadline_ratio())
*/
public static final String FINAL_DEADLINE_RATIO_SELECTOR = "0xdb8aaa26";

}
Loading

0 comments on commit dae8024

Please sign in to comment.