Skip to content

Commit

Permalink
Fix sync after get merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihajlo-Pavlovic committed Jan 22, 2025
1 parent dd7c3eb commit b171bcf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 65 deletions.
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 5 additions & 44 deletions src/commands/paranet/paranet-sync-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class ParanetSyncCommand extends Command {
let getResult;

await this.commandExecutor.add({
name: 'localGetCommand',
name: 'getFindShardCommand',
sequence: [],
delay: 0,
data: {
Expand All @@ -177,12 +177,16 @@ class ParanetSyncCommand extends Command {
blockchain,
contract,
knowledgeCollectionId,
state: assertionId,
paranetId,
paranetUAL,
paranetNodesAccessPolicy,
paranetSync: true,
},
transactional: false,
});

attempt = 0;
do {
await setTimeout(pollingInterval);
getResult = await this.operationIdService.getOperationIdRecord(getOperationId);
Expand All @@ -192,49 +196,6 @@ class ParanetSyncCommand extends Command {
getResult?.status !== OPERATION_ID_STATUS.FAILED &&
getResult?.status !== OPERATION_ID_STATUS.COMPLETED
);
// #endregion

// #region GET (NETWORK)
if (getResult?.status !== OPERATION_ID_STATUS.COMPLETED) {
this.logger.info(
`Local GET failed for Knowledge Collection Id: ${knowledgeCollectionId}, attempting network GET.`,
);

// TODO: Fix networkGet
const networkCommandName =
paranetNodesAccessPolicy === 'OPEN'
? 'networkGetCommand'
: 'curatedParanetNetworkGetCommand';

await this.commandExecutor.add({
name: networkCommandName,
sequence: [],
delay: 0,
data: {
operationId: getOperationId,
id: ual,
blockchain,
contract,
knowledgeCollectionId,
state: assertionId,
assertionId,
paranetId,
paranetUAL,
},
transactional: false,
});

attempt = 0;
do {
await setTimeout(pollingInterval);
getResult = await this.operationIdService.getOperationIdRecord(getOperationId);
attempt += 1;
} while (
attempt < maxAttempts &&
getResult?.status !== OPERATION_ID_STATUS.FAILED &&
getResult?.status !== OPERATION_ID_STATUS.COMPLETED
);
}
// #endregion NETWORK END

if (getResult?.status !== OPERATION_ID_STATUS.COMPLETED) {
Expand Down
9 changes: 6 additions & 3 deletions src/commands/protocols/get/sender/get-find-shard-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ class GetFindShardCommand extends FindShardCommand {

// eslint-disable-next-line no-unused-vars
getOperationCommandSequence(nodePartOfShard, commandData) {
const sequence = [];
sequence.push('localGetCommand', 'networkGetCommand');

const sequence = ['localGetCommand'];
sequence.push(
commandData.paranetNodesAccessPolicy === 'OPEN'
? 'networkGetCommand'
: 'curatedParanetNetworkGetCommand',
);
return sequence;
}

Expand Down
10 changes: 8 additions & 2 deletions src/commands/protocols/get/sender/local-get-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class LocalGetCommand extends Command {
isOperationV0,
isV6Contract,
paranetUAL,
paranetSync,
} = command.data;
let { knowledgeAssetId } = command.data;
await this.operationIdService.updateOperationIdStatus(
Expand All @@ -45,7 +46,7 @@ class LocalGetCommand extends Command {
OPERATION_ID_STATUS.GET.GET_LOCAL_START,
);

if (paranetUAL) {
if (paranetUAL && !paranetSync) {
let assertion;
let metadata;

Expand All @@ -57,6 +58,11 @@ class LocalGetCommand extends Command {
);

const paranetRepository = this.paranetService.getParanetRepositoryName(paranetUAL);
knowledgeAssetId = await this.blockchainModuleManager.getKnowledgeAssetsRange(
blockchain,
contract,
knowledgeCollectionId,
);

assertion = await this.tripleStoreService.getAssertion(
blockchain,
Expand All @@ -72,7 +78,7 @@ class LocalGetCommand extends Command {
? assertion.split('\n').filter((res) => res.length > 0)
: assertion;

if (!assertion?.length) {
if (!assertion?.public?.length) {
this.handleError(
operationId,
blockchain,
Expand Down

0 comments on commit b171bcf

Please sign in to comment.