Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use iexec-commons-poco@3.2.0 and iexec-common@8.3.1 #648

Merged
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ All notable changes to this project will be documented in this file.
- Upgrade to Spring Dependency Management Plugin 1.1.4. (#634)
- Upgrade to Spring Doc Openapi 1.7.0. (#637)
- Upgrade to `jenkins-library` 2.7.4. (#630)
- Upgrade to `iexec-commons-poco` 3.2.0. (#648)
- Upgrade to `iexec-common` 8.3.1. (#648)

## [[8.2.3]](https://github.com/iExecBlockchainComputing/iexec-core/releases/tag/v8.2.3) 2023-12-14

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version=8.2.3
iexecCommonVersion=8.3.0
iexecCommonsPocoVersion=3.1.0
iexecCommonVersion=8.3.1
iexecCommonsPocoVersion=3.2.0
iexecBlockchainAdapterVersion=8.2.0-NEXT-SNAPSHOT
iexecResultVersion=8.2.0
iexecSmsVersion=8.3.0
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/iexec/core/chain/IexecHubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public boolean isBeforeContributionDeadline(ChainDeal chainDeal) {
* <li> maxCategoryTime: duration of the deal's category.
* <li> nbOfCategoryUnits: number of category units dedicated
* for the contribution phase.
* </ul>
*
* @param chainDeal
* @return
Expand All @@ -147,6 +148,7 @@ public Date getChainDealContributionDeadline(ChainDeal chainDeal) {
* <li> maxCategoryTime: duration of the deal's category.
* <li> 10: number of category units dedicated
* for the hole execution.
* </ul>
*
* @param chainDeal
* @return
Expand Down Expand Up @@ -267,14 +269,14 @@ public boolean repeatIsRevealedTrue(String chainTaskId, String walletAddress) {
"isRevealedTrue", this::isRevealed, chainTaskId, walletAddress);
}

boolean isContributed(String... args) {
public boolean isContributed(String... args) {
return getChainContribution(args[0], args[1])
.map(ChainContribution::getStatus)
.filter(chainStatus -> chainStatus == CONTRIBUTED || chainStatus == REVEALED)
.isPresent();
}

boolean isRevealed(String... args) {
public boolean isRevealed(String... args) {
return getChainContribution(args[0], args[1])
.map(ChainContribution::getStatus)
.filter(chainStatus -> chainStatus == REVEALED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ protected UnnotifiedAbstractDetector(TaskService taskService,
/**
* Detects the following issues:
* <ul>
* <li>`onchainDone` status only if replicates are in `offchainOngoing` status;</li>
* <li>`onchainDone` if replicates are not in `offchainDone` status.</li>
* </ul></ul>
* <li>`onchainDone` status only if replicates are in `offchainOngoing` status
* <li>`onchainDone` if replicates are not in `offchainDone` status
* </ul>
* The second detection is not always ran, depending on the detector run occurrences.
*/
void detectOnChainChanges() {
Expand Down Expand Up @@ -101,11 +101,8 @@ void detectOnchainDoneWhenOffchainOngoing() {
continue;
}

final boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain(
task.getChainTaskId(),
replicate.getWalletAddress(),
onchainDone
);
final boolean statusTrueOnChain = detectStatusReachedOnChain(
task.getChainTaskId(), replicate.getWalletAddress());

if (statusTrueOnChain) {
log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]",
Expand All @@ -121,7 +118,7 @@ void detectOnchainDoneWhenOffchainOngoing() {
* (worker didn't notify any status)
* We want to detect them:
* - Frequently but no so often since it's eth node resource consuming and less probable
* - When we receive a "can't do <action>" relative to the `onchainDone` status (e.g.: `CANNOT_REVEAL`)
* - When we receive a "can't do &lt;action&gt;" relative to the `onchainDone` status (e.g.: `CANNOT_REVEAL`)
*/
public void detectOnchainDone() {
log.debug("Detect onchain {} [retryIn:{}]", onchainDone, this.detectorRate * LESS_OFTEN_DETECTOR_FREQUENCY);
Expand All @@ -133,11 +130,8 @@ public void detectOnchainDone() {
continue;
}

final boolean statusTrueOnChain = iexecHubService.isStatusTrueOnChain(
task.getChainTaskId(),
replicate.getWalletAddress(),
onchainDone
);
final boolean statusTrueOnChain = detectStatusReachedOnChain(
task.getChainTaskId(), replicate.getWalletAddress());

if (statusTrueOnChain) {
log.info("Detected confirmed missing update (replicate) [is:{}, should:{}, taskId:{}]",
Expand All @@ -148,6 +142,24 @@ public void detectOnchainDone() {
}
}

/**
* Checks if {@code onchainDone} status has been reached on blockchain network.
*
* @param chainTaskId ID of on-chain task
* @param walletAddress Address of a worker working on the current task.
* @return
*/
private boolean detectStatusReachedOnChain(String chainTaskId, String walletAddress) {
switch (onchainDone) {
case CONTRIBUTED:
return iexecHubService.isContributed(chainTaskId, walletAddress);
case REVEALED:
return iexecHubService.isRevealed(chainTaskId, walletAddress);
default:
return false;
}
}

/*
* This method should stay private. We need to ensure that
* it is only called by the POOL_MANAGER.
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/iexec/core/replicate/ReplicatesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,11 @@ public boolean isResultUploaded(TaskDescription task) {
}

public boolean didReplicateContributeOnchain(String chainTaskId, String walletAddress) {
return iexecHubService.isStatusTrueOnChain(
chainTaskId, walletAddress, getChainStatus(ReplicateStatus.CONTRIBUTED));
return iexecHubService.isContributed(chainTaskId, walletAddress);
}

public boolean didReplicateRevealOnchain(String chainTaskId, String walletAddress) {
return iexecHubService.isStatusTrueOnChain(
chainTaskId, walletAddress, getChainStatus(ReplicateStatus.REVEALED));
return iexecHubService.isRevealed(chainTaskId, walletAddress);
}

public void setRevealTimeoutStatusIfNeeded(String chainTaskId, Replicate replicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.iexec.common.replicate.ReplicateStatus;
import com.iexec.common.replicate.ReplicateStatusDetails;
import com.iexec.common.replicate.ReplicateStatusUpdate;
import com.iexec.commons.poco.chain.ChainContributionStatus;
import com.iexec.commons.poco.chain.ChainReceipt;
import com.iexec.core.chain.IexecHubService;
import com.iexec.core.chain.Web3jService;
Expand Down Expand Up @@ -55,6 +54,7 @@ void init() {
}

// region Detector aggregator

/**
* When running {@link ContributionAndFinalizationUnnotifiedDetector#detectOnChainChanges} 10 times,
* {@link ReplicatesService#updateReplicateStatus(String, String, ReplicateStatus, ReplicateStatusDetails)} should be called 11 times:
Expand All @@ -73,7 +73,7 @@ void shouldDetectBothChangesOnChain() {
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));

when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true);
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(true);
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
when(iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, 0))
.thenReturn(ChainReceipt.builder()
Expand All @@ -94,9 +94,11 @@ void shouldDetectBothChangesOnChain() {
any(ReplicateStatusDetails.class)
);
}

// endregion

//region detectOnchainDoneWhenOffchainOngoing (ContributeAndFinalizeOngoing)

@Test
void shouldDetectUnNotifiedContributeAndFinalizeDoneAfterContributeAndFinalizeOngoing() {
Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
Expand All @@ -107,7 +109,7 @@ void shouldDetectUnNotifiedContributeAndFinalizeDoneAfterContributeAndFinalizeOn
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));

when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true);
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(true);
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
when(iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, 0))
.thenReturn(ChainReceipt.builder()
Expand Down Expand Up @@ -137,7 +139,7 @@ void shouldDetectUnNotifiedContributeAndFinalizeDoneSinceBeforeContributeAndFina
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));

when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true);
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(true);

detector.detectOnchainDoneWhenOffchainOngoing();

Expand All @@ -155,15 +157,17 @@ void shouldNotDetectUnNotifiedContributeAndFinalizeDoneSinceNotFinalizedOnChain(
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));

when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(false);
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(false);
detector.detectOnchainDoneWhenOffchainOngoing();

Mockito.verify(replicatesService, Mockito.times(0))
.updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class));
}

// endregion

//region detectOnchainDone (REVEALED)

@Test
void shouldDetectUnNotifiedContributeAndFinalizeOngoing() {
Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
Expand All @@ -174,7 +178,7 @@ void shouldDetectUnNotifiedContributeAndFinalizeOngoing() {
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));

when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true);
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(true);
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
when(iexecHubService.getFinalizeBlock(CHAIN_TASK_ID, 0)).thenReturn(ChainReceipt.builder()
.blockNumber(10L)
Expand Down Expand Up @@ -202,12 +206,13 @@ void shouldNotDetectUnNotifiedContributedSinceContributeAndFinalizeDone() {
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));

when(replicatesService.getReplicates(CHAIN_TASK_ID)).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(CHAIN_TASK_ID, WALLET_ADDRESS, ChainContributionStatus.REVEALED)).thenReturn(true);
when(iexecHubService.isRevealed(CHAIN_TASK_ID, WALLET_ADDRESS)).thenReturn(true);
detector.detectOnchainDone();

Mockito.verify(replicatesService, Mockito.times(0))
.updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class));
}

// endregion

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void init() {
}

// region Detector aggregator

/**
* When running {@link ContributionUnnotifiedDetector#detectOnChainChanges} 10 times,
* {@link ReplicatesService#updateReplicateStatus(String, String, ReplicateStatus, ReplicateStatusDetails)} should be called 11 times:
Expand All @@ -89,7 +90,7 @@ void shouldDetectBothChangesOnChain() {
replicate.setStatusUpdateList(Collections.singletonList(statusUpdate));

when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
when(iexecHubService.isContributed(any(), any())).thenReturn(true);
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
when(iexecHubService.getContributionBlock(anyString(), anyString(), anyLong())).thenReturn(ChainReceipt.builder()
.blockNumber(10L)
Expand All @@ -103,9 +104,11 @@ void shouldDetectBothChangesOnChain() {
Mockito.verify(replicatesService, Mockito.times(11))
.updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class));
}

// endregion

//region detectOnchainDoneWhenOffchainOngoing (CONTRIBUTING)

@Test
void shouldDetectUnNotifiedContributedAfterContributing() {
Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
Expand All @@ -117,7 +120,7 @@ void shouldDetectUnNotifiedContributedAfterContributing() {

when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
when(iexecHubService.isContributed(any(), any())).thenReturn(true);
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
when(iexecHubService.getContributionBlock(anyString(), anyString(), anyLong()))
.thenReturn(ChainReceipt.builder().blockNumber(10L).txHash("0xabcef").build());
Expand All @@ -139,7 +142,7 @@ void shouldDetectUnNotifiedContributedAfterContributingSinceBeforeContributing()

when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
when(iexecHubService.isContributed(any(), any())).thenReturn(true);

contributionDetector.detectOnchainDoneWhenOffchainOngoing();

Expand All @@ -158,15 +161,17 @@ void shouldNotDetectUnNotifiedContributedAfterContributingSinceNotContributedOnC

// when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(false);
when(iexecHubService.isContributed(any(), any())).thenReturn(false);
contributionDetector.detectOnchainDoneWhenOffchainOngoing();

Mockito.verify(replicatesService, Mockito.times(0))
.updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class));
}

// endregion

// region detectOnchainDone (CONTRIBUTED)

@Test
void shouldDetectUnNotifiedContributed1() {
Task task = Task.builder().chainTaskId(CHAIN_TASK_ID).build();
Expand All @@ -178,7 +183,7 @@ void shouldDetectUnNotifiedContributed1() {

when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
when(iexecHubService.isContributed(any(), any())).thenReturn(true);
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
when(iexecHubService.getContributionBlock(anyString(), anyString(), anyLong())).thenReturn(ChainReceipt.builder()
.blockNumber(10L)
Expand All @@ -202,7 +207,7 @@ void shouldDetectUnNotifiedContributed2() {

when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
when(iexecHubService.isContributed(any(), any())).thenReturn(true);
when(web3jService.getLatestBlockNumber()).thenReturn(11L);
when(iexecHubService.getContributionBlock(anyString(), anyString(), anyLong())).thenReturn(ChainReceipt.builder()
.blockNumber(10L)
Expand All @@ -226,11 +231,12 @@ void shouldNotDetectUnNotifiedContributedSinceContributed() {

when(cronConfiguration.getContribute()).thenReturn(DETECTOR_PERIOD);
when(replicatesService.getReplicates(any())).thenReturn(Collections.singletonList(replicate));
when(iexecHubService.isStatusTrueOnChain(any(), any(), any())).thenReturn(true);
when(iexecHubService.isContributed(any(), any())).thenReturn(true);
contributionDetector.detectOnchainDone();

Mockito.verify(replicatesService, Mockito.times(0))
.updateReplicateStatus(any(), any(), any(), any(ReplicateStatusDetails.class));
}

// endregion
}
Loading