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

[DO NOT MERGE] Logic for pairing old and new uals on update #3490

Open
wants to merge 18 commits into
base: release/v8.0.0-sigma
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Add optio to get subject ual
  • Loading branch information
Mihajlo-Pavlovic committed Dec 9, 2024
commit ee64b81fa0949d8cf442478d1665d890e4a0872f
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import {
NETWORK_MESSAGE_TYPES,
OPERATION_ID_STATUS,
TRIPLES_VISIBILITY,
TRIPLE_STORE_REPOSITORY,
} from '../../../../../constants/constants.js';

class HandleGetRequestCommand extends HandleProtocolMessageCommand {
@@ -36,6 +37,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
knowledgeAssetId,
ual,
includeMetadata,
subjectUAL,
} = commandData;

// if (paranetUAL) {
@@ -97,7 +99,32 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
// };
// }
// }
if (subjectUAL) {
const subjectsUALs = await this.tripleStoreService.findAllSubjectsWithGraphNames(
TRIPLE_STORE_REPOSITORY.DKG,
ual,
);

if (subjectUAL?.length) {
await this.operationService.markOperationAsCompleted(
operationId,
blockchain,
subjectsUALs,
[
OPERATION_ID_STATUS.GET.GET_LOCAL_END,
OPERATION_ID_STATUS.GET.GET_END,
OPERATION_ID_STATUS.COMPLETED,
],
);
}

return subjectUAL?.length
? { messageType: NETWORK_MESSAGE_TYPES.RESPONSES.ACK, messageData: subjectsUALs }
: {
messageType: NETWORK_MESSAGE_TYPES.RESPONSES.NACK,
messageData: { errorMessage: `Unable to find assertion ${ual}` },
};
}
const promises = [];
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_REMOTE_GET_ASSERTION_START,
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ class GetScheduleMessagesCommand extends ProtocolScheduleMessagesCommand {
knowledgeAssetId: command.data.knowledgeAssetId,
includeMetadata: command.data.includeMetadata,
ual: command.data.ual,
subjectUAL: command.data.subjectUAL,
assetSync: command.data.assetSync,
paranetSync: command.data.paranetSync,
paranetTokenId: command.data.paranetTokenId,
181 changes: 83 additions & 98 deletions src/commands/protocols/get/sender/local-get-command.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import {
OPERATION_ID_STATUS,
ERROR_TYPE,
TRIPLES_VISIBILITY,
TRIPLE_STORE_REPOSITORY,
} from '../../../../constants/constants.js';

class LocalGetCommand extends Command {
@@ -33,129 +34,113 @@ class LocalGetCommand extends Command {
contract,
knowledgeCollectionId,
knowledgeAssetId,
subjectUAL,
ual,
} = command.data;
await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
OPERATION_ID_STATUS.GET.GET_LOCAL_START,
);

// const response = {};

// if (paranetUAL) {
// const paranetRepository = this.paranetService.getParanetRepositoryName(paranetUAL);

// const ual = this.ualService.deriveUAL(blockchain, contract, tokenId);
// const syncedAssetRecord =
// await this.repositoryModuleManager.getParanetSyncedAssetRecordByUAL(ual);

// const nquads = await this.tripleStoreService.getAssertion(
// paranetRepository,
// syncedAssetRecord.publicAssertionId,
// );

// let privateNquads;
// if (syncedAssetRecord.privateAssertionId) {
// privateNquads = await this.tripleStoreService.getAssertion(
// paranetRepository,
// syncedAssetRecord.privateAssertionId,
// );
// }

// if (nquads?.length) {
// response.assertion = nquads;
// if (privateNquads?.length) {
// response.privateAssertion = privateNquads;
// }
// } else {
// this.handleError(
// operationId,
// blockchain,
// `Couldn't find locally asset with ${ual} in paranet ${paranetUAL}`,
// this.errorType,
// );
// }

// await this.operationService.markOperationAsCompleted(
// operationId,
// blockchain,
// response,
// [
// OPERATION_ID_STATUS.GET.GET_LOCAL_END,
// OPERATION_ID_STATUS.GET.GET_END,
// OPERATION_ID_STATUS.COMPLETED,
// ],
// );

// return Command.empty();
// }

// else {

const promises = [];
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_START,
operationId,
blockchain,
);
const assertionPromise = this.tripleStoreService
.getAssertion(
if (subjectUAL) {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_SUBJECT_UAL_START,
operationId,
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
TRIPLES_VISIBILITY.ALL,
)
.then((result) => {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_END,
);
const subjectsUALs = await this.tripleStoreService.findAllSubjectsWithGraphNames(
TRIPLE_STORE_REPOSITORY.DKG,
ual,
);
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_SUBJECT_UAL_START,
operationId,
blockchain,
);
if (subjectsUALs?.length) {
await this.operationService.markOperationAsCompleted(
operationId,
blockchain,
subjectsUALs,
[
OPERATION_ID_STATUS.GET.GET_LOCAL_END,
OPERATION_ID_STATUS.GET.GET_END,
OPERATION_ID_STATUS.COMPLETED,
],
);
return result;
});
promises.push(assertionPromise);

