From fc3cb83bfb80867f9b0abf588073f6a80ff1d226 Mon Sep 17 00:00:00 2001 From: Bogdan Tomic Date: Fri, 24 Jan 2025 13:51:39 +0100 Subject: [PATCH 1/5] fixed bag --- .../network/implementation/libp2p-service.js | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/modules/network/implementation/libp2p-service.js b/src/modules/network/implementation/libp2p-service.js index f1baad9f7..fedaa0300 100644 --- a/src/modules/network/implementation/libp2p-service.js +++ b/src/modules/network/implementation/libp2p-service.js @@ -464,7 +464,12 @@ class Libp2pService { return { message, valid: false, busy: false }; } - message.header = JSON.parse(stringifiedHeader); + try { + message.header = JSON.parse(stringifiedHeader); + } catch (error) { + // Return the same format as invalid request case + return { message, valid: false, busy: false }; + } // validate request / response if (!(await isMessageValid(message.header, peerIdString))) { @@ -481,10 +486,20 @@ class Libp2pService { let stringifiedData = ''; // read data the data - for await (const chunk of source) { - stringifiedData += chunk; + + try { + for await (const chunk of source) { + + stringifiedData += chunk; + + } + message.data = JSON.parse(stringifiedData); + + } catch (error) { + + // If data parsing fails, return invalid message response + return { message, valid: false, busy: false }; } - message.data = JSON.parse(stringifiedData); return { message, valid: true, busy: false }; } From 45a5bd39380fa77eaa4c832311d2bae7a7c0558c Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Tue, 28 Jan 2025 12:46:51 +0100 Subject: [PATCH 2/5] Rework KC insert to insert in KA chunks --- .../implementation/ot-triple-store.js | 50 ++++++++++++++----- src/service/triple-store-service.js | 2 +- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/modules/triple-store/implementation/ot-triple-store.js b/src/modules/triple-store/implementation/ot-triple-store.js index 82b133475..7d2687418 100644 --- a/src/modules/triple-store/implementation/ot-triple-store.js +++ b/src/modules/triple-store/implementation/ot-triple-store.js @@ -270,23 +270,47 @@ class OtTripleStore { return this.ask(repository, query); } - async createKnowledgeCollectionNamedGraphs(repository, uals, assetsNQuads, visibility) { - const query = ` - PREFIX schema: <${SCHEMA_CONTEXT}> - INSERT DATA { - ${uals - .map( - (ual, index) => ` + async createKnowledgeCollectionNamedGraphs( + repository, + uals, + assetsNQuads, + visibility, + retries = 5, + retryDelay = 10, + ) { + const queries = uals.map( + (ual, index) => ` + PREFIX schema: <${SCHEMA_CONTEXT}> + INSERT DATA { GRAPH <${ual}/${visibility}> { ${assetsNQuads[index].join('\n')} } - `, - ) - .join('\n')} + } + `, + ); + for (const [index, query] of queries.entries()) { + let attempts = 0; + let success = false; + + while (attempts < retries && !success) { + try { + await this.queryVoid(repository, query); + success = true; + } catch (error) { + attempts += 1; + if (attempts < retries) { + this.logger.warn( + `Insert failed for GRAPH <${uals[index]}/${visibility}>. Attempt ${attempts}/${retries}. Retrying in ${retryDelay}ms.`, + ); + await setTimeout(retryDelay); + } else { + throw new Error( + `Failed to insert into GRAPH <${uals[index]}/${visibility}> after ${retries} attempts.`, + ); + } + } } - `; - - await this.queryVoid(repository, query); + } } async deleteKnowledgeCollectionNamedGraphs(repository, uals) { diff --git a/src/service/triple-store-service.js b/src/service/triple-store-service.js index 9fec7031d..41c1226c7 100644 --- a/src/service/triple-store-service.js +++ b/src/service/triple-store-service.js @@ -38,7 +38,7 @@ class TripleStoreService { knowledgeCollectionUAL, triples, retries = 5, - retryDelay = 0, + retryDelay = 50, ) { this.logger.info( `Inserting Knowledge Collection with the UAL: ${knowledgeCollectionUAL} ` + From b6732eef253df1dbba25085a91e75c9b22c0b3a0 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Wed, 29 Jan 2025 15:28:45 +0100 Subject: [PATCH 3/5] Move all logic in try catch inside findPeerAddressAndProtocols --- src/service/sharding-table-service.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/service/sharding-table-service.js b/src/service/sharding-table-service.js index d20bea388..4c0f1dec7 100644 --- a/src/service/sharding-table-service.js +++ b/src/service/sharding-table-service.js @@ -106,19 +106,19 @@ class ShardingTableService { } async dial(peerId) { - const { addresses } = await this.findPeerAddressAndProtocols(peerId); - if (addresses.length) { - try { + try { + const { addresses } = await this.findPeerAddressAndProtocols(peerId); + if (addresses.length) { if (peerId !== this.networkModuleManager.getPeerId().toB58String()) { this.logger.trace(`Dialing peer ${peerId}.`); await this.networkModuleManager.dial(peerId); } await this.updatePeerRecordLastSeenAndLastDialed(peerId); - } catch (error) { - this.logger.trace(`Unable to dial peer ${peerId}. Error: ${error.message}`); + } else { await this.updatePeerRecordLastDialed(peerId); } - } else { + } catch (error) { + this.logger.trace(`Unable to dial peer ${peerId}. Error: ${error.message}`); await this.updatePeerRecordLastDialed(peerId); } } From 1bfd8bb7a6a8bbaa353ac3de7d12b3ad5773de0e Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Thu, 30 Jan 2025 10:33:34 +0100 Subject: [PATCH 4/5] Change conidtion to show last log if insert failes --- src/modules/triple-store/implementation/ot-triple-store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/triple-store/implementation/ot-triple-store.js b/src/modules/triple-store/implementation/ot-triple-store.js index 7d2687418..9461b0375 100644 --- a/src/modules/triple-store/implementation/ot-triple-store.js +++ b/src/modules/triple-store/implementation/ot-triple-store.js @@ -298,7 +298,7 @@ class OtTripleStore { success = true; } catch (error) { attempts += 1; - if (attempts < retries) { + if (attempts <= retries) { this.logger.warn( `Insert failed for GRAPH <${uals[index]}/${visibility}>. Attempt ${attempts}/${retries}. Retrying in ${retryDelay}ms.`, ); From 15872dc8bd0de44a28d2aacc3d066a6e644dfa72 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Thu, 30 Jan 2025 11:09:06 +0100 Subject: [PATCH 5/5] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 996cfd893..571f620a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "8.0.1", + "version": "8.0.1+hotfix.1", "description": "OTNode V8", "main": "index.js", "type": "module",