Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OriginTrail Devnet Preelease v6.5.1 #3242

Merged
merged 9 commits into from
Jul 17, 2024
45 changes: 40 additions & 5 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@
"port": "3306",
"host": "localhost",
"dialect": "mysql",
"logging": false
"logging": false,
"pool": {
"max": 120,
"min": 0,
"acquire": 60000,
"idle": 10000,
"evict": 1000
}
}
}
}
Expand Down Expand Up @@ -260,7 +267,14 @@
"port": "3306",
"host": "localhost",
"dialect": "mysql",
"logging": false
"logging": false,
"pool": {
"max": 120,
"min": 0,
"acquire": 60000,
"idle": 10000,
"evict": 1000
}
}
}
}
Expand Down Expand Up @@ -413,7 +427,14 @@
"port": "3306",
"host": "localhost",
"dialect": "mysql",
"logging": false
"logging": false,
"pool": {
"max": 120,
"min": 0,
"acquire": 60000,
"idle": 10000,
"evict": 1000
}
}
}
}
Expand Down Expand Up @@ -597,7 +618,14 @@
"port": "3306",
"host": "localhost",
"dialect": "mysql",
"logging": false
"logging": false,
"pool": {
"max": 120,
"min": 0,
"acquire": 60000,
"idle": 10000,
"evict": 1000
}
}
}
}
Expand Down Expand Up @@ -781,7 +809,14 @@
"port": "3306",
"host": "localhost",
"dialect": "mysql",
"logging": false
"logging": false,
"pool": {
"max": 120,
"min": 0,
"acquire": 60000,
"idle": 10000,
"evict": 1000
}
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ class OTNode {
this.logger,
this.config,
);


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

MigrationExecutor.executeRemoveDuplicateServiceAgreementMigration(
this.container,
this.logger,
this.config,
);
}

