From 485c870f4cc368733bf6992e7685f5e999f38042 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Thu, 21 Dec 2023 14:12:25 +0100 Subject: [PATCH 01/22] Fixed authorization middleware to check operation case-insensitively, added migrations to update abilities for auth --- .../middleware/authentication-middleware.js | 2 +- .../middleware/authorization-middleware.js | 2 +- .../20231221131300-update-abilities.js | 91 +++++++++++++++++++ src/service/auth-service.js | 13 +-- 4 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js 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..0bffad294d --- /dev/null +++ b/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js @@ -0,0 +1,91 @@ +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 getAdminRoleId(queryInterface, transaction) { + const [[role]] = await queryInterface.sequelize.query( + "SELECT id FROM role WHERE name='ADMIN'", + { transaction }, + ); + + return role.id; +} + +async function getRoleAbilities(names, queryInterface, transaction) { + const abilityIds = await getAbilityIds(names, queryInterface, transaction); + const adminRoleId = await getAdminRoleId(queryInterface, transaction); + + return abilityIds.map((abilityId) => ({ + ability_id: abilityId, + role_id: adminRoleId, + })); +} + +async function removeAbilities(names, queryInterface, transaction) { + const adminRoleId = await getAdminRoleId(queryInterface, transaction); + const abilityIds = await getAbilityIds(names, queryInterface, transaction); + + await queryInterface.bulkDelete( + 'role_ability', + { + role_id: adminRoleId, + 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, + ); } /** From 7852ce4154a9ed9d4b5c90f47f73bde1656fa1f1 Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Mon, 8 Jan 2024 14:09:52 +0100 Subject: [PATCH 02/22] Added new events for transactions --- .../protocols/common/submit-commit-command.js | 26 ++++++++++++++++++- .../protocols/common/submit-proofs-command.js | 24 +++++++++++++++-- .../receiver/submit-update-commit-command.js | 23 +++++++++++++++- src/constants/constants.js | 9 +++++++ 4 files changed, 78 insertions(+), 4 deletions(-) diff --git a/src/commands/protocols/common/submit-commit-command.js b/src/commands/protocols/common/submit-commit-command.js index a0484d1c6c..22f14c2ee6 100644 --- a/src/commands/protocols/common/submit-commit-command.js +++ b/src/commands/protocols/common/submit-commit-command.js @@ -110,9 +110,26 @@ 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; + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_END, + sendSubmitCommitTransactionOperationId, + blockchain, + agreementId, + epoch, + operationId, + ); } catch (error) { this.logger.warn( `Failed to execute ${command.name}, Error Message: ${error.message} for the Service Agreement ` + @@ -121,7 +138,14 @@ 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.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + sendSubmitCommitTransactionOperationId, + blockchain, + error.message, + this.errorType, + operationId, + ); let newGasPrice; if ( error.message.includes(`timeout exceeded`) || diff --git a/src/commands/protocols/common/submit-proofs-command.js b/src/commands/protocols/common/submit-proofs-command.js index f3c7e6d9ca..73fb6466a5 100644 --- a/src/commands/protocols/common/submit-proofs-command.js +++ b/src/commands/protocols/common/submit-proofs-command.js @@ -161,10 +161,24 @@ 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; + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_START, + sendSubmitProofsTransactionOperationId, + blockchain, + agreementId, + epoch, + ); } catch (error) { this.logger.warn( `Failed to execute ${command.name}, Error Message: ${error.message} for the Service Agreement ` + @@ -173,7 +187,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.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + sendSubmitProofsTransactionOperationId, + blockchain, + error.message, + this.errorType, + ); let newGasPrice; if ( error.message.includes(`timeout exceeded`) || 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..46e9d984f4 100644 --- a/src/commands/protocols/update/receiver/submit-update-commit-command.js +++ b/src/commands/protocols/update/receiver/submit-update-commit-command.js @@ -89,7 +89,22 @@ 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, + ); + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_UPDATE_COMMIT_SEND_TX_END, + sendSubmitUpdateCommitTransactionOperationId, + blockchain, + agreementId, + epoch, + ); await transactionCompletePromise; } catch (error) { this.logger.warn( @@ -100,7 +115,13 @@ class SubmitUpdateCommitCommand extends Command { COMMAND_RETRIES.SUBMIT_UPDATE_COMMIT - command.retries + 1 }.`, ); - + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + sendSubmitUpdateCommitTransactionOperationId, + blockchain, + error.message, + this.errorType, + ); let newGasPrice; if ( error.message.includes(`timeout exceeded`) || diff --git a/src/constants/constants.js b/src/constants/constants.js index 052f17df4c..32048495a9 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -283,8 +283,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 +347,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', From 954e443b35a12b834a013cf463f4d2c8b60092b6 Mon Sep 17 00:00:00 2001 From: Milos Stanisavljevic Date: Tue, 9 Jan 2024 11:17:33 +0100 Subject: [PATCH 03/22] updated sql migration query --- .../sequelize/migrations/20231221131300-update-abilities.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js b/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js index 0bffad294d..51d1104deb 100644 --- a/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js +++ b/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js @@ -20,10 +20,10 @@ async function getAbilityIds(names, queryInterface, transaction) { async function getAdminRoleId(queryInterface, transaction) { const [[role]] = await queryInterface.sequelize.query( - "SELECT id FROM role WHERE name='ADMIN'", + 'SELECT id FROM role WHERE name IS NOT NULL', { transaction }, ); - + console.log(role); return role.id; } From 83e262f49de79ebe22d3991888ec31341e21d034 Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Tue, 9 Jan 2024 14:51:31 +0100 Subject: [PATCH 04/22] PR comment fixed --- .../protocols/update/receiver/submit-update-commit-command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 46e9d984f4..4b2aa62ccd 100644 --- a/src/commands/protocols/update/receiver/submit-update-commit-command.js +++ b/src/commands/protocols/update/receiver/submit-update-commit-command.js @@ -98,6 +98,7 @@ class SubmitUpdateCommitCommand extends Command { agreementId, epoch, ); + await transactionCompletePromise; this.operationIdService.emitChangeEvent( OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_UPDATE_COMMIT_SEND_TX_END, sendSubmitUpdateCommitTransactionOperationId, @@ -105,7 +106,6 @@ class SubmitUpdateCommitCommand extends Command { agreementId, epoch, ); - await transactionCompletePromise; } catch (error) { this.logger.warn( `Failed to execute ${command.name}, Error Message: ${error.message} for the Service Agreement ` + From f71e95e7eeb4f80cfa5e8b279404ad3c3c6b39be Mon Sep 17 00:00:00 2001 From: Milos Stanisavljevic Date: Wed, 10 Jan 2024 12:54:06 +0100 Subject: [PATCH 05/22] merged with latest node version --- .../sequelize/migrations/20231221131300-update-abilities.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js b/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js index 51d1104deb..995bcdb5b8 100644 --- a/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js +++ b/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js @@ -23,7 +23,6 @@ async function getAdminRoleId(queryInterface, transaction) { 'SELECT id FROM role WHERE name IS NOT NULL', { transaction }, ); - console.log(role); return role.id; } From 2405cfb32422e05bb4c2650898bf6577a3df9ba8 Mon Sep 17 00:00:00 2001 From: Milos Stanisavljevic Date: Wed, 10 Jan 2024 17:14:52 +0100 Subject: [PATCH 06/22] changed implementation to work for multiple roles --- .../20231221131300-update-abilities.js | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js b/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js index 995bcdb5b8..69db49ffa8 100644 --- a/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js +++ b/src/modules/repository/implementation/sequelize/migrations/20231221131300-update-abilities.js @@ -18,32 +18,37 @@ async function getAbilityIds(names, queryInterface, transaction) { return abilities.map((ability) => ability.id); } -async function getAdminRoleId(queryInterface, transaction) { - const [[role]] = await queryInterface.sequelize.query( - 'SELECT id FROM role WHERE name IS NOT NULL', - { transaction }, +async function getRoleIds(queryInterface, transaction) { + const [roles] = await queryInterface.sequelize.query( + 'SELECT id FROM role WHERE name IS NOT NULL;', + { + transaction, + }, ); - return role.id; + + return roles.map((role) => role.id); } async function getRoleAbilities(names, queryInterface, transaction) { const abilityIds = await getAbilityIds(names, queryInterface, transaction); - const adminRoleId = await getAdminRoleId(queryInterface, transaction); + const roleIds = await getRoleIds(queryInterface, transaction); - return abilityIds.map((abilityId) => ({ - ability_id: abilityId, - role_id: adminRoleId, - })); + return roleIds.flatMap((roleId) => + abilityIds.map((abilityId) => ({ + ability_id: abilityId, + role_id: roleId, + })), + ); } async function removeAbilities(names, queryInterface, transaction) { - const adminRoleId = await getAdminRoleId(queryInterface, transaction); + const roleIds = await getRoleIds(queryInterface, transaction); const abilityIds = await getAbilityIds(names, queryInterface, transaction); await queryInterface.bulkDelete( 'role_ability', { - role_id: adminRoleId, + role_id: roleIds, ability_id: abilityIds, }, { transaction }, From 899065306f8d36fe5002a5fb5c04c154a9a58c96 Mon Sep 17 00:00:00 2001 From: NZT48 Date: Thu, 11 Jan 2024 02:00:10 +0100 Subject: [PATCH 07/22] Fix pre-publish bid validation for neighbourhood --- .../publish-schedule-messages-command.js | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) 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..36e6fbe817 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, id) { + const peerRecord = await this.repositoryModuleManager.getPeerRecord(id, blockchain); + const ask = this.blockchainModuleManager.convertToWei(blockchain, peerRecord.ask); + + return this.blockchainModuleManager.toBigNumber(blockchain, ask); + } + /** * Builds default publishScheduleMessagesCommand * @param map From bc9cf1293a5e0a95d79f3a8b15ac05656c0998f0 Mon Sep 17 00:00:00 2001 From: Milos Stanisavljevic Date: Thu, 11 Jan 2024 11:29:10 +0100 Subject: [PATCH 08/22] bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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", From c0dc2856abd2f7bf6b199cba8b1a130058afef02 Mon Sep 17 00:00:00 2001 From: Milos Stanisavljevic Date: Thu, 11 Jan 2024 15:01:12 +0100 Subject: [PATCH 09/22] Reducing number of RPC calls from ValidationService --- .../blockchain/blockchain-module-manager.js | 4 +++ .../blockchain/implementation/web3-service.js | 15 ++++++++++ src/service/validation-service.js | 29 +++++++------------ 3 files changed, 29 insertions(+), 19 deletions(-) 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/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index 3d00134bfd..d085ec55a7 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -871,6 +871,21 @@ class Web3Service { return Number(assertionChunksNumber); } + async getAssertionData(assertionId) { + const assertionData = await this.callContractFunction( + this.AssertionStorageContract, + 'getAssertion', + [assertionId], + ); + return { + ...assertionData, + 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/service/validation-service.js b/src/service/validation-service.js index a841a4265d..28214f7a93 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 blockchainData = await this.blockchainModuleManager.getAssertionData( blockchain, assertionId, ); + await this.validateAssertionSize(blockchainData.size, assertion); + await this.validateTriplesNumber(blockchainData.triplesNumber, assertion); + await this.validateChunkSize(blockchainData.chunksNumber, assertion); + this.logger.info(`Assertion integrity validated!`); + } + + async 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); + async 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, - ); + async validateChunkSize(blockchainChunksNumber, assertion) { const chunksNumber = assertionMetadata.getAssertionChunksNumber(assertion); if (blockchainChunksNumber !== chunksNumber) { throw Error( From f22d2d041f17fcc5f9b4f2e8064b8d62a6175161 Mon Sep 17 00:00:00 2001 From: Milos Stanisavljevic Date: Thu, 11 Jan 2024 15:39:20 +0100 Subject: [PATCH 10/22] removed unnecessary values from return object in getAssertionData --- src/modules/blockchain/implementation/web3-service.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index d085ec55a7..89f74acfa1 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -878,7 +878,6 @@ class Web3Service { [assertionId], ); return { - ...assertionData, timestamp: Number(assertionData.timestamp), size: Number(assertionData.size), triplesNumber: Number(assertionData.triplesNumber), From cd84658c9ae054177f3bbd58c822242a9d56a6e3 Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Fri, 12 Jan 2024 09:41:33 +0100 Subject: [PATCH 11/22] Updated transaction error events --- .../protocols/common/submit-commit-command.js | 24 ++++++++++++------- .../protocols/common/submit-proofs-command.js | 21 ++++++++++------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/commands/protocols/common/submit-commit-command.js b/src/commands/protocols/common/submit-commit-command.js index 22f14c2ee6..bc3e0d1fa3 100644 --- a/src/commands/protocols/common/submit-commit-command.js +++ b/src/commands/protocols/common/submit-commit-command.js @@ -122,14 +122,6 @@ class SubmitCommitCommand extends Command { operationId, ); txSuccess = await transactionCompletePromise; - this.operationIdService.emitChangeEvent( - OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_END, - sendSubmitCommitTransactionOperationId, - blockchain, - agreementId, - epoch, - operationId, - ); } catch (error) { this.logger.warn( `Failed to execute ${command.name}, Error Message: ${error.message} for the Service Agreement ` + @@ -166,6 +158,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( @@ -177,6 +177,14 @@ class SubmitCommitCommand extends Command { ); } else { msgBase = 'Node has already submitted commit. Finishing'; + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + sendSubmitCommitTransactionOperationId, + blockchain, + msgBase, + this.errorType, + operationId, + ); } this.logger.trace( diff --git a/src/commands/protocols/common/submit-proofs-command.js b/src/commands/protocols/common/submit-proofs-command.js index 73fb6466a5..93aba5dda2 100644 --- a/src/commands/protocols/common/submit-proofs-command.js +++ b/src/commands/protocols/common/submit-proofs-command.js @@ -172,13 +172,6 @@ class SubmitProofsCommand extends Command { epoch, ); txSuccess = await transactionCompletePromise; - this.operationIdService.emitChangeEvent( - OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_START, - sendSubmitProofsTransactionOperationId, - blockchain, - agreementId, - epoch, - ); } catch (error) { this.logger.warn( `Failed to execute ${command.name}, Error Message: ${error.message} for the Service Agreement ` + @@ -214,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( @@ -225,6 +225,13 @@ class SubmitProofsCommand extends Command { ); } else { msgBase = 'Node has already sent proof. Finishing'; + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + sendSubmitProofsTransactionOperationId, + blockchain, + msgBase, + this.errorType, + ); } this.logger.trace( From b559953720bce6af9f8b5c5fec7be4c62b2e8261 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Fri, 12 Jan 2024 11:55:37 +0100 Subject: [PATCH 12/22] Send all triple stopres implementetion to telemetry --- src/commands/common/send-telemetry-command.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/commands/common/send-telemetry-command.js b/src/commands/common/send-telemetry-command.js index 949e6fb532..6af7dd91ea 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,13 @@ class SendTelemetryCommand extends Command { }; blockchainsNodeInfo.push(blockchainInfo); } + const tripleStoreImplementations = + this.tripleStoreModuleManager.getImplementationNames(); const nodeData = { version: pjson.version, identity: this.networkModuleManager.getPeerId().toB58String(), hostname: this.config.hostname, - triple_store: this.config.modules.tripleStore.defaultImplementation, + triple_stores: tripleStoreImplementations, auto_update_enabled: this.config.modules.autoUpdater.enabled, multiaddresses: this.networkModuleManager.getMultiaddrs(), blockchains: blockchainsNodeInfo, From 21a51b69b9fc82b1e97b91bd106ab3582cfe0ffa Mon Sep 17 00:00:00 2001 From: Nikola Todorovic Date: Fri, 12 Jan 2024 12:31:25 +0100 Subject: [PATCH 13/22] Update src/commands/protocols/publish/sender/publish-schedule-messages-command.js --- .../publish/sender/publish-schedule-messages-command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 36e6fbe817..3bb46dacbf 100644 --- a/src/commands/protocols/publish/sender/publish-schedule-messages-command.js +++ b/src/commands/protocols/publish/sender/publish-schedule-messages-command.js @@ -115,7 +115,7 @@ class PublishScheduleMessagesCommand extends ProtocolScheduleMessagesCommand { } async getAsk(blockchain, id) { - const peerRecord = await this.repositoryModuleManager.getPeerRecord(id, blockchain); + const peerRecord = await this.repositoryModuleManager.getPeerRecord(nodeId, blockchain); const ask = this.blockchainModuleManager.convertToWei(blockchain, peerRecord.ask); return this.blockchainModuleManager.toBigNumber(blockchain, ask); From 5bc09e285a7b17cfb482585028c38d021f01962c Mon Sep 17 00:00:00 2001 From: Nikola Todorovic Date: Fri, 12 Jan 2024 12:31:32 +0100 Subject: [PATCH 14/22] Update src/commands/protocols/publish/sender/publish-schedule-messages-command.js Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> --- .../publish/sender/publish-schedule-messages-command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3bb46dacbf..e8bec24443 100644 --- a/src/commands/protocols/publish/sender/publish-schedule-messages-command.js +++ b/src/commands/protocols/publish/sender/publish-schedule-messages-command.js @@ -114,7 +114,7 @@ class PublishScheduleMessagesCommand extends ProtocolScheduleMessagesCommand { return true; } - async getAsk(blockchain, id) { + async getAsk(blockchain, nodeId) { const peerRecord = await this.repositoryModuleManager.getPeerRecord(nodeId, blockchain); const ask = this.blockchainModuleManager.convertToWei(blockchain, peerRecord.ask); From 2067923809c52045acbd8f2d9ccfa70581ffd4d3 Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Fri, 12 Jan 2024 12:44:26 +0100 Subject: [PATCH 15/22] Mittigated issue with blockchain removal during RPC outage --- src/constants/constants.js | 4 ++++ src/service/blockchain-event-listener-service.js | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index 052f17df4c..31d0cd6a5b 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -576,6 +576,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/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; } From 9aebfc8c6ffccf1902da5fdbe5b9850a9e853630 Mon Sep 17 00:00:00 2001 From: Milos Stanisavljevic Date: Fri, 12 Jan 2024 13:28:35 +0100 Subject: [PATCH 16/22] removed unnecessary awaits --- src/service/validation-service.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/service/validation-service.js b/src/service/validation-service.js index 28214f7a93..6782ddbc36 100644 --- a/src/service/validation-service.js +++ b/src/service/validation-service.js @@ -35,18 +35,18 @@ class ValidationService { this.logger.info(`Validating assertionId: ${assertionId}`); this.validateAssertionId(assertion, assertionId); - const blockchainData = await this.blockchainModuleManager.getAssertionData( + const blockchainAssertionData = await this.blockchainModuleManager.getAssertionData( blockchain, assertionId, ); - await this.validateAssertionSize(blockchainData.size, assertion); - await this.validateTriplesNumber(blockchainData.triplesNumber, assertion); - await this.validateChunkSize(blockchainData.chunksNumber, assertion); + this.validateAssertionSize(blockchainAssertionData.size, assertion); + this.validateTriplesNumber(blockchainAssertionData.triplesNumber, assertion); + this.validateChunkSize(blockchainAssertionData.chunksNumber, assertion); - this.logger.info(`Assertion integrity validated!`); + this.logger.info(`Assertion integrity validated! AssertionId: ${assertionId}`); } - async validateAssertionSize(blockchainAssertionSize, assertion) { + validateAssertionSize(blockchainAssertionSize, assertion) { const blockchainAssertionSizeInKb = blockchainAssertionSize / BYTES_IN_KILOBYTE; if (blockchainAssertionSizeInKb > this.config.maximumAssertionSizeInKb) { throw Error( @@ -62,7 +62,7 @@ class ValidationService { } } - async validateTriplesNumber(blockchainTriplesNumber, assertion) { + validateTriplesNumber(blockchainTriplesNumber, assertion) { const triplesNumber = assertionMetadata.getAssertionTriplesNumber(assertion); if (blockchainTriplesNumber !== triplesNumber) { throw Error( @@ -71,7 +71,7 @@ class ValidationService { } } - async validateChunkSize(blockchainChunksNumber, assertion) { + validateChunkSize(blockchainChunksNumber, assertion) { const chunksNumber = assertionMetadata.getAssertionChunksNumber(assertion); if (blockchainChunksNumber !== chunksNumber) { throw Error( From 0858dd33ec36b7adfd003d48a6a228339115db61 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Fri, 12 Jan 2024 15:11:36 +0100 Subject: [PATCH 17/22] Send triple store info as object --- src/commands/common/send-telemetry-command.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/commands/common/send-telemetry-command.js b/src/commands/common/send-telemetry-command.js index 6af7dd91ea..9709b76994 100644 --- a/src/commands/common/send-telemetry-command.js +++ b/src/commands/common/send-telemetry-command.js @@ -44,13 +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_stores: tripleStoreImplementations, + triple_stores: tripleStoreNodeInfo, auto_update_enabled: this.config.modules.autoUpdater.enabled, multiaddresses: this.networkModuleManager.getMultiaddrs(), blockchains: blockchainsNodeInfo, From 812b660c0b9e772013432cb493a8ef844e093c4b Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Fri, 12 Jan 2024 17:02:02 +0100 Subject: [PATCH 18/22] Fixed error type thrown on transaction error --- package-lock.json | 4 ++-- package.json | 2 +- src/commands/protocols/common/submit-commit-command.js | 2 +- src/commands/protocols/common/submit-proofs-command.js | 2 +- .../protocols/update/receiver/submit-update-commit-command.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8e19c69950..22def46834 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.1.3", + "version": "6.1.3+hotfix.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.1.3", + "version": "6.1.3+hotfix.1", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index a47456623b..8dcd03151d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.1.3", + "version": "6.1.3+hotfix.1", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/commands/protocols/common/submit-commit-command.js b/src/commands/protocols/common/submit-commit-command.js index bc3e0d1fa3..d02e9b792d 100644 --- a/src/commands/protocols/common/submit-commit-command.js +++ b/src/commands/protocols/common/submit-commit-command.js @@ -131,7 +131,7 @@ class SubmitCommitCommand extends Command { `Retry number: ${COMMAND_RETRIES.SUBMIT_COMMIT - command.retries + 1}.`, ); this.operationIdService.emitChangeEvent( - OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, sendSubmitCommitTransactionOperationId, blockchain, error.message, diff --git a/src/commands/protocols/common/submit-proofs-command.js b/src/commands/protocols/common/submit-proofs-command.js index 93aba5dda2..f57028a617 100644 --- a/src/commands/protocols/common/submit-proofs-command.js +++ b/src/commands/protocols/common/submit-proofs-command.js @@ -181,7 +181,7 @@ class SubmitProofsCommand extends Command { `Retry number: ${COMMAND_RETRIES.SUBMIT_PROOFS - command.retries + 1}.`, ); this.operationIdService.emitChangeEvent( - OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_ERROR, sendSubmitProofsTransactionOperationId, blockchain, error.message, 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 4b2aa62ccd..97fd7dd87f 100644 --- a/src/commands/protocols/update/receiver/submit-update-commit-command.js +++ b/src/commands/protocols/update/receiver/submit-update-commit-command.js @@ -116,7 +116,7 @@ class SubmitUpdateCommitCommand extends Command { }.`, ); this.operationIdService.emitChangeEvent( - OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_UPDATE_COMMIT_SEND_TX_ERROR, sendSubmitUpdateCommitTransactionOperationId, blockchain, error.message, From 824b2ded25ff42fee1d384c8678c5edee6191346 Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Fri, 12 Jan 2024 17:11:18 +0100 Subject: [PATCH 19/22] Updated error handling with correct event name --- src/commands/protocols/common/submit-commit-command.js | 2 +- src/commands/protocols/common/submit-proofs-command.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/protocols/common/submit-commit-command.js b/src/commands/protocols/common/submit-commit-command.js index d02e9b792d..61bdc85712 100644 --- a/src/commands/protocols/common/submit-commit-command.js +++ b/src/commands/protocols/common/submit-commit-command.js @@ -178,7 +178,7 @@ class SubmitCommitCommand extends Command { } else { msgBase = 'Node has already submitted commit. Finishing'; this.operationIdService.emitChangeEvent( - OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, sendSubmitCommitTransactionOperationId, blockchain, msgBase, diff --git a/src/commands/protocols/common/submit-proofs-command.js b/src/commands/protocols/common/submit-proofs-command.js index f57028a617..a6e30ae014 100644 --- a/src/commands/protocols/common/submit-proofs-command.js +++ b/src/commands/protocols/common/submit-proofs-command.js @@ -226,7 +226,7 @@ class SubmitProofsCommand extends Command { } else { msgBase = 'Node has already sent proof. Finishing'; this.operationIdService.emitChangeEvent( - OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_ERROR, sendSubmitProofsTransactionOperationId, blockchain, msgBase, From c6b723421d4e13c991989a399e373f808043a8ee Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Tue, 16 Jan 2024 12:04:50 +0100 Subject: [PATCH 20/22] Version updated, update commit delay between nodes set to 5, updated error messages for transaction sending --- package-lock.json | 4 ++-- package.json | 2 +- src/commands/protocols/common/submit-commit-command.js | 10 ++++------ src/commands/protocols/common/submit-proofs-command.js | 8 ++++---- .../update/receiver/submit-update-commit-command.js | 4 ++-- .../v1.0.0/v1-0-0-handle-update-request-command.js | 2 +- src/constants/constants.js | 2 +- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 22def46834..8e19c69950 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.1.3+hotfix.1", + "version": "6.1.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.1.3+hotfix.1", + "version": "6.1.3", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index 8dcd03151d..a47456623b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.1.3+hotfix.1", + "version": "6.1.3", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/commands/protocols/common/submit-commit-command.js b/src/commands/protocols/common/submit-commit-command.js index 61bdc85712..d7a703d95e 100644 --- a/src/commands/protocols/common/submit-commit-command.js +++ b/src/commands/protocols/common/submit-commit-command.js @@ -131,12 +131,11 @@ class SubmitCommitCommand extends Command { `Retry number: ${COMMAND_RETRIES.SUBMIT_COMMIT - command.retries + 1}.`, ); this.operationIdService.emitChangeEvent( - ERROR_TYPE.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + OPERATION_ID_STATUS.FAILED, sendSubmitCommitTransactionOperationId, blockchain, error.message, - this.errorType, - operationId, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, ); let newGasPrice; if ( @@ -178,12 +177,11 @@ class SubmitCommitCommand extends Command { } else { msgBase = 'Node has already submitted commit. Finishing'; this.operationIdService.emitChangeEvent( - ERROR_TYPE.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, + OPERATION_ID_STATUS.FAILED, sendSubmitCommitTransactionOperationId, blockchain, msgBase, - this.errorType, - operationId, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, ); } diff --git a/src/commands/protocols/common/submit-proofs-command.js b/src/commands/protocols/common/submit-proofs-command.js index a6e30ae014..2f77239ff4 100644 --- a/src/commands/protocols/common/submit-proofs-command.js +++ b/src/commands/protocols/common/submit-proofs-command.js @@ -181,11 +181,11 @@ class SubmitProofsCommand extends Command { `Retry number: ${COMMAND_RETRIES.SUBMIT_PROOFS - command.retries + 1}.`, ); this.operationIdService.emitChangeEvent( - ERROR_TYPE.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_ERROR, + OPERATION_ID_STATUS.FAILED, sendSubmitProofsTransactionOperationId, blockchain, error.message, - this.errorType, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_ERROR, ); let newGasPrice; if ( @@ -226,11 +226,11 @@ class SubmitProofsCommand extends Command { } else { msgBase = 'Node has already sent proof. Finishing'; this.operationIdService.emitChangeEvent( - ERROR_TYPE.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_ERROR, + OPERATION_ID_STATUS.FAILED, sendSubmitProofsTransactionOperationId, blockchain, msgBase, - this.errorType, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR, ); } 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 97fd7dd87f..64d81de6d2 100644 --- a/src/commands/protocols/update/receiver/submit-update-commit-command.js +++ b/src/commands/protocols/update/receiver/submit-update-commit-command.js @@ -116,11 +116,11 @@ class SubmitUpdateCommitCommand extends Command { }.`, ); this.operationIdService.emitChangeEvent( - ERROR_TYPE.COMMIT_PROOF.SUBMIT_UPDATE_COMMIT_SEND_TX_ERROR, + OPERATION_ID_STATUS.FAILED, sendSubmitUpdateCommitTransactionOperationId, blockchain, error.message, - this.errorType, + ERROR_TYPE.COMMIT_PROOF.SUBMIT_UPDATE_COMMIT_SEND_TX_ERROR, ); let newGasPrice; if ( 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 da56d038a7..6a0d897a6c 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; From 83e321672fd353ba6c411cd0a5e2737adcbd2547 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Tue, 16 Jan 2024 12:57:15 +0100 Subject: [PATCH 21/22] Set Gsnosis default gas price to 2 Gwei --- .../implementation/gnosis/gnosis-service.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/modules/blockchain/implementation/gnosis/gnosis-service.js b/src/modules/blockchain/implementation/gnosis/gnosis-service.js index a265283c0a..92ba352f81 100644 --- a/src/modules/blockchain/implementation/gnosis/gnosis-service.js +++ b/src/modules/blockchain/implementation/gnosis/gnosis-service.js @@ -26,9 +26,23 @@ class GnosisService extends Web3Service { this.logger.debug(`Gas price on Gnosis: ${gasPrice}`); return gasPrice; } catch (error) { - return undefined; + this.logger.debug( + `Failed to fetch the gas price from the Gnosis: ${error}. Using default value: 2 Gwei.`, + ); + this.convertToWei(2, '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; From 87e4dfadd9aed7581583aa603e76153e3a1259cc Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Tue, 16 Jan 2024 13:17:26 +0100 Subject: [PATCH 22/22] Turn defualt gas price value to const, turn log to warn --- src/constants/constants.js | 2 ++ .../blockchain/implementation/gnosis/gnosis-service.js | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index da56d038a7..16d0f3588e 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -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, diff --git a/src/modules/blockchain/implementation/gnosis/gnosis-service.js b/src/modules/blockchain/implementation/gnosis/gnosis-service.js index 92ba352f81..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,10 +26,10 @@ class GnosisService extends Web3Service { this.logger.debug(`Gas price on Gnosis: ${gasPrice}`); return gasPrice; } catch (error) { - this.logger.debug( - `Failed to fetch the gas price from the Gnosis: ${error}. Using default value: 2 Gwei.`, + this.logger.warn( + `Failed to fetch the gas price from the Gnosis: ${error}. Using default value: ${GNOSIS_DEFAULT_GAS_PRICE} Gwei.`, ); - this.convertToWei(2, 'gwei'); + this.convertToWei(GNOSIS_DEFAULT_GAS_PRICE, 'gwei'); } }