diff --git a/package-lock.json b/package-lock.json index 768776987..a5d0d34f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.0.4", + "version": "6.0.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.0.4", + "version": "6.0.5", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index 487fed873..161c92df8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.0.4", + "version": "6.0.5", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/commands/common/commands-cleaner-command.js b/src/commands/common/commands-cleaner-command.js index 4d1fc7068..a1f214eec 100644 --- a/src/commands/common/commands-cleaner-command.js +++ b/src/commands/common/commands-cleaner-command.js @@ -1,4 +1,5 @@ import Command from '../command.js'; +// eslint-disable-next-line no-unused-vars import { COMMAND_STATUS, FINALIZED_COMMAND_CLEANUP_TIME_MILLS } from '../../constants/constants.js'; /** @@ -16,12 +17,13 @@ class CommandsCleanerCommand extends Command { * @param command */ async execute() { - await this.repositoryModuleManager.removeFinalizedCommands([ - COMMAND_STATUS.COMPLETED, - COMMAND_STATUS.FAILED, - COMMAND_STATUS.EXPIRED, - COMMAND_STATUS.UNKNOWN, - ]); + // TODO: Uncomment after discussion + // await this.repositoryModuleManager.removeFinalizedCommands([ + // COMMAND_STATUS.COMPLETED, + // COMMAND_STATUS.FAILED, + // COMMAND_STATUS.EXPIRED, + // COMMAND_STATUS.UNKNOWN, + // ]); return Command.repeat(); } diff --git a/src/commands/local-store/local-store-command.js b/src/commands/local-store/local-store-command.js index 25c0b78fe..de2450dd2 100644 --- a/src/commands/local-store/local-store-command.js +++ b/src/commands/local-store/local-store-command.js @@ -58,7 +58,8 @@ class LocalStoreCommand extends Command { ); const agreementEndTime = - agreementData.startTime + agreementData.epochsNumber * agreementData.epochLength; + Number(agreementData.startTime) + + Number(agreementData.epochsNumber) * Number(agreementData.epochLength); if (storeType === LOCAL_STORE_TYPES.TRIPLE) { const storePromises = []; @@ -71,7 +72,7 @@ class LocalStoreCommand extends Command { blockchain, contract, tokenId, - agreementData.startTime, + Number(agreementData.startTime), agreementEndTime, keyword, ), @@ -86,7 +87,7 @@ class LocalStoreCommand extends Command { blockchain, contract, tokenId, - agreementData.startTime, + Number(agreementData.startTime), agreementEndTime, keyword, ), @@ -101,7 +102,7 @@ class LocalStoreCommand extends Command { tokenId, { ...cachedData, - agreementStartTime: agreementData.startTime, + agreementStartTime: Number(agreementData.startTime), agreementEndTime, keyword, }, diff --git a/src/commands/protocols/common/epoch-command.js b/src/commands/protocols/common/epoch-command.js index b3a3a6b4c..86950075e 100644 --- a/src/commands/protocols/common/epoch-command.js +++ b/src/commands/protocols/common/epoch-command.js @@ -21,17 +21,18 @@ class EpochCommand extends Command { assertionId, ) { const currentEpoch = await this.calculateCurrentEpoch( - agreementData.startTime, - agreementData.epochLength, + Number(agreementData.startTime), + Number(agreementData.epochLength), blockchain, ); const nextEpochStartTime = - agreementData.startTime + agreementData.epochLength * (currentEpoch + 1); + Number(agreementData.startTime) + + Number(agreementData.epochLength) * (currentEpoch + 1); const commitWindowDurationPerc = await this.blockchainModuleManager.getCommitWindowDurationPerc(blockchain); // delay by 10% of commit window length - const offset = ((agreementData.epochLength * commitWindowDurationPerc) / 100) * 0.1; + const offset = ((Number(agreementData.epochLength) * commitWindowDurationPerc) / 100) * 0.1; const now = await this.blockchainModuleManager.getBlockchainTimestamp(blockchain); @@ -72,7 +73,7 @@ class EpochCommand extends Command { async calculateCurrentEpoch(startTime, epochLength, blockchain) { const now = await this.blockchainModuleManager.getBlockchainTimestamp(blockchain); - return Math.floor((now - startTime) / epochLength); + return Math.floor((Number(now) - Number(startTime)) / Number(epochLength)); } /** diff --git a/src/commands/protocols/common/handle-protocol-message-command.js b/src/commands/protocols/common/handle-protocol-message-command.js index 37f8b9a32..0bdbc46be 100644 --- a/src/commands/protocols/common/handle-protocol-message-command.js +++ b/src/commands/protocols/common/handle-protocol-message-command.js @@ -129,11 +129,11 @@ class HandleProtocolMessageCommand extends Command { // todo: use shared function with epoch commands const currentEpoch = Math.floor( - (now - agreementData.startTime) / agreementData.epochLength, + (Number(now) - Number(agreementData.startTime)) / Number(agreementData.epochLength), ); // todo: consider optimizing to take into account cases where some proofs have already been submitted - const epochsLeft = agreementData.epochsNumber - currentEpoch; + const epochsLeft = Number(agreementData.epochsNumber) - currentEpoch; const divisor = this.blockchainModuleManager .toBigNumber(blockchain, r0) diff --git a/src/commands/protocols/publish/receiver/calculate-proofs-command.js b/src/commands/protocols/publish/receiver/calculate-proofs-command.js index 006f26f10..b6f0c215d 100644 --- a/src/commands/protocols/publish/receiver/calculate-proofs-command.js +++ b/src/commands/protocols/publish/receiver/calculate-proofs-command.js @@ -45,8 +45,8 @@ class CalculateProofsCommand extends EpochCommand { ); const epoch = await this.calculateCurrentEpoch( - agreementData.startTime, - agreementData.epochLength, + Number(agreementData.startTime), + Number(agreementData.epochLength), blockchain, ); diff --git a/src/commands/protocols/publish/receiver/epoch-check-command.js b/src/commands/protocols/publish/receiver/epoch-check-command.js index 413f9239c..fc9683d43 100644 --- a/src/commands/protocols/publish/receiver/epoch-check-command.js +++ b/src/commands/protocols/publish/receiver/epoch-check-command.js @@ -34,8 +34,8 @@ class EpochCheckCommand extends EpochCommand { agreementId, ); const epoch = await this.calculateCurrentEpoch( - agreementData.startTime, - agreementData.epochLength, + Number(agreementData.startTime), + Number(agreementData.epochLength), blockchain, ); this.logger.trace(`Epoch number: ${epoch}`); @@ -120,7 +120,7 @@ class EpochCheckCommand extends EpochCommand { } assetLifetimeExpired(agreementData, epoch) { - return epoch >= agreementData.epochsNumber; + return epoch >= Number(agreementData.epochsNumber); } /** diff --git a/src/commands/protocols/publish/receiver/submit-commit-command.js b/src/commands/protocols/publish/receiver/submit-commit-command.js index 376a7c791..e74abcd6f 100644 --- a/src/commands/protocols/publish/receiver/submit-commit-command.js +++ b/src/commands/protocols/publish/receiver/submit-commit-command.js @@ -115,18 +115,20 @@ class SubmitCommitCommand extends EpochCommand { async (result) => { if (!result.error) { const currentEpochStartTime = - agreementData.startTime + agreementData.epochLength * epoch; + Number(agreementData.startTime) + Number(agreementData.epochLength) * epoch; const proofWindowDurationPerc = await that.blockchainModuleManager.getProofWindowDurationPerc(blockchain); const proofWindowDuration = - (agreementData.epochLength * proofWindowDurationPerc) / 100; + (Number(agreementData.epochLength) * proofWindowDurationPerc) / 100; const proofWindowStartTime = currentEpochStartTime + Math.floor( - (agreementData.epochLength * agreementData.proofWindowOffsetPerc) / 100, + (Number(agreementData.epochLength) * + Number(agreementData.proofWindowOffsetPerc)) / + 100, ); // we are not using Date.now() here becouse we have an issue with hardhat blockchain time const timeNow = await that.blockchainModuleManager.getBlockchainTimestamp(); diff --git a/src/commands/protocols/publish/receiver/v1.0.0/v1-0-0-handle-store-request-command.js b/src/commands/protocols/publish/receiver/v1.0.0/v1-0-0-handle-store-request-command.js index 3b0122576..7aee52acc 100644 --- a/src/commands/protocols/publish/receiver/v1.0.0/v1-0-0-handle-store-request-command.js +++ b/src/commands/protocols/publish/receiver/v1.0.0/v1-0-0-handle-store-request-command.js @@ -59,7 +59,8 @@ class HandleStoreRequestCommand extends HandleProtocolMessageCommand { ); const agreementEndTime = - agreementData.startTime + agreementData.epochsNumber * agreementData.epochLength; + Number(agreementData.startTime) + + Number(agreementData.epochsNumber) * Number(agreementData.epochLength); await this.tripleStoreService.localStoreAsset( TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, @@ -68,7 +69,7 @@ class HandleStoreRequestCommand extends HandleProtocolMessageCommand { blockchain, contract, tokenId, - agreementData.startTime, + Number(agreementData.startTime), agreementEndTime, keyword, ); diff --git a/src/commands/protocols/update/receiver/submit-update-commit-command.js b/src/commands/protocols/update/receiver/submit-update-commit-command.js index 86ec09d21..3997d0798 100644 --- a/src/commands/protocols/update/receiver/submit-update-commit-command.js +++ b/src/commands/protocols/update/receiver/submit-update-commit-command.js @@ -31,8 +31,8 @@ class SubmitUpdateCommitCommand extends EpochCommand { } = command.data; const epoch = await this.calculateCurrentEpoch( - agreementData.startTime, - agreementData.epochLength, + Number(agreementData.startTime), + Number(agreementData.epochLength), blockchain, ); diff --git a/src/constants/constants.js b/src/constants/constants.js index 1f71b8582..0d286cc5d 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -332,7 +332,7 @@ export const OPERATION_ID_COMMAND_CLEANUP_TIME_MILLS = 24 * 60 * 60 * 1000; * @constant {number} FINALIZED_COMMAND_CLEANUP_TIME_MILLS - Command cleanup interval time * finalized commands command cleanup interval time 24h */ -export const FINALIZED_COMMAND_CLEANUP_TIME_MILLS = 24 * 60 * 60 * 1000; +export const FINALIZED_COMMAND_CLEANUP_TIME_MILLS = 30 * 24 * 60 * 60 * 1000; /** * @constant {number} COMMAND_STATUS - * Status for commands diff --git a/src/migration/private-assets-metadata-migration.js b/src/migration/private-assets-metadata-migration.js index 4a11e81f2..1e0f8e319 100644 --- a/src/migration/private-assets-metadata-migration.js +++ b/src/migration/private-assets-metadata-migration.js @@ -128,7 +128,8 @@ class PrivateAssetsMetadataMigration extends BaseMigration { ); const agreementEndTime = - agreementData.startTime + agreementData.epochsNumber * agreementData.epochLength; + Number(agreementData.startTime) + + Number(agreementData.epochsNumber) * Number(agreementData.epochLength); await this.tripleStoreService.insertAssetMetadata( TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, @@ -136,7 +137,7 @@ class PrivateAssetsMetadataMigration extends BaseMigration { assetStorageContractAddress, tokenId, assertionId, - agreementData.startTime, + Number(agreementData.startTime), agreementEndTime, keyword, ); @@ -156,7 +157,7 @@ class PrivateAssetsMetadataMigration extends BaseMigration { assetStorageContractAddress, tokenId, privateAssertionId, - agreementData.startTime, + Number(agreementData.startTime), agreementEndTime, keyword, ); diff --git a/src/modules/repository/implementation/sequelize/migrations/20230413194400-update-command-period-type.js b/src/modules/repository/implementation/sequelize/migrations/20230413194400-update-command-period-type.js new file mode 100644 index 000000000..5b19b434f --- /dev/null +++ b/src/modules/repository/implementation/sequelize/migrations/20230413194400-update-command-period-type.js @@ -0,0 +1,11 @@ +export async function up({ context: { queryInterface, Sequelize } }) { + await queryInterface.changeColumn('commands', 'period', { + type: Sequelize.BIGINT, + }); +} + +export async function down({ context: { queryInterface, Sequelize } }) { + await queryInterface.changeColumn('commands', 'period', { + type: Sequelize.BIGINT, + }); +}