Skip to content

Commit

Permalink
Merge pull request #3701 from OriginTrail/v6/prerelease/testnet
Browse files Browse the repository at this point in the history
8.0.1+hotfix.1 Testnet Release
  • Loading branch information
Mihajlo-Pavlovic authored Jan 30, 2025
2 parents 3850f79 + 26ef484 commit 71f1a4c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 19 additions & 4 deletions src/modules/network/implementation/libp2p-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand All @@ -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 };
}
Expand Down
50 changes: 37 additions & 13 deletions src/modules/triple-store/implementation/ot-triple-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions src/service/sharding-table-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/service/triple-store-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TripleStoreService {
knowledgeCollectionUAL,
triples,
retries = 5,
retryDelay = 0,
retryDelay = 50,
) {
this.logger.info(
`Inserting Knowledge Collection with the UAL: ${knowledgeCollectionUAL} ` +
Expand Down

0 comments on commit 71f1a4c

Please sign in to comment.