Skip to content

Commit

Permalink
Merge pull request #3140 from OriginTrail/v6/develop
Browse files Browse the repository at this point in the history
hotfix 1 updates
  • Loading branch information
djordjekovac authored Apr 19, 2024
2 parents e724bec + 1320e33 commit f11bf0a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,29 @@ class BlockchainGetLatestServiceAgreement extends Command {
const assetStorageContractAddresses =
this.blockchainModuleManager.getAssetStorageContractAddresses(blockchain);

await Promise.all(
const results = await Promise.all(
assetStorageContractAddresses.map((contract) =>
this.updateAgreementDataForAssetContract(contract, blockchain),
this.updateAgreementDataForAssetContract(
contract,
blockchain,
command.data[contract],
),
),
);

results.forEach((result) => {
if (result) {
// eslint-disable-next-line no-param-reassign
command.data[result.contract] = result.lastProcessedTokenId;
}
});

return Command.repeat();
}

async updateAgreementDataForAssetContract(contract, blockchain) {
async updateAgreementDataForAssetContract(contract, blockchain, lastProcessedTokenId) {
this.logger.info(
`Get latest service agreement: Starting get latest service agreement command for blockchain: ${blockchain}`,
`Get latest service agreement: Starting get latest service agreement command, last processed token id: ${lastProcessedTokenId} for blockchain: ${blockchain}`,
);
let latestBlockchainTokenId;
try {
Expand All @@ -63,7 +74,19 @@ class BlockchainGetLatestServiceAgreement extends Command {
}

const latestDbTokenId =
(await this.repositoryModuleManager.getLatestServiceAgreementTokenId(blockchain)) ?? 0;
lastProcessedTokenId ??
(await this.repositoryModuleManager.getLatestServiceAgreementTokenId(blockchain)) ??
0;

if (latestBlockchainTokenId < latestDbTokenId) {
this.logger.debug(
`Get latest service agreement: No new agreements found on blockchain: ${blockchain}.`,
);
return {
contract,
lastProcessedTokenId: latestDbTokenId,
};
}

if (latestBlockchainTokenId < latestDbTokenId) {
this.logger.debug(
Expand Down Expand Up @@ -99,13 +122,17 @@ class BlockchainGetLatestServiceAgreement extends Command {
tokenIdDifference -= GET_LATEST_SERVICE_AGREEMENT_BATCH_SIZE;
}
}
if (latestBlockchainTokenId - latestDbTokenId !== 0) {
if (latestBlockchainTokenId - latestDbTokenId > 0) {
this.logger.debug(
`Get latest service agreement: Successfully fetched ${
latestBlockchainTokenId - latestDbTokenId
} on blockchain: ${blockchain}`,
);
}
return {
contract,
lastProcessedTokenId: latestDbTokenId,
};
}

async getAgreementDataForToken(
Expand Down
6 changes: 5 additions & 1 deletion src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,13 @@ export const ARCHIVE_UPDATE_RESPONSES_FOLDER = 'update_responses';
export const COMMAND_QUEUE_PARALLELISM = 100;

export const GET_LATEST_SERVICE_AGREEMENT_BATCH_SIZE = 50;

export const GET_ASSERTION_IDS_MAX_RETRY_COUNT = 5;

export const GET_ASSERTION_IDS_RETRY_DELAY_IN_SECONDS = 2;
export const GET_LATEST_SERVICE_AGREEMENT_EXCLUDE_LATEST_TOKEN_ID = 10;

export const GET_LATEST_SERVICE_AGREEMENT_EXCLUDE_LATEST_TOKEN_ID = 1;

/**
* @constant {object} HTTP_API_ROUTES -
* HTTP API Routes with parameters
Expand Down

0 comments on commit f11bf0a

Please sign in to comment.