Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use query to get assertion id of ual instead of blockchain #3560

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
knowledgeAssetId,
ual,
includeMetadata,
assertionId,
isOperationV0,
} = commandData;

let { assertionId } = commandData;

// if (paranetUAL) {
// const paranetNodeAccessPolicy = await this.blockchainModuleManager.getNodesAccessPolicy(
// blockchain,
Expand Down Expand Up @@ -109,7 +111,31 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {

let assertionPromise;

if (assertionId) {
if (isOperationV0) {
if (!assertionId) {
assertionId = await this.tripleStoreService.getLatestAssertionId(
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
ual,
);

if (!assertionId) {
assertionId = await this.tripleStoreService.getLatestAssertionId(
TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT,
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}`,
);
}
assertionPromise = this.tripleStoreService
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if no assertionid was found? should we return nack then already

.getV6Assertion(TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, assertionId)
.then((result) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Command from '../../../command.js';
import { ERROR_TYPE } from '../../../../constants/constants.js';
import { ERROR_TYPE, TRIPLE_STORE_REPOSITORIES } from '../../../../constants/constants.js';

class GetAssertionMerkleRootCommand extends Command {
constructor(ctx) {
super(ctx);
this.operationService = ctx.getService;
this.blockchainModuleManager = ctx.blockchainModuleManager;
this.tripleStoreService = ctx.tripleStoreService;

this.errorType = ERROR_TYPE.GET.GET_ASSERTION_ID_ERROR;
}
Expand All @@ -15,19 +16,23 @@ class GetAssertionMerkleRootCommand extends Command {
* @param command
*/
async execute(command) {
const { operationId, blockchain, contract, knowledgeCollectionId } = command.data;
this.logger.info(
`Getting assertion id for token id: ${knowledgeCollectionId}, contract: ${contract}, operation id: ${operationId} on blockchain: ${blockchain}`,
);
const { operationId, ual } = command.data;
this.logger.info(`Getting assertion id and operation id ${operationId} for ual: ${ual}`);

const assertionId = await this.blockchainModuleManager.getLatestAssertionId(
blockchain,
contract,
knowledgeCollectionId,
let assertionId = await this.tripleStoreService.getLatestAssertionId(
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
ual,
);

if (!assertionId) {
assertionId = await this.tripleStoreService.getLatestAssertionId(
TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT,
ual,
);
}

this.logger.info(
`Found assertion id: ${assertionId} for token id: ${knowledgeCollectionId}, contract: ${contract} on blockchain: ${blockchain} for operation id: ${operationId}`,
`Found assertion id: ${assertionId}, operation id ${operationId}, ual: ${ual}`,
);
return this.continueSequence({ ...command.data, assertionId }, command.sequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class GetFindShardCommand extends FindShardCommand {
getOperationCommandSequence(nodePartOfShard, commandData) {
const sequence = [];
if (nodePartOfShard) {
sequence.push('localGetCommand');
// If operationV0 and no assertionId found go directly to networkGet
if (!commandData.isOperationV0 || commandData.assertionId) {
sequence.push('localGetCommand');
}
}
sequence.push('networkGetCommand');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +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,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class GetRequestCommand extends ProtocolRequestCommand {
ual,
paranetUAL,
paranetId,
isOperationV0,
assertionId,
} = command.data;

return {
Expand All @@ -58,6 +60,8 @@ class GetRequestCommand extends ProtocolRequestCommand {
ual,
paranetUAL,
paranetId,
isOperationV0,
assertionId,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class GetController extends BaseController {
//

const commandSequence = [];
commandSequence.push('getValidateAssetCommand');

if (
!tripleStoreMigrationAlreadyExecuted &&
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/rpc/get-rpc-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class GetController extends BaseController {
state: message.data.state ?? DEFAULT_GET_STATE,
paranetUAL: message.data.paranetUAL,
paranetId: message.data.paranetId,
isOperationV0: message.data.isOperationV0,
assertionId: message.data.assertionId,
},
transactional: false,
});
Expand Down
15 changes: 15 additions & 0 deletions src/modules/triple-store/implementation/ot-triple-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,21 @@ class OtTripleStore {
this.select(repository, query);
}

async getLatestAssertionId(repository, ual) {
const query = `SELECT ?assertionId
WHERE {
GRAPH <assets:graph> {
<${ual}> ?p ?assertionId
}
}`;

const data = await this.select(repository, query);

const latestAssertionId = data?.[0]?.assertionId;

return latestAssertionId;
}

async construct(repository, query) {
return this._executeQuery(repository, query, MEDIA_TYPES.N_QUADS);
}
Expand Down
9 changes: 9 additions & 0 deletions src/modules/triple-store/triple-store-module-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ class TripleStoreModuleManager extends BaseModuleManager {
}
}

async getLatestAssertionId(implementationName, repository, ual) {
if (this.getImplementation(implementationName)) {
return this.getImplementation(implementationName).module.getLatestAssertionId(
repository,
ual,
);
}
}

async construct(implementationName, repository, query) {
if (this.getImplementation(implementationName)) {
return this.getImplementation(implementationName).module.construct(repository, query);
Expand Down
10 changes: 10 additions & 0 deletions src/service/triple-store-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,16 @@ class TripleStoreService {
return nquads;
}

async getLatestAssertionId(repository, ual) {
const nquads = await this.tripleStoreModuleManager.getLatestAssertionId(
this.repositoryImplementations[repository],
repository,
ual,
);

return nquads;
}

async construct(query, repository = TRIPLE_STORE_REPOSITORY.DKG) {
return this.tripleStoreModuleManager.construct(
this.repositoryImplementations[repository] ??
Expand Down
Loading