Skip to content

Commit

Permalink
Merge pull request #3569 from OriginTrail/v8/add-backwards-compaitbil…
Browse files Browse the repository at this point in the history
…ity-to-publish

V8/add backwards compatibility to publish
  • Loading branch information
Mihajlo-Pavlovic authored Dec 20, 2024
2 parents c72029d + 28a92af commit 6712b00
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 23 deletions.
23 changes: 9 additions & 14 deletions src/commands/local-store/local-store-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
LOCAL_STORE_TYPES,
OPERATION_REQUEST_STATUS,
NETWORK_MESSAGE_TYPES,
TRIPLE_STORE_REPOSITORIES,
NETWORK_SIGNATURES_FOLDER,
PUBLISHER_NODE_SIGNATURES_FOLDER,
} from '../../constants/constants.js';
Expand Down Expand Up @@ -66,20 +65,16 @@ class LocalStoreCommand extends Command {
const storePromises = [];

if (isOperationV0) {
const assertions = [cachedData.public, cachedData.private];
if (cachedData.public?.assertion && cachedData.public?.assertionId) {
const ual = this.ualService.deriveUAL(blockchain, contract, tokenId);

for (const data of assertions) {
if (data?.assertion && data?.assertionId) {
const ual = this.ualService.deriveUAL(blockchain, contract, tokenId);

storePromises.push(
this.tripleStoreService.insertKnowledgeCollection(
TRIPLE_STORE_REPOSITORIES.DKG,
ual,
data.assertion,
),
);
}
storePromises.push(
this.tripleStoreService.createV6KnowledgeCollection(
cachedData.public.assertion,
ual,
cachedData.private.assertion,
),
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class ProtocolScheduleMessagesCommand extends Command {
batchSize,
minAckResponses,
leftoverNodes: currentBatchLeftoverNodes,
isOperationV0: command.data.isOperationV0,
},
period: 5000,
retries: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,18 @@ class HandleStoreRequestCommand extends HandleProtocolMessageCommand {
blockchain,
OPERATION_ID_STATUS.PUBLISH.PUBLISH_LOCAL_STORE_REMOTE_CACHE_DATASET_START,
);
await this.pendingStorageService.cacheDataset(
operationId,
datasetRoot,
dataset,
remotePeerId,
);

if (isOperationV0) {
const { contract, tokenId } = commandData;
const ual = this.ualService.deriveUAL(blockchain, contract, tokenId);
await this.tripleStoreService.createV6KnowledgeCollection(dataset, ual);
} else {
await this.pendingStorageService.cacheDataset(
operationId,
datasetRoot,
dataset,
remotePeerId,
);
}
await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ class PublishScheduleMessagesCommand extends ProtocolScheduleMessagesCommand {
this.errorType = ERROR_TYPE.PUBLISH.PUBLISH_START_ERROR;
}

getNextCommandData(command) {
const { datasetRoot, blockchain, isOperationV0, contract, tokenId } = command.data;
return {
blockchain,
datasetRoot,
isOperationV0,
contract,
tokenId,
};
}

/**
* Builds default publishScheduleMessagesCommand
* @param map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PublishRequestCommand extends ProtocolRequestCommand {
}

async prepareMessage(command) {
const { datasetRoot, operationId, isOperationV0 } = command.data;
const { datasetRoot, operationId, isOperationV0, contract, tokenId } = command.data;

// TODO: Backwards compatibility, send blockchain without chainId
const { blockchain } = command.data;
Expand All @@ -47,6 +47,19 @@ class PublishRequestCommand extends ProtocolRequestCommand {
datasetRoot,
blockchain,
isOperationV0,
contract,
tokenId,
};
}

getNextCommandData(command) {
const { datasetRoot, blockchain, isOperationV0, contract, tokenId } = command.data;
return {
blockchain,
datasetRoot,
isOperationV0,
contract,
tokenId,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/controllers/rpc/publish-rpc-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class PublishController extends BaseController {
datasetRoot: message.data.datasetRoot,
blockchain: message.data.blockchain,
isOperationV0: message.data.isOperationV0,
contract: message.data.contract,
tokenId: message.data.tokenId,
};

await this.commandExecutor.add(command);
Expand Down
34 changes: 34 additions & 0 deletions src/service/triple-store-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,40 @@ class TripleStoreService {
}
}

async createV6KnowledgeCollection(triplesPublic, ual, triplesPrivate = null) {
this.logger.info(
`Inserting Knowledge Collection with the UAL: ${ual} ` +
`to the Triple Store's ${TRIPLE_STORE_REPOSITORY.DKG} repository.`,
);
const publicKnowledgeAssetsTriplesGrouped = [triplesPublic];
const publicKnowledgeAssetsUALs = [`${ual}/1`];
await this.tripleStoreModuleManager.createKnowledgeCollectionNamedGraphs(
this.repositoryImplementations[TRIPLE_STORE_REPOSITORY.DKG],
TRIPLE_STORE_REPOSITORY.DKG,
publicKnowledgeAssetsUALs,
publicKnowledgeAssetsTriplesGrouped,
TRIPLES_VISIBILITY.PUBLIC,
);

if (triplesPrivate) {
const privateKnowledgeAssetsTriplesGrouped = [triplesPrivate];
await this.tripleStoreModuleManager.createKnowledgeCollectionNamedGraphs(
this.repositoryImplementations[TRIPLE_STORE_REPOSITORY.DKG],
TRIPLE_STORE_REPOSITORY.DKG,
publicKnowledgeAssetsUALs,
privateKnowledgeAssetsTriplesGrouped,
TRIPLES_VISIBILITY.PRIVATE,
);
}

const metadataTriples = [`<${ual}> <http://schema.org/states> "${ual}:0" .`];
await this.tripleStoreModuleManager.insertKnowledgeCollectionMetadata(
this.repositoryImplementations[TRIPLE_STORE_REPOSITORY.DKG],
TRIPLE_STORE_REPOSITORY.DKG,
metadataTriples,
);
}

async insertUpdatedKnowledgeCollection(preUpdateUalNamedGraphs, ual, triples, firstNewKAIndex) {
const preUpdateSubjectUalMap = new Map(
preUpdateUalNamedGraphs.map((entry) => [
Expand Down

0 comments on commit 6712b00

Please sign in to comment.