@@ -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