From 4b4b2bf435c287e440d234c3d7f4a3b816fb311d Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Fri, 19 Apr 2024 11:39:10 +0200 Subject: [PATCH 1/5] Added retry logic for agreement ids --- package-lock.json | 4 +- package.json | 2 +- ...blockchain-get-latest-service-agreement.js | 130 +++++++++++------- 3 files changed, 80 insertions(+), 56 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3a18c9d491..1690bab2ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.3.0", + "version": "6.3.0+hotfix.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.3.0", + "version": "6.3.0+hotfix.1", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index 57fad629e8..829f671121 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.3.0", + "version": "6.3.0+hotfix.1", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js b/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js index 80ec73e83c..a2619ad464 100644 --- a/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js +++ b/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js @@ -1,3 +1,5 @@ +/* eslint-disable no-await-in-loop */ +import { setTimeout as sleep } from 'timers/promises'; import Command from '../../command.js'; import { CONTENT_ASSET_HASH_FUNCTION_ID, @@ -7,6 +9,8 @@ import { } from '../../../constants/constants.js'; const BATCH_SIZE = 50; +const MAX_RETRY_COUNT = 5; +const RETRY_DELAY_IN_SECONDS = 2; class BlockchainGetLatestServiceAgreement extends Command { constructor(ctx) { @@ -42,9 +46,8 @@ class BlockchainGetLatestServiceAgreement extends Command { ); let latestBlockchainTokenId; try { - latestBlockchainTokenId = await this.blockchainModuleManager.getLatestTokenId( - blockchain, - contract, + latestBlockchainTokenId = Number( + await this.blockchainModuleManager.getLatestTokenId(blockchain, contract), ); } catch (error) { if (error.message.includes(EXPECTED_TRANSACTION_ERRORS.NO_MINTED_ASSETS)) { @@ -53,7 +56,10 @@ class BlockchainGetLatestServiceAgreement extends Command { ); return; } - throw error; + this.logger.error( + `Unable to process agreement data for asset contract ${contract}. Error: ${error}`, + ); + return; } const latestDbTokenId = @@ -77,10 +83,8 @@ class BlockchainGetLatestServiceAgreement extends Command { getAgreementDataPromise.length === tokenIdDifference || getAgreementDataPromise.length === BATCH_SIZE ) { - // eslint-disable-next-line no-await-in-loop const missingAgreements = await Promise.all(getAgreementDataPromise); - // eslint-disable-next-line no-await-in-loop await this.repositoryModuleManager.bulkCreateServiceAgreementRecords( missingAgreements.filter((agreement) => agreement != null), ); @@ -103,56 +107,76 @@ class BlockchainGetLatestServiceAgreement extends Command { contract, hashFunctionId = CONTENT_ASSET_HASH_FUNCTION_ID, ) { - this.logger.debug( - `Get latest service agreement: Getting agreement data for token id: ${tokenId} on blockchain: ${blockchain}`, - ); - const assertionIds = await this.blockchainModuleManager.getAssertionIds( - blockchain, - contract, - tokenId, - ); - const keyword = await this.ualService.calculateLocationKeyword( - blockchain, - contract, - tokenId, - assertionIds[0], - ); - const agreementId = await this.serviceAgreementService.generateId( - blockchain, - contract, - tokenId, - keyword, - hashFunctionId, - ); - const agreementData = await this.blockchainModuleManager.getAgreementData( - blockchain, - agreementId, - ); + try { + this.logger.debug( + `Get latest service agreement: Getting agreement data for token id: ${tokenId} on blockchain: ${blockchain}`, + ); + let assertionIds = []; + let retryCount = 0; + + while (assertionIds.length === 0) { + if (retryCount === MAX_RETRY_COUNT) { + throw Error( + `Get latest service agreement: Unable to get assertion ids for token id: ${tokenId} on blockchain: ${blockchain}`, + ); + } + this.logger.debug( + `Get latest service agreement: getting assertion ids retry ${retryCount} for token id: ${tokenId} on blockchain: ${blockchain}`, + ); + assertionIds = await this.blockchainModuleManager.getAssertionIds( + blockchain, + contract, + tokenId, + ); + retryCount += 1; + await sleep(RETRY_DELAY_IN_SECONDS * 1000); + } - if (!agreementData) { - this.logger.warn( - `Unable to fetch agreement data while processing asset created event for agreement id: ${agreementId}, blockchain id: ${blockchain}`, + const keyword = await this.ualService.calculateLocationKeyword( + blockchain, + contract, + tokenId, + assertionIds[0], + ); + const agreementId = await this.serviceAgreementService.generateId( + blockchain, + contract, + tokenId, + keyword, + hashFunctionId, + ); + const agreementData = await this.blockchainModuleManager.getAgreementData( + blockchain, + agreementId, ); - } - const latestStateIndex = assertionIds.length - 1; - - return { - blockchainId: blockchain, - assetStorageContractAddress: contract, - tokenId, - agreementId, - startTime: agreementData.startTime, - epochsNumber: agreementData.epochsNumber, - epochLength: agreementData.epochLength, - scoreFunctionId: agreementData.scoreFunctionId, - stateIndex: latestStateIndex, - assertionId: assertionIds[latestStateIndex], - hashFunctionId, - keyword, - proofWindowOffsetPerc: agreementData.proofWindowOffsetPerc, - dataSource: SERVICE_AGREEMENT_SOURCES.NODE, - }; + if (!agreementData) { + throw Error( + `Get latest service agreement: Unable to fetch agreement data while processing asset created event for agreement id: ${agreementId}, blockchain id: ${blockchain}`, + ); + } + + const latestStateIndex = assertionIds.length - 1; + + return { + blockchainId: blockchain, + assetStorageContractAddress: contract, + tokenId, + agreementId, + startTime: agreementData.startTime, + epochsNumber: agreementData.epochsNumber, + epochLength: agreementData.epochLength, + scoreFunctionId: agreementData.scoreFunctionId, + stateIndex: latestStateIndex, + assertionId: assertionIds[latestStateIndex], + hashFunctionId, + keyword, + proofWindowOffsetPerc: agreementData.proofWindowOffsetPerc, + dataSource: SERVICE_AGREEMENT_SOURCES.NODE, + }; + } catch (error) { + this.logger.error(error.message); + } } /** From dfb9c5f00b2d6ece9e00bf6fb5743b6f81249ae3 Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Fri, 19 Apr 2024 12:35:27 +0200 Subject: [PATCH 2/5] PR comments fixed --- ...blockchain-get-latest-service-agreement.js | 29 ++++++++++++------- src/constants/constants.js | 4 +++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js b/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js index a2619ad464..3ee827b175 100644 --- a/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js +++ b/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js @@ -4,14 +4,14 @@ import Command from '../../command.js'; import { CONTENT_ASSET_HASH_FUNCTION_ID, EXPECTED_TRANSACTION_ERRORS, + GET_ASSERTION_IDS_MAX_RETRY_COUNT, + GET_ASSERTION_IDS_RETRY_DELAY_IN_SECONDS, + GET_LATEST_SERVICE_AGREEMENT_BATCH_SIZE, + GET_LATEST_SERVICE_AGREEMENT_EXCLUDE_LATEST_TOKEN_ID, GET_LATEST_SERVICE_AGREEMENT_FREQUENCY_MILLS, SERVICE_AGREEMENT_SOURCES, } from '../../../constants/constants.js'; -const BATCH_SIZE = 50; -const MAX_RETRY_COUNT = 5; -const RETRY_DELAY_IN_SECONDS = 2; - class BlockchainGetLatestServiceAgreement extends Command { constructor(ctx) { super(ctx); @@ -46,9 +46,9 @@ class BlockchainGetLatestServiceAgreement extends Command { ); let latestBlockchainTokenId; try { - latestBlockchainTokenId = Number( - await this.blockchainModuleManager.getLatestTokenId(blockchain, contract), - ); + latestBlockchainTokenId = + Number(await this.blockchainModuleManager.getLatestTokenId(blockchain, contract)) - + GET_LATEST_SERVICE_AGREEMENT_EXCLUDE_LATEST_TOKEN_ID; } catch (error) { if (error.message.includes(EXPECTED_TRANSACTION_ERRORS.NO_MINTED_ASSETS)) { this.logger.info( @@ -65,6 +65,13 @@ class BlockchainGetLatestServiceAgreement extends Command { const latestDbTokenId = (await this.repositoryModuleManager.getLatestServiceAgreementTokenId(blockchain)) ?? 0; + if (latestBlockchainTokenId < latestDbTokenId) { + this.logger.debug( + `Get latest service agreement: No new agreements found on blockchain: ${blockchain}.`, + ); + return; + } + this.logger.debug( `Get latest service agreement: Latest token id on chain: ${latestBlockchainTokenId}, latest token id in database: ${latestDbTokenId} on blockchain: ${blockchain}`, ); @@ -81,7 +88,7 @@ class BlockchainGetLatestServiceAgreement extends Command { ); if ( getAgreementDataPromise.length === tokenIdDifference || - getAgreementDataPromise.length === BATCH_SIZE + getAgreementDataPromise.length === GET_LATEST_SERVICE_AGREEMENT_BATCH_SIZE ) { const missingAgreements = await Promise.all(getAgreementDataPromise); @@ -89,7 +96,7 @@ class BlockchainGetLatestServiceAgreement extends Command { missingAgreements.filter((agreement) => agreement != null), ); getAgreementDataPromise = []; - tokenIdDifference -= BATCH_SIZE; + tokenIdDifference -= GET_LATEST_SERVICE_AGREEMENT_BATCH_SIZE; } } if (latestBlockchainTokenId - latestDbTokenId !== 0) { @@ -115,7 +122,7 @@ class BlockchainGetLatestServiceAgreement extends Command { let retryCount = 0; while (assertionIds.length === 0) { - if (retryCount === MAX_RETRY_COUNT) { + if (retryCount === GET_ASSERTION_IDS_MAX_RETRY_COUNT) { throw Error( `Get latest service agreement: Unable to get assertion ids for token id: ${tokenId} on blockchain: ${blockchain}`, ); @@ -129,7 +136,7 @@ class BlockchainGetLatestServiceAgreement extends Command { tokenId, ); retryCount += 1; - await sleep(RETRY_DELAY_IN_SECONDS * 1000); + await sleep(GET_ASSERTION_IDS_RETRY_DELAY_IN_SECONDS * 1000); } const keyword = await this.ualService.calculateLocationKeyword( diff --git a/src/constants/constants.js b/src/constants/constants.js index 66f7ad18a1..65c409ff79 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -548,6 +548,10 @@ 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; /** * @constant {object} HTTP_API_ROUTES - * HTTP API Routes with parameters From b6e91a97cd3bc7abfedef78f08a77cd974ce2490 Mon Sep 17 00:00:00 2001 From: djordjekovac Date: Fri, 19 Apr 2024 13:55:27 +0200 Subject: [PATCH 3/5] Devnet 4.3.0 hotfix 1 (#3136) * Added retry logic for agreement ids * PR comments fixed --- package-lock.json | 4 +- package.json | 2 +- ...blockchain-get-latest-service-agreement.js | 147 +++++++++++------- src/constants/constants.js | 4 + 4 files changed, 96 insertions(+), 61 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3a18c9d491..1690bab2ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.3.0", + "version": "6.3.0+hotfix.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.3.0", + "version": "6.3.0+hotfix.1", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index 57fad629e8..829f671121 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.3.0", + "version": "6.3.0+hotfix.1", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js b/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js index 80ec73e83c..3ee827b175 100644 --- a/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js +++ b/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js @@ -1,13 +1,17 @@ +/* eslint-disable no-await-in-loop */ +import { setTimeout as sleep } from 'timers/promises'; import Command from '../../command.js'; import { CONTENT_ASSET_HASH_FUNCTION_ID, EXPECTED_TRANSACTION_ERRORS, + GET_ASSERTION_IDS_MAX_RETRY_COUNT, + GET_ASSERTION_IDS_RETRY_DELAY_IN_SECONDS, + GET_LATEST_SERVICE_AGREEMENT_BATCH_SIZE, + GET_LATEST_SERVICE_AGREEMENT_EXCLUDE_LATEST_TOKEN_ID, GET_LATEST_SERVICE_AGREEMENT_FREQUENCY_MILLS, SERVICE_AGREEMENT_SOURCES, } from '../../../constants/constants.js'; -const BATCH_SIZE = 50; - class BlockchainGetLatestServiceAgreement extends Command { constructor(ctx) { super(ctx); @@ -42,10 +46,9 @@ class BlockchainGetLatestServiceAgreement extends Command { ); let latestBlockchainTokenId; try { - latestBlockchainTokenId = await this.blockchainModuleManager.getLatestTokenId( - blockchain, - contract, - ); + latestBlockchainTokenId = + Number(await this.blockchainModuleManager.getLatestTokenId(blockchain, contract)) - + GET_LATEST_SERVICE_AGREEMENT_EXCLUDE_LATEST_TOKEN_ID; } catch (error) { if (error.message.includes(EXPECTED_TRANSACTION_ERRORS.NO_MINTED_ASSETS)) { this.logger.info( @@ -53,12 +56,22 @@ class BlockchainGetLatestServiceAgreement extends Command { ); return; } - throw error; + this.logger.error( + `Unable to process agreement data for asset contract ${contract}. Error: ${error}`, + ); + return; } const latestDbTokenId = (await this.repositoryModuleManager.getLatestServiceAgreementTokenId(blockchain)) ?? 0; + if (latestBlockchainTokenId < latestDbTokenId) { + this.logger.debug( + `Get latest service agreement: No new agreements found on blockchain: ${blockchain}.`, + ); + return; + } + this.logger.debug( `Get latest service agreement: Latest token id on chain: ${latestBlockchainTokenId}, latest token id in database: ${latestDbTokenId} on blockchain: ${blockchain}`, ); @@ -75,17 +88,15 @@ class BlockchainGetLatestServiceAgreement extends Command { ); if ( getAgreementDataPromise.length === tokenIdDifference || - getAgreementDataPromise.length === BATCH_SIZE + getAgreementDataPromise.length === GET_LATEST_SERVICE_AGREEMENT_BATCH_SIZE ) { - // eslint-disable-next-line no-await-in-loop const missingAgreements = await Promise.all(getAgreementDataPromise); - // eslint-disable-next-line no-await-in-loop await this.repositoryModuleManager.bulkCreateServiceAgreementRecords( missingAgreements.filter((agreement) => agreement != null), ); getAgreementDataPromise = []; - tokenIdDifference -= BATCH_SIZE; + tokenIdDifference -= GET_LATEST_SERVICE_AGREEMENT_BATCH_SIZE; } } if (latestBlockchainTokenId - latestDbTokenId !== 0) { @@ -103,56 +114,76 @@ class BlockchainGetLatestServiceAgreement extends Command { contract, hashFunctionId = CONTENT_ASSET_HASH_FUNCTION_ID, ) { - this.logger.debug( - `Get latest service agreement: Getting agreement data for token id: ${tokenId} on blockchain: ${blockchain}`, - ); - const assertionIds = await this.blockchainModuleManager.getAssertionIds( - blockchain, - contract, - tokenId, - ); - const keyword = await this.ualService.calculateLocationKeyword( - blockchain, - contract, - tokenId, - assertionIds[0], - ); - const agreementId = await this.serviceAgreementService.generateId( - blockchain, - contract, - tokenId, - keyword, - hashFunctionId, - ); - const agreementData = await this.blockchainModuleManager.getAgreementData( - blockchain, - agreementId, - ); + try { + this.logger.debug( + `Get latest service agreement: Getting agreement data for token id: ${tokenId} on blockchain: ${blockchain}`, + ); + let assertionIds = []; + let retryCount = 0; + + while (assertionIds.length === 0) { + if (retryCount === GET_ASSERTION_IDS_MAX_RETRY_COUNT) { + throw Error( + `Get latest service agreement: Unable to get assertion ids for token id: ${tokenId} on blockchain: ${blockchain}`, + ); + } + this.logger.debug( + `Get latest service agreement: getting assertion ids retry ${retryCount} for token id: ${tokenId} on blockchain: ${blockchain}`, + ); + assertionIds = await this.blockchainModuleManager.getAssertionIds( + blockchain, + contract, + tokenId, + ); + retryCount += 1; + await sleep(GET_ASSERTION_IDS_RETRY_DELAY_IN_SECONDS * 1000); + } - if (!agreementData) { - this.logger.warn( - `Unable to fetch agreement data while processing asset created event for agreement id: ${agreementId}, blockchain id: ${blockchain}`, + const keyword = await this.ualService.calculateLocationKeyword( + blockchain, + contract, + tokenId, + assertionIds[0], + ); + const agreementId = await this.serviceAgreementService.generateId( + blockchain, + contract, + tokenId, + keyword, + hashFunctionId, + ); + const agreementData = await this.blockchainModuleManager.getAgreementData( + blockchain, + agreementId, ); - } - const latestStateIndex = assertionIds.length - 1; - - return { - blockchainId: blockchain, - assetStorageContractAddress: contract, - tokenId, - agreementId, - startTime: agreementData.startTime, - epochsNumber: agreementData.epochsNumber, - epochLength: agreementData.epochLength, - scoreFunctionId: agreementData.scoreFunctionId, - stateIndex: latestStateIndex, - assertionId: assertionIds[latestStateIndex], - hashFunctionId, - keyword, - proofWindowOffsetPerc: agreementData.proofWindowOffsetPerc, - dataSource: SERVICE_AGREEMENT_SOURCES.NODE, - }; + if (!agreementData) { + throw Error( + `Get latest service agreement: Unable to fetch agreement data while processing asset created event for agreement id: ${agreementId}, blockchain id: ${blockchain}`, + ); + } + + const latestStateIndex = assertionIds.length - 1; + + return { + blockchainId: blockchain, + assetStorageContractAddress: contract, + tokenId, + agreementId, + startTime: agreementData.startTime, + epochsNumber: agreementData.epochsNumber, + epochLength: agreementData.epochLength, + scoreFunctionId: agreementData.scoreFunctionId, + stateIndex: latestStateIndex, + assertionId: assertionIds[latestStateIndex], + hashFunctionId, + keyword, + proofWindowOffsetPerc: agreementData.proofWindowOffsetPerc, + dataSource: SERVICE_AGREEMENT_SOURCES.NODE, + }; + } catch (error) { + this.logger.error(error.message); + } } /** diff --git a/src/constants/constants.js b/src/constants/constants.js index 66f7ad18a1..65c409ff79 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -548,6 +548,10 @@ 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; /** * @constant {object} HTTP_API_ROUTES - * HTTP API Routes with parameters From 285ffa6b038540131a3919d98080509e057ef3ee Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Fri, 19 Apr 2024 14:11:19 +0200 Subject: [PATCH 4/5] Updated logic for fetching latest token ids --- ...blockchain-get-latest-service-agreement.js | 34 +++++++++++++++---- src/constants/constants.js | 6 +++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js b/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js index 3ee827b175..ee4189a600 100644 --- a/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js +++ b/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js @@ -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 { @@ -63,13 +74,18 @@ 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; + return { + contract, + lastProcessedTokenId: latestDbTokenId, + }; } this.logger.debug( @@ -99,13 +115,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( diff --git a/src/constants/constants.js b/src/constants/constants.js index 65c409ff79..be2b6d2da2 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -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 From 122f1176f09f9bf384b81e89d836c641309d96dd Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Fri, 19 Apr 2024 14:46:33 +0200 Subject: [PATCH 5/5] Updated repository to ignore duplicates on adding new service agreement --- .../sequelize/repositories/service-agreement-repository.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js index 562f9d0617..19ffb462a3 100644 --- a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js +++ b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js @@ -85,7 +85,7 @@ class ServiceAgreementRepository { async bulkCreateServiceAgreementRecords(serviceAgreements) { return this.model.bulkCreate(serviceAgreements, { - validate: true, + ignoreDuplicates: true, }); }