2121import com .iexec .common .utils .FileHelper ;
2222import com .iexec .common .worker .result .ResultUtils ;
2323import com .iexec .commons .poco .chain .ChainContribution ;
24- import com .iexec .commons .poco .chain .ChainContributionStatus ;
2524import com .iexec .commons .poco .chain .ChainTask ;
2625import com .iexec .commons .poco .chain .ChainTaskStatus ;
2726import com .iexec .commons .poco .task .TaskDescription ;
3938
4039import static com .iexec .common .utils .IexecFileHelper .SLASH_IEXEC_OUT ;
4140import static com .iexec .common .utils .IexecFileHelper .readComputedFile ;
41+ import static com .iexec .commons .poco .chain .ChainContributionStatus .REVEALED ;
4242
4343/**
4444 * Service class to manage all the results. If the result is public, it will be stored on IPFS. If there is a dedicated
@@ -59,17 +59,18 @@ public ProxyService(IexecHubService iexecHubService,
5959
6060
6161 boolean canUploadResult (String chainTaskId , String walletAddress , byte [] zip ) {
62- if (iexecHubService .isTeeTask (chainTaskId )){
63- Optional <ChainTask > chainTask = iexecHubService .getChainTask (chainTaskId );//TODO Add requester field to getChainTask
64- if (chainTask .isEmpty ()){
62+ if (iexecHubService .isTeeTask (chainTaskId )) {
63+ //TODO Add requester field to getChainTask
64+ Optional <ChainTask > chainTask = iexecHubService .getChainTask (chainTaskId );
65+ if (chainTask .isEmpty ()) {
6566 log .error ("Trying to upload result for TEE but getChainTask failed [chainTaskId:{}, uploader:{}]" ,
6667 chainTaskId , walletAddress );
6768 return false ;
6869 }
69- boolean isActive = chainTask .get ().getStatus (). equals ( ChainTaskStatus .ACTIVE ) ;
70+ boolean isActive = chainTask .get ().getStatus () == ChainTaskStatus .ACTIVE ;
7071
7172 Optional <TaskDescription > taskDescription = iexecHubService .getTaskDescriptionFromChain (chainTaskId );
72- if (taskDescription .isEmpty ()){
73+ if (taskDescription .isEmpty ()) {
7374 log .error ("Trying to upload result for TEE but getTaskDescription failed [chainTaskId:{}, uploader:{}]" ,
7475 chainTaskId , walletAddress );
7576 return false ;
@@ -85,15 +86,6 @@ boolean canUploadResult(String chainTaskId, String walletAddress, byte[] zip) {
8586 return false ;
8687 }
8788
88- // ContributionStatus of chainTask should be REVEALED
89- boolean isChainContributionStatusSetToRevealed = iexecHubService .isStatusTrueOnChain (chainTaskId ,
90- walletAddress , ChainContributionStatus .REVEALED );
91- if (!isChainContributionStatusSetToRevealed ) {
92- log .error ("Trying to upload result even though ChainContributionStatus is not REVEALED [chainTaskId:{}, uploadRequester:{}]" ,
93- chainTaskId , walletAddress );
94- return false ;
95- }
96-
9789 return isResultValid (chainTaskId , walletAddress , zip );
9890 }
9991 }
@@ -102,7 +94,8 @@ boolean canUploadResult(String chainTaskId, String walletAddress, byte[] zip) {
10294 * A result for a standard task is considered as valid if:
10395 * <ul>
10496 * <li>It has an associated on-chain contribution
105- * <li>The on-chain contribution result hash is the one we compute here again.
97+ * <li>The associated on-chain contribution status is {@code REVEALED}
98+ * <li>The on-chain contribution result hash is the one we compute here again
10699 * </ul>
107100 *
108101 * @param chainTaskId ID of the task
@@ -116,8 +109,13 @@ boolean isResultValid(String chainTaskId, String walletAddress, byte[] zip) {
116109 final String zipDestinationPath = resultFolderPath + SLASH_IEXEC_OUT ;
117110 try {
118111 final Optional <ChainContribution > oChainContribution = iexecHubService .getChainContribution (chainTaskId , walletAddress );
119- if (oChainContribution .isEmpty ()) {
120- log .error ("Trying to upload result but no on-chain contribution [chainTaskId:{}, uploader:{}]" ,
112+ // ContributionStatus of chainTask should be REVEALED
113+ boolean isChainContributionStatusSetToRevealed = oChainContribution
114+ .map (ChainContribution ::getStatus )
115+ .filter (chainStatus -> chainStatus == REVEALED )
116+ .isPresent ();
117+ if (!isChainContributionStatusSetToRevealed ) {
118+ log .error ("Trying to upload result even though ChainContributionStatus is not REVEALED [chainTaskId:{}, uploadRequester:{}]" ,
121119 chainTaskId , walletAddress );
122120 return false ;
123121 }
@@ -129,7 +127,7 @@ boolean isResultValid(String chainTaskId, String walletAddress, byte[] zip) {
129127 log .error ("Can't write result file [chainTaskId:{}, uploader:{}]" , chainTaskId , walletAddress );
130128 return false ;
131129 }
132- FileHelper .unZipFile (resultZipPath , zipDestinationPath );
130+ FileHelper .unZipFile (resultZipPath , zipDestinationPath );
133131
134132 final ComputedFile computedFile = readComputedFile (chainTaskId , zipDestinationPath );
135133 final String resultDigest = ResultUtils .computeWeb2ResultDigest (computedFile , resultFolderPath );
0 commit comments