if (includeMetadata) {
return Command.empty();
}
} else {
const promises = [];
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_METADATA_START,
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_START,
operationId,
blockchain,
);
const metadataPromise = this.tripleStoreService
.getAssertionMetadata(blockchain, contract, knowledgeCollectionId, knowledgeAssetId)
const assertionPromise = this.tripleStoreService
.getAssertion(
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
TRIPLES_VISIBILITY.ALL,
)
.then((result) => {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_METADATA_END,
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_END,
operationId,
blockchain,
);
return result;
});
promises.push(metadataPromise);
}
promises.push(assertionPromise);

const [assertion, metadata] = await Promise.all(promises);

const responseData = {
assertion,
...(includeMetadata && metadata && { metadata }),
};
if (assertion.length) {
await this.operationService.markOperationAsCompleted(
operationId,
blockchain,
responseData,
[
OPERATION_ID_STATUS.GET.GET_LOCAL_END,
OPERATION_ID_STATUS.GET.GET_END,
OPERATION_ID_STATUS.COMPLETED,
],
);
if (includeMetadata) {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_METADATA_START,
operationId,
blockchain,
);
const metadataPromise = this.tripleStoreService
.getAssertionMetadata(
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
)
.then((result) => {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_METADATA_END,
operationId,
blockchain,
);
return result;
});
promises.push(metadataPromise);
}

const [assertion, metadata] = await Promise.all(promises);

const responseData = {
assertion,
...(includeMetadata && metadata && { metadata }),
};
if (assertion.length) {
await this.operationService.markOperationAsCompleted(
operationId,
blockchain,
responseData,
[
OPERATION_ID_STATUS.GET.GET_LOCAL_END,
OPERATION_ID_STATUS.GET.GET_END,
OPERATION_ID_STATUS.COMPLETED,
],
);

return Command.empty();
return Command.empty();
}
}
// }

