Skip to content

Commit

Permalink
Merge pull request #2689 from OriginTrail/v6/release/mainnet
Browse files Browse the repository at this point in the history
OriginTrail v6.0.13
  • Loading branch information
u-hubar authored Aug 24, 2023
2 parents a6b7321 + 3e22ffa commit 223e5b7
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 87 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: checks

on:
pull_request:
branches:
- v6/develop
types: [opened, reopened, synchronize]

env:
REPOSITORY_PASSWORD: password
Expand Down
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.

7 changes: 5 additions & 2 deletions src/commands/local-store/local-store-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ class LocalStoreCommand extends Command {
await this.commandExecutor.add({
name: 'deletePendingStateCommand',
sequence: [],
delay: updateCommitWindowDuration * 1000,
data: { ...command.data, repository: PENDING_STORAGE_REPOSITORIES.PRIVATE },
delay: (updateCommitWindowDuration + 60) * 1000,
data: {
...command.data,
assertionId: cachedData.public.assertionId,
},
transactional: false,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,24 @@ class HandleGetInitCommand extends HandleProtocolMessageCommand {
blockchain,
contract,
tokenId,
assertionId,
);
}

for (const repository of [
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY,
]) {
if (assertionExists) {
break;
if (!assertionExists) {
for (const repository of [
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY,
]) {
// eslint-disable-next-line no-await-in-loop
assertionExists = await this.tripleStoreService.assertionExists(
repository,
assertionId,
);
if (assertionExists) {
break;
}
}

// eslint-disable-next-line no-await-in-loop
assertionExists = await this.tripleStoreService.assertionExists(
repository,
assertionId,
);
}

await this.operationIdService.updateOperationIdStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
OPERATION_ID_STATUS.GET.GET_REMOTE_START,
);

let nquads;
if (
state !== GET_STATES.FINALIZED &&
blockchain != null &&
Expand All @@ -37,26 +38,24 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
blockchain,
contract,
tokenId,
assertionId,
operationId,
);
if (cachedAssertion?.public?.assertion?.length) {
return {
messageType: NETWORK_MESSAGE_TYPES.RESPONSES.ACK,
messageData: { nquads: cachedAssertion.public.assertion },
};
nquads = cachedAssertion.public.assertion;
}
}

let nquads;
for (const repository of [
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY,
]) {
// eslint-disable-next-line no-await-in-loop
nquads = await this.tripleStoreService.getAssertion(repository, assertionId);

if (nquads.length) {
break;
if (!nquads?.length) {
for (const repository of [
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY,
]) {
// eslint-disable-next-line no-await-in-loop
nquads = await this.tripleStoreService.getAssertion(repository, assertionId);
if (nquads.length) {
break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ class GetAssertionIdCommand extends Command {
}
}

return this.continueSequence(
{ ...command.data, state: assertionId, assertionId },
command.sequence,
);
return this.continueSequence({ ...command.data, state, assertionId }, command.sequence);
}

async handleError(operationId, errorMessage, errorType) {
Expand Down
58 changes: 35 additions & 23 deletions src/commands/protocols/get/sender/local-get-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Command from '../../../command.js';
import {
OPERATION_ID_STATUS,
ERROR_TYPE,
GET_STATES,
TRIPLE_STORE_REPOSITORIES,
PENDING_STORAGE_REPOSITORIES,
} from '../../../../constants/constants.js';
Expand All @@ -24,42 +25,50 @@ class LocalGetCommand extends Command {
* @param command
*/
async execute(command) {
const { operationId, blockchain, contract, tokenId, state } = command.data;
const { operationId, blockchain, contract, tokenId, assertionId, state } = command.data;
await this.operationIdService.updateOperationIdStatus(
operationId,
OPERATION_ID_STATUS.GET.GET_LOCAL_START,
);

const response = {};
for (const repository of [
PENDING_STORAGE_REPOSITORIES.PRIVATE,
PENDING_STORAGE_REPOSITORIES.PUBLIC,
]) {
// eslint-disable-next-line no-await-in-loop
const stateIsPending = await this.pendingStorageService.assetHasPendingState(
repository,
blockchain,
contract,
tokenId,
state,
);

if (stateIsPending) {
if (
state !== GET_STATES.FINALIZED &&
blockchain != null &&
contract != null &&
tokenId != null
) {
for (const repository of [
PENDING_STORAGE_REPOSITORIES.PRIVATE,
PENDING_STORAGE_REPOSITORIES.PUBLIC,
]) {
// eslint-disable-next-line no-await-in-loop
const cachedAssertion = await this.pendingStorageService.getCachedAssertion(
const stateIsPending = await this.pendingStorageService.assetHasPendingState(
repository,
blockchain,
contract,
tokenId,
operationId,
assertionId,
);

if (cachedAssertion?.public?.assertion?.length) {
response.assertion = cachedAssertion.public.assertion;
if (cachedAssertion?.private?.assertion?.length) {
response.privateAssertion = cachedAssertion.private.assertion;
if (stateIsPending) {
// eslint-disable-next-line no-await-in-loop
const cachedAssertion = await this.pendingStorageService.getCachedAssertion(
repository,
blockchain,
contract,
tokenId,
assertionId,
operationId,
);

if (cachedAssertion?.public?.assertion?.length) {
response.assertion = cachedAssertion.public.assertion;
if (cachedAssertion?.private?.assertion?.length) {
response.privateAssertion = cachedAssertion.private.assertion;
}
break;
}
break;
}
}
}
Expand All @@ -72,7 +81,10 @@ class LocalGetCommand extends Command {
TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY,
]) {
// eslint-disable-next-line no-await-in-loop
response.assertion = await this.tripleStoreService.getAssertion(repository, state);
response.assertion = await this.tripleStoreService.getAssertion(
repository,
assertionId,
);
if (response?.assertion?.length) break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,64 @@
import Command from '../../../command.js';
import { ERROR_TYPE } from '../../../../constants/constants.js';
import { ERROR_TYPE, PENDING_STORAGE_REPOSITORIES } from '../../../../constants/constants.js';

class DeletePendingStateCommand extends Command {
constructor(ctx) {
super(ctx);
this.blockchainModuleManager = ctx.blockchainModuleManager;
this.pendingStorageService = ctx.pendingStorageService;

this.errorType = ERROR_TYPE.UPDATE.UPDATE_DELETE_PENDING_STATE_ERROR;
}

async execute(command) {
const { blockchain, contract, tokenId, operationId, repository } = command.data;
const { blockchain, contract, tokenId, assertionId, operationId } = command.data;

await this.pendingStorageService.removeCachedAssertion(
repository,
this.logger.trace(
`Started ${command.name} for blockchain: ${blockchain} contract: ${contract}, ` +
`token id: ${tokenId}, assertion id: ${assertionId}`,
);

const assetStates = await this.blockchainModuleManager.getAssertionIds(
blockchain,
contract,
tokenId,
operationId,
);

if (assetStates.includes(assertionId)) {
this.logger.trace(
`Not clearing the pending storage as state was finalized and clearing is triggered by StateFinalized event.`,
);
return Command.empty();
}

for (const repository of [
PENDING_STORAGE_REPOSITORIES.PUBLIC,
PENDING_STORAGE_REPOSITORIES.PRIVATE,
]) {
// eslint-disable-next-line no-await-in-loop
const pendingStateExists = await this.pendingStorageService.assetHasPendingState(
repository,
blockchain,
contract,
tokenId,
assertionId,
);

if (!pendingStateExists) {
continue;
}

// eslint-disable-next-line no-await-in-loop
await this.pendingStorageService.removeCachedAssertion(
repository,
blockchain,
contract,
tokenId,
assertionId,
operationId,
);
}

return Command.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ class HandleUpdateRequestCommand extends HandleProtocolMessageCommand {
this.commandExecutor.add({
name: 'deletePendingStateCommand',
sequence: [],
delay: updateCommitWindowDuration * 1000,
data: { ...commandData, repository: PENDING_STORAGE_REPOSITORIES.PUBLIC },
delay: (updateCommitWindowDuration + 60) * 1000,
data: {
...commandData,
assertionId: cachedData.assertionId,
},
transactional: false,
}),
);
Expand Down
16 changes: 10 additions & 6 deletions src/service/blockchain-event-listener-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ class BlockchainEventListenerService {
blockchain,
contract,
tokenId,
assertionId,
);

const storePromises = [];
Expand Down Expand Up @@ -559,12 +560,15 @@ class BlockchainEventListenerService {
await Promise.all(storePromises);

// remove asset from pending storage
await this.pendingStorageService.removeCachedAssertion(
pendingRepository,
blockchain,
contract,
tokenId,
);
if (cachedData) {
await this.pendingStorageService.removeCachedAssertion(
pendingRepository,
blockchain,
contract,
tokenId,
assertionId,
);
}
}
}

Expand Down
15 changes: 6 additions & 9 deletions src/service/file-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class FileService {
}

async removeFolder(folderPath) {
// this.logger.trace(`Removing folder at path: ${folderPath}`);
this.logger.trace(`Removing folder at path: ${folderPath}`);

try {
await rm(folderPath, { recursive: true });
Expand Down Expand Up @@ -146,19 +146,16 @@ class FileService {
tokenId,
);

let pendingStorageFileName;
if (assertionId === undefined) {
[pendingStorageFileName] = await this.readDirectory(pendingStorageFolder);
} else {
pendingStorageFileName = assertionId;
}

return path.join(pendingStorageFolder, pendingStorageFileName);
return path.join(pendingStorageFolder, assertionId);
}

getArchiveFolderPath(subFolder) {
return path.join(this.getDataFolderPath(), ARCHIVE_FOLDER_NAME, subFolder);
}

getParentDirectory(filePath) {
return path.dirname(filePath);
}
}

export default FileService;
Loading

0 comments on commit 223e5b7

Please sign in to comment.