From 133cb68206d161ed5ce2d2f0faf704e66c8929e6 Mon Sep 17 00:00:00 2001 From: NZT48 Date: Tue, 1 Mar 2022 16:22:47 +0100 Subject: [PATCH 01/26] Implement measurement for handle functions --- modules/service/publish-service.js | 23 +++++- modules/service/query-service.js | 127 +++++++++++++++++++++++------ 2 files changed, 122 insertions(+), 28 deletions(-) diff --git a/modules/service/publish-service.js b/modules/service/publish-service.js index c31f53fa8b..51d8b4d2cf 100644 --- a/modules/service/publish-service.js +++ b/modules/service/publish-service.js @@ -1,4 +1,5 @@ -const constants = require('../constants') +const { v1: uuidv1 } = require('uuid'); +const constants = require('../constants'); class PublishService { constructor(ctx) { @@ -61,7 +62,7 @@ class PublishService { const documentPath = await this.fileService .writeContentsToFile(handlerIdCachePath, handlerId, await this.workerPool.exec('JSONStringify', [{ - nquads, assertion + nquads, assertion, }])); const commandSequence = [ @@ -75,7 +76,7 @@ class PublishService { sequence: commandSequence.slice(1), delay: 0, data: { - documentPath, handlerId, method, isUrgent + documentPath, handlerId, method, isUrgent, }, transactional: false, }); @@ -90,6 +91,14 @@ class PublishService { async handleStore(data) { if (!data || data.rdf) return false; + const operationId = uuidv1(); + this.logger.emit({ + msg: 'Started measuring execution of store command', + Event_name: 'store_start', + Operation_name: 'store', + Id_operation: operationId, + }); + const { jsonld, nquads } = await this.dataService.createAssertion(data.nquads); const status = await this.dataService.verifyAssertion(jsonld, nquads); @@ -98,6 +107,14 @@ class PublishService { await this.dataService.insert(data.nquads.join('\n'), `${constants.DID_PREFIX}:${data.id}`); this.logger.info(`Assertion ${data.id} has been successfully inserted`); } + + this.logger.emit({ + msg: 'Finished measuring execution of store command', + Event_name: 'store_end', + Operation_name: 'store', + Id_operation: operationId, + }); + return status; } } diff --git a/modules/service/query-service.js b/modules/service/query-service.js index 0961efe4a4..bbf112f955 100644 --- a/modules/service/query-service.js +++ b/modules/service/query-service.js @@ -1,5 +1,5 @@ -const Models = require('../../models/index'); -const constants = require('../constants') +const { v1: uuidv1 } = require('uuid'); +const constants = require('../constants'); class QueryService { constructor(ctx) { @@ -30,12 +30,28 @@ class QueryService { } async handleResolve(id) { - const {nquads, isAsset} = await this.dataService.resolve(id); + const operationId = uuidv1(); + this.logger.emit({ + msg: 'Started measuring execution of handle store command', + Event_name: 'handle_store_start', + Operation_name: 'handle_store', + Id_operation: operationId, + }); + + const { nquads, isAsset } = await this.dataService.resolve(id); this.logger.info(`Retrieved data from the database: ${await this.workerPool.exec('JSONStringify', [nquads])}`); - if (!nquads) + this.logger.emit({ + msg: 'Finished measuring execution of handle store command', + Event_name: 'handle_store_end', + Operation_name: 'handle_store', + Id_operation: operationId, + }); + + if (!nquads) { return null; - return {nquads, isAsset}; + } + return { nquads, isAsset }; } async search(data, node) { @@ -44,25 +60,50 @@ class QueryService { } async handleSearch(request) { - const {query, issuers, types, prefix, limit, handlerId} = request; - let response = await this.dataService.searchByQuery(query, {issuers, types, prefix, limit}); - - return {response, handlerId}; + const operationId = uuidv1(); + this.logger.emit({ + msg: 'Started measuring execution of handle search command', + Event_name: 'handle_search_start', + Operation_name: 'handle_search', + Id_operation: operationId, + }); + + const { query, issuers, types, prefix, limit, handlerId } = request; + const response = await this.dataService.searchByQuery(query, { issuers, types, prefix, limit }); + + this.logger.emit({ + msg: 'Finished measuring execution of handle search command', + Event_name: 'handle_search_end', + Operation_name: 'handle_search', + Id_operation: operationId, + }); + + return { response, handlerId }; } async handleSearchResult(request) { // TODO: add mutex - const {handlerId, response} = request; + const operationId = uuidv1(); + this.logger.emit({ + msg: 'Started measuring execution of handle search result command', + Event_name: 'handle_search_result_start', + Operation_name: 'handle_search_result', + Id_operation: operationId, + }); + + const { handlerId, response } = request; const documentPath = this.fileService.getHandlerIdDocumentPath(handlerId); const handlerData = await this.fileService.loadJsonFromFile(documentPath); for (const assertion of response) { - if (!assertion || !assertion.nquads) continue; + if (!assertion || !assertion.nquads) { + continue; + } const rawNquads = assertion.nquads ? assertion.nquads : assertion.rdf; const { jsonld, nquads } = await this.dataService.createAssertion(rawNquads); - let object = handlerData.find(x => x.type === jsonld.metadata.type && x.id === jsonld.metadata.UALs[0]) + let object = handlerData.find((x) => x.type === jsonld.metadata.type && x.id === jsonld.metadata.UALs[0]) if (!object) { object = { type: jsonld.metadata.type, @@ -70,9 +111,9 @@ class QueryService { timestamp: jsonld.metadata.timestamp, issuers: [], assertions: [], - nodes: [assertion.node] - } - handlerData.push(object) + nodes: [assertion.node], + }; + handlerData.push(object); } if (object.nodes.indexOf(assertion.node) === -1) { @@ -91,13 +132,19 @@ class QueryService { } } - await this.fileService.writeContentsToFile( this.fileService.getHandlerIdCachePath(), handlerId, await this.workerPool.exec('JSONStringify', [handlerData]), ); + this.logger.emit({ + msg: 'Finished measuring execution of handle search result command', + Event_name: 'handle_search_result_end', + Operation_name: 'handle_search_result', + Id_operation: operationId, + }); + return true; } @@ -107,14 +154,36 @@ class QueryService { } async handleSearchAssertions(request) { - const {query, options, handlerId} = request; - let response = await this.dataService.searchAssertions(query, options || {}); - return {response, handlerId}; + const operationId = uuidv1(); + this.logger.emit({ + msg: 'Started measuring execution of handle search assertions command', + Event_name: 'handle_search_assertions_start', + Operation_name: 'handle_search_assertions', + Id_operation: operationId, + }); + + const { query, options, handlerId } = request; + const response = await this.dataService.searchAssertions(query, options || {}); + + this.logger.emit({ + msg: 'Finished measuring execution of handle search assertions command', + Event_name: 'handle_search_assertions_end', + Operation_name: 'handle_search_assertions', + Id_operation: operationId, + }); + return { response, handlerId }; } async handleSearchAssertionsResult(request) { // TODO: add mutex - const {handlerId, response} = request; + const operationId = uuidv1(); + this.logger.emit({ + msg: 'Started measuring execution of handle search assertions result command', + Event_name: 'handle_search_assertions_result_start', + Operation_name: 'handle_search_assertions_result', + Id_operation: operationId, + }); + const { handlerId, response } = request; const documentPath = this.fileService.getHandlerIdDocumentPath(handlerId); const handlerData = await this.fileService.loadJsonFromFile(documentPath); @@ -122,11 +191,13 @@ class QueryService { for (const object of response) { const assertion = handlerData.find((x) => x.id === object.assertionId); if (assertion) { - if (assertion.nodes.indexOf(object.node) === -1) - assertion.nodes = [...new Set(assertion.nodes.concat(object.node))] + if (assertion.nodes.indexOf(object.node) === -1) { + assertion.nodes = [...new Set(assertion.nodes.concat(object.node))]; + } } else { - if (!object || !object.nquads) + if (!object || !object.nquads) { continue + } const rawNquads = object.nquads ? object.nquads : object.rdf; const assertion = await this.dataService.createAssertion(rawNquads); @@ -134,8 +205,8 @@ class QueryService { id: assertion.jsonld.id, metadata: assertion.jsonld.metadata, signature: assertion.jsonld.signature, - nodes: [object.node] - }) + nodes: [object.node], + }); } } @@ -146,6 +217,12 @@ class QueryService { ); } + this.logger.emit({ + msg: 'Finished measuring execution of handle search assertions result command', + Event_name: 'handle_search_assertions_result_end', + Operation_name: 'handle_search_assertions_result', + Id_operation: operationId, + }); return true; } } From 7e48230b194199082a3e3e1bf17525abf75d2a2f Mon Sep 17 00:00:00 2001 From: zeroxbt Date: Wed, 2 Mar 2022 13:24:46 +0100 Subject: [PATCH 02/26] update replicationFactor and handleMessage timeout --- config/config.json | 6 +++--- external/libp2p-service.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/config.json b/config/config.json index 676cbf3572..d0f6c2a7e1 100644 --- a/config/config.json +++ b/config/config.json @@ -24,7 +24,7 @@ "password": "" }, "logLevel": "trace", - "replicationFactor" : 3, + "replicationFactor" : 5, "rpcPort": 8900, "network": { "port": 9000, @@ -65,7 +65,7 @@ "password": "" }, "logLevel": "trace", - "replicationFactor" : 3, + "replicationFactor" : 5, "rpcPort": 8900, "network": { "port": 9000, @@ -101,7 +101,7 @@ "password": "" }, "logLevel": "trace", - "replicationFactor" : 3, + "replicationFactor" : 5, "rpcPort": 8900, "network": { "port": 9000, diff --git a/external/libp2p-service.js b/external/libp2p-service.js index e532a8bf6b..b628bcf14e 100644 --- a/external/libp2p-service.js +++ b/external/libp2p-service.js @@ -147,7 +147,7 @@ class Libp2pService { async handleMessage(eventName, handler, options) { this.logger.info(`Enabling network protocol: ${eventName}`); - let async = false, timeout = 5e3; + let async = false, timeout = 60e3; if (options) { async = options.async; timeout = options.timeout; From 6f3b2e2aa3ba7726e9d669a9adfa77147bde488d Mon Sep 17 00:00:00 2001 From: NZT48 Date: Wed, 2 Mar 2022 13:31:47 +0100 Subject: [PATCH 03/26] Remove measurment start for publish from rpc controller --- modules/controller/rpc-controller.js | 35 +++++----------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/modules/controller/rpc-controller.js b/modules/controller/rpc-controller.js index fc55523916..28df9c0307 100644 --- a/modules/controller/rpc-controller.js +++ b/modules/controller/rpc-controller.js @@ -134,7 +134,6 @@ class RpcController { this.networkService.handleMessage('/search/result', (result) => this.queryService.handleSearchResult(result)); - this.networkService.handleMessage('/search/assertions', (result) => this.queryService.handleSearchAssertions(result), { async: true, timeout: 5e3, @@ -820,14 +819,6 @@ class RpcController { }); } - const operationId = uuidv1(); - this.logger.emit({ - msg: 'Started measuring execution of publish command', - Event_name: 'publish_start', - Operation_name: 'publish', - Id_operation: operationId - }); - const handlerObject = await Models.handler_ids.create({ status: 'PENDING', }) @@ -836,14 +827,14 @@ class RpcController { res.status(202).send({ handler_id: handlerId, }); - let fileContent,fileExtension; + let fileContent, fileExtension; if (req.files) { fileContent = req.files.file.data; fileExtension = path.extname(req.files.file.name).toLowerCase(); } else{ - fileContent = req.body.data - fileExtension = '.json' + fileContent = req.body.data; + fileExtension = '.json'; } const visibility = req.body.visibility ? req.body.visibility.toLowerCase() : 'public'; const ual = options.isAsset ? options.ual : undefined; @@ -856,8 +847,8 @@ class RpcController { } promise - .then(keywords => this.publishService.publish(fileContent, fileExtension, keywords, visibility, ual, handlerId)) - .then(assertion => { + .then((keywords) => this.publishService.publish(fileContent, fileExtension, keywords, visibility, ual, handlerId)) + .then((assertion) => { const handlerData = { id: assertion.id, rootHash: assertion.rootHash, @@ -867,7 +858,7 @@ class RpcController { Models.handler_ids.update( { - data: JSON.stringify(handlerData) + data: JSON.stringify(handlerData), }, { where: { handler_id: handlerId, @@ -876,21 +867,7 @@ class RpcController { ); }) .catch((e) => { - this.logger.error({ - msg: `Unexpected error at publish route: ${e.message}. ${e.stack}`, - Event_name: constants.ERROR_TYPE.PUBLISH_ROUTE_ERROR, - Event_value1: e.message, - Id_operation: operationId, - }); this.updateFailedHandlerId(handlerId, e, next); - }) - .then(() => { - this.logger.emit({ - msg: 'Finished measuring execution of publish command', - Event_name: 'publish_end', - Operation_name: 'publish', - Id_operation: operationId - }); }); } From 2098441d010093694b82dbd8729305a2dbc2a4ab Mon Sep 17 00:00:00 2001 From: NZT48 Date: Wed, 2 Mar 2022 13:35:08 +0100 Subject: [PATCH 04/26] Change measurment points for publish operation --- .../publish/insert-assertion-command.js | 9 +- .../command/publish/send-assertion-command.js | 10 +- .../command/publish/submit-proofs-command.js | 15 +- modules/service/publish-service.js | 161 ++++++++++-------- 4 files changed, 115 insertions(+), 80 deletions(-) diff --git a/modules/command/publish/insert-assertion-command.js b/modules/command/publish/insert-assertion-command.js index 9f20d6d085..b7087d8cd9 100644 --- a/modules/command/publish/insert-assertion-command.js +++ b/modules/command/publish/insert-assertion-command.js @@ -15,7 +15,7 @@ class InsertAssertionCommand extends Command { * @param command */ async execute(command) { - const { documentPath, handlerId } = command.data; + const { documentPath, handlerId, operationId } = command.data; let { nquads, assertion } = await this.fileService.loadJsonFromFile(documentPath); try { @@ -23,6 +23,13 @@ class InsertAssertionCommand extends Command { this.logger.info(`Assertion ${assertion.id} has been successfully inserted`); } catch (e) { await this.handleError(handlerId, e, constants.ERROR_TYPE.INSERT_ASSERTION_ERROR, true); + this.logger.emit({ + msg: 'Finished measuring execution of publish command', + Event_name: 'publish_end', + Operation_name: 'publish', + Id_operation: operationId, + }); + return Command.empty(); } return this.continueSequence(command.data, command.sequence); diff --git a/modules/command/publish/send-assertion-command.js b/modules/command/publish/send-assertion-command.js index 57fbb5519a..742ee3d6b4 100644 --- a/modules/command/publish/send-assertion-command.js +++ b/modules/command/publish/send-assertion-command.js @@ -18,7 +18,7 @@ class SendAssertionCommand extends Command { * @param command */ async execute(command) { - const { documentPath, handlerId } = command.data; + const { documentPath, handlerId, operationId } = command.data; let { nquads, assertion } = await this.fileService.loadJsonFromFile(documentPath); @@ -45,7 +45,7 @@ class SendAssertionCommand extends Command { nodes = [...new Set(nodes)]; for (const node of nodes) { - this.publishService.store({ id:assertion.id, nquads: nquads }, node).catch((e) => { + this.publishService.store({ id: assertion.id, nquads: nquads }, node).catch((e) => { this.handleError(handlerId, e, `Error while sending data with assertion id ${assertion.id} to node ${node._idB58String}. Error message: ${e.message}. ${e.stack}`); }); } @@ -59,6 +59,12 @@ class SendAssertionCommand extends Command { }, }, ); + this.logger.emit({ + msg: 'Finished measuring execution of publish command', + Event_name: 'publish_end', + Operation_name: 'publish', + Id_operation: operationId, + }); return this.continueSequence(command.data, command.sequence); } diff --git a/modules/command/publish/submit-proofs-command.js b/modules/command/publish/submit-proofs-command.js index 7bf229a6b8..744b41fd80 100644 --- a/modules/command/publish/submit-proofs-command.js +++ b/modules/command/publish/submit-proofs-command.js @@ -20,7 +20,7 @@ class SubmitProofsCommand extends Command { * @param command */ async execute(command) { - const { documentPath, handlerId, method, isUrgent } = command.data; + const { documentPath, handlerId, method, isUrgent, operationId } = command.data; try { let { nquads, assertion } = await this.fileService.loadJsonFromFile(documentPath); @@ -50,20 +50,25 @@ class SubmitProofsCommand extends Command { await this.fileService .writeContentsToFile(handlerIdCachePath, handlerId, sortedStringify({ - nquads, assertion + nquads, assertion, })); } catch (e) { await this.handleError(handlerId, e, constants.ERROR_TYPE.SUBMIT_PROOFS_ERROR, true); - + this.logger.emit({ + msg: 'Finished measuring execution of publish command', + Event_name: 'publish_end', + Operation_name: 'publish', + Id_operation: operationId, + }); return Command.empty(); } return this.continueSequence(command.data, command.sequence); } - async sendTransaction (args){ - const { assertion, method} = args; + async sendTransaction(args) { + const { assertion, method } = args; let result; switch (method) { case 'publish': diff --git a/modules/service/publish-service.js b/modules/service/publish-service.js index 51d8b4d2cf..97c9c177d7 100644 --- a/modules/service/publish-service.js +++ b/modules/service/publish-service.js @@ -14,74 +14,91 @@ class PublishService { } async publish(fileContent, fileExtension, keywords, visibility, ual, handlerId, isUrgent = false) { - let { - assertion, - nquads, - } = await this.dataService.canonize(fileContent, fileExtension); - - if (keywords.length > 10) { - keywords = keywords.slice(0, 10); - this.logger.warn('Too many keywords provided, limit is 10. Publishing only to the first 10 keywords.'); - } - - assertion.metadata.issuer = this.validationService.getIssuer(); - assertion.metadata.visibility = visibility; - assertion.metadata.keywords = keywords; - assertion.metadata.keywords.sort(); - let method = 'publish'; - if (ual === null) { - method = 'provision'; - ual = this.validationService.calculateHash(assertion.metadata.timestamp + assertion.metadata.type + assertion.metadata.issuer); - assertion.metadata.UALs = [ual]; - } else if (ual !== undefined) { - method = 'update'; - assertion.metadata.UALs = [ual]; - } - - assertion.metadata.dataHash = this.validationService.calculateHash(assertion.data); - assertion.metadataHash = this.validationService.calculateHash(assertion.metadata); - assertion.id = this.validationService.calculateHash(assertion.metadataHash + assertion.metadata.dataHash); - assertion.signature = this.validationService.sign(assertion.id); - - nquads = await this.dataService.appendMetadata(nquads, assertion); - assertion.rootHash = this.validationService.calculateRootHash(nquads); - - if (ual !== undefined) { - this.logger.info(`UAL: ${ual}`); - } - this.logger.info(`Assertion ID: ${assertion.id}`); - this.logger.info(`Assertion metadataHash: ${assertion.metadataHash}`); - this.logger.info(`Assertion dataHash: ${assertion.metadata.dataHash}`); - this.logger.info(`Assertion rootHash: ${assertion.rootHash}`); - this.logger.info(`Assertion signature: ${assertion.signature}`); - this.logger.info(`Assertion length in N-QUADS format: ${nquads.length}`); - this.logger.info(`Keywords: ${keywords}`); - - const handlerIdCachePath = this.fileService.getHandlerIdCachePath(); - - const documentPath = await this.fileService - .writeContentsToFile(handlerIdCachePath, handlerId, - await this.workerPool.exec('JSONStringify', [{ - nquads, assertion, - }])); - - const commandSequence = [ - 'submitProofsCommand', - 'insertAssertionCommand', - 'sendAssertionCommand', - ]; - - await this.commandExecutor.add({ - name: commandSequence[0], - sequence: commandSequence.slice(1), - delay: 0, - data: { - documentPath, handlerId, method, isUrgent, - }, - transactional: false, + const operationId = uuidv1(); + this.logger.emit({ + msg: 'Started measuring execution of publish command', + Event_name: 'publish_start', + Operation_name: 'publish', + Id_operation: operationId, }); - return assertion; + try { + let { + assertion, + nquads, + } = await this.dataService.canonize(fileContent, fileExtension); + + if (keywords.length > 10) { + keywords = keywords.slice(0, 10); + this.logger.warn('Too many keywords provided, limit is 10. Publishing only to the first 10 keywords.'); + } + + assertion.metadata.issuer = this.validationService.getIssuer(); + assertion.metadata.visibility = visibility; + assertion.metadata.keywords = keywords; + assertion.metadata.keywords.sort(); + let method = 'publish'; + if (ual === null) { + method = 'provision'; + ual = this.validationService.calculateHash(assertion.metadata.timestamp + assertion.metadata.type + assertion.metadata.issuer); + assertion.metadata.UALs = [ual]; + } else if (ual !== undefined) { + method = 'update'; + assertion.metadata.UALs = [ual]; + } + + assertion.metadata.dataHash = this.validationService.calculateHash(assertion.data); + assertion.metadataHash = this.validationService.calculateHash(assertion.metadata); + assertion.id = this.validationService.calculateHash(assertion.metadataHash + assertion.metadata.dataHash); + assertion.signature = this.validationService.sign(assertion.id); + + nquads = await this.dataService.appendMetadata(nquads, assertion); + assertion.rootHash = this.validationService.calculateRootHash(nquads); + + if (ual !== undefined) { + this.logger.info(`UAL: ${ual}`); + } + this.logger.info(`Assertion ID: ${assertion.id}`); + this.logger.info(`Assertion metadataHash: ${assertion.metadataHash}`); + this.logger.info(`Assertion dataHash: ${assertion.metadata.dataHash}`); + this.logger.info(`Assertion rootHash: ${assertion.rootHash}`); + this.logger.info(`Assertion signature: ${assertion.signature}`); + this.logger.info(`Assertion length in N-QUADS format: ${nquads.length}`); + this.logger.info(`Keywords: ${keywords}`); + + const handlerIdCachePath = this.fileService.getHandlerIdCachePath(); + + const documentPath = await this.fileService + .writeContentsToFile(handlerIdCachePath, handlerId, + await this.workerPool.exec('JSONStringify', [{ + nquads, assertion, + }])); + + const commandSequence = [ + 'submitProofsCommand', + 'insertAssertionCommand', + 'sendAssertionCommand', + ]; + + await this.commandExecutor.add({ + name: commandSequence[0], + sequence: commandSequence.slice(1), + delay: 0, + data: { + documentPath, handlerId, method, isUrgent, operationId, + }, + transactional: false, + }); + + return assertion; + } catch (e) { + this.logger.emit({ + msg: 'Finished measuring execution of publish command', + Event_name: 'publish_end', + Operation_name: 'publish', + Id_operation: operationId, + }); + } } async store(assertion, node) { @@ -93,9 +110,9 @@ class PublishService { if (!data || data.rdf) return false; const operationId = uuidv1(); this.logger.emit({ - msg: 'Started measuring execution of store command', - Event_name: 'store_start', - Operation_name: 'store', + msg: 'Started measuring execution of handle store command', + Event_name: 'handle_store_start', + Operation_name: 'handle_store', Id_operation: operationId, }); @@ -109,9 +126,9 @@ class PublishService { } this.logger.emit({ - msg: 'Finished measuring execution of store command', - Event_name: 'store_end', - Operation_name: 'store', + msg: 'Finished measuring execution of handle store command', + Event_name: 'handle_store_end', + Operation_name: 'handle_store', Id_operation: operationId, }); From 303eebef234c9fb262a661e89dc23779736a3653 Mon Sep 17 00:00:00 2001 From: NZT48 Date: Wed, 2 Mar 2022 13:35:56 +0100 Subject: [PATCH 05/26] Change message for handle resolve --- modules/service/query-service.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/service/query-service.js b/modules/service/query-service.js index bbf112f955..e863dc54e2 100644 --- a/modules/service/query-service.js +++ b/modules/service/query-service.js @@ -32,9 +32,9 @@ class QueryService { async handleResolve(id) { const operationId = uuidv1(); this.logger.emit({ - msg: 'Started measuring execution of handle store command', - Event_name: 'handle_store_start', - Operation_name: 'handle_store', + msg: 'Started measuring execution of handle resolve command', + Event_name: 'handle_resolve_start', + Operation_name: 'handle_resolve', Id_operation: operationId, }); @@ -42,9 +42,9 @@ class QueryService { this.logger.info(`Retrieved data from the database: ${await this.workerPool.exec('JSONStringify', [nquads])}`); this.logger.emit({ - msg: 'Finished measuring execution of handle store command', - Event_name: 'handle_store_end', - Operation_name: 'handle_store', + msg: 'Finished measuring execution of handle resolve command', + Event_name: 'handle_resolve_end', + Operation_name: 'handle_resolve', Id_operation: operationId, }); From 817d099d1469dd08c2968b0858146c7d5c77b9be Mon Sep 17 00:00:00 2001 From: zeroxbt Date: Wed, 2 Mar 2022 13:36:36 +0100 Subject: [PATCH 06/26] stringify data before logging it --- external/libp2p-service.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/external/libp2p-service.js b/external/libp2p-service.js index b628bcf14e..8e1047fd78 100644 --- a/external/libp2p-service.js +++ b/external/libp2p-service.js @@ -193,8 +193,9 @@ class Libp2pService { } } } catch (e) { + const stringifiedData = await this.workerPool.exec('JSONStringify', [data]); this.logger.error({ - msg: `Error: ${e}, stack: ${e.stack} \n Data received: ${data}`, + msg: `Error: ${e}, stack: ${e.stack} \n Data received: ${stringifiedData}`, Event_name: constants.ERROR_TYPE.LIBP2P_HANDLE_MSG_ERROR, }); await pipe( From 8a96123726951dee7952810f4eb60e74ae0b120f Mon Sep 17 00:00:00 2001 From: zeroxbt Date: Wed, 2 Mar 2022 14:03:40 +0100 Subject: [PATCH 07/26] update timeouts in rpc-controller --- modules/controller/rpc-controller.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/controller/rpc-controller.js b/modules/controller/rpc-controller.js index fc55523916..29b339f3be 100644 --- a/modules/controller/rpc-controller.js +++ b/modules/controller/rpc-controller.js @@ -129,7 +129,7 @@ class RpcController { this.networkService.handleMessage('/search', (result) => this.queryService.handleSearch(result), { async: true, - timeout: 5e3, + timeout: 60e3, }); this.networkService.handleMessage('/search/result', (result) => this.queryService.handleSearchResult(result)); @@ -137,7 +137,7 @@ class RpcController { this.networkService.handleMessage('/search/assertions', (result) => this.queryService.handleSearchAssertions(result), { async: true, - timeout: 5e3, + timeout: 60e3, }); this.networkService.handleMessage('/search/assertions/result', (result) => this.queryService.handleSearchAssertionsResult(result)); From ddca49739a9e8cb23c203cddc51edcefa4482888 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 2 Mar 2022 15:03:57 +0100 Subject: [PATCH 08/26] add signaling message --- modules/command/common/keep-alive-command.js | 28 +++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index 4e7236e9fc..3493781219 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -1,10 +1,13 @@ const { v1: uuidv1 } = require('uuid'); const Command = require('../command'); +const pjson = require("../../../package.json"); +const PeerId = require("peer-id"); class KeepAliveCommand extends Command { constructor(ctx) { super(ctx); this.logger = ctx.logger; + this.config = ctx.config; } /** @@ -19,6 +22,29 @@ class KeepAliveCommand extends Command { msg: message, Event_name: 'keep_alive', Operation_name: 'KeepAlive', Id_operation, }); + const signalingMessage = { + nodeVersion: pjson.version, + autoUpdate: this.config.autoUpdate.enabled, + telemetry: { + enabled: this.config.telemetryHub.enabled, + }, + proof: {} + }; + try{ + const peerId = await PeerId.createFromPrivKey(this.config.network.privateKey); + signalingMessage.issuerWallet = this.config.blockchain[0].publicKey; + signalingMessage.kademliaNodeId = peerId; + signalingMessage.nodeVersion = pjson.version; + signalingMessage.telemetry.latestAssertions = []; + } catch (e) { + this.logger.error(`An error has occurred with signaling data. ${e.message}`) + } + + signalingMessage.proof.hash = this.validationService.calculateHash(signalingMessage); + signalingMessage.proof.signature = this.validationService.sign(signalingMessage.proof.hash); + + //TODO send data + return Command.repeat(); } @@ -34,7 +60,7 @@ class KeepAliveCommand extends Command { data: { message: 'OT-Node is alive...', }, - period: 1 * 60 * 1000, + period: 15 * 60 * 1000, transactional: false, }; Object.assign(command, map); From 3e4e634330c31ec85bbbe9ce9cdf5261f4d3060f Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 2 Mar 2022 15:22:39 +0100 Subject: [PATCH 09/26] add axos post --- modules/command/common/keep-alive-command.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index 3493781219..e9e98bb410 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -2,12 +2,15 @@ const { v1: uuidv1 } = require('uuid'); const Command = require('../command'); const pjson = require("../../../package.json"); const PeerId = require("peer-id"); +var axios = require('axios'); +var FormData = require('form-data'); class KeepAliveCommand extends Command { constructor(ctx) { super(ctx); this.logger = ctx.logger; this.config = ctx.config; + this.validationService = ctx.validationService; } /** @@ -43,7 +46,16 @@ class KeepAliveCommand extends Command { signalingMessage.proof.hash = this.validationService.calculateHash(signalingMessage); signalingMessage.proof.signature = this.validationService.sign(signalingMessage.proof.hash); - //TODO send data + const config = { + method: 'post', + url: 'http://localhost:3000/signal', + headers: { + 'Content-Type': 'application/javascript' + }, + data : signalingMessage + }; + + axios(config); return Command.repeat(); } From 81c8e59f71d36d65b401f8900a048c2b84011ffd Mon Sep 17 00:00:00 2001 From: zeroxbt Date: Wed, 2 Mar 2022 16:00:49 +0100 Subject: [PATCH 10/26] add telemetry assertions to db --- modules/command/common/keep-alive-command.js | 23 +++++++++------ .../command/publish/send-assertion-command.js | 8 ++++++ .../command/publish/submit-proofs-command.js | 28 +++++++++---------- modules/service/publish-service.js | 4 +-- 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index e9e98bb410..859cf6a448 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -1,9 +1,9 @@ const { v1: uuidv1 } = require('uuid'); -const Command = require('../command'); -const pjson = require("../../../package.json"); -const PeerId = require("peer-id"); +const PeerId = require('peer-id'); var axios = require('axios'); -var FormData = require('form-data'); +const Command = require('../command'); +const pjson = require('../../../package.json'); +const Models = require('../../../models/index'); class KeepAliveCommand extends Command { constructor(ctx) { @@ -31,16 +31,22 @@ class KeepAliveCommand extends Command { telemetry: { enabled: this.config.telemetryHub.enabled, }, - proof: {} + proof: {}, }; - try{ + try { const peerId = await PeerId.createFromPrivKey(this.config.network.privateKey); signalingMessage.issuerWallet = this.config.blockchain[0].publicKey; signalingMessage.kademliaNodeId = peerId; signalingMessage.nodeVersion = pjson.version; - signalingMessage.telemetry.latestAssertions = []; + signalingMessage.telemetry.latestAssertions = Models.assertions.findAll({ + limit: 5, + order: [ + ['created_at', 'DESC'], + ], + attributes: ['hash', 'topics', 'created_at'], + }).map(x => ({assertionId: x.hash, keyword: x.topics, publishTimestamp: x.created_at})); } catch (e) { - this.logger.error(`An error has occurred with signaling data. ${e.message}`) + this.logger.error(`An error has occurred with signaling data. ${e.message}`); } signalingMessage.proof.hash = this.validationService.calculateHash(signalingMessage); @@ -56,7 +62,6 @@ class KeepAliveCommand extends Command { }; axios(config); - return Command.repeat(); } diff --git a/modules/command/publish/send-assertion-command.js b/modules/command/publish/send-assertion-command.js index 57fbb5519a..1bd2a5ec72 100644 --- a/modules/command/publish/send-assertion-command.js +++ b/modules/command/publish/send-assertion-command.js @@ -60,6 +60,14 @@ class SendAssertionCommand extends Command { }, ); + if (command.data.isTelemetry) { + await Models.assertions.create({ + hash: assertion.id, + topics: assertion.metadata.keywords, + createdAt: assertion.metadata.timestamp, + }); + } + return this.continueSequence(command.data, command.sequence); } diff --git a/modules/command/publish/submit-proofs-command.js b/modules/command/publish/submit-proofs-command.js index 7bf229a6b8..e802b0e07b 100644 --- a/modules/command/publish/submit-proofs-command.js +++ b/modules/command/publish/submit-proofs-command.js @@ -1,7 +1,7 @@ +const sortedStringify = require('json-stable-stringify'); const Command = require('../command'); const Models = require('../../../models/index'); const constants = require('../../constants'); -const sortedStringify = require("json-stable-stringify"); class SubmitProofsCommand extends Command { constructor(ctx) { @@ -20,21 +20,22 @@ class SubmitProofsCommand extends Command { * @param command */ async execute(command) { - const { documentPath, handlerId, method, isUrgent } = command.data; + const { + documentPath, handlerId, method, isTelemetry, + } = command.data; try { let { nquads, assertion } = await this.fileService.loadJsonFromFile(documentPath); - - this.logger.info(`Sending transaction to the blockchain`); + this.logger.info('Sending transaction to the blockchain'); let result; - if (isUrgent){ - result = await this.blockchainQueue.unshift({method, assertion}); - }else { - if (this.blockchainQueue.length()>constants.BLOCKCHAIN_QUEUE_LIMIT){ - throw new Error ('Blockchain queue is full'); + if (isTelemetry) { + result = await this.blockchainQueue.unshift({ method, assertion }); + } else { + if (this.blockchainQueue.length() > constants.BLOCKCHAIN_QUEUE_LIMIT) { + throw new Error('Blockchain queue is full'); } - result = await this.blockchainQueue.push({method, assertion}); + result = await this.blockchainQueue.push({ method, assertion }); } const { transactionHash, blockchain } = result; @@ -50,9 +51,8 @@ class SubmitProofsCommand extends Command { await this.fileService .writeContentsToFile(handlerIdCachePath, handlerId, sortedStringify({ - nquads, assertion + nquads, assertion, })); - } catch (e) { await this.handleError(handlerId, e, constants.ERROR_TYPE.SUBMIT_PROOFS_ERROR, true); @@ -62,8 +62,8 @@ class SubmitProofsCommand extends Command { return this.continueSequence(command.data, command.sequence); } - async sendTransaction (args){ - const { assertion, method} = args; + async sendTransaction(args) { + const { assertion, method } = args; let result; switch (method) { case 'publish': diff --git a/modules/service/publish-service.js b/modules/service/publish-service.js index c31f53fa8b..54dd9aae2d 100644 --- a/modules/service/publish-service.js +++ b/modules/service/publish-service.js @@ -12,7 +12,7 @@ class PublishService { this.workerPool = ctx.workerPool; } - async publish(fileContent, fileExtension, keywords, visibility, ual, handlerId, isUrgent = false) { + async publish(fileContent, fileExtension, keywords, visibility, ual, handlerId, isTelemetry = false) { let { assertion, nquads, @@ -75,7 +75,7 @@ class PublishService { sequence: commandSequence.slice(1), delay: 0, data: { - documentPath, handlerId, method, isUrgent + documentPath, handlerId, method, isTelemetry, }, transactional: false, }); From be26d2c436e340dc4d31b9dff0e38e841e9b5361 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 2 Mar 2022 16:22:09 +0100 Subject: [PATCH 11/26] fix header type --- modules/command/common/keep-alive-command.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index e9e98bb410..2a3522cde4 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -36,7 +36,7 @@ class KeepAliveCommand extends Command { try{ const peerId = await PeerId.createFromPrivKey(this.config.network.privateKey); signalingMessage.issuerWallet = this.config.blockchain[0].publicKey; - signalingMessage.kademliaNodeId = peerId; + signalingMessage.kademliaNodeId = peerId._idB58String; signalingMessage.nodeVersion = pjson.version; signalingMessage.telemetry.latestAssertions = []; } catch (e) { @@ -50,9 +50,9 @@ class KeepAliveCommand extends Command { method: 'post', url: 'http://localhost:3000/signal', headers: { - 'Content-Type': 'application/javascript' + 'Content-Type': 'application/json' }, - data : signalingMessage + data : JSON.stringify(signalingMessage) }; axios(config); From b16cc298898ca5f3fa6e81ea3e2aa5a82cb53037 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 2 Mar 2022 16:25:09 +0100 Subject: [PATCH 12/26] update signaling endpoint --- modules/command/common/keep-alive-command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index afa499e14f..b2a3853378 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -54,7 +54,7 @@ class KeepAliveCommand extends Command { const config = { method: 'post', - url: 'http://localhost:3000/signal', + url: 'https://signum.origintrail.io:3000/signal', headers: { 'Content-Type': 'application/json' }, From 5942c27f1580809a87508566ee20d902cde9f45e Mon Sep 17 00:00:00 2001 From: zeroxbt Date: Wed, 2 Mar 2022 16:41:50 +0100 Subject: [PATCH 13/26] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a26cc65da6..21565a5db3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.0.0-beta.1.27", + "version": "6.0.0-beta.1.28", "description": "OTNode v6 Beta 1", "main": "index.js", "scripts": { From 42f6cfb81bf9f4b14f93c5fb98b9bebcace4aae5 Mon Sep 17 00:00:00 2001 From: NZT48 Date: Wed, 2 Mar 2022 17:00:02 +0100 Subject: [PATCH 14/26] Remove proof from empty object --- modules/command/common/keep-alive-command.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index b2a3853378..9a444534c7 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -31,7 +31,6 @@ class KeepAliveCommand extends Command { telemetry: { enabled: this.config.telemetryHub.enabled, }, - proof: {}, }; try { const peerId = await PeerId.createFromPrivKey(this.config.network.privateKey); From 5cd7e009ec2960fb609596877b3a29ee381a9971 Mon Sep 17 00:00:00 2001 From: NZT48 Date: Wed, 2 Mar 2022 17:01:01 +0100 Subject: [PATCH 15/26] Handle failed publishings, stop measurement --- modules/controller/rpc-controller.js | 32 +++--- modules/service/publish-service.js | 150 +++++++++++++++------------ 2 files changed, 101 insertions(+), 81 deletions(-) diff --git a/modules/controller/rpc-controller.js b/modules/controller/rpc-controller.js index dabf79857f..a9c13c4c30 100644 --- a/modules/controller/rpc-controller.js +++ b/modules/controller/rpc-controller.js @@ -849,22 +849,24 @@ class RpcController { promise .then((keywords) => this.publishService.publish(fileContent, fileExtension, keywords, visibility, ual, handlerId)) .then((assertion) => { - const handlerData = { - id: assertion.id, - rootHash: assertion.rootHash, - signature: assertion.signature, - metadata: assertion.metadata, - }; - - Models.handler_ids.update( - { - data: JSON.stringify(handlerData), - }, { - where: { - handler_id: handlerId, + if (assertion) { + const handlerData = { + id: assertion.id, + rootHash: assertion.rootHash, + signature: assertion.signature, + metadata: assertion.metadata, + }; + + Models.handler_ids.update( + { + data: JSON.stringify(handlerData), + }, { + where: { + handler_id: handlerId, + }, }, - }, - ); + ); + } }) .catch((e) => { this.updateFailedHandlerId(handlerId, e, next); diff --git a/modules/service/publish-service.js b/modules/service/publish-service.js index 1461e531df..166b737623 100644 --- a/modules/service/publish-service.js +++ b/modules/service/publish-service.js @@ -14,74 +14,92 @@ class PublishService { } async publish(fileContent, fileExtension, keywords, visibility, ual, handlerId, isTelemetry = false) { - let { - assertion, - nquads, - } = await this.dataService.canonize(fileContent, fileExtension); - - if (keywords.length > 10) { - keywords = keywords.slice(0, 10); - this.logger.warn('Too many keywords provided, limit is 10. Publishing only to the first 10 keywords.'); - } - - assertion.metadata.issuer = this.validationService.getIssuer(); - assertion.metadata.visibility = visibility; - assertion.metadata.keywords = keywords; - assertion.metadata.keywords.sort(); - let method = 'publish'; - if (ual === null) { - method = 'provision'; - ual = this.validationService.calculateHash(assertion.metadata.timestamp + assertion.metadata.type + assertion.metadata.issuer); - assertion.metadata.UALs = [ual]; - } else if (ual !== undefined) { - method = 'update'; - assertion.metadata.UALs = [ual]; - } - - assertion.metadata.dataHash = this.validationService.calculateHash(assertion.data); - assertion.metadataHash = this.validationService.calculateHash(assertion.metadata); - assertion.id = this.validationService.calculateHash(assertion.metadataHash + assertion.metadata.dataHash); - assertion.signature = this.validationService.sign(assertion.id); - - nquads = await this.dataService.appendMetadata(nquads, assertion); - assertion.rootHash = this.validationService.calculateRootHash(nquads); + const operationId = uuidv1(); + this.logger.emit({ + msg: 'Started measuring execution of publish command', + Event_name: 'publish_start', + Operation_name: 'publish', + Id_operation: operationId, + }); - if (ual !== undefined) { - this.logger.info(`UAL: ${ual}`); + try { + let { + assertion, + nquads, + } = await this.dataService.canonize(fileContent, fileExtension); + + if (keywords.length > 10) { + keywords = keywords.slice(0, 10); + this.logger.warn('Too many keywords provided, limit is 10. Publishing only to the first 10 keywords.'); + } + + assertion.metadata.issuer = this.validationService.getIssuer(); + assertion.metadata.visibility = visibility; + assertion.metadata.keywords = keywords; + assertion.metadata.keywords.sort(); + let method = 'publish'; + if (ual === null) { + method = 'provision'; + ual = this.validationService.calculateHash(assertion.metadata.timestamp + assertion.metadata.type + assertion.metadata.issuer); + assertion.metadata.UALs = [ual]; + } else if (ual !== undefined) { + method = 'update'; + assertion.metadata.UALs = [ual]; + } + + assertion.metadata.dataHash = this.validationService.calculateHash(assertion.data); + assertion.metadataHash = this.validationService.calculateHash(assertion.metadata); + assertion.id = this.validationService.calculateHash(assertion.metadataHash + assertion.metadata.dataHash); + assertion.signature = this.validationService.sign(assertion.id); + + nquads = await this.dataService.appendMetadata(nquads, assertion); + assertion.rootHash = this.validationService.calculateRootHash(nquads); + + if (ual !== undefined) { + this.logger.info(`UAL: ${ual}`); + } + this.logger.info(`Assertion ID: ${assertion.id}`); + this.logger.info(`Assertion metadataHash: ${assertion.metadataHash}`); + this.logger.info(`Assertion dataHash: ${assertion.metadata.dataHash}`); + this.logger.info(`Assertion rootHash: ${assertion.rootHash}`); + this.logger.info(`Assertion signature: ${assertion.signature}`); + this.logger.info(`Assertion length in N-QUADS format: ${nquads.length}`); + this.logger.info(`Keywords: ${keywords}`); + + const handlerIdCachePath = this.fileService.getHandlerIdCachePath(); + + const documentPath = await this.fileService + .writeContentsToFile(handlerIdCachePath, handlerId, + await this.workerPool.exec('JSONStringify', [{ + nquads, assertion + }])); + + const commandSequence = [ + 'submitProofsCommand', + 'insertAssertionCommand', + 'sendAssertionCommand', + ]; + + await this.commandExecutor.add({ + name: commandSequence[0], + sequence: commandSequence.slice(1), + delay: 0, + data: { + documentPath, handlerId, method, isTelemetry, + }, + transactional: false, + }); + + return assertion; + } catch (e) { + this.logger.emit({ + msg: 'Finished measuring execution of publish command', + Event_name: 'publish_end', + Operation_name: 'publish', + Id_operation: operationId, + }); + return null; } - this.logger.info(`Assertion ID: ${assertion.id}`); - this.logger.info(`Assertion metadataHash: ${assertion.metadataHash}`); - this.logger.info(`Assertion dataHash: ${assertion.metadata.dataHash}`); - this.logger.info(`Assertion rootHash: ${assertion.rootHash}`); - this.logger.info(`Assertion signature: ${assertion.signature}`); - this.logger.info(`Assertion length in N-QUADS format: ${nquads.length}`); - this.logger.info(`Keywords: ${keywords}`); - - const handlerIdCachePath = this.fileService.getHandlerIdCachePath(); - - const documentPath = await this.fileService - .writeContentsToFile(handlerIdCachePath, handlerId, - await this.workerPool.exec('JSONStringify', [{ - nquads, assertion - }])); - - const commandSequence = [ - 'submitProofsCommand', - 'insertAssertionCommand', - 'sendAssertionCommand', - ]; - - await this.commandExecutor.add({ - name: commandSequence[0], - sequence: commandSequence.slice(1), - delay: 0, - data: { - documentPath, handlerId, method, isTelemetry, - }, - transactional: false, - }); - - return assertion; } async store(assertion, node) { From 2150e7e7a48ac9c80527ff20cb8d09982dc65142 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 2 Mar 2022 17:08:52 +0100 Subject: [PATCH 16/26] fix signaling proof --- modules/command/common/keep-alive-command.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index 9a444534c7..677036d8cd 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -48,8 +48,11 @@ class KeepAliveCommand extends Command { this.logger.error(`An error has occurred with signaling data. ${e.message}`); } - signalingMessage.proof.hash = this.validationService.calculateHash(signalingMessage); - signalingMessage.proof.signature = this.validationService.sign(signalingMessage.proof.hash); + const proof = {}; + proof.hash = this.validationService.calculateHash(signalingMessage); + proof.signature = this.validationService.sign(proof.hash); + + signalingMessage.proof = proof; const config = { method: 'post', @@ -60,7 +63,7 @@ class KeepAliveCommand extends Command { data : JSON.stringify(signalingMessage) }; - axios(config); + await axios(config); return Command.repeat(); } From c0c1adbcd1241b63c3c7ea0488038676933c1ad2 Mon Sep 17 00:00:00 2001 From: NZT48 Date: Wed, 2 Mar 2022 17:09:54 +0100 Subject: [PATCH 17/26] Fix proof in signaling Message --- modules/command/common/keep-alive-command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index 9a444534c7..7928e972d9 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -47,7 +47,7 @@ class KeepAliveCommand extends Command { } catch (e) { this.logger.error(`An error has occurred with signaling data. ${e.message}`); } - + signalingMessage.proof = {}; signalingMessage.proof.hash = this.validationService.calculateHash(signalingMessage); signalingMessage.proof.signature = this.validationService.sign(signalingMessage.proof.hash); From 765750d04a257ce91d63398de73650be577351cb Mon Sep 17 00:00:00 2001 From: NZT48 Date: Wed, 2 Mar 2022 17:14:29 +0100 Subject: [PATCH 18/26] Add missing operation id --- modules/command/publish/submit-proofs-command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/command/publish/submit-proofs-command.js b/modules/command/publish/submit-proofs-command.js index cbf3386618..22136275fd 100644 --- a/modules/command/publish/submit-proofs-command.js +++ b/modules/command/publish/submit-proofs-command.js @@ -21,7 +21,7 @@ class SubmitProofsCommand extends Command { */ async execute(command) { const { - documentPath, handlerId, method, isTelemetry, + documentPath, handlerId, method, isTelemetry, operationId, } = command.data; try { From 50bde741f00fb35eab9d3e7a09ad70bd72d2678a Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 2 Mar 2022 17:40:31 +0100 Subject: [PATCH 19/26] fix error handling --- modules/command/common/keep-alive-command.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index 677036d8cd..63c66757e3 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -1,9 +1,10 @@ -const { v1: uuidv1 } = require('uuid'); +const {v1: uuidv1} = require('uuid'); const PeerId = require('peer-id'); var axios = require('axios'); const Command = require('../command'); const pjson = require('../../../package.json'); const Models = require('../../../models/index'); +const constants = require("../../constants"); class KeepAliveCommand extends Command { constructor(ctx) { @@ -27,7 +28,7 @@ class KeepAliveCommand extends Command { const signalingMessage = { nodeVersion: pjson.version, - autoUpdate: this.config.autoUpdate.enabled, + autoUpdate: { enabled: this.config.autoUpdate.enabled }, telemetry: { enabled: this.config.telemetryHub.enabled, }, @@ -60,10 +61,13 @@ class KeepAliveCommand extends Command { headers: { 'Content-Type': 'application/json' }, - data : JSON.stringify(signalingMessage) + data: JSON.stringify(signalingMessage) }; - await axios(config); + const that = this; + axios(config).catch(e=>{ + that.handleError(uuidv1(), e, constants.ERROR_TYPE.KEEP_ALIVE, false) + }); return Command.repeat(); } From 7d6d01a6095dcc68a6504a7bdfcbfd12dd083cec Mon Sep 17 00:00:00 2001 From: zeroxbt Date: Wed, 2 Mar 2022 17:41:04 +0100 Subject: [PATCH 20/26] add stringified keyword to assertions db --- modules/command/publish/send-assertion-command.js | 2 +- tools/local-network-setup/.bootstrap_origintrail_noderc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/command/publish/send-assertion-command.js b/modules/command/publish/send-assertion-command.js index fd2259492f..89eb27f301 100644 --- a/modules/command/publish/send-assertion-command.js +++ b/modules/command/publish/send-assertion-command.js @@ -69,7 +69,7 @@ class SendAssertionCommand extends Command { if (command.data.isTelemetry) { await Models.assertions.create({ hash: assertion.id, - topics: assertion.metadata.keywords, + topics: JSON.stringify(assertion.metadata.keywords[0]), createdAt: assertion.metadata.timestamp, }); } diff --git a/tools/local-network-setup/.bootstrap_origintrail_noderc b/tools/local-network-setup/.bootstrap_origintrail_noderc index fddf00c86b..ba95539f82 100644 --- a/tools/local-network-setup/.bootstrap_origintrail_noderc +++ b/tools/local-network-setup/.bootstrap_origintrail_noderc @@ -6,8 +6,8 @@ "rpcEndpoints": [ "https://rpc-mumbai.maticvigil.com/" ], - "publicKey": "", - "privateKey": "" + "publicKey": "0xd08eCEFb11C5e767fA196E2010B736155272537e", + "privateKey": "8db5ecd44052100b03c8d5fd0221390ea0145868a58971a70e456c90697135ee" } ], "graphDatabase": { From d28cee641ea4c591009d6a7db2e0caa4c693d374 Mon Sep 17 00:00:00 2001 From: NZT48 Date: Wed, 2 Mar 2022 17:54:22 +0100 Subject: [PATCH 21/26] Fix blazegraph error msg --- external/blazegraph-service.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/external/blazegraph-service.js b/external/blazegraph-service.js index 0f50369493..5f3fcd214c 100644 --- a/external/blazegraph-service.js +++ b/external/blazegraph-service.js @@ -31,7 +31,10 @@ class BlazegraphService { await axios(this.config.axios).then((response) => true) .catch((error) => { - this.logger.error(`Failed to write into Blazegraph: ${error} - ${error.stack}`); + this.logger.error({ + msg: `Failed to write into Blazegraph: ${error} - ${error.stack}`, + Event_name: constants.ERROR_TYPE.TRIPLE_STORE_INSERT_ERROR, + }); return false; }); } From 3d0fc3bfce6f49b76074390af1c49d29ccd3a102 Mon Sep 17 00:00:00 2001 From: NZT48 Date: Wed, 2 Mar 2022 17:54:42 +0100 Subject: [PATCH 22/26] Change bootstrap noderc --- tools/local-network-setup/.bootstrap_origintrail_noderc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/local-network-setup/.bootstrap_origintrail_noderc b/tools/local-network-setup/.bootstrap_origintrail_noderc index ba95539f82..1a01d5c791 100644 --- a/tools/local-network-setup/.bootstrap_origintrail_noderc +++ b/tools/local-network-setup/.bootstrap_origintrail_noderc @@ -6,8 +6,8 @@ "rpcEndpoints": [ "https://rpc-mumbai.maticvigil.com/" ], - "publicKey": "0xd08eCEFb11C5e767fA196E2010B736155272537e", - "privateKey": "8db5ecd44052100b03c8d5fd0221390ea0145868a58971a70e456c90697135ee" + "publicKey": "", + "privateKey": "" } ], "graphDatabase": { @@ -24,4 +24,4 @@ "::1", "127.0.0.1" ] -} \ No newline at end of file +} From f9af36d6f10ac8e4c2bc4d3df8cdc910baa2b9f4 Mon Sep 17 00:00:00 2001 From: NZT48 Date: Wed, 2 Mar 2022 17:56:24 +0100 Subject: [PATCH 23/26] Handle keep alive messages error --- modules/command/common/keep-alive-command.js | 7 +++++-- modules/constants.js | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index 63c66757e3..911c8bbfd6 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -46,7 +46,10 @@ class KeepAliveCommand extends Command { attributes: ['hash', 'topics', 'created_at'], }).map(x => ({assertionId: x.hash, keyword: x.topics, publishTimestamp: x.created_at})); } catch (e) { - this.logger.error(`An error has occurred with signaling data. ${e.message}`); + this.logger.error({ + msg: `An error has occurred with signaling data error: ${e}, stack: ${e.stack}`, + Event_name: constants.ERROR_TYPE.KEEP_ALIVE_ERROR, + }); } const proof = {}; @@ -66,7 +69,7 @@ class KeepAliveCommand extends Command { const that = this; axios(config).catch(e=>{ - that.handleError(uuidv1(), e, constants.ERROR_TYPE.KEEP_ALIVE, false) + that.handleError(uuidv1(), e, constants.ERROR_TYPE.KEEP_ALIVE_ERROR, false) }); return Command.repeat(); } diff --git a/modules/constants.js b/modules/constants.js index 6d43573f56..b5dcd64194 100644 --- a/modules/constants.js +++ b/modules/constants.js @@ -63,7 +63,6 @@ exports.TRIPLE_STORE_CONNECT_MAX_RETRIES = 10; */ exports.TRIPLE_STORE_CONNECT_RETRY_FREQUENCY = 10; // 10 seconds - /** * @constant {number} BLOCKCHAIN_QUEUE_LIMIT * - Blockchain queue limit @@ -101,6 +100,7 @@ exports.ERROR_TYPE = { NODE_INFO_ROUTE_ERROR: 'NodeInfoRouteError', EXTRACT_METADATA_ERROR: 'ExtractMetadataError', TRIPLE_STORE_UNAVAILABLE_ERROR: 'TripleStoreUnavailableError', + TRIPLE_STORE_INSERT_ERROR: 'TripleStoreInsertError', LIBP2P_HANDLE_MSG_ERROR: 'Libp2pHandleMessageError', VERIFY_ASSERTION_ERROR: 'VerifyAssertionError', BLOCKCHAIN_CHECK_ERROR: 'BlockchainCheckError', @@ -113,4 +113,5 @@ exports.ERROR_TYPE = { BLOCKCHAIN_INITIALIZATION_ERROR: 'BlockchainInitializationError', COMMAND_EXECUTOR_INITIALIZATION_ERROR: 'CommandExecutorInitializationError', RPC_INITIALIZATION_ERROR: 'RpcInitializationError', + KEEP_ALIVE_ERROR: 'KeepAliveError', }; From cdb63e48a1bfcf7411f08bfca0b9475fc4055a7c Mon Sep 17 00:00:00 2001 From: NZT48 Date: Wed, 2 Mar 2022 18:22:14 +0100 Subject: [PATCH 24/26] Fix keep alive info mapping --- modules/command/common/keep-alive-command.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index 911c8bbfd6..90037c6690 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -1,10 +1,11 @@ -const {v1: uuidv1} = require('uuid'); +const { v1: uuidv1 } = require('uuid'); const PeerId = require('peer-id'); var axios = require('axios'); +const fs = require('fs'); const Command = require('../command'); const pjson = require('../../../package.json'); const Models = require('../../../models/index'); -const constants = require("../../constants"); +const constants = require('../../constants'); class KeepAliveCommand extends Command { constructor(ctx) { @@ -34,17 +35,21 @@ class KeepAliveCommand extends Command { }, }; try { + if (!this.config.network.privateKey) { + const configFile = JSON.parse(fs.readFileSync(this.config.config)); + this.config.network.privateKey = configFile.network.privateKey; + } const peerId = await PeerId.createFromPrivKey(this.config.network.privateKey); signalingMessage.issuerWallet = this.config.blockchain[0].publicKey; signalingMessage.kademliaNodeId = peerId._idB58String; signalingMessage.nodeVersion = pjson.version; - signalingMessage.telemetry.latestAssertions = Models.assertions.findAll({ + signalingMessage.telemetry.latestAssertions = (await Models.assertions.findAll({ limit: 5, order: [ ['created_at', 'DESC'], ], attributes: ['hash', 'topics', 'created_at'], - }).map(x => ({assertionId: x.hash, keyword: x.topics, publishTimestamp: x.created_at})); + })).map(x => ({assertionId: x.dataValues.hash, keyword: x.dataValues.topics, publishTimestamp: x.dataValues.created_at})); } catch (e) { this.logger.error({ msg: `An error has occurred with signaling data error: ${e}, stack: ${e.stack}`, From 4527f739435e09da9c06e67ce0894b2ef99469f5 Mon Sep 17 00:00:00 2001 From: zeroxbt Date: Wed, 2 Mar 2022 18:45:50 +0100 Subject: [PATCH 25/26] add config file path --- modules/command/common/keep-alive-command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/command/common/keep-alive-command.js b/modules/command/common/keep-alive-command.js index 90037c6690..94b3008011 100644 --- a/modules/command/common/keep-alive-command.js +++ b/modules/command/common/keep-alive-command.js @@ -36,7 +36,7 @@ class KeepAliveCommand extends Command { }; try { if (!this.config.network.privateKey) { - const configFile = JSON.parse(fs.readFileSync(this.config.config)); + const configFile = JSON.parse(fs.readFileSync(this.config.config ? this.config.config : '.origintrail_noderc')); this.config.network.privateKey = configFile.network.privateKey; } const peerId = await PeerId.createFromPrivKey(this.config.network.privateKey); From f635b2c801e23e1c01d024068ca701a4499ae5e4 Mon Sep 17 00:00:00 2001 From: zeroxbt Date: Thu, 3 Mar 2022 12:35:27 +0100 Subject: [PATCH 26/26] remove stringify from handleResolve --- modules/service/query-service.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/service/query-service.js b/modules/service/query-service.js index e863dc54e2..08f34cb82f 100644 --- a/modules/service/query-service.js +++ b/modules/service/query-service.js @@ -39,7 +39,9 @@ class QueryService { }); const { nquads, isAsset } = await this.dataService.resolve(id); - this.logger.info(`Retrieved data from the database: ${await this.workerPool.exec('JSONStringify', [nquads])}`); + if (nquads) { + this.logger.info(`Number of n-quads retrieved from the database is ${nquads.length}`); + } this.logger.emit({ msg: 'Finished measuring execution of handle resolve command',