diff --git a/build.gradle b/build.gradle index 1a9a9c2..97a9774 100644 --- a/build.gradle +++ b/build.gradle @@ -34,7 +34,7 @@ dependencies { implementation platform('org.springframework.boot:spring-boot-dependencies:3.3.8') // web3j - api 'org.web3j:core:4.12.3' + api 'org.web3j:core:4.13.0' // apache commons.lang3 implementation 'org.apache.commons:commons-lang3' diff --git a/src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java b/src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java index 5693a2d..36180f9 100644 --- a/src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java +++ b/src/main/java/com/iexec/commons/poco/chain/IexecHubAbstractService.java @@ -30,6 +30,7 @@ import org.web3j.tuples.generated.Tuple3; import org.web3j.tx.RawTransactionManager; import org.web3j.tx.gas.ContractGasProvider; +import org.web3j.tx.response.PollingTransactionReceiptProcessor; import org.web3j.utils.Numeric; import java.io.IOException; @@ -41,8 +42,6 @@ import static com.iexec.commons.poco.encoding.AccessorsEncoder.*; import static com.iexec.commons.poco.tee.TeeEnclaveConfiguration.buildEnclaveConfigurationFromJsonString; import static com.iexec.commons.poco.utils.BytesUtils.isNonZeroedBytes32; -import static org.web3j.tx.TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH; - /* * Contracts (located at *.contract.generated) which are used in this service are generated from: @@ -52,13 +51,15 @@ @Slf4j public abstract class IexecHubAbstractService { + public static final int POLLING_ATTEMPTS_PER_TX_HASH = 12; public static final int NB_BLOCKS_TO_WAIT_PER_RETRY = 6; public static final int MAX_RETRIES = 3; protected final Credentials credentials; private final String iexecHubAddress; - private final RawTransactionManager txManager; - protected IexecHubContract iexecHubContract; + protected final RawTransactionManager txManager; + protected final PollingTransactionReceiptProcessor txReceiptProcessor; + protected final IexecHubContract iexecHubContract; private final Web3jAbstractService web3jAbstractService; private long maxNbOfPeriodsForConsensus = -1; private final long retryDelay;// ms @@ -94,12 +95,17 @@ protected IexecHubAbstractService( this.retryDelay = nbBlocksToWaitPerRetry * this.web3jAbstractService.getBlockTime().toMillis(); this.maxRetries = maxRetries; + txReceiptProcessor = new PollingTransactionReceiptProcessor( + web3jAbstractService.getWeb3j(), + web3jAbstractService.getBlockTime().toMillis(), + POLLING_ATTEMPTS_PER_TX_HASH + ); + txManager = new RawTransactionManager( web3jAbstractService.getWeb3j(), credentials, web3jAbstractService.getChainId(), - DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH, - web3jAbstractService.getBlockTime().toMillis() + txReceiptProcessor ); iexecHubContract = getHubContract(web3jAbstractService.getContractGasProvider()); diff --git a/src/main/java/com/iexec/commons/poco/chain/Web3jAbstractService.java b/src/main/java/com/iexec/commons/poco/chain/Web3jAbstractService.java index a3fc73f..aad00ec 100644 --- a/src/main/java/com/iexec/commons/poco/chain/Web3jAbstractService.java +++ b/src/main/java/com/iexec/commons/poco/chain/Web3jAbstractService.java @@ -16,7 +16,6 @@ package com.iexec.commons.poco.chain; -import com.iexec.commons.poco.encoding.PoCoDataEncoder; import com.iexec.commons.poco.utils.WaitUtils; import jakarta.annotation.PostConstruct; import lombok.Getter; @@ -27,6 +26,8 @@ import org.web3j.protocol.core.methods.response.TransactionReceipt; import org.web3j.protocol.http.HttpService; import org.web3j.tx.gas.ContractGasProvider; +import org.web3j.tx.gas.DynamicGasProvider; +import org.web3j.tx.gas.PriorityGasProvider; import org.web3j.utils.Async; import java.io.IOException; @@ -93,7 +94,7 @@ protected Web3jAbstractService( this.gasPriceCap = gasPriceCap; this.isSidechain = isSidechain; this.web3j = Web3j.build(new HttpService(chainNodeAddress), this.blockTime.toMillis(), Async.defaultExecutorService()); - this.contractGasProvider = getWritingContractGasProvider(); + this.contractGasProvider = new DynamicGasProvider(web3j, PriorityGasProvider.Priority.CUSTOM, BigDecimal.valueOf(gasPriceMultiplier)); } @PostConstruct @@ -271,31 +272,6 @@ public BigInteger getUserGasPrice() { return getUserGasPrice(gasPriceMultiplier, gasPriceCap); } - private ContractGasProvider getWritingContractGasProvider() { - return new ContractGasProvider() { - - @Override - public BigInteger getGasPrice(String s) { - return getUserGasPrice(gasPriceMultiplier, gasPriceCap); - } - - @Override - public BigInteger getGasPrice() { - return getUserGasPrice(gasPriceMultiplier, gasPriceCap); - } - - @Override - public BigInteger getGasLimit(String functionName) { - return PoCoDataEncoder.getGasLimitForFunction(functionName); - } - - @Override - public BigInteger getGasLimit() { - return BigInteger.valueOf(GAS_LIMIT_CAP); - } - }; - } - /** * Repeat a check until a condition is met or the max number of tries have been done. *