From 8e59fba3718e69e68215324f33d54429de699f8c Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Thu, 18 Jul 2024 13:39:23 +0200 Subject: [PATCH] OriginTrail Devnet prerelease v6.5.1 Hotfix 1 (#3246) * Update installer.sh (#3224) - Added base blockchain integration. Co-authored-by: Mihajlo Pavlovic * Base mainnet integration (#3229) * Add hub contract * Update set scripts * Remove hotfix * Update package-lock * Fixed removal of the AbortSignal event listener (#3227) * Increasing number of service agreements considered in command and command executor (#3241) * Increase number of service agreements for commits fetched from DB * Increase number of service agreements for commits fetched from DB * Increse limit and command queue pararelism * Add dynamic scaling factor when scheduling commits and proofs * Migration to remove duplicate service agreements (#3240) * Add findDuplicateServiceAgreement function * Expand query in findDuplicateServiceAgreement function * Add RemoveDuplicateServiceAgreementMigration * Fix migration queries * Migration tested and working * version bump * Add default connection pool to node (#3238) * Prune corrupted service agreement (#3237) * Add removeServiceAgreementsByBlockchainAndContract function * Change removeServiceAgreementsByBlockchainAndContract to remove all service agreements except ones with given contract * Add service agreement pruning migration * Fix epoch check scaling factor * Migration fixes --------- Co-authored-by: Samuel Wamala <35219064+swamala@users.noreply.github.com> Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> --- ot-node.js | 13 ++++++------ package-lock.json | 4 ++-- package.json | 2 +- src/migration/migration-executor.js | 2 +- .../service-agreement-pruning-migration.js | 21 ++++++++++++++----- .../service-agreement-repository.js | 19 +++++++++++++---- .../repository/repository-module-manager.js | 8 +++++++ 7 files changed, 49 insertions(+), 20 deletions(-) diff --git a/ot-node.js b/ot-node.js index 4900e328d..754425752 100644 --- a/ot-node.js +++ b/ot-node.js @@ -78,6 +78,12 @@ class OTNode { this.config, ); + await MigrationExecutor.executeServiceAgreementPruningMigration( + this.container, + this.logger, + this.config, + ); + await this.initializeRouters(); await this.startNetworkModule(); this.startTelemetryModule(); @@ -90,13 +96,6 @@ class OTNode { this.config, ); - - MigrationExecutor.executeServiceAgreementPruningMigration( - this.container, - this.logger, - this.config, - ); - MigrationExecutor.executeRemoveDuplicateServiceAgreementMigration( this.container, this.logger, diff --git a/package-lock.json b/package-lock.json index bc8afa769..4004d3ae0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.5.1", + "version": "6.5.1+hotfix.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.5.1", + "version": "6.5.1+hotfix.1", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index e7f54dafa..e72debf9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.5.1", + "version": "6.5.1+hotfix.1", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/migration/migration-executor.js b/src/migration/migration-executor.js index a3e2635ec..77469b986 100644 --- a/src/migration/migration-executor.js +++ b/src/migration/migration-executor.js @@ -496,7 +496,7 @@ class MigrationExecutor { await migration.migrate(); } catch (error) { logger.error( - `Unable to execute service agreement pruning migration. Error: ${error.message}`, + `Unable to execute remove duplicate service agreement migration. Error: ${error.message}`, ); } } diff --git a/src/migration/service-agreement-pruning-migration.js b/src/migration/service-agreement-pruning-migration.js index 2e7853c75..c29ba4de1 100644 --- a/src/migration/service-agreement-pruning-migration.js +++ b/src/migration/service-agreement-pruning-migration.js @@ -24,11 +24,22 @@ class ServiceAgreementPruningMigration extends BaseMigration { // eslint-disable-next-line no-await-in-loop await this.blockchainModuleManager.getAssetStorageContractAddresses(blockchainId); - // eslint-disable-next-line no-await-in-loop - await this.repositoryModuleManager.removeServiceAgreementsByBlockchainAndContract( - blockchainId, - assetStorageContractAddresses[0], - ); + const countOfServiceAgreementsToBeRemoved = + // eslint-disable-next-line no-await-in-loop + await this.repositoryModuleManager.getCountOfServiceAgreementsByBlockchainAndContract( + blockchainId, + assetStorageContractAddresses[0], + ); + + // removeServiceAgreementsByBlockchainAndContract deletes in batches od 100_000 + const numberOfIteration = Math.ceil(countOfServiceAgreementsToBeRemoved / 100_000); + for (let i = 0; i < numberOfIteration; i += 1) { + // eslint-disable-next-line no-await-in-loop + await this.repositoryModuleManager.removeServiceAgreementsByBlockchainAndContract( + blockchainId, + assetStorageContractAddresses[0], + ); + } } } } diff --git a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js index 6857a46a5..1c3a6725c 100644 --- a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js +++ b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js @@ -287,9 +287,8 @@ class ServiceAgreementRepository { }); } - - async removeServiceAgreementsByBlockchainAndContract(blockchainId, contract) { - await this.model.destroy({ + async getCountOfServiceAgreementsByBlockchainAndContract(blockchainId, contract) { + await this.model.count({ where: { blockchainId, assetStorageContractAddress: { @@ -298,7 +297,19 @@ class ServiceAgreementRepository { }, }); } - + + async removeServiceAgreementsByBlockchainAndContract(blockchainId, contract) { + const query = ` + DELETE FROM service_agreement + WHERE blockchain_id = '${blockchainId}' + AND asset_storage_contract_address = '${contract}' + LIMIT 100000; + `; + await this.model.query(query, { + type: Sequelize.QueryTypes.DELETE, + }); + } + async findDuplicateServiceAgreements(blockchainId) { return this.model.findAll({ attributes: ['token_id', [Sequelize.fn('COUNT', Sequelize.col('*')), 'count']], diff --git a/src/modules/repository/repository-module-manager.js b/src/modules/repository/repository-module-manager.js index 33f6ffb44..eea9d4983 100644 --- a/src/modules/repository/repository-module-manager.js +++ b/src/modules/repository/repository-module-manager.js @@ -403,6 +403,14 @@ class RepositoryModuleManager extends BaseModuleManager { } } + async getCountOfServiceAgreementsByBlockchainAndContract(blockchainId, contract) { + if (this.initialized) { + return this.getRepository( + 'service_agreement', + ).getCountOfServiceAgreementsByBlockchainAndContract(blockchainId, contract); + } + } + async removeServiceAgreementsByBlockchainAndContract(blockchainId, contract) { if (this.initialized) { return this.getRepository(