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

Backwards compatibility fixes Prerelease Testnet #3571

Merged
merged 10 commits into from
Dec 20, 2024
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-sigma.7",
"version": "8.0.0-sigma.8",
"description": "OTNode V8",
"main": "index.js",
"type": "module",
Expand Down
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 @@ -118,13 +118,6 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
ual,
);

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

if (!assertionId) {
return {
messageType: NETWORK_MESSAGE_TYPES.RESPONSES.NACK,
Expand All @@ -144,7 +137,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
operationId,
blockchain,
);
return result;
return result.split('\n').filter((res) => res.length > 0);
});
} else {
assertionPromise = this.tripleStoreService
Expand Down
53 changes: 34 additions & 19 deletions src/commands/protocols/get/sender/get-validate-asset-command.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import ValidateAssetCommand from '../../../common/validate-asset-command.js';
import Command from '../../../command.js';
import { OPERATION_ID_STATUS, ERROR_TYPE } from '../../../../constants/constants.js';
import {
OPERATION_ID_STATUS,
ERROR_TYPE,
OLD_CONTENT_STORAGE_MAP,
} from '../../../../constants/constants.js';

class GetValidateAssetCommand extends ValidateAssetCommand {
constructor(ctx) {
Expand Down Expand Up @@ -49,30 +53,41 @@ class GetValidateAssetCommand extends ValidateAssetCommand {
blockchain,
);
// TODO: Update to validate knowledge asset index
const isValidUal = isOperationV0
? true
: await this.validationService.validateUal(blockchain, contract, knowledgeCollectionId);
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_VALIDATE_UAL_END,
operationId,
blockchain,
);
if (
!isOperationV0 &&
Object.values(OLD_CONTENT_STORAGE_MAP).every(
(ca) => !ca.toLowerCase().includes(contract.toLowerCase()),
)
) {
const isValidUal = await this.validationService.validateUal(
blockchain,
contract,
knowledgeCollectionId,
);

if (!isValidUal) {
await this.handleError(
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_VALIDATE_UAL_END,
operationId,
blockchain,
`Get for operation id: ${operationId}, UAL: ${ual}: there is no asset with this UAL.`,
this.errorType,
);
return Command.empty();

if (!isValidUal) {
await this.handleError(
operationId,
blockchain,
`Get for operation id: ${operationId}, UAL: ${ual}: there is no asset with this UAL.`,
this.errorType,
);
return Command.empty();
}

await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
OPERATION_ID_STATUS.GET.GET_VALIDATE_ASSET_END,
);
}

await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
OPERATION_ID_STATUS.GET.GET_VALIDATE_ASSET_END,
);
return this.continueSequence(
{
...command.data,
Expand Down
4 changes: 2 additions & 2 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,7 @@ class LocalGetCommand extends Command {

if (assertionId) {
assertionPromise = (async () => {
let result = null;
let result = {};
for (const repository of [
TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT,
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
Expand All @@ -124,7 +124,7 @@ class LocalGetCommand extends Command {
);
}

return result;
return result.split('\n').filter((res) => res.length > 0);
})();
} else {
assertionPromise = this.tripleStoreService
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 @@ -20,9 +20,10 @@ class PublishFindShardCommand extends FindShardCommand {

getOperationCommandSequence(nodePartOfShard, commandData) {
const sequence = [];
sequence.push(
commandData.isOperationV0 ? 'validateAssetCommand' : 'publishValidateAssetCommand',
);
if (!commandData.isOperationV0) {
sequence.push('publishValidateAssetCommand');
}

if (nodePartOfShard && !commandData.isOperationV0) {
sequence.push('localStoreCommand');
} else {
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
20 changes: 19 additions & 1 deletion src/commands/query/query-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,25 @@ class QueryCommand extends Command {
OPERATION_ID_STATUS.QUERY.QUERY_CONSTRUCT_QUERY_START,
operationId,
);
data = await this.tripleStoreService.construct(query, repository);

if (Array.isArray(repository)) {
const dataV6 = await this.tripleStoreService.construct(
query,
repository[0],
);
const dataV8 = await this.tripleStoreService.construct(
query,
repository[1],
);

data = this.dataService.removeDuplicateObjectsFromArray([
...dataV6,
...dataV8,
]);
} else {
data = await this.tripleStoreService.construct(query, repository);
}

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.QUERY.QUERY_CONSTRUCT_QUERY_END,
operationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class LocalStoreController extends BaseController {

await this.operationIdService.cacheOperationIdDataToFile(operationId, cachedAssertions);

const commandSequence = ['validateAssetCommand', 'localStoreCommand'];
const commandSequence = ['localStoreCommand'];

await this.commandExecutor.add({
name: commandSequence[0],
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
Loading