await this.operationIdService.updateOperationIdStatus(
operationId,
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ class GetRequestCommand extends ProtocolRequestCommand {
knowledgeAssetId,
includeMetadata,
ual,
subjectUAL,
hashFunctionId,
paranetUAL,
paranetId,
@@ -58,6 +59,7 @@ class GetRequestCommand extends ProtocolRequestCommand {
knowledgeAssetId,
includeMetadata,
ual,
subjectUAL,
hashFunctionId,
proximityScoreFunctionsPairId,
paranetUAL,
2 changes: 2 additions & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
@@ -713,6 +713,8 @@ export const OPERATION_ID_STATUS = {
GET_FIND_NODES_PROCESS_FOUND_NODES_START: 'GET_FIND_NODES_PROCESS_FOUND_NODES_START',
GET_FIND_NODES_PROCESS_FOUND_NODES_END: 'GET_FIND_NODES_PROCESS_FOUND_NODES_END',
GET_END: 'GET_END',
GET_LOCAL_GET_SUBJECT_UAL_START: 'GET_LOCAL_GET_SUBJECT_UAL_START',
GET_LOCAL_GET_SUBJECT_UAL_END: 'GET_LOCAL_GET_SUBJECT_UAL_END',
},
COMMIT_PROOF: {
EPOCH_CHECK_START: 'EPOCH_CHECK_START',
3 changes: 3 additions & 0 deletions src/controllers/http-api/v0/request-schema/get-schema-v0.js
Original file line number Diff line number Diff line change
@@ -18,5 +18,8 @@ export default () => ({
paranetUAL: {
type: ['string', 'null'],
},
subjectUAL: {
type: 'boolean',
},
},
});
3 changes: 2 additions & 1 deletion src/controllers/http-api/v1/get-http-api-controller-v1.js
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ class GetController extends BaseController {
let tokenId;
let contract;
try {
const { id, paranetUAL } = req.body;
const { id, paranetUAL, subjectUAL } = req.body;

({ blockchain, tokenId, contract } = this.ualService.resolveUAL(id));
const hashFunctionId = req.body.hashFunctionId ?? CONTENT_ASSET_HASH_FUNCTION_ID;
@@ -65,6 +65,7 @@ class GetController extends BaseController {
paranetUAL,
tokenId,
contract,
subjectUAL,
},
transactional: false,
});
1 change: 1 addition & 0 deletions src/controllers/rpc/get-rpc-controller.js
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ class GetController extends BaseController {
knowledgeCollectionId: message.data.knowledgeCollectionId,
knowledgeAssetId: message.data.knowledgeAssetId,
includeMetadata: message.data.includeMetadata,
subjectUAL: message.data.subjectUAL,
hashFunctionId: message.data.hashFunctionId ?? CONTENT_ASSET_HASH_FUNCTION_ID,
state: message.data.state ?? DEFAULT_GET_STATE,
paranetUAL: message.data.paranetUAL,
24 changes: 20 additions & 4 deletions src/service/triple-store-service.js
Original file line number Diff line number Diff line change
@@ -412,10 +412,7 @@ class TripleStoreService {

async moveToHistoricAndDeleteAssertion(ual, stateIndex) {
// Find all named graph that exist for given UAL
const ualNamedGraphs = this.tripleStoreModuleManager.findAllNamedGraphsByUAL(
TRIPLE_STORE_REPOSITORY.DKG,
ual,
);
const ualNamedGraphs = await this.findAllNamedGraphsByUAL(TRIPLE_STORE_REPOSITORY.DKG, ual);
let stateNamedGraphExistInHistoric = [];
const ulaNamedGraphsWithState = [];
const checkPromises = [];
@@ -427,6 +424,7 @@ class TripleStoreService {
ulaNamedGraphsWithState.push(ulaNamedGraphWithState);
checkPromises.push(
this.tripleStoreModuleManager.namedGraphExist(
this.repositoryImplementations[TRIPLE_STORE_REPOSITORY.DKG_HISTORIC],
TRIPLE_STORE_REPOSITORY.DKG_HISTORIC,
ulaNamedGraphWithState,
),
@@ -439,10 +437,12 @@ class TripleStoreService {
for (const [index, promiseResult] of stateNamedGraphExistInHistoric.entries()) {
if (!promiseResult) {
const nquads = await this.tripleStoreModuleManager.getAssertionFromNamedGraph(
this.repositoryImplementations[TRIPLE_STORE_REPOSITORY.DKG],
TRIPLE_STORE_REPOSITORY.DKG,
ualNamedGraphs[index],
);
await this.tripleStoreModuleManager.insetAssertionInNamedGraph(
this.repositoryImplementations[TRIPLE_STORE_REPOSITORY.DKG_HISTORIC],
TRIPLE_STORE_REPOSITORY.DKG_HISTORIC,
ulaNamedGraphsWithState[index],
nquads,
@@ -458,6 +458,22 @@ class TripleStoreService {
return ualNamedGraphs;
}

async findAllNamedGraphsByUAL(repositories, ual) {
return this.tripleStoreModuleManager.findAllNamedGraphsByUAL(
this.repositoryImplementations[repositories],
repositories,
ual,
);
}

async findAllSubjectsWithGraphNames(repositories, ual) {
return this.tripleStoreModuleManager.findAllSubjectsWithGraphNames(
this.repositoryImplementations[repositories],
repositories,
ual,
);
}

async getKnowledgeAssetNamedGraph(repository, ual, visibility) {
return this.tripleStoreModuleManager.getKnowledgeAssetNamedGraph(
this.repositoryImplementations[repository],