From cfbf5ef5f61103ab50eaf844113813e7030c6df6 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Wed, 21 Jun 2023 11:43:42 +0100 Subject: [PATCH 01/11] Changed triggers fro Github Actions to trigger on PR to default branch and with 'release' labels --- .github/workflows/checks.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 64356fb2f4..b5067c0df0 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -3,7 +3,9 @@ name: checks on: pull_request: branches: - - v6/develop + - ${{ github.event.repository.default_branch }} + pull_request: + types: [labeled] env: REPOSITORY_PASSWORD: password @@ -15,6 +17,7 @@ concurrency: jobs: lint: + if: (github.event.pull_request.base.ref == '${{ github.event.repository.default_branch }}') || (github.event.label.name == 'release') runs-on: ubuntu-latest steps: - name: Checkout repository @@ -27,6 +30,7 @@ jobs: run: npm run lint unit-tests: + if: (github.event.pull_request.base.ref == '${{ github.event.repository.default_branch }}') || (github.event.label.name == 'release') runs-on: ubuntu-latest services: graphdb: @@ -44,6 +48,7 @@ jobs: run: npm run test:unit bdd-tests: + if: (github.event.pull_request.base.ref == '${{ github.event.repository.default_branch }}') || (github.event.label.name == 'release') runs-on: ubuntu-latest services: mysql: From 73d9c5b00c312bae69f68ebf0ec55b33af94f6d5 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Mon, 21 Aug 2023 15:14:09 +0100 Subject: [PATCH 02/11] Added missing assertionId in the pending-storage-service and get protocol commands, changed the way of deleting assertions in the pending storage --- .../local-store/local-store-command.js | 6 +- .../v1.0.0/v1-0-0-handle-get-init-command.js | 26 +++++---- .../v1-0-0-handle-get-request-command.js | 27 +++++---- .../get/sender/get-assertion-id-command.js | 5 +- .../protocols/get/sender/local-get-command.js | 58 +++++++++++-------- .../receiver/delete-pending-state-command.js | 4 +- .../v1-0-0-handle-update-request-command.js | 6 +- .../blockchain-event-listener-service.js | 2 + src/service/file-service.js | 15 ++--- src/service/pending-storage-service.js | 31 ++++++++-- 10 files changed, 109 insertions(+), 71 deletions(-) diff --git a/src/commands/local-store/local-store-command.js b/src/commands/local-store/local-store-command.js index 8719f8d322..b521cad034 100644 --- a/src/commands/local-store/local-store-command.js +++ b/src/commands/local-store/local-store-command.js @@ -94,7 +94,11 @@ class LocalStoreCommand extends Command { name: 'deletePendingStateCommand', sequence: [], delay: updateCommitWindowDuration * 1000, - data: { ...command.data, repository: PENDING_STORAGE_REPOSITORIES.PRIVATE }, + data: { + ...command.data, + repository: PENDING_STORAGE_REPOSITORIES.PRIVATE, + assertionId: cachedData.public.assertionId, + }, transactional: false, }); } diff --git a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-init-command.js b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-init-command.js index e8bcd7aee4..8dbef0a104 100644 --- a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-init-command.js +++ b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-init-command.js @@ -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( diff --git a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js index 55adc3989e..6723db4509 100644 --- a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js +++ b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js @@ -26,6 +26,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { OPERATION_ID_STATUS.GET.GET_REMOTE_START, ); + let nquads; if ( state !== GET_STATES.FINALIZED && blockchain != null && @@ -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; + } } } diff --git a/src/commands/protocols/get/sender/get-assertion-id-command.js b/src/commands/protocols/get/sender/get-assertion-id-command.js index b4af9d93d3..cf40c8d681 100644 --- a/src/commands/protocols/get/sender/get-assertion-id-command.js +++ b/src/commands/protocols/get/sender/get-assertion-id-command.js @@ -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) { diff --git a/src/commands/protocols/get/sender/local-get-command.js b/src/commands/protocols/get/sender/local-get-command.js index f9d09cf0f8..8d64f8186e 100644 --- a/src/commands/protocols/get/sender/local-get-command.js +++ b/src/commands/protocols/get/sender/local-get-command.js @@ -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'; @@ -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; } } } @@ -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; } } diff --git a/src/commands/protocols/update/receiver/delete-pending-state-command.js b/src/commands/protocols/update/receiver/delete-pending-state-command.js index a8b824e674..596f8a1755 100644 --- a/src/commands/protocols/update/receiver/delete-pending-state-command.js +++ b/src/commands/protocols/update/receiver/delete-pending-state-command.js @@ -10,13 +10,15 @@ class DeletePendingStateCommand extends Command { } async execute(command) { - const { blockchain, contract, tokenId, operationId, repository } = command.data; + const { repository, blockchain, contract, tokenId, assertionId, operationId } = + command.data; await this.pendingStorageService.removeCachedAssertion( repository, blockchain, contract, tokenId, + assertionId, operationId, ); diff --git a/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js b/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js index 83eff51b71..152eeb56b5 100644 --- a/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js +++ b/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js @@ -101,7 +101,11 @@ class HandleUpdateRequestCommand extends HandleProtocolMessageCommand { name: 'deletePendingStateCommand', sequence: [], delay: updateCommitWindowDuration * 1000, - data: { ...commandData, repository: PENDING_STORAGE_REPOSITORIES.PUBLIC }, + data: { + ...commandData, + repository: PENDING_STORAGE_REPOSITORIES.PUBLIC, + assertionId: cachedData.assertionId, + }, transactional: false, }), ); diff --git a/src/service/blockchain-event-listener-service.js b/src/service/blockchain-event-listener-service.js index c5a252be41..0d1ce737c6 100644 --- a/src/service/blockchain-event-listener-service.js +++ b/src/service/blockchain-event-listener-service.js @@ -488,6 +488,7 @@ class BlockchainEventListenerService { blockchain, contract, tokenId, + assertionId, ); const storePromises = []; @@ -564,6 +565,7 @@ class BlockchainEventListenerService { blockchain, contract, tokenId, + assertionId, ); } } diff --git a/src/service/file-service.js b/src/service/file-service.js index aa1c5be91b..68096b91f6 100644 --- a/src/service/file-service.js +++ b/src/service/file-service.js @@ -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 }); @@ -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; diff --git a/src/service/pending-storage-service.js b/src/service/pending-storage-service.js index a882ce40af..1fa64b2ebd 100644 --- a/src/service/pending-storage-service.js +++ b/src/service/pending-storage-service.js @@ -34,11 +34,11 @@ class PendingStorageService { ); } - async getCachedAssertion(repository, blockchain, contract, tokenId, operationId) { + async getCachedAssertion(repository, blockchain, contract, tokenId, assertionId, operationId) { const ual = this.ualService.deriveUAL(blockchain, contract, tokenId); this.logger.debug( - `Reading cached assertion for ual: ${ual}, operation id: ${operationId} from file in ${repository} pending storage`, + `Reading cached assertion for ual: ${ual}, assertion id: ${assertionId}, operation id: ${operationId} from file in ${repository} pending storage`, ); try { const documentPath = await this.fileService.getPendingStorageDocumentPath( @@ -46,30 +46,49 @@ class PendingStorageService { blockchain, contract, tokenId, + assertionId, ); const data = await this.fileService.readFile(documentPath, true); return data; } catch (error) { - this.logger.debug('Assertion not found in pending storage'); + this.logger.debug( + `Assertion not found in pending storage. Error message: ${error.message}, ${error.stackTrace}`, + ); return null; } } - async removeCachedAssertion(repository, blockchain, contract, tokenId, operationId) { + async removeCachedAssertion( + repository, + blockchain, + contract, + tokenId, + assertionId, + operationId, + ) { const ual = this.ualService.deriveUAL(blockchain, contract, tokenId); this.logger.debug( `Removing cached assertion for ual: ${ual} operation id: ${operationId} from file in ${repository} pending storage`, ); - const pendingStorageFolderPath = this.fileService.getPendingStorageFolderPath( + const pendingAssertionPath = this.fileService.getPendingStorageDocumentPath( repository, blockchain, contract, tokenId, + assertionId, ); - await this.fileService.removeFolder(pendingStorageFolderPath); + await this.fileService.removeFile(pendingAssertionPath); + + const pendingStorageFolderPath = this.fileService.getParentDirectory(pendingAssertionPath); + const otherPendingAssertions = await this.fileService.readDirectory( + pendingStorageFolderPath, + ); + if (otherPendingAssertions.length === 0) { + await this.fileService.removeFolder(pendingStorageFolderPath); + } } async assetHasPendingState(repository, blockchain, contract, tokenId, assertionId) { From 354da760b331ae1803e7e5e9e77886bbe100860b Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Mon, 21 Aug 2023 15:33:13 +0100 Subject: [PATCH 03/11] Removed pending storage folders deletion --- src/service/file-service.js | 4 ---- src/service/pending-storage-service.js | 8 -------- 2 files changed, 12 deletions(-) diff --git a/src/service/file-service.js b/src/service/file-service.js index 68096b91f6..13eb0155a3 100644 --- a/src/service/file-service.js +++ b/src/service/file-service.js @@ -152,10 +152,6 @@ class FileService { getArchiveFolderPath(subFolder) { return path.join(this.getDataFolderPath(), ARCHIVE_FOLDER_NAME, subFolder); } - - getParentDirectory(filePath) { - return path.dirname(filePath); - } } export default FileService; diff --git a/src/service/pending-storage-service.js b/src/service/pending-storage-service.js index 1fa64b2ebd..4b7f9fb1cc 100644 --- a/src/service/pending-storage-service.js +++ b/src/service/pending-storage-service.js @@ -81,14 +81,6 @@ class PendingStorageService { assertionId, ); await this.fileService.removeFile(pendingAssertionPath); - - const pendingStorageFolderPath = this.fileService.getParentDirectory(pendingAssertionPath); - const otherPendingAssertions = await this.fileService.readDirectory( - pendingStorageFolderPath, - ); - if (otherPendingAssertions.length === 0) { - await this.fileService.removeFolder(pendingStorageFolderPath); - } } async assetHasPendingState(repository, blockchain, contract, tokenId, assertionId) { From 80fc8510eb1c03269d94a8e56bc67162122c4e9c Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Tue, 22 Aug 2023 09:48:10 +0100 Subject: [PATCH 04/11] Reverted pending storage folders removal, updated deletePendingStateCommand to only remove unfinalized states --- .../local-store/local-store-command.js | 3 +- .../receiver/delete-pending-state-command.js | 28 ++++++++++++++----- .../v1-0-0-handle-update-request-command.js | 3 +- src/service/file-service.js | 4 +++ src/service/pending-storage-service.js | 8 ++++++ 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/commands/local-store/local-store-command.js b/src/commands/local-store/local-store-command.js index b521cad034..5bf84abc00 100644 --- a/src/commands/local-store/local-store-command.js +++ b/src/commands/local-store/local-store-command.js @@ -93,10 +93,9 @@ class LocalStoreCommand extends Command { await this.commandExecutor.add({ name: 'deletePendingStateCommand', sequence: [], - delay: updateCommitWindowDuration * 1000, + delay: (updateCommitWindowDuration + 60) * 1000, data: { ...command.data, - repository: PENDING_STORAGE_REPOSITORIES.PRIVATE, assertionId: cachedData.public.assertionId, }, transactional: false, diff --git a/src/commands/protocols/update/receiver/delete-pending-state-command.js b/src/commands/protocols/update/receiver/delete-pending-state-command.js index 596f8a1755..f803ff6607 100644 --- a/src/commands/protocols/update/receiver/delete-pending-state-command.js +++ b/src/commands/protocols/update/receiver/delete-pending-state-command.js @@ -1,27 +1,41 @@ 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 { repository, blockchain, contract, tokenId, assertionId, operationId } = - command.data; + const { blockchain, contract, tokenId, assertionId, operationId } = command.data; - await this.pendingStorageService.removeCachedAssertion( - repository, + const assetStates = this.blockchainModuleManager.getAssertionIds( blockchain, contract, tokenId, - assertionId, - operationId, ); + if (!assetStates.includes(assertionId)) { + for (const repository of [ + PENDING_STORAGE_REPOSITORIES.PUBLIC, + PENDING_STORAGE_REPOSITORIES.PRIVATE, + ]) { + // eslint-disable-next-line no-await-in-loop + await this.pendingStorageService.removeCachedAssertion( + repository, + blockchain, + contract, + tokenId, + assertionId, + operationId, + ); + } + } + return Command.empty(); } diff --git a/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js b/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js index 152eeb56b5..0429b3c1f3 100644 --- a/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js +++ b/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js @@ -100,10 +100,9 @@ class HandleUpdateRequestCommand extends HandleProtocolMessageCommand { this.commandExecutor.add({ name: 'deletePendingStateCommand', sequence: [], - delay: updateCommitWindowDuration * 1000, + delay: (updateCommitWindowDuration + 60) * 1000, data: { ...commandData, - repository: PENDING_STORAGE_REPOSITORIES.PUBLIC, assertionId: cachedData.assertionId, }, transactional: false, diff --git a/src/service/file-service.js b/src/service/file-service.js index 13eb0155a3..68096b91f6 100644 --- a/src/service/file-service.js +++ b/src/service/file-service.js @@ -152,6 +152,10 @@ class FileService { getArchiveFolderPath(subFolder) { return path.join(this.getDataFolderPath(), ARCHIVE_FOLDER_NAME, subFolder); } + + getParentDirectory(filePath) { + return path.dirname(filePath); + } } export default FileService; diff --git a/src/service/pending-storage-service.js b/src/service/pending-storage-service.js index 4b7f9fb1cc..1fa64b2ebd 100644 --- a/src/service/pending-storage-service.js +++ b/src/service/pending-storage-service.js @@ -81,6 +81,14 @@ class PendingStorageService { assertionId, ); await this.fileService.removeFile(pendingAssertionPath); + + const pendingStorageFolderPath = this.fileService.getParentDirectory(pendingAssertionPath); + const otherPendingAssertions = await this.fileService.readDirectory( + pendingStorageFolderPath, + ); + if (otherPendingAssertions.length === 0) { + await this.fileService.removeFolder(pendingStorageFolderPath); + } } async assetHasPendingState(repository, blockchain, contract, tokenId, assertionId) { From 3d3cc67c8babe11919a90ee453adf589b57d880f Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Tue, 22 Aug 2023 10:26:26 +0100 Subject: [PATCH 05/11] Bumped version to 6.0.13+hotfix.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 175adb0e38..a6b688d824 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.0.12", + "version": "6.0.13+hotfix.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.0.12", + "version": "6.0.13+hotfix.1", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index 5ce51dfe14..f4f0f19f15 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.0.13", + "version": "6.0.13+hotfix.1", "description": "OTNode V6", "main": "index.js", "type": "module", From 3d57e619dffbba3283b5edda9ef9d210f83be06f Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Tue, 22 Aug 2023 10:37:09 +0100 Subject: [PATCH 06/11] Fixed github checks triggers --- .github/workflows/checks.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index b5067c0df0..af3460ce07 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -2,10 +2,7 @@ name: checks on: pull_request: - branches: - - ${{ github.event.repository.default_branch }} - pull_request: - types: [labeled] + types: [opened, synchronize, labeled] env: REPOSITORY_PASSWORD: password @@ -17,7 +14,7 @@ concurrency: jobs: lint: - if: (github.event.pull_request.base.ref == '${{ github.event.repository.default_branch }}') || (github.event.label.name == 'release') + if: (github.event.pull_request.base.ref == github.event.repository.default_branch) || (github.event.label && github.event.label.name == 'release') runs-on: ubuntu-latest steps: - name: Checkout repository @@ -30,7 +27,7 @@ jobs: run: npm run lint unit-tests: - if: (github.event.pull_request.base.ref == '${{ github.event.repository.default_branch }}') || (github.event.label.name == 'release') + if: (github.event.pull_request.base.ref == github.event.repository.default_branch) || (github.event.label && github.event.label.name == 'release') runs-on: ubuntu-latest services: graphdb: @@ -48,7 +45,7 @@ jobs: run: npm run test:unit bdd-tests: - if: (github.event.pull_request.base.ref == '${{ github.event.repository.default_branch }}') || (github.event.label.name == 'release') + if: (github.event.pull_request.base.ref == github.event.repository.default_branch) || (github.event.label && github.event.label.name == 'release') runs-on: ubuntu-latest services: mysql: From a5deb642c5af2eaa9856bc1ea10dfbd6c9946fa5 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Tue, 22 Aug 2023 10:48:45 +0100 Subject: [PATCH 07/11] Changed github action checks trigger to all PRs --- .github/workflows/checks.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index af3460ce07..f7dee6cf44 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -2,7 +2,7 @@ name: checks on: pull_request: - types: [opened, synchronize, labeled] + types: [opened, reopened, synchronize] env: REPOSITORY_PASSWORD: password @@ -14,7 +14,6 @@ concurrency: jobs: lint: - if: (github.event.pull_request.base.ref == github.event.repository.default_branch) || (github.event.label && github.event.label.name == 'release') runs-on: ubuntu-latest steps: - name: Checkout repository @@ -27,7 +26,6 @@ jobs: run: npm run lint unit-tests: - if: (github.event.pull_request.base.ref == github.event.repository.default_branch) || (github.event.label && github.event.label.name == 'release') runs-on: ubuntu-latest services: graphdb: @@ -45,7 +43,6 @@ jobs: run: npm run test:unit bdd-tests: - if: (github.event.pull_request.base.ref == github.event.repository.default_branch) || (github.event.label && github.event.label.name == 'release') runs-on: ubuntu-latest services: mysql: From 71d23498c8d34630eb73018c85bde509d25d2d74 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Tue, 22 Aug 2023 12:50:17 +0100 Subject: [PATCH 08/11] Added missing await and folder existance check while removing pending storage folders --- package-lock.json | 4 ++-- package.json | 2 +- src/service/pending-storage-service.js | 14 ++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index a6b688d824..df11932a33 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.0.13+hotfix.1", + "version": "6.0.13+hotfix.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.0.13+hotfix.1", + "version": "6.0.13+hotfix.2", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index f4f0f19f15..4b38948566 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.0.13+hotfix.1", + "version": "6.0.13+hotfix.2", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/service/pending-storage-service.js b/src/service/pending-storage-service.js index 1fa64b2ebd..ebcd84f262 100644 --- a/src/service/pending-storage-service.js +++ b/src/service/pending-storage-service.js @@ -73,7 +73,7 @@ class PendingStorageService { `Removing cached assertion for ual: ${ual} operation id: ${operationId} from file in ${repository} pending storage`, ); - const pendingAssertionPath = this.fileService.getPendingStorageDocumentPath( + const pendingAssertionPath = await this.fileService.getPendingStorageDocumentPath( repository, blockchain, contract, @@ -83,11 +83,17 @@ class PendingStorageService { await this.fileService.removeFile(pendingAssertionPath); const pendingStorageFolderPath = this.fileService.getParentDirectory(pendingAssertionPath); - const otherPendingAssertions = await this.fileService.readDirectory( + const pendingStorageFolderExists = await this.fileService.pathExists( pendingStorageFolderPath, ); - if (otherPendingAssertions.length === 0) { - await this.fileService.removeFolder(pendingStorageFolderPath); + + if (pendingStorageFolderExists) { + const otherPendingAssertions = await this.fileService.readDirectory( + pendingStorageFolderPath, + ); + if (otherPendingAssertions.length === 0) { + await this.fileService.removeFolder(pendingStorageFolderPath); + } } } From 9b1d432973a185516a1fc72ef015de12bab4a804 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Tue, 22 Aug 2023 15:37:11 +0100 Subject: [PATCH 09/11] Added missing await, added checks before trying to delete pending storage assertions --- package-lock.json | 4 +- package.json | 2 +- .../v1-0-0-handle-get-request-command.js | 2 +- .../receiver/delete-pending-state-command.js | 53 +++++++++++++------ .../blockchain-event-listener-service.js | 16 +++--- src/service/pending-storage-service.js | 12 +++-- test/bdd/steps/lib/local-blockchain.mjs | 1 + 7 files changed, 59 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index df11932a33..fac197d02f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.0.13+hotfix.2", + "version": "6.0.13+hotfix.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.0.13+hotfix.2", + "version": "6.0.13+hotfix.3", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index 4b38948566..74822e2721 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.0.13+hotfix.2", + "version": "6.0.13+hotfix.3", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js index 6723db4509..576dbe8a5a 100644 --- a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js +++ b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js @@ -46,7 +46,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { } } - if (!nquads.length) { + if (!nquads?.length) { for (const repository of [ TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, diff --git a/src/commands/protocols/update/receiver/delete-pending-state-command.js b/src/commands/protocols/update/receiver/delete-pending-state-command.js index f803ff6607..defa18d8d2 100644 --- a/src/commands/protocols/update/receiver/delete-pending-state-command.js +++ b/src/commands/protocols/update/receiver/delete-pending-state-command.js @@ -13,27 +13,50 @@ class DeletePendingStateCommand extends Command { async execute(command) { const { blockchain, contract, tokenId, assertionId, operationId } = command.data; - const assetStates = this.blockchainModuleManager.getAssertionIds( + 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, ); - if (!assetStates.includes(assertionId)) { - for (const repository of [ - PENDING_STORAGE_REPOSITORIES.PUBLIC, - PENDING_STORAGE_REPOSITORIES.PRIVATE, - ]) { - // eslint-disable-next-line no-await-in-loop - await this.pendingStorageService.removeCachedAssertion( - repository, - blockchain, - contract, - tokenId, - assertionId, - 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(); diff --git a/src/service/blockchain-event-listener-service.js b/src/service/blockchain-event-listener-service.js index 0d1ce737c6..29d63ff71a 100644 --- a/src/service/blockchain-event-listener-service.js +++ b/src/service/blockchain-event-listener-service.js @@ -560,13 +560,15 @@ class BlockchainEventListenerService { await Promise.all(storePromises); // remove asset from pending storage - await this.pendingStorageService.removeCachedAssertion( - pendingRepository, - blockchain, - contract, - tokenId, - assertionId, - ); + if (cachedData) { + await this.pendingStorageService.removeCachedAssertion( + pendingRepository, + blockchain, + contract, + tokenId, + assertionId, + ); + } } } diff --git a/src/service/pending-storage-service.js b/src/service/pending-storage-service.js index ebcd84f262..0817453d27 100644 --- a/src/service/pending-storage-service.js +++ b/src/service/pending-storage-service.js @@ -53,7 +53,7 @@ class PendingStorageService { return data; } catch (error) { this.logger.debug( - `Assertion not found in pending storage. Error message: ${error.message}, ${error.stackTrace}`, + `Assertion not found in ${repository} pending storage. Error message: ${error.message}, ${error.stackTrace}`, ); return null; } @@ -83,17 +83,19 @@ class PendingStorageService { await this.fileService.removeFile(pendingAssertionPath); const pendingStorageFolderPath = this.fileService.getParentDirectory(pendingAssertionPath); - const pendingStorageFolderExists = await this.fileService.pathExists( - pendingStorageFolderPath, - ); - if (pendingStorageFolderExists) { + try { const otherPendingAssertions = await this.fileService.readDirectory( pendingStorageFolderPath, ); if (otherPendingAssertions.length === 0) { await this.fileService.removeFolder(pendingStorageFolderPath); } + } catch (error) { + this.logger.debug( + `Assertions folder not found in ${repository} pending storage. ` + + `Error message: ${error.message}, ${error.stackTrace}`, + ); } } diff --git a/test/bdd/steps/lib/local-blockchain.mjs b/test/bdd/steps/lib/local-blockchain.mjs index f9abf86ec8..9e64673298 100644 --- a/test/bdd/steps/lib/local-blockchain.mjs +++ b/test/bdd/steps/lib/local-blockchain.mjs @@ -20,6 +20,7 @@ const testParametersStorageParams = { minProofWindowOffsetPerc: 66, // 4 minutes maxProofWindowOffsetPerc: 66, // 4 minutes proofWindowDurationPerc: 33, // 2 minutes + updateCommitWindowDuration: 60, // 1 minite finalizationCommitsNumber: 3, }; /** From 034e49ba339e7a646bb7021a761640eb601a14ea Mon Sep 17 00:00:00 2001 From: Nikola Todorovic Date: Tue, 22 Aug 2023 16:48:57 +0200 Subject: [PATCH 10/11] Update test/bdd/steps/lib/local-blockchain.mjs --- test/bdd/steps/lib/local-blockchain.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bdd/steps/lib/local-blockchain.mjs b/test/bdd/steps/lib/local-blockchain.mjs index 9e64673298..777238c95d 100644 --- a/test/bdd/steps/lib/local-blockchain.mjs +++ b/test/bdd/steps/lib/local-blockchain.mjs @@ -20,7 +20,7 @@ const testParametersStorageParams = { minProofWindowOffsetPerc: 66, // 4 minutes maxProofWindowOffsetPerc: 66, // 4 minutes proofWindowDurationPerc: 33, // 2 minutes - updateCommitWindowDuration: 60, // 1 minite + updateCommitWindowDuration: 60, // 1 minute finalizationCommitsNumber: 3, }; /** From 77cecbd1b05fd62ad93a2cf44ba08ff862673458 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Wed, 23 Aug 2023 09:02:59 +0100 Subject: [PATCH 11/11] Removed hotfix suffix from the version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index fac197d02f..85d120a487 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.0.13+hotfix.3", + "version": "6.0.13", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.0.13+hotfix.3", + "version": "6.0.13", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index 74822e2721..5ce51dfe14 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.0.13+hotfix.3", + "version": "6.0.13", "description": "OTNode V6", "main": "index.js", "type": "module",