Skip to content

Commit

Permalink
Merge pull request #3574 from OriginTrail/v8/fix-for-get-backwrads-comp
Browse files Browse the repository at this point in the history
V8 make sure get works when getting assets created by old client
  • Loading branch information
Mihajlo-Pavlovic authored Dec 20, 2024
2 parents ea6d443 + 0176b30 commit eac64b4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,46 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
ual,
);

if (!assertionId) {
return {
messageType: NETWORK_MESSAGE_TYPES.RESPONSES.NACK,
messageData: { errorMessage: `Unable to find assertion ${ual}` },
};
}

this.logger.info(
`Found assertion id: ${assertionId}, operation id ${operationId}, ual: ${ual}`,
);
}

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

const fallbackResult = 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.public ?? []),
...(fallbackResult.private ?? []),
];
}

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

return result.split('\n').filter((res) => res.length > 0);
});
} else {
Expand Down Expand Up @@ -185,15 +206,15 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
...(includeMetadata && metadata && { metadata }),
};

if (assertion?.public?.length) {
if (assertion?.public?.length || assertion?.length) {
await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
OPERATION_ID_STATUS.GET.GET_REMOTE_END,
);
}

return assertion?.public?.length
return assertion?.public?.length || assertion?.length
? { messageType: NETWORK_MESSAGE_TYPES.RESPONSES.ACK, messageData: responseData }
: {
messageType: NETWORK_MESSAGE_TYPES.RESPONSES.NACK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class GetScheduleMessagesCommand extends ProtocolScheduleMessagesCommand {
paranetUAL: command.data.paranetUAL,
paranetId: command.data.paranetId,
paranetMetadata: command.data.paranetMetadata,
assertionId: command.data.isOperationV0,
isOperationV0: command.data.assertionId,
assertionId: command.data.assertionId,
isOperationV0: command.data.isOperationV0,
};
}

Expand Down
24 changes: 17 additions & 7 deletions src/commands/protocols/get/sender/local-get-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class LocalGetCommand extends Command {

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

for (const repository of [
TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT,
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
Expand All @@ -116,15 +117,24 @@ class LocalGetCommand extends Command {
}
}

if (result?.length) {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_END,
operationId,
if (!result?.length) {
result = await this.tripleStoreService.getAssertion(
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
contentType,
);
}
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_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 {
assertionPromise = this.tripleStoreService
Expand Down Expand Up @@ -172,7 +182,7 @@ class LocalGetCommand extends Command {
assertion,
...(includeMetadata && metadata && { metadata }),
};
if (assertion?.public?.length || assertion?.private?.length) {
if (assertion?.public?.length || assertion?.private?.length || assertion?.length) {
await this.operationService.markOperationAsCompleted(
operationId,
blockchain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ class GetRequestCommand extends ProtocolRequestCommand {

return ProtocolRequestCommand.empty();
}
if (responseData?.assertion?.length) {
// V6 assertion

await this.operationService.processResponse(
command,
OPERATION_REQUEST_STATUS.COMPLETED,
responseData,
);

return ProtocolRequestCommand.empty();
}

return this.handleNack(command, responseData);
}
Expand Down
2 changes: 2 additions & 0 deletions src/modules/triple-store/implementation/ot-triple-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ class OtTripleStore {
}

async getV6Assertion(repository, assertionId) {
if (!assertionId) return '';

const escapedGraphName = this.cleanEscapeCharacter(assertionId);

const query = `PREFIX schema: <${SCHEMA_CONTEXT}>
Expand Down

0 comments on commit eac64b4

Please sign in to comment.