Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
* <p>
Expand Down