Skip to content

Commit

Permalink
Merge pull request #3072 from OriginTrail/v6/prerelease/mainnet
Browse files Browse the repository at this point in the history
OriginTrail Mainnet Release v6.2.2
  • Loading branch information
djordjekovac authored Mar 1, 2024
2 parents 96cf197 + 17901cb commit de85f9c
Show file tree
Hide file tree
Showing 14 changed files with 363 additions and 92 deletions.
6 changes: 6 additions & 0 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class OTNode {
this.startTelemetryModule();
this.resumeCommandExecutor();
this.logger.info('Node is up and running!');

MigrationExecutor.executeGetOldServiceAgreementsMigration(
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.2.1",
"version": "6.2.2",
"description": "OTNode V6",
"main": "index.js",
"type": "module",
Expand Down
5 changes: 2 additions & 3 deletions src/commands/command-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class CommandExecutor {
* @private
*/
async _addDefaultCommand(name) {
await this._delete(name);
await this.delete(name);
const handler = this.commandResolver.resolve(name);
if (!handler) {
this.logger.warn(`Command '${name}' will not be executed.`);
Expand Down Expand Up @@ -376,9 +376,8 @@ class CommandExecutor {
* Delete command from database
* @param name
* @returns {Promise<void>}
* @private
*/
async _delete(name) {
async delete(name) {
await this.repositoryModuleManager.destroyCommand(name);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-await-in-loop */
import Command from '../../command.js';
import Command from '../../../command.js';
import {
COMMAND_QUEUE_PARALLELISM,
COMMAND_RETRIES,
Expand All @@ -8,9 +8,9 @@ import {
ERROR_TYPE,
TRIPLE_STORE_REPOSITORIES,
SERVICE_AGREEMENT_START_TIME_DELAY_FOR_COMMITS_SECONDS,
} from '../../../constants/constants.js';
} from '../../../../constants/constants.js';

class EpochCheckCommand extends Command {
class BlockchainEpochCheckCommand extends Command {
constructor(ctx) {
super(ctx);
this.commandExecutor = ctx.commandExecutor;
Expand All @@ -24,76 +24,81 @@ class EpochCheckCommand extends Command {
this.hashingService = ctx.hashingService;
this.tripleStoreService = ctx.tripleStoreService;

this.errorType = ERROR_TYPE.COMMIT_PROOF.EPOCH_CHECK_ERROR;
this.errorType = ERROR_TYPE.COMMIT_PROOF.BLOCKCHAIN_EPOCH_CHECK_ERROR;
}

async execute(command) {
this.logger.info('Epoch check: Starting epoch check command');
const operationId = this.operationIdService.generateId();

await Promise.all(
this.blockchainModuleManager.getImplementationNames().map(async (blockchain) => {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.EPOCH_CHECK_START,
operationId,
blockchain,
);
const { operationId, blockchain } = command.data;
this.logger.info(
`Epoch check: Starting blockchain epoch check command for ${blockchain} with operation id: ${operationId}`,
);

const commitWindowDurationPerc =
await this.blockchainModuleManager.getCommitWindowDurationPerc(blockchain);
const proofWindowDurationPerc =
await this.blockchainModuleManager.getProofWindowDurationPerc(blockchain);
let totalTransactions = await this.calculateTotalTransactions(
blockchain,
commitWindowDurationPerc,
proofWindowDurationPerc,
command.period,
);
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.EPOCH_CHECK_START,
operationId,
blockchain,
);

// 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);
const commitWindowDurationPerc =
await this.blockchainModuleManager.getCommitWindowDurationPerc(blockchain);
const proofWindowDurationPerc =
await this.blockchainModuleManager.getProofWindowDurationPerc(blockchain);
let totalTransactions = await this.calculateTotalTransactions(
blockchain,
commitWindowDurationPerc,
proofWindowDurationPerc,
command.period,
);

const transactionQueueLength =
this.blockchainModuleManager.getTotalTransactionQueueLength(blockchain);
if (transactionQueueLength >= totalTransactions) return;
// 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);

const transactionQueueLength =
this.blockchainModuleManager.getTotalTransactionQueueLength(blockchain);
if (transactionQueueLength >= totalTransactions) {
this.logger.debug(
`Epoch check: Current transaction queue length is ${transactionQueueLength}, ` +
`exceeding the maximum total transactions: ${totalTransactions} for ${blockchain}` +
`with operation id: ${operationId}`,
);
return Command.repeat();
}

totalTransactions -= transactionQueueLength;
totalTransactions -= transactionQueueLength;

const [r0, r2, totalNodesNumber, minStake, maxStake] = await Promise.all([
this.blockchainModuleManager.getR0(blockchain),
this.blockchainModuleManager.getR2(blockchain),
this.repositoryModuleManager.getPeersCount(blockchain),
this.blockchainModuleManager.getMinimumStake(blockchain),
this.blockchainModuleManager.getMaximumStake(blockchain),
]);
const [r0, r2, totalNodesNumber, minStake, maxStake] = await Promise.all([
this.blockchainModuleManager.getR0(blockchain),
this.blockchainModuleManager.getR2(blockchain),
this.repositoryModuleManager.getPeersCount(blockchain),
this.blockchainModuleManager.getMinimumStake(blockchain),
this.blockchainModuleManager.getMaximumStake(blockchain),
]);

await Promise.all([
this.scheduleSubmitCommitCommands(
blockchain,
Math.floor(totalTransactions / 2),
commitWindowDurationPerc,
r0,
r2,
totalNodesNumber,
minStake,
maxStake,
),
this.scheduleCalculateProofsCommands(
blockchain,
Math.ceil(totalTransactions / 2),
proofWindowDurationPerc,
r0,
),
]);
await Promise.all([
this.scheduleSubmitCommitCommands(
blockchain,
Math.floor(totalTransactions / 2),
commitWindowDurationPerc,
r0,
r2,
totalNodesNumber,
minStake,
maxStake,
),
this.scheduleCalculateProofsCommands(
blockchain,
Math.ceil(totalTransactions / 2),
proofWindowDurationPerc,
r0,
),
]);

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.EPOCH_CHECK_END,
operationId,
blockchain,
);
}),
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.EPOCH_CHECK_END,
operationId,
blockchain,
);

return Command.repeat();
Expand Down Expand Up @@ -440,13 +445,6 @@ class EpochCheckCommand extends Command {
return transactionsPerEpochCheck * numberOfWallets;
}

calculateCommandPeriod() {
const devEnvironment =
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';

return devEnvironment ? 30_000 : 120_000;
}

/**
* Recover system from failure
* @param command
Expand All @@ -465,14 +463,13 @@ class EpochCheckCommand extends Command {
*/
default(map) {
const command = {
name: 'epochCheckCommand',
name: 'blockchainEpochCheckCommand',
data: {},
transactional: false,
period: this.calculateCommandPeriod(),
};
Object.assign(command, map);
return command;
}
}

export default EpochCheckCommand;
export default BlockchainEpochCheckCommand;
74 changes: 74 additions & 0 deletions src/commands/protocols/common/epoch-check/epoch-check-command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import Command from '../../../command.js';
import { ERROR_TYPE } from '../../../../constants/constants.js';

class EpochCheckCommand extends Command {
constructor(ctx) {
super(ctx);
this.commandExecutor = ctx.commandExecutor;
this.blockchainModuleManager = ctx.blockchainModuleManager;

this.errorType = ERROR_TYPE.COMMIT_PROOF.EPOCH_CHECK_ERROR;
}

calculateCommandPeriod() {
const devEnvironment =
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';

return devEnvironment ? 30_000 : 120_000;
}

async execute() {
const operationId = this.operationIdService.generateId();

this.logger.info(
`Epoch check: Starting epoch check command for operation id: ${operationId}`,
);

await this.commandExecutor.delete('blockchainEpochCheckCommand');

await Promise.all(
this.blockchainModuleManager.getImplementationNames().map(async (blockchain) => {
const commandData = {
blockchain,
operationId,
};
return this.commandExecutor.add({
name: 'blockchainEpochCheckCommand',
data: commandData,
period: this.calculateCommandPeriod(),
});
}),
);

return Command.empty();
}

/**
* Recover system from failure
* @param command
* @param error
*/
async recover(command) {
this.logger.warn(`Failed to execute ${command.name}. Error: ${command.message}`);

return Command.repeat();
}

/**
* Builds default epochCheckCommand
* @param map
* @returns {{add, data: *, delay: *, deadline: *}}
*/
default(map) {
const command = {
name: 'epochCheckCommand',
data: {},
transactional: false,
period: this.calculateCommandPeriod(),
};
Object.assign(command, map);
return command;
}
}

export default EpochCheckCommand;
21 changes: 12 additions & 9 deletions src/commands/protocols/common/simple-asset-sync-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,29 @@ class SimpleAssetSyncCommand extends Command {
blockchain,
OPERATION_ID_STATUS.COMMIT_PROOF.SIMPLE_ASSET_SYNC_END,
);

if (getResult?.status === OPERATION_ID_STATUS.COMPLETED) {
const getOperationCachedData = await this.operationIdService.getCachedOperationIdData(
getOperationId,
);
if (getOperationCachedData.message === 'Unable to find assertion on the network!') {
this.logger.info(
`[SIMPLE_ASSET_SYNC] (${operationId}): Successfully executed command for the ` +
`[SIMPLE_ASSET_SYNC] (${operationId}): Failed to executed command. Couldn't find asset on the network for the ` +
`Blockchain: ${blockchain}, Contract: ${contract}, Token ID: ${tokenId}, ` +
`Keyword: ${keyword}, Hash function ID: ${hashFunctionId}, Epoch: ${epoch}, ` +
`State Index: ${stateIndex}, Network Get Operation ID: ${getOperationId}, `,
);

return this.continueSequence(command.data, command.sequence, {
retries: COMMAND_RETRIES.SUBMIT_COMMIT,
});
return Command.empty();
}

this.logger.log(
`[SIMPLE_ASSET_SYNC] (${operationId}): Failed to executed command. Couldn't find asset on the network for the ` +
this.logger.info(
`[SIMPLE_ASSET_SYNC] (${operationId}): Successfully executed command for the ` +
`Blockchain: ${blockchain}, Contract: ${contract}, Token ID: ${tokenId}, ` +
`Keyword: ${keyword}, Hash function ID: ${hashFunctionId}, Epoch: ${epoch}, ` +
`State Index: ${stateIndex}, Network Get Operation ID: ${getOperationId}, `,
);

return this.continueSequence(command.data, command.sequence, {
retries: COMMAND_RETRIES.SUBMIT_COMMIT,
});
}

async retryFinished(command) {
Expand Down
3 changes: 2 additions & 1 deletion src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export const NEURO_DEFAULT_GAS_PRICE = {

export const CONTRACT_FUNCTION_FIXED_GAS_PRICE = {
'otp:2043': {
SUBMIT_UPDATE_COMMIT: 15,
SUBMIT_UPDATE_COMMIT: 30,
},
};

Expand Down Expand Up @@ -337,6 +337,7 @@ export const ERROR_TYPE = {
COMMIT_PROOF: {
CALCULATE_PROOFS_ERROR: 'CalculateProofsError',
EPOCH_CHECK_ERROR: 'EpochCheckError',
BLOCKCHAIN_EPOCH_CHECK_ERROR: 'BlockchainEpochCheckError',
SIMPLE_ASSET_SYNC_ERROR: 'SimpleAssetSyncError',
SUBMIT_COMMIT_ERROR: 'SubmitCommitError',
SUBMIT_COMMIT_SEND_TX_ERROR: 'SubmitCommitSendTxError',
Expand Down
Loading

0 comments on commit de85f9c

Please sign in to comment.