Skip to content

Commit

Permalink
OriginTrail Devnet prerelease v6.5.1 Hotfix 1 (#3246)
Browse files Browse the repository at this point in the history
* Update installer.sh (#3224)

- Added base blockchain integration.

Co-authored-by: Mihajlo Pavlovic <mihajlo.pavlovic@origin-trail.com>

* 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>
  • Loading branch information
3 people authored Jul 18, 2024
1 parent 076aea3 commit 8e59fba
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 20 deletions.
13 changes: 6 additions & 7 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -90,13 +96,6 @@ class OTNode {
this.config,
);


MigrationExecutor.executeServiceAgreementPruningMigration(
this.container,
this.logger,
this.config,
);

MigrationExecutor.executeRemoveDuplicateServiceAgreementMigration(
this.container,
this.logger,
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.

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": "6.5.1",
"version": "6.5.1+hotfix.1",
"description": "OTNode V6",
"main": "index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/migration/migration-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
);
}
}
Expand Down
21 changes: 16 additions & 5 deletions src/migration/service-agreement-pruning-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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']],
Expand Down
8 changes: 8 additions & 0 deletions src/modules/repository/repository-module-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8e59fba

Please sign in to comment.