Skip to content

Commit

Permalink
Devnet pruning migration for Neuro tables (#3267)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihajlo-Pavlovic authored Aug 1, 2024
1 parent 2f67b37 commit 5dbae1b
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@
"enabled": false,
"package": "./blockchain/implementation/ot-parachain/ot-parachain-service.js",
"config": {
"hubContractAddress": "0x833048F6e6BEa78E0AAdedeCd2Dc2231dda443FB",
"hubContractAddress": "0x0425d8717a9c63345a26C7885CF8c0fEAbcE7bC9",
"rpcEndpoints": [
"https://lofar-tm-rpc.origin-trail.network",
"https://lofar.origintrail.network"
Expand Down
12 changes: 12 additions & 0 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ class OTNode {
this.config,
);

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

await MigrationExecutor.executeDevnetNeuroPruningMigration(
this.container,
this.logger,
this.config,
);

await this.initializeRouters();
await this.startNetworkModule();
this.startTelemetryModule();
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
34 changes: 34 additions & 0 deletions src/migration/devnet-neuro-pruning-migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import BaseMigration from './base-migration.js';
import { NODE_ENVIRONMENTS } from '../constants/constants.js';

class DevnetNeuroPruningMigration extends BaseMigration {
constructor(migrationName, logger, config, repositoryModuleManager) {
super(migrationName, logger, config);
this.repositoryModuleManager = repositoryModuleManager;
}

async executeMigration() {
if (process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVNET) {
this.logger.info('Pruning Neuro devenet tables');
// commands are not here as parsing JSON in SQL would take too much time
const tables = [
'blockchain',
'blockchain_event',
'event',
'missed_paranet_asset',
'paranet',
'service_agreement',
'shard',
];
for (const table of tables) {
const query = `
DELETE FROM ${table}
WHERE blockchain_id = 'otp:2160'`;
// eslint-disable-next-line no-await-in-loop
await this.repositoryModuleManager.query(query);
}
}
}
}

export default DevnetNeuroPruningMigration;
27 changes: 27 additions & 0 deletions src/migration/migration-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import MultipleOpWalletsUserConfigurationMigration from './multiple-op-wallets-u
import GetOldServiceAgreementsMigration from './get-old-service-agreements-migration.js';
import ServiceAgreementPruningMigration from './service-agreement-pruning-migration.js';
import RemoveDuplicateServiceAgreementMigration from './remove-duplicate-service-agreement-migration.js';
import DevnetNeuroPruningMigration from './devnet-neuro-pruning-migration.js';

class MigrationExecutor {
static async executePullShardingTableMigration(container, logger, config) {
Expand Down Expand Up @@ -502,6 +503,32 @@ class MigrationExecutor {
}
}

static async executeDevnetNeuroPruningMigration(container, logger, config) {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST
)
return;

const repositoryModuleManager = container.resolve('repositoryModuleManager');

const migration = new DevnetNeuroPruningMigration(
'devnetNeuroPruningMigration',
logger,
config,
repositoryModuleManager,
);
if (!(await migration.migrationAlreadyExecuted())) {
try {
await migration.migrate();
} catch (error) {
logger.error(
`Unable to execute devnet neuro pruning migration. Error: ${error.message}`,
);
}
}
}

static exitNode(code = 0) {
process.exit(code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OtParachainService extends Web3Service {
this.logger = logger;
this.rpcNumber = 0;
await this.initializeParachainProvider();
await this.checkEvmWallets();
// await this.checkEvmWallets();
await this.parachainProvider.disconnect();
await super.initialize(config, logger);
}
Expand Down

0 comments on commit 5dbae1b

Please sign in to comment.