Skip to content

Commit

Permalink
Merge pull request #3663 from OriginTrail/v6/release/testnet
Browse files Browse the repository at this point in the history
V8 Hotfix 4 Mainnet Prerlease
  • Loading branch information
Mihajlo-Pavlovic authored Dec 31, 2024
2 parents 93a7c12 + 0db8245 commit 6a580f8
Show file tree
Hide file tree
Showing 31 changed files with 616 additions and 335 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.0+hotfix.3",
"version": "8.0.0+hotfix.4",
"description": "OTNode V8",
"main": "index.js",
"type": "module",
Expand Down
62 changes: 38 additions & 24 deletions src/commands/local-store/local-store-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class LocalStoreCommand extends Command {
tokenId,
minimumNumberOfNodeReplications,
batchSize,
nodePartOfShard,
} = command.data;

try {
Expand Down Expand Up @@ -191,21 +192,26 @@ class LocalStoreCommand extends Command {

return Command.empty();
}

let v;
let r;
let s;
let vs;
const identityId = await this.blockchainModuleManager.getIdentityId(blockchain);
const { v, r, s, vs } = await this.signatureService.signMessage(
blockchain,
datasetRoot,
);
await this.signatureService.addSignatureToStorage(
NETWORK_SIGNATURES_FOLDER,
operationId,
identityId,
v,
r,
s,
vs,
);
if (nodePartOfShard) {
({ v, r, s, vs } = await this.signatureService.signMessage(
blockchain,
datasetRoot,
));
await this.signatureService.addSignatureToStorage(
NETWORK_SIGNATURES_FOLDER,
operationId,
identityId,
v,
r,
s,
vs,
);
}

const {
v: publisherNodeV,
Expand Down Expand Up @@ -239,16 +245,24 @@ class LocalStoreCommand extends Command {
batchSize: batchSizePar,
minAckResponses,
};

await this.operationService.processResponse(
{ ...command, data: updatedData },
OPERATION_REQUEST_STATUS.COMPLETED,
{
messageType: NETWORK_MESSAGE_TYPES.RESPONSES.ACK,
messageData: { identityId, v, r, s, vs },
},
null,
);
if (nodePartOfShard) {
await this.operationService.processResponse(
{ ...command, data: updatedData },
OPERATION_REQUEST_STATUS.COMPLETED,
{
messageType: NETWORK_MESSAGE_TYPES.RESPONSES.ACK,
messageData: { identityId, v, r, s, vs },
},
null,
);
} else {
await this.operationService.processResponse(
{ ...command, data: updatedData },
OPERATION_REQUEST_STATUS.FAILED,
{},
'Node is not part of the shard.',
);
}
} catch (e) {
await this.handleError(operationId, blockchain, e.message, this.errorType, true);
return Command.empty();
Expand Down
1 change: 1 addition & 0 deletions src/commands/protocols/common/find-shard-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class FindShardCommand extends Command {
return this.continueSequence(
{
...command.data,
nodePartOfShard,
leftoverNodes: shardNodes,
numberOfFoundNodes: shardNodes.length + (nodePartOfShard ? 1 : 0),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
ual,
includeMetadata,
isOperationV0,
isV6Contract,
} = commandData;

let { assertionId, knowledgeAssetId } = commandData;
Expand Down Expand Up @@ -109,6 +110,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
);

let assertionPromise;
let notMigrated = false;

if (!assertionId) {
assertionId = await this.tripleStoreService.getLatestAssertionId(
Expand All @@ -123,39 +125,50 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {

if (assertionId) {
// DO NOT RUN THIS IF !assertionId
assertionPromise = this.tripleStoreService
.getV6Assertion(TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, assertionId)
.then(async (result) => {
if (!result?.length) {
this.logger.info(
`No V6 assertion found for assertionId: ${assertionId}, falling back to V8 getAssertion`,
);
assertionPromise = (async () => {
let result = null;

if (!isOperationV0) {
result = await this.tripleStoreService.getAssertion(
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
TRIPLES_VISIBILITY.PUBLIC,
);
}

if (!result?.length) {
// eslint-disable-next-line no-await-in-loop
result = await this.tripleStoreService.getV6Assertion(
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
assertionId,
);
if (result?.length && !isOperationV0) {
notMigrated = true;
}

const fallbackResult = await this.tripleStoreService.getAssertion(
if (!result?.length && isOperationV0) {
result = await this.tripleStoreService.getAssertion(
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
TRIPLES_VISIBILITY.PUBLIC,
);

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_REMOTE_GET_ASSERTION_END,
operationId,
blockchain,
);

return fallbackResult;
}
}

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_REMOTE_GET_ASSERTION_END,
operationId,
blockchain,
);
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_REMOTE_GET_ASSERTION_END,
operationId,
blockchain,
);

return result.split('\n').filter((res) => res.length > 0);
});
return typeof result === 'string'
? result.split('\n').filter((res) => res.length > 0)
: result;
})();
} else {
if (!knowledgeAssetId) {
try {
Expand Down Expand Up @@ -223,9 +236,10 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
const [assertion, metadata] = await Promise.all(promises);

const responseData = {
assertion: isOperationV0
? [...(assertion.public ?? []), ...(assertion.private ?? [])]
: assertion,
assertion:
(isOperationV0 || notMigrated) && isV6Contract
? [...(assertion.public ?? []), ...(assertion.private ?? [])]
: assertion,
...(includeMetadata && metadata && { metadata }),
};

Expand Down
5 changes: 1 addition & 4 deletions src/commands/protocols/get/sender/get-find-shard-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ class GetFindShardCommand extends FindShardCommand {
// eslint-disable-next-line no-unused-vars
getOperationCommandSequence(nodePartOfShard, commandData) {
const sequence = [];
if (nodePartOfShard) {
sequence.push('localGetCommand');
}
sequence.push('networkGetCommand');
sequence.push('localGetCommand', 'networkGetCommand');

return sequence;
}
Expand Down
25 changes: 11 additions & 14 deletions src/commands/protocols/get/sender/get-validate-asset-command.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import ValidateAssetCommand from '../../../common/validate-asset-command.js';
import Command from '../../../command.js';
import {
OPERATION_ID_STATUS,
ERROR_TYPE,
OLD_CONTENT_STORAGE_MAP,
} from '../../../../constants/constants.js';
import { OPERATION_ID_STATUS, ERROR_TYPE } from '../../../../constants/constants.js';

class GetValidateAssetCommand extends ValidateAssetCommand {
constructor(ctx) {
Expand All @@ -27,8 +23,15 @@ class GetValidateAssetCommand extends ValidateAssetCommand {
* @param command
*/
async execute(command) {
const { operationId, blockchain, contract, knowledgeCollectionId, ual, isOperationV0 } =
command.data;
const {
operationId,
blockchain,
contract,
knowledgeCollectionId,
ual,
isOperationV0,
isV6Contract,
} = command.data;
await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
Expand All @@ -53,13 +56,7 @@ class GetValidateAssetCommand extends ValidateAssetCommand {
blockchain,
);
// TODO: Update to validate knowledge asset index
// TODO: Use isOldContract as variable and pass it through with command.data since it's used
if (
!isOperationV0 &&
Object.values(OLD_CONTENT_STORAGE_MAP).every(
(ca) => !ca.toLowerCase().includes(contract.toLowerCase()),
)
) {
if (!isOperationV0 && !isV6Contract) {
const isValidUal = await this.validationService.validateUal(
blockchain,
contract,
Expand Down
51 changes: 36 additions & 15 deletions src/commands/protocols/get/sender/local-get-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class LocalGetCommand extends Command {
contentType,
assertionId,
isOperationV0,
isV6Contract,
} = command.data;
let { knowledgeAssetId } = command.data;
await this.operationIdService.updateOperationIdStatus(
Expand Down Expand Up @@ -103,23 +104,13 @@ class LocalGetCommand extends Command {
);

let assertionPromise;
let notMigrated = false;

if (assertionId) {
assertionPromise = (async () => {
let result = null;

for (const repository of [
TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT,
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
]) {
// eslint-disable-next-line no-await-in-loop
result = await this.tripleStoreService.getV6Assertion(repository, assertionId);
if (result?.length) {
break;
}
}

if (!result?.length) {
if (!isOperationV0) {
result = await this.tripleStoreService.getAssertion(
blockchain,
contract,
Expand All @@ -128,6 +119,35 @@ class LocalGetCommand extends Command {
contentType,
);
}

if (!result?.length) {
for (const repository of [
TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT,
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
]) {
// eslint-disable-next-line no-await-in-loop
result = await this.tripleStoreService.getV6Assertion(
repository,
assertionId,
);
if (result?.length) {
if (!isOperationV0) {
notMigrated = true;
}
break;
}
}
if (!result?.length && isOperationV0) {
result = await this.tripleStoreService.getAssertion(
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
contentType,
);
}
}

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_END,
operationId,
Expand Down Expand Up @@ -206,9 +226,10 @@ class LocalGetCommand extends Command {
const [assertion, metadata] = await Promise.all(promises);

const responseData = {
assertion: isOperationV0
? [...(assertion?.public ?? []), ...(assertion?.private ?? [])]
: assertion,
assertion:
(isOperationV0 || notMigrated) && isV6Contract
? [...(assertion?.public ?? []), ...(assertion?.private ?? [])]
: assertion,
...(includeMetadata && metadata && { metadata }),
};

Expand Down
Loading

0 comments on commit 6a580f8

Please sign in to comment.