diff --git a/package-lock.json b/package-lock.json index 71744602bc..8e19c69950 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.1.2", + "version": "6.1.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.1.2", + "version": "6.1.3", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index 36d67b1463..a47456623b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.1.2", + "version": "6.1.3", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/commands/common/send-telemetry-command.js b/src/commands/common/send-telemetry-command.js index 949e6fb532..9709b76994 100644 --- a/src/commands/common/send-telemetry-command.js +++ b/src/commands/common/send-telemetry-command.js @@ -12,6 +12,7 @@ class SendTelemetryCommand extends Command { this.config = ctx.config; this.networkModuleManager = ctx.networkModuleManager; this.blockchainModuleManager = ctx.blockchainModuleManager; + this.tripleStoreModuleManager = ctx.tripleStoreModuleManager; this.repositoryModuleManager = ctx.repositoryModuleManager; this.telemetryModuleManager = ctx.telemetryModuleManager; } @@ -31,8 +32,8 @@ class SendTelemetryCommand extends Command { try { const events = (await this.getUnpublishedEvents()) || []; const blockchainsNodeInfo = []; - const implementations = this.blockchainModuleManager.getImplementationNames(); - for (const implementation of implementations) { + const blockchainImplementations = this.blockchainModuleManager.getImplementationNames(); + for (const implementation of blockchainImplementations) { const blockchainInfo = { blockchain_id: implementation, // eslint-disable-next-line no-await-in-loop @@ -43,11 +44,21 @@ class SendTelemetryCommand extends Command { }; blockchainsNodeInfo.push(blockchainInfo); } + + const tripleStoreNodeInfo = []; + const tripleStoreImplementations = + this.tripleStoreModuleManager.getImplementationNames(); + for (const implementation of tripleStoreImplementations) { + const tripleStoreInfo = { + implementationName: implementation, + }; + tripleStoreNodeInfo.push(tripleStoreInfo); + } const nodeData = { version: pjson.version, identity: this.networkModuleManager.getPeerId().toB58String(), hostname: this.config.hostname, - triple_store: this.config.modules.tripleStore.defaultImplementation, + triple_stores: tripleStoreNodeInfo, auto_update_enabled: this.config.modules.autoUpdater.enabled, multiaddresses: this.networkModuleManager.getMultiaddrs(), blockchains: blockchainsNodeInfo, diff --git a/src/commands/protocols/common/submit-commit-command.js b/src/commands/protocols/common/submit-commit-command.js index a0484d1c6c..d7a703d95e 100644 --- a/src/commands/protocols/common/submit-commit-command.js +++ b/src/commands/protocols/common/submit-commit-command.js @@ -110,8 +110,17 @@ class SubmitCommitCommand extends Command { ); }); + const sendSubmitCommitTransactionOperationId = this.operationIdService.generateId(); let txSuccess; try { + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_START, + sendSubmitCommitTransactionOperationId, + blockchain, + agreementId, + epoch, + operationId, + ); txSuccess = await transactionCompletePromise; } catch (error) { this.logger.warn( @@ -121,7 +130,13 @@ class SubmitCommitCommand extends Command { `Epoch: ${epoch}, State Index: ${stateIndex}, Operation ID: ${operationId}, ` + `Retry number: ${COMMAND_RETRIES.SUBMIT_COMMIT - command.retries + 1}.`, ); - + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.FAILED, + sendSubmitCommitTransactionOperationId, + blockchain, + error.message, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + ); let newGasPrice; if ( error.message.includes(`timeout exceeded`) || @@ -142,6 +157,14 @@ class SubmitCommitCommand extends Command { let msgBase; if (txSuccess) { + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_END, + sendSubmitCommitTransactionOperationId, + blockchain, + agreementId, + epoch, + operationId, + ); msgBase = 'Successfully executed'; this.operationIdService.emitChangeEvent( @@ -153,6 +176,13 @@ class SubmitCommitCommand extends Command { ); } else { msgBase = 'Node has already submitted commit. Finishing'; + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.FAILED, + sendSubmitCommitTransactionOperationId, + blockchain, + msgBase, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + ); } this.logger.trace( diff --git a/src/commands/protocols/common/submit-proofs-command.js b/src/commands/protocols/common/submit-proofs-command.js index f3c7e6d9ca..2f77239ff4 100644 --- a/src/commands/protocols/common/submit-proofs-command.js +++ b/src/commands/protocols/common/submit-proofs-command.js @@ -161,9 +161,16 @@ class SubmitProofsCommand extends Command { txGasPrice, ); }); - + const sendSubmitProofsTransactionOperationId = this.operationIdService.generateId(); let txSuccess; try { + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_START, + sendSubmitProofsTransactionOperationId, + blockchain, + agreementId, + epoch, + ); txSuccess = await transactionCompletePromise; } catch (error) { this.logger.warn( @@ -173,7 +180,13 @@ class SubmitProofsCommand extends Command { `Epoch: ${epoch}, State Index: ${stateIndex}, Operation ID: ${operationId}, ` + `Retry number: ${COMMAND_RETRIES.SUBMIT_PROOFS - command.retries + 1}.`, ); - + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.FAILED, + sendSubmitProofsTransactionOperationId, + blockchain, + error.message, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_ERROR, + ); let newGasPrice; if ( error.message.includes(`timeout exceeded`) || @@ -194,6 +207,13 @@ class SubmitProofsCommand extends Command { let msgBase; if (txSuccess) { + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_START, + sendSubmitProofsTransactionOperationId, + blockchain, + agreementId, + epoch, + ); msgBase = 'Successfully executed'; this.operationIdService.emitChangeEvent( @@ -205,6 +225,13 @@ class SubmitProofsCommand extends Command { ); } else { msgBase = 'Node has already sent proof. Finishing'; + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.FAILED, + sendSubmitProofsTransactionOperationId, + blockchain, + msgBase, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + ); } this.logger.trace( diff --git a/src/commands/protocols/publish/sender/publish-schedule-messages-command.js b/src/commands/protocols/publish/sender/publish-schedule-messages-command.js index 4c4977a09e..e8bec24443 100644 --- a/src/commands/protocols/publish/sender/publish-schedule-messages-command.js +++ b/src/commands/protocols/publish/sender/publish-schedule-messages-command.js @@ -6,6 +6,9 @@ class PublishScheduleMessagesCommand extends ProtocolScheduleMessagesCommand { constructor(ctx) { super(ctx); this.operationService = ctx.publishService; + this.serviceAgreementService = ctx.serviceAgreementService; + this.blockchainModuleManager = ctx.blockchainModuleManager; + this.repositoryModuleManager = ctx.repositoryModuleManager; this.startEvent = OPERATION_ID_STATUS.PUBLISH.PUBLISH_REPLICATE_START; this.errorType = ERROR_TYPE.PUBLISH.PUBLISH_START_ERROR; @@ -26,7 +29,7 @@ class PublishScheduleMessagesCommand extends ProtocolScheduleMessagesCommand { } = command.data; let isValid = true; // perform check only first time not for every batch - if (leftoverNodes === numberOfFoundNodes) { + if (leftoverNodes.length === numberOfFoundNodes) { isValid = await this.validateBidsForNeighbourhood( blockchain, contract, @@ -90,15 +93,15 @@ class PublishScheduleMessagesCommand extends ProtocolScheduleMessagesCommand { let validBids = 0; - nodes.forEach((node) => { - const askNumber = this.blockchainModuleManager.convertToWei(blockchain, node.ask); - - const ask = this.blockchainModuleManager.toBigNumber(blockchain, askNumber); + await Promise.all( + nodes.map(async (node) => { + const ask = await this.getAsk(blockchain, node.id); + if (ask.lte(serviceAgreementBid)) { + validBids += 1; + } + }), + ); - if (ask.lte(serviceAgreementBid)) { - validBids += 1; - } - }); if (validBids < minAckResponses) { await this.operationService.markOperationAsFailed( operationId, @@ -111,6 +114,13 @@ class PublishScheduleMessagesCommand extends ProtocolScheduleMessagesCommand { return true; } + async getAsk(blockchain, nodeId) { + const peerRecord = await this.repositoryModuleManager.getPeerRecord(nodeId, blockchain); + const ask = this.blockchainModuleManager.convertToWei(blockchain, peerRecord.ask); + + return this.blockchainModuleManager.toBigNumber(blockchain, ask); + } + /** * Builds default publishScheduleMessagesCommand * @param map diff --git a/src/commands/protocols/update/receiver/submit-update-commit-command.js b/src/commands/protocols/update/receiver/submit-update-commit-command.js index d8c9b27297..64d81de6d2 100644 --- a/src/commands/protocols/update/receiver/submit-update-commit-command.js +++ b/src/commands/protocols/update/receiver/submit-update-commit-command.js @@ -89,8 +89,23 @@ class SubmitUpdateCommitCommand extends Command { ); }); + const sendSubmitUpdateCommitTransactionOperationId = this.operationIdService.generateId(); try { + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_UPDATE_COMMIT_SEND_TX_START, + sendSubmitUpdateCommitTransactionOperationId, + blockchain, + agreementId, + epoch, + ); await transactionCompletePromise; + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_UPDATE_COMMIT_SEND_TX_END, + sendSubmitUpdateCommitTransactionOperationId, + blockchain, + agreementId, + epoch, + ); } catch (error) { this.logger.warn( `Failed to execute ${command.name}, Error Message: ${error.message} for the Service Agreement ` + @@ -100,7 +115,13 @@ class SubmitUpdateCommitCommand extends Command { COMMAND_RETRIES.SUBMIT_UPDATE_COMMIT - command.retries + 1 }.`, ); - + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.FAILED, + sendSubmitUpdateCommitTransactionOperationId, + blockchain, + error.message, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_UPDATE_COMMIT_SEND_TX_ERROR, + ); let newGasPrice; if ( error.message.includes(`timeout exceeded`) || diff --git a/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js b/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js index c02ae88649..3f82ad11df 100644 --- a/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js +++ b/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js @@ -131,7 +131,7 @@ class HandleUpdateRequestCommand extends HandleProtocolMessageCommand { // wait for 5 blocks for first batch to send commits const commitsBlockDuration = blockTime * COMMIT_BLOCK_DURATION_IN_BLOCKS; const commitBlock = Math.floor(rank / finalizationCommitsNumber); - // put 2 blocks delay between nodes if they are not in first batch + // put 5 blocks delay between nodes if they are not in first batch const nextNodeDelay = commitBlock === 0 ? 0 diff --git a/src/constants/constants.js b/src/constants/constants.js index 052f17df4c..9afa6ed6b9 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -29,7 +29,7 @@ export const PRIVATE_ASSERTION_PREDICATE = export const COMMIT_BLOCK_DURATION_IN_BLOCKS = 5; -export const COMMITS_DELAY_BETWEEN_NODES_IN_BLOCKS = 2; +export const COMMITS_DELAY_BETWEEN_NODES_IN_BLOCKS = 5; export const TRANSACTION_POLLING_TIMEOUT_MILLIS = 300 * 1000; @@ -188,6 +188,8 @@ export const COMMAND_TX_GAS_INCREASE_FACTORS = { SUBMIT_PROOFS: 1.2, }; +export const GNOSIS_DEFAULT_GAS_PRICE = 2; + export const WEBSOCKET_PROVIDER_OPTIONS = { reconnect: { auto: true, @@ -283,8 +285,11 @@ export const ERROR_TYPE = { CALCULATE_PROOFS_ERROR: 'CalculateProofsError', EPOCH_CHECK_ERROR: 'EpochCheckError', SUBMIT_COMMIT_ERROR: 'SubmitCommitError', + SUBMIT_COMMIT_SEND_TX_ERROR: 'SubmitCommitSendTxError', SUBMIT_PROOFS_ERROR: 'SubmitProofsError', + SUBMIT_PROOFS_SEND_TX_ERROR: 'SubmitProofsSendTxError', SUBMIT_UPDATE_COMMIT_ERROR: 'SubmitUpdateCommitError', + SUBMIT_UPDATE_COMMIT_SEND_TX_ERROR: 'SubmitUpdateCommitSendTxError', }, }; export const OPERATION_ID_STATUS = { @@ -344,12 +349,18 @@ export const OPERATION_ID_STATUS = { EPOCH_CHECK_END: 'EPOCH_CHECK_END', SUBMIT_COMMIT_START: 'SUBMIT_COMMIT_START', SUBMIT_COMMIT_END: 'SUBMIT_COMMIT_END', + SUBMIT_COMMIT_SEND_TX_START: 'SUBMIT_COMMIT_SEND_TX_START', + SUBMIT_COMMIT_SEND_TX_END: 'SUBMIT_COMMIT_SEND_TX_END', CALCULATE_PROOFS_START: 'CALCULATE_PROOFS_START', CALCULATE_PROOFS_END: 'CALCULATE_PROOFS_END', SUBMIT_PROOFS_START: 'SUBMIT_PROOFS_START', SUBMIT_PROOFS_END: 'SUBMIT_PROOFS_END', + SUBMIT_PROOFS_SEND_TX_START: 'SUBMIT_PROOFS_START', + SUBMIT_PROOFS_SEND_TX_END: 'SUBMIT_PROOFS_END', SUBMIT_UPDATE_COMMIT_START: 'SUBMIT_UPDATE_COMMIT_START', SUBMIT_UPDATE_COMMIT_END: 'SUBMIT_UPDATE_COMMIT_END', + SUBMIT_UPDATE_COMMIT_SEND_TX_START: 'SUBMIT_UPDATE_COMMIT_START', + SUBMIT_UPDATE_COMMIT_SEND_TX_END: 'SUBMIT_UPDATE_COMMIT_END', }, QUERY: { QUERY_INIT_START: 'QUERY_INIT_START', @@ -576,6 +587,10 @@ export const NODE_ENVIRONMENTS = { MAINNET: 'mainnet', }; +export const MAXIMUM_FETCH_EVENTS_FAILED_COUNT = 1000; + +export const DELAY_BETWEEN_FAILED_FETCH_EVENTS_MILLIS = 10 * 1000; + export const CONTRACT_EVENT_FETCH_INTERVALS = { MAINNET: 10 * 1000, DEVELOPMENT: 4 * 1000, diff --git a/src/modules/blockchain/blockchain-module-manager.js b/src/modules/blockchain/blockchain-module-manager.js index dfce41cee5..3cc9055ee2 100644 --- a/src/modules/blockchain/blockchain-module-manager.js +++ b/src/modules/blockchain/blockchain-module-manager.js @@ -238,6 +238,10 @@ class BlockchainModuleManager extends BaseModuleManager { ]); } + async getAssertionData(blockchain, assertionid) { + return this.callImplementationFunction(blockchain, 'getAssertionData', [assertionid]); + } + submitCommit( blockchain, assetContractAddress, diff --git a/src/modules/blockchain/implementation/gnosis/gnosis-service.js b/src/modules/blockchain/implementation/gnosis/gnosis-service.js index a265283c0a..089ad52f81 100644 --- a/src/modules/blockchain/implementation/gnosis/gnosis-service.js +++ b/src/modules/blockchain/implementation/gnosis/gnosis-service.js @@ -1,6 +1,6 @@ import axios from 'axios'; import Web3Service from '../web3-service.js'; -import { BLOCK_TIME_MILLIS } from '../../../../constants/constants.js'; +import { BLOCK_TIME_MILLIS, GNOSIS_DEFAULT_GAS_PRICE } from '../../../../constants/constants.js'; class GnosisService extends Web3Service { constructor(ctx) { @@ -26,9 +26,23 @@ class GnosisService extends Web3Service { this.logger.debug(`Gas price on Gnosis: ${gasPrice}`); return gasPrice; } catch (error) { - return undefined; + this.logger.warn( + `Failed to fetch the gas price from the Gnosis: ${error}. Using default value: ${GNOSIS_DEFAULT_GAS_PRICE} Gwei.`, + ); + this.convertToWei(GNOSIS_DEFAULT_GAS_PRICE, 'gwei'); } } + + async healthCheck() { + try { + const blockNumber = await this.getBlockNumber(); + if (blockNumber) return true; + } catch (e) { + this.logger.error(`Error on checking Gnosis blockchain. ${e}`); + return false; + } + return false; + } } export default GnosisService; diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index 3d00134bfd..89f74acfa1 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -871,6 +871,20 @@ class Web3Service { return Number(assertionChunksNumber); } + async getAssertionData(assertionId) { + const assertionData = await this.callContractFunction( + this.AssertionStorageContract, + 'getAssertion', + [assertionId], + ); + return { + timestamp: Number(assertionData.timestamp), + size: Number(assertionData.size), + triplesNumber: Number(assertionData.triplesNumber), + chunksNumber: Number(assertionData.chunksNumber), + }; + } + selectCommitManagerContract(latestStateIndex) { return latestStateIndex === 0 ? this.CommitManagerV1Contract diff --git a/src/modules/http-client/implementation/middleware/authentication-middleware.js b/src/modules/http-client/implementation/middleware/authentication-middleware.js index bb3ce98246..4a8d951774 100644 --- a/src/modules/http-client/implementation/middleware/authentication-middleware.js +++ b/src/modules/http-client/implementation/middleware/authentication-middleware.js @@ -18,7 +18,7 @@ export default (authService) => async (req, res, next) => { const match = req.path.match(/^\/(?:v[0-9]+\/)?([^\/\?]+)/); if (!match) return res.status(404).send('Not found.'); - const operation = match[0].substring(1); + const operation = match[0].substring(1).toUpperCase(); if (authService.isPublicOperation(operation)) { return next(); diff --git a/src/modules/http-client/implementation/middleware/authorization-middleware.js b/src/modules/http-client/implementation/middleware/authorization-middleware.js index 5c92020f15..43a73385f3 100644 --- a/src/modules/http-client/implementation/middleware/authorization-middleware.js +++ b/src/modules/http-client/implementation/middleware/authorization-middleware.js @@ -9,7 +9,7 @@ export default (authService) => async (req, res, next) => { const match = req.path.match(/^\/(?:v[0-9]+\/)?([^\/\?]+)/); if (!match) return res.status(404).send('Not found.'); - const operation = match[0].substring(1); + const operation = match[0].substring(1).toUpperCase(); if (authService.isPublicOperation(operation)) { return next(); diff --git a/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js b/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js new file mode 100644 index 0000000000..69db49ffa8 --- /dev/null +++ b/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js @@ -0,0 +1,95 @@ +const newRoutes = [ + 'V0/PUBLISH', + 'V0/UPDATE', + 'V0/GET', + 'V0/QUERY', + 'V0/OPERATION_RESULT', + 'V0/INFO', + 'V0/BID-SUGGESTION', + 'V0/LOCAL-STORE', +]; +const outdatedRoutes = ['PROVISION', 'SEARCH', 'SEARCH_ASSERTION', 'PROOFS']; + +async function getAbilityIds(names, queryInterface, transaction) { + const [abilities] = await queryInterface.sequelize.query( + `SELECT id FROM ability WHERE name IN (${names.map((name) => `'${name}'`).join(', ')})`, + { transaction }, + ); + return abilities.map((ability) => ability.id); +} + +async function getRoleIds(queryInterface, transaction) { + const [roles] = await queryInterface.sequelize.query( + 'SELECT id FROM role WHERE name IS NOT NULL;', + { + transaction, + }, + ); + + return roles.map((role) => role.id); +} + +async function getRoleAbilities(names, queryInterface, transaction) { + const abilityIds = await getAbilityIds(names, queryInterface, transaction); + const roleIds = await getRoleIds(queryInterface, transaction); + + return roleIds.flatMap((roleId) => + abilityIds.map((abilityId) => ({ + ability_id: abilityId, + role_id: roleId, + })), + ); +} + +async function removeAbilities(names, queryInterface, transaction) { + const roleIds = await getRoleIds(queryInterface, transaction); + const abilityIds = await getAbilityIds(names, queryInterface, transaction); + + await queryInterface.bulkDelete( + 'role_ability', + { + role_id: roleIds, + ability_id: abilityIds, + }, + { transaction }, + ); + + await queryInterface.bulkDelete('ability', { id: abilityIds }, { transaction }); +} + +async function addAbilities(names, queryInterface, transaction) { + await queryInterface.bulkInsert( + 'ability', + names.map((name) => ({ name })), + { transaction }, + ); + await queryInterface.bulkInsert( + 'role_ability', + await getRoleAbilities(names, queryInterface, transaction), + { transaction }, + ); +} + +export async function up({ context: { queryInterface } }) { + const transaction = await queryInterface.sequelize.transaction(); + try { + await addAbilities(newRoutes, queryInterface, transaction); + await removeAbilities(outdatedRoutes, queryInterface, transaction); + transaction.commit(); + } catch (e) { + transaction.rollback(); + throw e; + } +} + +export async function down({ context: { queryInterface } }) { + const transaction = await queryInterface.sequelize.transaction(); + try { + await removeAbilities(newRoutes, queryInterface, transaction); + await addAbilities(outdatedRoutes, queryInterface, transaction); + transaction.commit(); + } catch (e) { + transaction.rollback(); + throw e; + } +} diff --git a/src/service/auth-service.js b/src/service/auth-service.js index 05c6c3093e..6665462433 100644 --- a/src/service/auth-service.js +++ b/src/service/auth-service.js @@ -62,15 +62,10 @@ class AuthService { return false; } - const lowerCaseOperationName = operationName.toLowerCase(); - - return this._authConfig.publicOperations.some((publicOperation) => { - const lowerCasePublicOperation = publicOperation.toLowerCase(); - return ( - lowerCasePublicOperation === `v0/${lowerCaseOperationName}` || - lowerCasePublicOperation === lowerCaseOperationName - ); - }); + return this._authConfig.publicOperations.some( + (publicOperation) => + publicOperation === `V0/${operationName}` || publicOperation === operationName, + ); } /** diff --git a/src/service/blockchain-event-listener-service.js b/src/service/blockchain-event-listener-service.js index 39aab4c22b..c406e34b91 100644 --- a/src/service/blockchain-event-listener-service.js +++ b/src/service/blockchain-event-listener-service.js @@ -1,3 +1,4 @@ +import { setTimeout } from 'timers/promises'; import { CONTENT_ASSET_HASH_FUNCTION_ID, CONTRACTS, @@ -6,9 +7,10 @@ import { NODE_ENVIRONMENTS, PENDING_STORAGE_REPOSITORIES, CONTRACT_EVENTS, + MAXIMUM_FETCH_EVENTS_FAILED_COUNT, + DELAY_BETWEEN_FAILED_FETCH_EVENTS_MILLIS, } from '../constants/constants.js'; -const MAXIMUM_FETCH_EVENTS_FAILED_COUNT = 5; const fetchEventsFailedCount = {}; const eventNames = Object.values(CONTRACT_EVENTS).flatMap((e) => e); @@ -140,6 +142,7 @@ class BlockchainEventListenerService { `Failed to get and process blockchain events for blockchain: ${blockchainId}. Error: ${e}`, ); fetchEventsFailedCount[blockchainId] += 1; + await setTimeout(DELAY_BETWEEN_FAILED_FETCH_EVENTS_MILLIS); } finally { working = false; } diff --git a/src/service/validation-service.js b/src/service/validation-service.js index a841a4265d..6782ddbc36 100644 --- a/src/service/validation-service.js +++ b/src/service/validation-service.js @@ -35,21 +35,18 @@ class ValidationService { this.logger.info(`Validating assertionId: ${assertionId}`); this.validateAssertionId(assertion, assertionId); - - // TODO: get assertion data in one call - await this.validateAssertionSize(blockchain, assertionId, assertion); - await this.validateTriplesNumber(blockchain, assertionId, assertion); - await this.validateChunkSize(blockchain, assertionId, assertion); - - this.logger.info(`Assertion integrity validated!`); - } - - async validateAssertionSize(blockchain, assertionId, assertion) { - const blockchainAssertionSize = await this.blockchainModuleManager.getAssertionSize( + const blockchainAssertionData = await this.blockchainModuleManager.getAssertionData( blockchain, assertionId, ); + this.validateAssertionSize(blockchainAssertionData.size, assertion); + this.validateTriplesNumber(blockchainAssertionData.triplesNumber, assertion); + this.validateChunkSize(blockchainAssertionData.chunksNumber, assertion); + this.logger.info(`Assertion integrity validated! AssertionId: ${assertionId}`); + } + + validateAssertionSize(blockchainAssertionSize, assertion) { const blockchainAssertionSizeInKb = blockchainAssertionSize / BYTES_IN_KILOBYTE; if (blockchainAssertionSizeInKb > this.config.maximumAssertionSizeInKb) { throw Error( @@ -65,9 +62,7 @@ class ValidationService { } } - async validateTriplesNumber(blockchain, assertionId, assertion) { - const blockchainTriplesNumber = - await this.blockchainModuleManager.getAssertionTriplesNumber(blockchain, assertionId); + validateTriplesNumber(blockchainTriplesNumber, assertion) { const triplesNumber = assertionMetadata.getAssertionTriplesNumber(assertion); if (blockchainTriplesNumber !== triplesNumber) { throw Error( @@ -76,11 +71,7 @@ class ValidationService { } } - async validateChunkSize(blockchain, assertionId, assertion) { - const blockchainChunksNumber = await this.blockchainModuleManager.getAssertionChunksNumber( - blockchain, - assertionId, - ); + validateChunkSize(blockchainChunksNumber, assertion) { const chunksNumber = assertionMetadata.getAssertionChunksNumber(assertion); if (blockchainChunksNumber !== chunksNumber) { throw Error(