checkNodeVersion() {
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.0",
"version": "6.5.1",
"description": "OTNode V6",
"main": "index.js",
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ class BlockchainEpochCheckCommand extends Command {
command.period,
);

const numberOfBlockchains = this.blockchainModuleManager.getImplementationNames().length;

// We don't expect to have this many transactions in one epoch check window.
// This is just to make sure we don't schedule too many commands and block the queue
// TODO: find general solution for all commands scheduling blockchain transactions
totalTransactions = Math.min(totalTransactions, COMMAND_QUEUE_PARALLELISM * 0.3);
totalTransactions = Math.min(
totalTransactions,
Math.floor(COMMAND_QUEUE_PARALLELISM / numberOfBlockchains),
);

const transactionQueueLength =
this.blockchainModuleManager.getTotalTransactionQueueLength(blockchain);
Expand Down
2 changes: 1 addition & 1 deletion src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ export const ARCHIVE_UPDATE_RESPONSES_FOLDER = 'update_responses';
* How many commands will run in parallel
* @type {number}
*/
export const COMMAND_QUEUE_PARALLELISM = 100;
export const COMMAND_QUEUE_PARALLELISM = 150;

export const GET_LATEST_SERVICE_AGREEMENT_BATCH_SIZE = 50;

Expand Down
60 changes: 60 additions & 0 deletions src/migration/migration-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import MarkStakingEventsAsProcessedMigration from './mark-staking-events-as-proc
import RemoveServiceAgreementsForChiadoMigration from './remove-service-agreements-for-chiado-migration.js';
import MultipleOpWalletsUserConfigurationMigration from './multiple-op-wallets-user-configuration-migration.js';
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';

class MigrationExecutor {
static async executePullShardingTableMigration(container, logger, config) {
Expand Down Expand Up @@ -442,6 +444,64 @@ class MigrationExecutor {
}
}

static async executeServiceAgreementPruningMigration(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 blockchainModuleManager = container.resolve('blockchainModuleManager');
const serviceAgreementService = container.resolve('serviceAgreementService');

const migration = new ServiceAgreementPruningMigration(
'serviceAgreementPruningMigration',
logger,
config,
repositoryModuleManager,
blockchainModuleManager,
serviceAgreementService,
);
if (!(await migration.migrationAlreadyExecuted())) {
try {
await migration.migrate();
} catch (error) {
logger.error(
`Unable to execute service agreement pruning migration. Error: ${error.message}`,
);
}
}
}

static async executeRemoveDuplicateServiceAgreementMigration(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 blockchainModuleManager = container.resolve('blockchainModuleManager');

const migration = new RemoveDuplicateServiceAgreementMigration(
'removeDuplicateServiceAgreementMigration',
logger,
config,
repositoryModuleManager,
blockchainModuleManager,
);
if (!(await migration.migrationAlreadyExecuted())) {
try {
await migration.migrate();
} catch (error) {
logger.error(
`Unable to execute service agreement pruning migration. Error: ${error.message}`,
);
}
}
}

static exitNode(code = 0) {
process.exit(code);
}
Expand Down
43 changes: 43 additions & 0 deletions src/migration/remove-duplicate-service-agreement-migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import BaseMigration from './base-migration.js';

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

async executeMigration() {
const blockchainIds = this.blockchainModuleManager.getImplementationNames();

for (const blockchainId of blockchainIds) {
const incorrectServiceAgreementId = [];
const duplicateTokenIdsRestult =
// eslint-disable-next-line no-await-in-loop
await this.repositoryModuleManager.findDuplicateServiceAgreements(blockchainId);
const duplicateTokenIds = duplicateTokenIdsRestult.map((t) => t.dataValues.token_id);
const findDuplicateServiceAgreements =
// eslint-disable-next-line no-await-in-loop
await this.repositoryModuleManager.findServiceAgreementsByTokenIds(
duplicateTokenIds,
blockchainId,
);
for (const serviceAgreement of findDuplicateServiceAgreements) {
const blockchainAssertionId =
// eslint-disable-next-line no-await-in-loop
await this.blockchainModuleManager.getAssertionIdByIndex(
blockchainId,
serviceAgreement.assetStorageContractAddress,
serviceAgreement.tokenId,
serviceAgreement.stateIndex,
);
if (serviceAgreement.assertionId !== blockchainAssertionId) {
incorrectServiceAgreementId.push(serviceAgreement.agreementId);
}
}
// eslint-disable-next-line no-await-in-loop
await this.repositoryModuleManager.removeServiceAgreements(incorrectServiceAgreementId);
}
}
}
export default RemoveDuplicateServiceAgreementMigration;
35 changes: 35 additions & 0 deletions src/migration/service-agreement-pruning-migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import BaseMigration from './base-migration.js';

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

async executeMigration() {
const blockchainIds = this.blockchainModuleManager.getImplementationNames();

// eslint-disable-next-line no-await-in-loop
for (const blockchainId of blockchainIds) {
const assetStorageContractAddresses =
// 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],
);
}
}
}
export default ServiceAgreementPruningMigration;
19 changes: 9 additions & 10 deletions src/modules/network/implementation/libp2p-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,18 +397,17 @@ class Libp2pService {
let readResponseStart;
let readResponseEnd;
let response;
const abortSignalEventListener = async () => {
stream.abort();
response = null;
};
const timeoutController = new TimeoutController(timeout);
try {
readResponseStart = Date.now();

timeoutController.signal.addEventListener(
'abort',
async () => {
stream.abort();
response = null;
},
{ once: true },
);
timeoutController.signal.addEventListener('abort', abortSignalEventListener, {
once: true,
});

response = await this._readMessageFromStream(
stream,
Expand All @@ -420,12 +419,12 @@ class Libp2pService {
throw Error('Message timed out!');
}

timeoutController.signal.removeEventListener('abort');
timeoutController.signal.removeEventListener('abort', abortSignalEventListener);
timeoutController.clear();

readResponseEnd = Date.now();
} catch (error) {
timeoutController.signal.removeEventListener('abort');
timeoutController.signal.removeEventListener('abort', abortSignalEventListener);
timeoutController.clear();

readResponseEnd = Date.now();
Expand Down
Loading
Loading