From 9d5b447a87821c7dcb58335341902152b2003523 Mon Sep 17 00:00:00 2001 From: Zvonimir Sculac Date: Fri, 4 Oct 2024 11:39:37 +0200 Subject: [PATCH 1/8] Rename OTP to NEURO --- README.md | 8 ++--- config/config.json | 6 ++-- installer/installer.sh | 12 ++++---- src/constants/constants.js | 4 +-- .../devnet-neuro-pruning-migration.js | 2 +- ...k-staking-events-as-processed-migration.js | 2 +- ...-extension-user-configuration-migration.js | 2 +- .../neuroweb-service.js} | 8 ++--- .../20233010122500-update-blockchain-id.js | 16 +++++----- src/service/ual-service.js | 2 +- .../create-account-mapping-signature.js | 2 +- tools/substrate-accounts-mapping/README.md | 14 ++++----- .../accounts-mapping.js | 30 +++++++++---------- 13 files changed, 54 insertions(+), 54 deletions(-) rename src/modules/blockchain/implementation/{ot-parachain/ot-parachain-service.js => neuroweb/neuroweb-service.js} (97%) diff --git a/README.md b/README.md index 1bce41177e..00ec03ea89 100644 --- a/README.md +++ b/README.md @@ -124,25 +124,25 @@ By their nature, Knowledge Assets are semantic resources (following the W3C Sema
- + Knowledge Assets Graph 1
Supply Chains
- + Knowledge Assets Graph 2
Construction
- + Knowledge Assets Graph 3
Life sciences and healthcare
- + Knowledge Assets Graph 3
Metaverse diff --git a/config/config.json b/config/config.json index 9fb137d8ec..8778db649c 100644 --- a/config/config.json +++ b/config/config.json @@ -776,11 +776,11 @@ }, "blockchain": { "enabled": true, - "defaultImplementation": "otp:2043", + "defaultImplementation": "neuro:2043", "implementation": { - "otp:2043": { + "neuro:2043": { "enabled": false, - "package": "./blockchain/implementation/ot-parachain/ot-parachain-service.js", + "package": "./blockchain/implementation/neuroweb/neuroweb-service.js", "config": { "hubContractAddress": "0x5fA7916c48Fe6D5F1738d12Ad234b78c90B4cAdA", "rpcEndpoints": [ diff --git a/installer/installer.sh b/installer/installer.sh index 77754cc11a..759d7886dd 100755 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -297,13 +297,13 @@ install_node() { # Set blockchain options based on the selected environment if [ "$nodeEnv" == "mainnet" ]; then - blockchain_options=("OriginTrail Parachain" "Gnosis" "Base") - otp_blockchain_id=2043 + blockchain_options=("Neuroweb" "Gnosis" "Base") + neuroweb_blockchain_id=2043 gnosis_blockchain_id=100 base_blockchain_id=8453 else - blockchain_options=("OriginTrail Parachain" "Gnosis" "Base-Sepolia") - otp_blockchain_id=20430 + blockchain_options=("Neuroweb" "Gnosis" "Base-Sepolia") + neuroweb_blockchain_id=20430 gnosis_blockchain_id=10200 base_blockchain_id=84532 fi @@ -468,8 +468,8 @@ EOF # Configure selected blockchains for blockchain in "${selected_blockchains[@]}"; do case "$blockchain" in - "OriginTrail Parachain") - configure_blockchain "otp" $otp_blockchain_id + "Neuroweb") + configure_blockchain "neuro" $neuroweb_blockchain_id ;; "Gnosis") configure_blockchain "gnosis" $gnosis_blockchain_id diff --git a/src/constants/constants.js b/src/constants/constants.js index 14fd944b62..6b96e57fa5 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -218,7 +218,7 @@ export const NEURO_DEFAULT_GAS_PRICE = { }; export const CONTRACT_FUNCTION_FIXED_GAS_PRICE = { - 'otp:2043': { + 'neuro:2043': { SUBMIT_UPDATE_COMMIT: 30, }, }; @@ -691,7 +691,7 @@ export const CONTRACT_EVENT_FETCH_INTERVALS = { }; export const BLOCK_TIME_MILLIS = { - OTP: 12_000, + NEURO: 12_000, HARDHAT: 5_000, GNOSIS: 5_000, DEFAULT: 12_000, diff --git a/src/migration/devnet-neuro-pruning-migration.js b/src/migration/devnet-neuro-pruning-migration.js index 1fb9d6ca27..0ddd060b6e 100644 --- a/src/migration/devnet-neuro-pruning-migration.js +++ b/src/migration/devnet-neuro-pruning-migration.js @@ -23,7 +23,7 @@ class DevnetNeuroPruningMigration extends BaseMigration { for (const table of tables) { const query = ` DELETE FROM ${table} - WHERE blockchain_id = 'otp:2160'`; + WHERE blockchain_id = 'neuro:2160'`; // eslint-disable-next-line no-await-in-loop await this.repositoryModuleManager.query(query); } diff --git a/src/migration/mark-staking-events-as-processed-migration.js b/src/migration/mark-staking-events-as-processed-migration.js index 2fe63ac39d..c92688bb4b 100644 --- a/src/migration/mark-staking-events-as-processed-migration.js +++ b/src/migration/mark-staking-events-as-processed-migration.js @@ -16,7 +16,7 @@ class MarkStakingEventsAsProcessedMigration extends BaseMigration { const query = `update blockchain set last_checked_block = ${block.number}, last_checked_timestamp = ${timestamp} - where blockchain_id = 'otp:2043'`; + where blockchain_id = 'neuro:2043'`; await this.repositoryModuleManager.query(query); } } diff --git a/src/migration/ual-extension-user-configuration-migration.js b/src/migration/ual-extension-user-configuration-migration.js index 5d0c74f570..50fafb5363 100644 --- a/src/migration/ual-extension-user-configuration-migration.js +++ b/src/migration/ual-extension-user-configuration-migration.js @@ -56,7 +56,7 @@ class UalExtensionUserConfigurationMigration extends BaseMigration { let oldBlockchainId; if (userConfiguration.modules.blockchain.implementation) { for (const implementationName in userConfiguration.modules.blockchain.implementation) { - if (implementationName.includes('otp')) { + if (implementationName.includes('neuro')) { oldBlockchainId = implementationName; } } diff --git a/src/modules/blockchain/implementation/ot-parachain/ot-parachain-service.js b/src/modules/blockchain/implementation/neuroweb/neuroweb-service.js similarity index 97% rename from src/modules/blockchain/implementation/ot-parachain/ot-parachain-service.js rename to src/modules/blockchain/implementation/neuroweb/neuroweb-service.js index 9f4e15e51f..37c60a5a01 100644 --- a/src/modules/blockchain/implementation/ot-parachain/ot-parachain-service.js +++ b/src/modules/blockchain/implementation/neuroweb/neuroweb-service.js @@ -9,11 +9,11 @@ import Web3Service from '../web3-service.js'; const NATIVE_TOKEN_DECIMALS = 12; -class OtParachainService extends Web3Service { +class NeurowebService extends Web3Service { constructor(ctx) { super(ctx); - this.baseTokenTicker = 'OTP'; + this.baseTokenTicker = 'NEURO'; this.tracTicker = 'TRAC'; } @@ -175,7 +175,7 @@ class OtParachainService extends Web3Service { } getBlockTimeMillis() { - return BLOCK_TIME_MILLIS.OTP; + return BLOCK_TIME_MILLIS.NEURO; } getValidOperationalWallets() { @@ -203,4 +203,4 @@ class OtParachainService extends Web3Service { } } -export default OtParachainService; +export default NeurowebService; diff --git a/src/modules/repository/implementation/sequelize/migrations/20233010122500-update-blockchain-id.js b/src/modules/repository/implementation/sequelize/migrations/20233010122500-update-blockchain-id.js index 4074736ed8..4299b5351b 100644 --- a/src/modules/repository/implementation/sequelize/migrations/20233010122500-update-blockchain-id.js +++ b/src/modules/repository/implementation/sequelize/migrations/20233010122500-update-blockchain-id.js @@ -9,36 +9,36 @@ const chainId = CHAIN_IDS[process.env.NODE_ENV]; export async function up({ context: { queryInterface } }) { await queryInterface.sequelize.query(` - update shard set blockchain_id='otp:${chainId}' + update shard set blockchain_id='neuro:${chainId}' `); await queryInterface.sequelize.query(` - update service_agreement set blockchain_id='otp:${chainId}' + update service_agreement set blockchain_id='neuro:${chainId}' `); await queryInterface.sequelize.query(` - update blockchain_event set blockchain_id='otp:${chainId}' + update blockchain_event set blockchain_id='neuro:${chainId}' `); await queryInterface.sequelize.query(` - update blockchain set blockchain_id='otp:${chainId}' + update blockchain set blockchain_id='neuro:${chainId}' `); } export async function down({ context: { queryInterface } }) { await queryInterface.sequelize.query(` - update shard set blockchain_id='otp' + update shard set blockchain_id='neuro' `); await queryInterface.sequelize.query(` - update service_agreement set blockchain_id='otp' + update service_agreement set blockchain_id='neuro' `); await queryInterface.sequelize.query(` - update blockchain_event set blockchain_id='otp' + update blockchain_event set blockchain_id='neuro' `); await queryInterface.sequelize.query(` - update blockchain set blockchain_id='otp' + update blockchain set blockchain_id='neuro' `); } diff --git a/src/service/ual-service.js b/src/service/ual-service.js index f3f2b35266..92bcd83532 100644 --- a/src/service/ual-service.js +++ b/src/service/ual-service.js @@ -10,7 +10,7 @@ class UALService { return `did:dkg:${blockchain.toLowerCase()}/${contract.toLowerCase()}/${tokenId}`; } - // did:dkg:otp:2043/0x123231/5 + // did:dkg:neuro:2043/0x123231/5 isUAL(ual) { if (!ual.startsWith('did:dkg:')) return false; const parts = ual.replace('did:', '').replace('dkg:', '').split('/'); diff --git a/tools/ot-parachain-account-mapping/create-account-mapping-signature.js b/tools/ot-parachain-account-mapping/create-account-mapping-signature.js index 44ab86e6c0..50393f0971 100644 --- a/tools/ot-parachain-account-mapping/create-account-mapping-signature.js +++ b/tools/ot-parachain-account-mapping/create-account-mapping-signature.js @@ -58,7 +58,7 @@ async function sign() { }, primaryType: 'Transaction', domain: { - name: 'OTP EVM claim', + name: 'NEURO EVM claim', version: '1', chainId: '2160', salt: '0x0542e99b538e30d713d3e020f18fa6717eb2c5452bd358e0dd791628260a36f0', diff --git a/tools/substrate-accounts-mapping/README.md b/tools/substrate-accounts-mapping/README.md index 18f6129255..fe69de6e82 100644 --- a/tools/substrate-accounts-mapping/README.md +++ b/tools/substrate-accounts-mapping/README.md @@ -3,14 +3,14 @@ This tool: - generates one shared management wallet (pair of substrate and eth addresses) - generates NUMBER_OF_ACCOUNTS (default 32) operational wallets -- sends OTP to all substrate accounts +- sends NEURO to all substrate accounts - performs mapping between substrate and eth pairs - sends TRAC to all eth wallets - confirms that TRAC is received ## How to run -Inside the .env file is stored substrate and eth pair for distribution account that will send OTP and TRAC to newly generated wallets. +Inside the .env file is stored substrate and eth pair for distribution account that will send NEURO and TRAC to newly generated wallets. Example of env: ``` SUBSTRATE_ACCOUNT_PUBLIC_KEY="gJn..." @@ -42,22 +42,22 @@ Result will be stored in `wallets.json` in this format: ## How to modify -To change number of generated accounts, amount of OTP or TRAC to be sent, or other parameters, following variables should be modified: +To change number of generated accounts, amount of NEURO or TRAC to be sent, or other parameters, following variables should be modified: ```js const NUMBER_OF_ACCOUNTS = 32; -const OTP_AMOUNT = 50 * 1e12; // 50 OTP +const NEURO_AMOUNT = 50 * 1e12; // 50 NEURO const TRACE_AMOUNT = '0.000000001'; const GAS_PRICE = 20; const GAS_LIMIT = 60000; // Estimation is 45260 ``` -Script by default script is created to be used for OriginTrail Parachain Mainnet, by modification of following variables it can be used for other parachains: +Script by default script is created to be used for Neuroweb Mainnet, by modification of following variables it can be used for other parachains: ```js const TOKEN_ADDRESS = '0xffffffff00000000000000000000000000000001'; const HTTPS_ENDPOINT = 'https://astrosat-parachain-rpc.origin-trail.network'; -const OTP_CHAIN_ID = '2043'; -const OTP_GENESIS_HASH = '0xe7e0962324a3b86c83404dbea483f25fb5dab4c224791c81b756cfc948006174'; +const NEURO_CHAIN_ID = '2043'; +const NEURO_GENESIS_HASH = '0xe7e0962324a3b86c83404dbea483f25fb5dab4c224791c81b756cfc948006174'; ``` diff --git a/tools/substrate-accounts-mapping/accounts-mapping.js b/tools/substrate-accounts-mapping/accounts-mapping.js index b42858a3c9..daabd9d464 100644 --- a/tools/substrate-accounts-mapping/accounts-mapping.js +++ b/tools/substrate-accounts-mapping/accounts-mapping.js @@ -19,7 +19,7 @@ const ERC20Token = require('dkg-evm-module/abi/Token.json'); const WALLETS_PATH = path.join(appRootPath.path, 'tools/substrate-accounts-mapping/wallets.json'); -const otpAccountWithTokens = { +const neuroAccountWithTokens = { accountPublicKey: process.env.SUBSTRATE_ACCOUNT_PUBLIC_KEY, accountPrivateKey: process.env.SUBSTRATE_ACCOUNT_PRIVATE_KEY, }; @@ -33,9 +33,9 @@ const HTTPS_ENDPOINT = 'https://astrosat-parachain-rpc.origin-trail.network'; const NUMBER_OF_ACCOUNTS = 32; -const OTP_AMOUNT = 50 * 1e12; // 50 OTP <--- Check this! -const OTP_CHAIN_ID = '2043'; -const OTP_GENESIS_HASH = '0xe7e0962324a3b86c83404dbea483f25fb5dab4c224791c81b756cfc948006174'; +const NEURO_AMOUNT = 50 * 1e12; // 50 NEURO <--- Check this! +const NEURO_CHAIN_ID = '2043'; +const NEURO_GENESIS_HASH = '0xe7e0962324a3b86c83404dbea483f25fb5dab4c224791c81b756cfc948006174'; const GAS_PRICE = 20; const GAS_LIMIT = 60000; // Estimation is 45260 @@ -70,11 +70,11 @@ class AccountsMapping { } = await this.generateWallets(); // Fund management wallet - await this.fundAccountsWithOtp(substrateManagementWalletPublicKey); + await this.fundAccountsWithNeuro(substrateManagementWalletPublicKey); // Generate and fund all other wallets for (let i = 0; i < NUMBER_OF_ACCOUNTS; i += 1) { - console.log(`Generating and funding with OTP wallet #${i + 1}`); + console.log(`Generating and funding with NEURO wallet #${i + 1}`); const { evmPublicKey: evmOperationalWalletPublicKey, @@ -83,7 +83,7 @@ class AccountsMapping { substratePrivateKey: substrateOperationalWalletPrivateKey, } = await this.generateWallets(); - await this.fundAccountsWithOtp(substrateOperationalWalletPublicKey); + await this.fundAccountsWithNeuro(substrateOperationalWalletPublicKey); // Store new wallets currentWallets.push({ @@ -100,7 +100,7 @@ class AccountsMapping { } console.log('Waiting 35s for funding TXs to get into block!'); await this.sleepForMilliseconds(35 * 1000); - console.log(`${NUMBER_OF_ACCOUNTS} wallets are generated and funded with OTP!`); + console.log(`${NUMBER_OF_ACCOUNTS} wallets are generated and funded with NEURO!`); console.log(`Executing mapping!`); // Map the management wallet @@ -190,18 +190,18 @@ class AccountsMapping { 'claimAccount', [evmPublicKey, signature], ); - if (result.toHex() === '0x') throw Error('Unable to create account mapping for otp'); + if (result.toHex() === '0x') throw Error('Unable to create account mapping for neuro'); console.log(result.toString()); console.log(`Account mapped for evm public key: ${evmPublicKey}`); } - async fundAccountsWithOtp(substratePublicKey) { + async fundAccountsWithNeuro(substratePublicKey) { const keyring = new Keyring({ type: 'sr25519' }); keyring.setSS58Format(101); - const uriKeyring = keyring.addFromSeed(otpAccountWithTokens.accountPrivateKey); + const uriKeyring = keyring.addFromSeed(neuroAccountWithTokens.accountPrivateKey); return this.callParachainExtrinsic(uriKeyring, 'balances', 'transfer', [ substratePublicKey, - OTP_AMOUNT, + NEURO_AMOUNT, ]); } @@ -265,10 +265,10 @@ class AccountsMapping { }, primaryType: 'Transaction', domain: { - name: 'OTP EVM claim', + name: 'NEURO EVM claim', version: '1', - chainId: OTP_CHAIN_ID, - salt: OTP_GENESIS_HASH, + chainId: NEURO_CHAIN_ID, + salt: NEURO_GENESIS_HASH, }, message: { substrateAddress: hexPubKey, From ae28ba440efdfce2f658ce20a09f86588938db39 Mon Sep 17 00:00:00 2001 From: Zvonimir Sculac Date: Fri, 4 Oct 2024 12:17:47 +0200 Subject: [PATCH 2/8] Create MAX_BN and EVM_ZERO constants --- src/commands/common/validate-asset-command.js | 4 +- .../get/sender/get-assertion-id-command.js | 12 ++++-- .../publish-paranet-validate-asset.command.js | 4 +- src/constants/constants.js | 41 +++++++++++-------- .../blockchain/implementation/web3-service.js | 8 ++-- .../blockchain-event-listener-service.js | 4 +- src/service/proximity-scoring-service.js | 23 ++++------- src/service/validation-service.js | 4 +- .../simulation.js | 4 +- 9 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/commands/common/validate-asset-command.js b/src/commands/common/validate-asset-command.js index ec25cd8c01..c2e8fa4d0e 100644 --- a/src/commands/common/validate-asset-command.js +++ b/src/commands/common/validate-asset-command.js @@ -3,7 +3,7 @@ import { ERROR_TYPE, OPERATION_ID_STATUS, LOCAL_STORE_TYPES, - ZERO_BYTES32, + EVM_ZERO, } from '../../constants/constants.js'; class ValidateAssetCommand extends Command { @@ -49,7 +49,7 @@ class ValidateAssetCommand extends Command { tokenId, ); } - if (!blockchainAssertionId || blockchainAssertionId === ZERO_BYTES32) { + if (!blockchainAssertionId || blockchainAssertionId === EVM_ZERO.BYTES32) { return Command.retry(); } const cachedData = await this.operationIdService.getCachedOperationIdData(operationId); diff --git a/src/commands/protocols/get/sender/get-assertion-id-command.js b/src/commands/protocols/get/sender/get-assertion-id-command.js index beea10c2ce..9639b0a065 100644 --- a/src/commands/protocols/get/sender/get-assertion-id-command.js +++ b/src/commands/protocols/get/sender/get-assertion-id-command.js @@ -3,7 +3,7 @@ import { ERROR_TYPE, GET_STATES, PENDING_STORAGE_REPOSITORIES, - ZERO_BYTES32, + EVM_ZERO, } from '../../../../constants/constants.js'; class GetAssertionIdCommand extends Command { @@ -30,7 +30,7 @@ class GetAssertionIdCommand extends Command { ); let assertionId; if (!Object.values(GET_STATES).includes(state)) { - if (state === ZERO_BYTES32) { + if (state === EVM_ZERO.BYTES32) { await this.handleError( operationId, blockchain, @@ -104,7 +104,7 @@ class GetAssertionIdCommand extends Command { tokenId, ); } - if (unfinalizedAssertionId !== ZERO_BYTES32) { + if (unfinalizedAssertionId !== EVM_ZERO.BYTES32) { const updateCommitWindowOpen = await this.isUpdateCommitWindowOpen( blockchain, contract, @@ -125,7 +125,11 @@ class GetAssertionIdCommand extends Command { } } } - if (assertionId === null || assertionId === ZERO_BYTES32 || assertionId === undefined) { + if ( + assertionId === null || + assertionId === EVM_ZERO.BYTES32 || + assertionId === undefined + ) { assertionId = latestFinalizedAssertionId; } } diff --git a/src/commands/protocols/publish-paranet/sender/publish-paranet-validate-asset.command.js b/src/commands/protocols/publish-paranet/sender/publish-paranet-validate-asset.command.js index 9a389e2771..f285107888 100644 --- a/src/commands/protocols/publish-paranet/sender/publish-paranet-validate-asset.command.js +++ b/src/commands/protocols/publish-paranet/sender/publish-paranet-validate-asset.command.js @@ -4,7 +4,7 @@ import { // ERROR_TYPE, OPERATION_ID_STATUS, LOCAL_STORE_TYPES, - ZERO_BYTES32, + EVM_ZERO, PARANET_ACCESS_POLICY, } from '../../../../constants/constants.js'; @@ -116,7 +116,7 @@ class PublishParanetValidateAssetCommand extends ValidateAssetCommand { tokenId, ); } - if (!blockchainAssertionId || blockchainAssertionId === ZERO_BYTES32) { + if (!blockchainAssertionId || blockchainAssertionId === EVM_ZERO.BYTES32) { return Command.retry(); } this.logger.info( diff --git a/src/constants/constants.js b/src/constants/constants.js index 6b96e57fa5..d764db2c6f 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -8,27 +8,25 @@ export const FALLBACK_PROVIDER_QUORUM = 1; export const RPC_PROVIDER_STALL_TIMEOUT = 60 * 1000; -export const UINT256_MAX_BN = ethers.constants.MaxUint256; - -export const UINT128_MAX_BN = BigNumber.from(2).pow(128).sub(1); - -export const UINT64_MAX_BN = BigNumber.from(2).pow(64).sub(1); - -export const UINT40_MAX_BN = BigNumber.from(2).pow(40).sub(1); - -export const UINT32_MAX_BN = BigNumber.from(2).pow(32).sub(1); +export const MAX_BN = { + UINT256: ethers.constants.MaxUint256, + UINT128: BigNumber.from(2).pow(128).sub(1), + UINT64: BigNumber.from(2).pow(64).sub(1), + UINT40: BigNumber.from(2).pow(40).sub(1), + UINT32: BigNumber.from(2).pow(32).sub(1), +}; export const HASH_RING_SIZE = ethers.constants.MaxUint256; -export const STAKE_UINT256_MULTIPLIER_BN = UINT256_MAX_BN.div(500000000); +export const STAKE_UINT256_MULTIPLIER_BN = MAX_BN.UINT256.div(500000000); -export const UINT256_UINT32_DIVISOR_BN = UINT256_MAX_BN.div(UINT32_MAX_BN); +export const UINT256_UINT32_DIVISOR_BN = MAX_BN.UINT256.div(MAX_BN.UINT32); -export const ZERO_PREFIX = '0x'; - -export const ZERO_BYTES32 = ethers.constants.HashZero; - -export const ZERO_ADDRESS = ethers.constants.AddressZero; +export const EVM_ZERO = { + PREFIX: '0x', + BYTES32: ethers.constants.HashZero, + ADDRESS: ethers.constants.AddressZero, +}; export const SCHEMA_CONTEXT = 'http://schema.org/'; @@ -189,6 +187,17 @@ export const TRANSACTION_PRIORITY = { REGULAR: 2, }; +// TODO: this should be removed we won't have proofs & commits +export const CONTRACT_FUNCTION_PRIORITY = { + 'submitCommit((address,uint256,bytes,uint8,uint16,uint72,uint72,uint72))': + TRANSACTION_PRIORITY.REGULAR, + 'submitCommit((address,uint256,bytes,uint8,uint16))': TRANSACTION_PRIORITY.REGULAR, + 'submitUpdateCommit((address,uint256,bytes,uint8,uint16,uint72,uint72,uint72))': + TRANSACTION_PRIORITY.HIGH, + 'submitUpdateCommit((address,uint256,bytes,uint8,uint16))': TRANSACTION_PRIORITY.HIGH, + sendProof: TRANSACTION_PRIORITY.REGULAR, +}; + export const COMMAND_RETRIES = { SUBMIT_UPDATE_COMMIT: 5, }; diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index e3aba97a3e..89c40d2eee 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -9,7 +9,7 @@ import { SOLIDITY_ERROR_STRING_PREFIX, SOLIDITY_PANIC_CODE_PREFIX, SOLIDITY_PANIC_REASONS, - ZERO_PREFIX, + EVM_ZERO, MAXIMUM_NUMBERS_OF_BLOCKS_TO_FETCH, TRANSACTION_QUEUE_CONCURRENCY, TRANSACTION_POLLING_TIMEOUT_MILLIS, @@ -820,7 +820,7 @@ class Web3Service { } _decodeInputData(inputData, contractInterface) { - if (inputData === ZERO_PREFIX) { + if (inputData === EVM_ZERO.PREFIX) { return 'Empty input data.'; } @@ -837,7 +837,7 @@ class Web3Service { } // Handle empty error data - if (errorData === ZERO_PREFIX) { + if (errorData === EVM_ZERO.PREFIX) { return 'Empty error data.'; } @@ -881,7 +881,7 @@ class Web3Service { } _decodeResultData(fragment, resultData, contractInterface) { - if (resultData === ZERO_PREFIX) { + if (resultData === EVM_ZERO.PREFIX) { return 'Empty input data.'; } diff --git a/src/service/blockchain-event-listener-service.js b/src/service/blockchain-event-listener-service.js index b8210436a7..d89014aca1 100644 --- a/src/service/blockchain-event-listener-service.js +++ b/src/service/blockchain-event-listener-service.js @@ -11,7 +11,7 @@ import { DELAY_BETWEEN_FAILED_FETCH_EVENTS_MILLIS, CONTRACT_EVENT_TO_GROUP_MAPPING, GROUPED_CONTRACT_EVENTS, - ZERO_BYTES32, + EVM_ZERO, } from '../constants/constants.js'; const fetchEventsFailedCount = {}; @@ -564,7 +564,7 @@ class BlockchainEventListenerService { blockchain, knowledgeAssetId, ); - if (paranetId && paranetId !== ZERO_BYTES32) { + if (paranetId && paranetId !== EVM_ZERO.BYTES32) { // eslint-disable-next-line no-await-in-loop const paranetExists = await this.repositoryModuleManager.paranetExists( paranetId, diff --git a/src/service/proximity-scoring-service.js b/src/service/proximity-scoring-service.js index cf62d708f4..5d20496da7 100644 --- a/src/service/proximity-scoring-service.js +++ b/src/service/proximity-scoring-service.js @@ -1,10 +1,5 @@ import { xor as uint8ArrayXor } from 'uint8arrays/xor'; -import { - HASH_RING_SIZE, - UINT40_MAX_BN, - UINT64_MAX_BN, - UINT256_MAX_BN, -} from '../constants/constants.js'; +import { HASH_RING_SIZE, MAX_BN } from '../constants/constants.js'; class ProximityScoringService { constructor(ctx) { @@ -132,7 +127,7 @@ class ProximityScoringService { ? maxNeighborhoodDistance : idealMaxDistanceInNeighborhood; - const maxMultiplier = UINT256_MAX_BN.div(distance); + const maxMultiplier = MAX_BN.UINT256.div(distance); let scaledDistanceScaleFactor = distanceScaleFactor; let compensationFactor = 1; @@ -146,21 +141,21 @@ class ProximityScoringService { const adjustedDivisor = divisor.div(compensationFactor); let normalizedDistance = scaledDistance.div(adjustedDivisor); - if (normalizedDistance.gt(UINT64_MAX_BN)) { + if (normalizedDistance.gt(MAX_BN.UINT64)) { this.logger.warn( - `Invalid normalized distance: ${normalizedDistance.toString()}. Max value: ${UINT64_MAX_BN.toString()}`, + `Invalid normalized distance: ${normalizedDistance.toString()}. Max value: ${MAX_BN.UINT64.toString()}`, ); - normalizedDistance = normalizedDistance.mod(UINT64_MAX_BN.add(1)); + normalizedDistance = normalizedDistance.mod(MAX_BN.UINT64.add(1)); } let normalizedStake = stakeScaleFactor .mul(mappedStake.sub(mappedMinStake)) .div(mappedMaxStake.sub(mappedMinStake)); - if (normalizedStake.gt(UINT64_MAX_BN)) { + if (normalizedStake.gt(MAX_BN.UINT64)) { this.logger.warn( - `Invalid normalized stake: ${normalizedDistance.toString()}. Max value: ${UINT64_MAX_BN.toString()}`, + `Invalid normalized stake: ${normalizedDistance.toString()}. Max value: ${MAX_BN.UINT64.toString()}`, ); - normalizedStake = normalizedStake.mod(UINT64_MAX_BN.add(1)); + normalizedStake = normalizedStake.mod(MAX_BN.UINT64.add(1)); } const oneEther = await this.blockchainModuleManager.toBigNumber( @@ -190,7 +185,7 @@ class ProximityScoringService { } toUint40(value, maxValue) { - const result = value.mul(UINT40_MAX_BN).div(maxValue); + const result = value.mul(MAX_BN.UINT40).div(maxValue); return result; } } diff --git a/src/service/validation-service.js b/src/service/validation-service.js index 6782ddbc36..af1f6871f4 100644 --- a/src/service/validation-service.js +++ b/src/service/validation-service.js @@ -1,5 +1,5 @@ import { assertionMetadata } from 'assertion-tools'; -import { BYTES_IN_KILOBYTE, ZERO_ADDRESS } from '../constants/constants.js'; +import { BYTES_IN_KILOBYTE, EVM_ZERO } from '../constants/constants.js'; class ValidationService { constructor(ctx) { @@ -21,7 +21,7 @@ class ValidationService { contract, tokenId, ); - if (!result || result === ZERO_ADDRESS) { + if (!result || result === EVM_ZERO.ADDRESS) { isValid = false; } } catch (err) { diff --git a/tools/knowledge-assets-distribution-simulation/simulation.js b/tools/knowledge-assets-distribution-simulation/simulation.js index 1bab2dbfd4..bcfdfa43dc 100644 --- a/tools/knowledge-assets-distribution-simulation/simulation.js +++ b/tools/knowledge-assets-distribution-simulation/simulation.js @@ -11,7 +11,7 @@ import sharp from 'sharp'; import { readFile } from 'fs/promises'; import { createRequire } from 'module'; import { create as createLibP2PKey, createFromPrivKey } from 'peer-id'; -import { HASH_RING_SIZE, UINT128_MAX_BN } from '../../src/constants/constants.js'; +import { HASH_RING_SIZE, MAX_BN } from '../../src/constants/constants.js'; import BlockchainModuleManagerMock from './mocks/blockchain-module-manager-mock.js'; import HashingService from '../../src/service/hashing-service.js'; import ProximityScoringService from '../../src/service/proximity-scoring-service.js'; @@ -498,7 +498,7 @@ async function runSimulation( let dividend = node.distance; let divisor = maxDistance; - if (dividend.gt(UINT128_MAX_BN) || divisor.gt(UINT128_MAX_BN)) { + if (dividend.gt(MAX_BN.UINT128) || divisor.gt(MAX_BN.UINT128)) { dividend = dividend.div(distanceScaleFactor); divisor = divisor.div(distanceScaleFactor); } From 00850b9fe43e1e292f3bda662220f805fd3cc3a0 Mon Sep 17 00:00:00 2001 From: Zvonimir Sculac Date: Fri, 4 Oct 2024 12:48:33 +0200 Subject: [PATCH 3/8] Create LIBP2P constant --- src/migration/network-private-key-migration.js | 8 ++++---- src/modules/network/implementation/libp2p-service.js | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/migration/network-private-key-migration.js b/src/migration/network-private-key-migration.js index 70a18b1e8e..a90986ee08 100644 --- a/src/migration/network-private-key-migration.js +++ b/src/migration/network-private-key-migration.js @@ -1,7 +1,7 @@ import { join } from 'path'; import appRootPath from 'app-root-path'; import BaseMigration from './base-migration.js'; -import { LIBP2P_KEY_DIRECTORY, LIBP2P_KEY_FILENAME } from '../constants/constants.js'; +import { LIBP2P_KEY } from '../constants/constants.js'; class NetworkPrivateKeyMigration extends BaseMigration { async executeMigration() { @@ -19,18 +19,18 @@ class NetworkPrivateKeyMigration extends BaseMigration { appRootPath.path, '..', this.config.appDataPath, - LIBP2P_KEY_DIRECTORY, + LIBP2P_KEY.DIRECTORY, ); } else { directoryPath = join( appRootPath.path, this.config.appDataPath, - LIBP2P_KEY_DIRECTORY, + LIBP2P_KEY.DIRECTORY, ); } await this.fileService.writeContentsToFile( directoryPath, - LIBP2P_KEY_FILENAME, + LIBP2P_KEY.FILENAME, networkPrivateKey, ); } diff --git a/src/modules/network/implementation/libp2p-service.js b/src/modules/network/implementation/libp2p-service.js index 19d1eeb9df..0e44653ad8 100644 --- a/src/modules/network/implementation/libp2p-service.js +++ b/src/modules/network/implementation/libp2p-service.js @@ -20,8 +20,7 @@ import { NETWORK_API_SPAM_DETECTION, NETWORK_MESSAGE_TYPES, NETWORK_API_BLACK_LIST_TIME_WINDOW_MINUTES, - LIBP2P_KEY_DIRECTORY, - LIBP2P_KEY_FILENAME, + LIBP2P_KEY, NODE_ENVIRONMENTS, BYTES_IN_MEGABYTE, } from '../../../constants/constants.js'; @@ -144,13 +143,13 @@ class Libp2pService { appRootPath.path, '..', this.config.appDataPath, - LIBP2P_KEY_DIRECTORY, + LIBP2P_KEY.DIRECTORY, ); } else { - directoryPath = join(appRootPath.path, this.config.appDataPath, LIBP2P_KEY_DIRECTORY); + directoryPath = join(appRootPath.path, this.config.appDataPath, LIBP2P_KEY.DIRECTORY); } - const fullPath = join(directoryPath, LIBP2P_KEY_FILENAME); + const fullPath = join(directoryPath, LIBP2P_KEY.FILENAME); return { fullPath, directoryPath }; } From 88e1f31689ed873944676a2cbb048e9bedf379fd Mon Sep 17 00:00:00 2001 From: Zvonimir Sculac Date: Fri, 4 Oct 2024 12:49:53 +0200 Subject: [PATCH 4/8] Create SOLIDITY constant --- .../blockchain/implementation/web3-service.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index 89c40d2eee..5fa36b6e3a 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -6,9 +6,7 @@ import { setTimeout as sleep } from 'timers/promises'; import { createRequire } from 'module'; import { - SOLIDITY_ERROR_STRING_PREFIX, - SOLIDITY_PANIC_CODE_PREFIX, - SOLIDITY_PANIC_REASONS, + SOLIDITY, EVM_ZERO, MAXIMUM_NUMBERS_OF_BLOCKS_TO_FETCH, TRANSACTION_QUEUE_CONCURRENCY, @@ -842,8 +840,8 @@ class Web3Service { } // Handle standard solidity string error - if (errorData.startsWith(SOLIDITY_ERROR_STRING_PREFIX)) { - const encodedReason = errorData.slice(SOLIDITY_ERROR_STRING_PREFIX.length); + if (errorData.startsWith(SOLIDITY.ERROR_STRING_PREFIX)) { + const encodedReason = errorData.slice(SOLIDITY.ERROR_STRING_PREFIX.length); try { return ethers.utils.defaultAbiCoder.decode(['string'], `0x${encodedReason}`)[0]; } catch (error) { @@ -852,8 +850,8 @@ class Web3Service { } // Handle solidity panic code - if (errorData.startsWith(SOLIDITY_PANIC_CODE_PREFIX)) { - const encodedReason = errorData.slice(SOLIDITY_PANIC_CODE_PREFIX.length); + if (errorData.startsWith(SOLIDITY.PANIC_CODE_PREFIX)) { + const encodedReason = errorData.slice(SOLIDITY.PANIC_CODE_PREFIX.length); let code; try { [code] = ethers.utils.defaultAbiCoder.decode(['uint256'], `0x${encodedReason}`); @@ -861,7 +859,7 @@ class Web3Service { return error.message; } - return SOLIDITY_PANIC_REASONS[code] ?? 'Unknown Solidity panic code.'; + return SOLIDITY.PANIC_REASONS[code] ?? 'Unknown Solidity panic code.'; } // Try parsing a custom error using the contract ABI From 45b7ef1db2c6352f8439f9f2da7aa21d148c1f65 Mon Sep 17 00:00:00 2001 From: Zvonimir Sculac Date: Fri, 4 Oct 2024 12:53:58 +0200 Subject: [PATCH 5/8] Create TRIPLE_STORE constant --- scripts/copy-assertions.js | 10 +-- .../local-store/local-store-command.js | 6 +- src/commands/paranet/paranet-sync-command.js | 10 +-- .../v1.0.0/v1-0-0-handle-get-init-command.js | 6 +- .../v1-0-0-handle-get-request-command.js | 6 +- .../protocols/get/sender/local-get-command.js | 10 +-- .../v1-0-0-handle-store-request-command.js | 4 +- .../receiver/delete-pending-state-command.js | 10 +-- src/commands/query/query-command.js | 9 +-- src/constants/constants.js | 68 ++++++++++--------- .../private-assets-metadata-migration.js | 14 ++-- ...move-agreement-start-end-time-migration.js | 4 +- .../service-agreements-data-inspector.js | 6 +- ...rvice-agreements-invalid-data-migration.js | 34 +++++----- .../service-agreements-metadata-migration.js | 4 +- .../triple-store-metadata-migration.js | 14 ++-- .../ual-extension-triple-store-migration.js | 8 +-- src/modules/module-config-validation.js | 4 +- .../implementation/ot-triple-store.js | 17 ++--- .../blockchain-event-listener-service.js | 10 +-- src/service/get-service.js | 8 +-- src/service/triple-store-service.js | 6 +- .../modules/triple-store/triple-store.test.js | 6 +- 23 files changed, 137 insertions(+), 137 deletions(-) diff --git a/scripts/copy-assertions.js b/scripts/copy-assertions.js index a107f6a88b..75b235f6fc 100644 --- a/scripts/copy-assertions.js +++ b/scripts/copy-assertions.js @@ -3,7 +3,7 @@ import fs from 'fs-extra'; import rc from 'rc'; import appRootPath from 'app-root-path'; import path from 'path'; -import { TRIPLE_STORE_REPOSITORIES, SCHEMA_CONTEXT } from '../src/constants/constants.js'; +import { TRIPLE_STORE, SCHEMA_CONTEXT } from '../src/constants/constants.js'; import TripleStoreModuleManager from '../src/modules/triple-store/triple-store-module-manager.js'; import DataService from '../src/service/data-service.js'; import Logger from '../src/logger/logger.js'; @@ -29,15 +29,15 @@ for (const implementationName of tripleStoreModuleManager.getImplementationNames } } -const fromRepository = TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT; -const fromImplementation = repositoryImplementations[TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT]; +const fromRepository = TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT; +const fromImplementation = repositoryImplementations[TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT]; const fromRepositoryName = tripleStoreModuleManager.getImplementation(fromImplementation).module.repositories[ fromRepository ].name; -const toRepository = TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT; -const toImplementation = repositoryImplementations[TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT]; +const toRepository = TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT; +const toImplementation = repositoryImplementations[TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT]; const toRepositoryName = tripleStoreModuleManager.getImplementation(toImplementation).module.repositories[toRepository] .name; diff --git a/src/commands/local-store/local-store-command.js b/src/commands/local-store/local-store-command.js index 4a0aa82b31..a906f6502b 100644 --- a/src/commands/local-store/local-store-command.js +++ b/src/commands/local-store/local-store-command.js @@ -3,7 +3,7 @@ import { ERROR_TYPE, LOCAL_STORE_TYPES, PENDING_STORAGE_REPOSITORIES, - TRIPLE_STORE_REPOSITORIES, + TRIPLE_STORE, } from '../../constants/constants.js'; import Command from '../command.js'; @@ -51,7 +51,7 @@ class LocalStoreCommand extends Command { if (cachedData.public.assertion && cachedData.public.assertionId) { storePromises.push( this.tripleStoreService.localStoreAsset( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, cachedData.public.assertionId, cachedData.public.assertion, blockchain, @@ -64,7 +64,7 @@ class LocalStoreCommand extends Command { if (cachedData.private.assertion && cachedData.private.assertionId) { storePromises.push( this.tripleStoreService.localStoreAsset( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, cachedData.private.assertionId, cachedData.private.assertion, blockchain, diff --git a/src/commands/paranet/paranet-sync-command.js b/src/commands/paranet/paranet-sync-command.js index 6c702bb1e5..8754abb563 100644 --- a/src/commands/paranet/paranet-sync-command.js +++ b/src/commands/paranet/paranet-sync-command.js @@ -8,7 +8,7 @@ import { OPERATION_ID_STATUS, CONTENT_ASSET_HASH_FUNCTION_ID, PARANET_SYNC_PARAMETERS, - TRIPLE_STORE_REPOSITORIES, + TRIPLE_STORE, PARANET_SYNC_KA_COUNT, OPERATION_STATUS, PARANET_NODES_ACCESS_POLICIES, @@ -107,7 +107,7 @@ class ParanetSyncCommand extends Command { stateIndex, paranetId, tokenId, - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, false, // It should never delete as it never was in storage // But maybe will because this is unfinalized @@ -129,7 +129,7 @@ class ParanetSyncCommand extends Command { assertionIds.length - 1, paranetId, tokenId, - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, true, false, paranetUAL, @@ -236,7 +236,7 @@ class ParanetSyncCommand extends Command { stateIndex, paranetId, tokenId, - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, false, // It should never delete as it never was in storage // But maybe will because this is not finalized @@ -259,7 +259,7 @@ class ParanetSyncCommand extends Command { assertionIds.length - 1, paranetId, tokenId, - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, true, false, paranetUAL, diff --git a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-init-command.js b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-init-command.js index 663cec2e90..6e097db60c 100644 --- a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-init-command.js +++ b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-init-command.js @@ -5,7 +5,7 @@ import { NETWORK_MESSAGE_TYPES, OPERATION_ID_STATUS, PENDING_STORAGE_REPOSITORIES, - TRIPLE_STORE_REPOSITORIES, + TRIPLE_STORE, } from '../../../../../constants/constants.js'; class HandleGetInitCommand extends HandleProtocolMessageCommand { @@ -120,8 +120,8 @@ class HandleGetInitCommand extends HandleProtocolMessageCommand { if (!assertionExists) { for (const repository of [ - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, ]) { // eslint-disable-next-line no-await-in-loop assertionExists = await this.tripleStoreService.assertionExists( diff --git a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js index 19b50b71af..531097dfbe 100644 --- a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js +++ b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js @@ -5,7 +5,7 @@ import { NETWORK_MESSAGE_TYPES, OPERATION_ID_STATUS, GET_STATES, - TRIPLE_STORE_REPOSITORIES, + TRIPLE_STORE, PENDING_STORAGE_REPOSITORIES, } from '../../../../../constants/constants.js'; @@ -119,8 +119,8 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { if (!nquads?.length) { for (const repository of [ - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, ]) { // eslint-disable-next-line no-await-in-loop nquads = await this.tripleStoreService.getAssertion(repository, assertionId); diff --git a/src/commands/protocols/get/sender/local-get-command.js b/src/commands/protocols/get/sender/local-get-command.js index ba7f090576..3574fd5c38 100644 --- a/src/commands/protocols/get/sender/local-get-command.js +++ b/src/commands/protocols/get/sender/local-get-command.js @@ -3,7 +3,7 @@ import { OPERATION_ID_STATUS, ERROR_TYPE, GET_STATES, - TRIPLE_STORE_REPOSITORIES, + TRIPLE_STORE, PENDING_STORAGE_REPOSITORIES, } from '../../../../constants/constants.js'; @@ -129,10 +129,10 @@ class LocalGetCommand extends Command { if (!response?.assertion?.length) { for (const repository of [ - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, - TRIPLE_STORE_REPOSITORIES.PRIVATE_HISTORY, - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, ]) { // eslint-disable-next-line no-await-in-loop response.assertion = await this.tripleStoreService.getAssertion( 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 bda74a7bb0..7131d2cee4 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 @@ -4,7 +4,7 @@ import { NETWORK_MESSAGE_TYPES, OPERATION_ID_STATUS, ERROR_TYPE, - TRIPLE_STORE_REPOSITORIES, + TRIPLE_STORE, SERVICE_AGREEMENT_SOURCES, } from '../../../../../constants/constants.js'; @@ -62,7 +62,7 @@ class HandleStoreRequestCommand extends HandleProtocolMessageCommand { ); await this.tripleStoreService.localStoreAsset( - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, assertionId, assertion, blockchain, diff --git a/src/commands/protocols/update/receiver/delete-pending-state-command.js b/src/commands/protocols/update/receiver/delete-pending-state-command.js index 4edf754a55..745027ee71 100644 --- a/src/commands/protocols/update/receiver/delete-pending-state-command.js +++ b/src/commands/protocols/update/receiver/delete-pending-state-command.js @@ -2,7 +2,7 @@ import Command from '../../../command.js'; import { ERROR_TYPE, PENDING_STORAGE_REPOSITORIES, - TRIPLE_STORE_REPOSITORIES, + TRIPLE_STORE, } from '../../../../constants/constants.js'; class DeletePendingStateCommand extends Command { @@ -46,8 +46,8 @@ class DeletePendingStateCommand extends Command { ); await Promise.all([ this.pendingStorageService.moveAndDeletePendingState( - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, PENDING_STORAGE_REPOSITORIES.PUBLIC, blockchain, contract, @@ -58,8 +58,8 @@ class DeletePendingStateCommand extends Command { stateIndex, ), this.pendingStorageService.moveAndDeletePendingState( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, - TRIPLE_STORE_REPOSITORIES.PRIVATE_HISTORY, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_HISTORY, PENDING_STORAGE_REPOSITORIES.PRIVATE, blockchain, contract, diff --git a/src/commands/query/query-command.js b/src/commands/query/query-command.js index 74412a0cf5..1b79a7e8a8 100644 --- a/src/commands/query/query-command.js +++ b/src/commands/query/query-command.js @@ -1,6 +1,6 @@ import Command from '../command.js'; import { - TRIPLE_STORE_REPOSITORIES, + TRIPLE_STORE, QUERY_TYPES, OPERATION_ID_STATUS, ERROR_TYPE, @@ -20,7 +20,7 @@ class QueryCommand extends Command { async execute(command) { const { queryType, operationId } = command.data; - let { query, repository = TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT } = command.data; + let { query, repository = TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT } = command.data; let data; @@ -92,8 +92,9 @@ class QueryCommand extends Command { return paranetRepoName; } } - const isTripleStoreRepoValid = - Object.values(TRIPLE_STORE_REPOSITORIES).includes(repository); + const isTripleStoreRepoValid = Object.values(TRIPLE_STORE.REPOSITORIES).includes( + repository, + ); if (isTripleStoreRepoValid) { return repository; } diff --git a/src/constants/constants.js b/src/constants/constants.js index d764db2c6f..d78c36a24b 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -39,27 +39,44 @@ export const COMMITS_DELAY_BETWEEN_NODES_IN_BLOCKS = 5; export const TRANSACTION_POLLING_TIMEOUT_MILLIS = 300 * 1000; -export const SOLIDITY_ERROR_STRING_PREFIX = '0x08c379a0'; - -export const SOLIDITY_PANIC_CODE_PREFIX = '0x4e487b71'; - -export const SOLIDITY_PANIC_REASONS = { - 0x1: 'Assertion error', - 0x11: 'Arithmetic operation underflowed or overflowed outside of an unchecked block', - 0x12: 'Division or modulo division by zero', - 0x21: 'Tried to convert a value into an enum, but the value was too big or negative', - 0x22: 'Incorrectly encoded storage byte array', - 0x31: '.pop() was called on an empty array', - 0x32: 'Array accessed at an out-of-bounds or negative index', - 0x41: 'Too much memory was allocated, or an array was created that is too large', - 0x51: 'Called a zero-initialized variable of internal function type', +export const SOLIDITY = { + ERROR_STRING_PREFIX: '0x08c379a0', + PANIC_CODE_PREFIX: '0x4e487b71', + PANIC_REASONS: { + 0x1: 'Assertion error', + 0x11: 'Arithmetic operation underflowed or overflowed outside of an unchecked block', + 0x12: 'Division or modulo division by zero', + 0x21: 'Tried to convert a value into an enum, but the value was too big or negative', + 0x22: 'Incorrectly encoded storage byte array', + 0x31: '.pop() was called on an empty array', + 0x32: 'Array accessed at an out-of-bounds or negative index', + 0x41: 'Too much memory was allocated, or an array was created that is too large', + 0x51: 'Called a zero-initialized variable of internal function type', + }, }; -export const LIBP2P_KEY_DIRECTORY = 'libp2p'; - -export const LIBP2P_KEY_FILENAME = 'privateKey'; +export const LIBP2P_KEY = { + DIRECTORY: 'libp2p', + FILENAME: 'privateKey', +}; -export const TRIPLE_STORE_CONNECT_MAX_RETRIES = 10; +export const TRIPLE_STORE = { + CONNECT: { + MAX_RETRIES: 10, + RETRY_FREQUENCY: 10, + }, + REPOSITORIES: { + PUBLIC_CURRENT: 'publicCurrent', + PUBLIC_HISTORY: 'publicHistory', + PRIVATE_CURRENT: 'privateCurrent', + PRIVATE_HISTORY: 'privateHistory', + }, + IMPLEMENTATION: { + BLAZEGRAPH: 'Blazegraph', + GRAPHDB: 'GraphDB', + FUSEKI: 'Fuseki', + }, +}; export const DEFAULT_BLOCKCHAIN_EVENT_SYNC_PERIOD_IN_MILLS = 15 * 24 * 60 * 60 * 1000; // 15 days @@ -69,8 +86,6 @@ export const MAXIMUM_NUMBERS_OF_BLOCKS_TO_FETCH = 50; export const TRANSACTION_QUEUE_CONCURRENCY = 1; -export const TRIPLE_STORE_CONNECT_RETRY_FREQUENCY = 10; - export const MAX_FILE_SIZE = 10000000; export const GET_STATES = { LATEST: 'LATEST', FINALIZED: 'LATEST_FINALIZED' }; @@ -91,13 +106,6 @@ export const PARANET_ACCESS_POLICY = { CURATED: 1, }; -export const TRIPLE_STORE_REPOSITORIES = { - PUBLIC_CURRENT: 'publicCurrent', - PUBLIC_HISTORY: 'publicHistory', - PRIVATE_CURRENT: 'privateCurrent', - PRIVATE_HISTORY: 'privateHistory', -}; - export const PENDING_STORAGE_REPOSITORIES = { PUBLIC: 'public', PRIVATE: 'private', @@ -244,12 +252,6 @@ export const WEBSOCKET_PROVIDER_OPTIONS = { }, }; -export const TRIPLE_STORE_IMPLEMENTATION = { - BLAZEGRAPH: 'Blazegraph', - GRAPHDB: 'GraphDB', - FUSEKI: 'Fuseki', -}; - export const NETWORK_MESSAGE_TYPES = { REQUESTS: { PROTOCOL_INIT: 'PROTOCOL_INIT', diff --git a/src/migration/private-assets-metadata-migration.js b/src/migration/private-assets-metadata-migration.js index 3558c8aa68..42e8e25a94 100644 --- a/src/migration/private-assets-metadata-migration.js +++ b/src/migration/private-assets-metadata-migration.js @@ -1,6 +1,6 @@ /* eslint-disable no-await-in-loop */ import BaseMigration from './base-migration.js'; -import { TRIPLE_STORE_REPOSITORIES } from '../constants/constants.js'; +import { TRIPLE_STORE } from '../constants/constants.js'; class PrivateAssetsMetadataMigration extends BaseMigration { constructor( @@ -23,7 +23,7 @@ class PrivateAssetsMetadataMigration extends BaseMigration { async executeMigration() { const graphs = await this.tripleStoreService.select( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, `SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o } @@ -36,13 +36,13 @@ class PrivateAssetsMetadataMigration extends BaseMigration { if (!assertionIds?.length) { this.logger.debug( - `No assertions found in ${TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT} repository. Skipping migration.`, + `No assertions found in ${TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT} repository. Skipping migration.`, ); return; } this.logger.debug( - `${assertionIds.length} assertions found in ${TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT} repository.`, + `${assertionIds.length} assertions found in ${TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT} repository.`, ); for (const blockchain of this.blockchainModuleManager.getImplementationNames()) { const assetStorageContractAddresses = @@ -114,7 +114,7 @@ class PrivateAssetsMetadataMigration extends BaseMigration { ); await this.tripleStoreService.insertAssetAssertionMetadata( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, blockchain, assetStorageContractAddress, tokenId, @@ -123,7 +123,7 @@ class PrivateAssetsMetadataMigration extends BaseMigration { ); const assertion = await this.tripleStoreService.getAssertion( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, assertionId, ); @@ -132,7 +132,7 @@ class PrivateAssetsMetadataMigration extends BaseMigration { if (privateAssertionId == null || !assertionIds.includes(privateAssertionId)) return; await this.tripleStoreService.insertAssetAssertionMetadata( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, blockchain, assetStorageContractAddress, tokenId, diff --git a/src/migration/remove-agreement-start-end-time-migration.js b/src/migration/remove-agreement-start-end-time-migration.js index 469aab1290..95e7892eb8 100644 --- a/src/migration/remove-agreement-start-end-time-migration.js +++ b/src/migration/remove-agreement-start-end-time-migration.js @@ -1,5 +1,5 @@ import BaseMigration from './base-migration.js'; -import { TRIPLE_STORE_REPOSITORIES, SCHEMA_CONTEXT } from '../constants/constants.js'; +import { TRIPLE_STORE, SCHEMA_CONTEXT } from '../constants/constants.js'; class RemoveAgreementStartEndTimeMigration extends BaseMigration { constructor(migrationName, logger, config, tripleStoreService) { @@ -8,7 +8,7 @@ class RemoveAgreementStartEndTimeMigration extends BaseMigration { } async executeMigration() { - const repositories = Object.values(TRIPLE_STORE_REPOSITORIES); + const repositories = Object.values(TRIPLE_STORE.REPOSITORIES); const query = ` PREFIX schema: <${SCHEMA_CONTEXT}> diff --git a/src/migration/service-agreements-data-inspector.js b/src/migration/service-agreements-data-inspector.js index aad52f2fe8..8d722a2c0e 100644 --- a/src/migration/service-agreements-data-inspector.js +++ b/src/migration/service-agreements-data-inspector.js @@ -1,6 +1,6 @@ /* eslint-disable no-await-in-loop */ import BaseMigration from './base-migration.js'; -import { TRIPLE_STORE_REPOSITORIES } from '../constants/constants.js'; +import { TRIPLE_STORE } from '../constants/constants.js'; const fixedServiceAgreements = []; const fixedHistoricalAssertions = []; @@ -101,7 +101,7 @@ class ServiceAgreementsDataInspector extends BaseMigration { const historicalAssertionIds = assertionIds.slice(0, -1); const publicHistoricalAssertionLinks = await this.tripleStoreService.getAssetAssertionLinks( - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, serviceAgreement.blockchain, serviceAgreement.assetStorageContractAddress, serviceAgreement.tokenId, @@ -118,7 +118,7 @@ class ServiceAgreementsDataInspector extends BaseMigration { const privateHistoricalAssertionLinks = await this.tripleStoreService.getAssetAssertionLinks( - TRIPLE_STORE_REPOSITORIES.PRIVATE_HISTORY, + TRIPLE_STORE.REPOSITORIES.PRIVATE_HISTORY, serviceAgreement.blockchain, serviceAgreement.assetStorageContractAddress, serviceAgreement.tokenId, diff --git a/src/migration/service-agreements-invalid-data-migration.js b/src/migration/service-agreements-invalid-data-migration.js index 59f1636cc6..c22246283d 100644 --- a/src/migration/service-agreements-invalid-data-migration.js +++ b/src/migration/service-agreements-invalid-data-migration.js @@ -1,6 +1,6 @@ /* eslint-disable no-await-in-loop */ import BaseMigration from './base-migration.js'; -import { TRIPLE_STORE_REPOSITORIES } from '../constants/constants.js'; +import { TRIPLE_STORE } from '../constants/constants.js'; class ServiceAgreementsInvalidDataMigration extends BaseMigration { constructor(migrationName, logger, config, repositoryModuleManager, tripleStoreService) { @@ -50,7 +50,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { if (serviceAgreement.currentAssertionId !== serviceAgreement.correctAssertionId) { const assertionLinkedInPublicCurrentRepository = await this.tripleStoreService.assetAssertionLinkExists( - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -59,7 +59,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { if (assertionLinkedInPublicCurrentRepository) { await this.tripleStoreService.updateAssetAssertionLink( - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -70,7 +70,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { const assertionLinkedInPrivateCurrentRepository = await this.tripleStoreService.assetAssertionLinkExists( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -79,7 +79,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { if (assertionLinkedInPrivateCurrentRepository) { await this.tripleStoreService.updateAssetAssertionLink( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -92,7 +92,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { // Fix wrong keyword for the Asset Metadata in the Triple Store if (serviceAgreement.currentKeyword !== serviceAgreement.correctKeyword) { const assetInPublicCurrentRepository = await this.tripleStoreService.assetExists( - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -100,7 +100,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { if (assetInPublicCurrentRepository) { await this.tripleStoreService.updateAssetNonAssertionMetadata( - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -109,7 +109,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { } const assetInPrivateCurrentRepository = await this.tripleStoreService.assetExists( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -117,7 +117,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { if (assetInPrivateCurrentRepository) { await this.tripleStoreService.updateAssetNonAssertionMetadata( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -126,7 +126,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { } const assetInPublicHistoricalRepository = await this.tripleStoreService.assetExists( - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -134,7 +134,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { if (assetInPublicHistoricalRepository) { await this.tripleStoreService.updateAssetNonAssertionMetadata( - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -144,7 +144,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { const assetInPrivateHistoricalRepository = await this.tripleStoreService.assetExists( - TRIPLE_STORE_REPOSITORIES.PRIVATE_HISTORY, + TRIPLE_STORE.REPOSITORIES.PRIVATE_HISTORY, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -152,7 +152,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { if (assetInPrivateHistoricalRepository) { await this.tripleStoreService.updateAssetNonAssertionMetadata( - TRIPLE_STORE_REPOSITORIES.PRIVATE_HISTORY, + TRIPLE_STORE.REPOSITORIES.PRIVATE_HISTORY, serviceAgreement.blockchain, serviceAgreement.contract, serviceAgreement.tokenId, @@ -174,7 +174,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { for (const assertionId of state.missingPublicHistoricalAssertions) { await this.tripleStoreService.insertAssetAssertionLink( - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, state.blockchain, state.contract, state.tokenId, @@ -184,7 +184,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { for (const assertionId of state.missingPrivateHistoricalAssertions) { await this.tripleStoreService.insertAssetAssertionLink( - TRIPLE_STORE_REPOSITORIES.PRIVATE_HISTORY, + TRIPLE_STORE.REPOSITORIES.PRIVATE_HISTORY, state.blockchain, state.contract, state.tokenId, @@ -194,7 +194,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { for (const assertionId of state.redundantPublicHistoricalAssertions) { await this.tripleStoreService.deleteAssetAssertionLink( - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, state.blockchain, state.contract, state.tokenId, @@ -204,7 +204,7 @@ class ServiceAgreementsInvalidDataMigration extends BaseMigration { for (const assertionId of state.redundantPrivateHistoricalAssertions) { await this.tripleStoreService.deleteAssetAssertionLink( - TRIPLE_STORE_REPOSITORIES.PRIVATE_HISTORY, + TRIPLE_STORE.REPOSITORIES.PRIVATE_HISTORY, state.blockchain, state.contract, state.tokenId, diff --git a/src/migration/service-agreements-metadata-migration.js b/src/migration/service-agreements-metadata-migration.js index 382c2eaf94..e8713c86e8 100644 --- a/src/migration/service-agreements-metadata-migration.js +++ b/src/migration/service-agreements-metadata-migration.js @@ -5,7 +5,7 @@ import BaseMigration from './base-migration.js'; import { CONTENT_ASSET_HASH_FUNCTION_ID, SCHEMA_CONTEXT, - TRIPLE_STORE_REPOSITORIES, + TRIPLE_STORE, SERVICE_AGREEMENT_SOURCES, } from '../constants/constants.js'; @@ -53,7 +53,7 @@ class ServiceAgreementsMetadataMigration extends BaseMigration { } ORDER BY ASC(xsd:integer(?tokenId))`; const assetsMetadata = await this.tripleStoreService.select( - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, query, ); const identities = {}; diff --git a/src/migration/triple-store-metadata-migration.js b/src/migration/triple-store-metadata-migration.js index dc087689d8..94d98d2265 100644 --- a/src/migration/triple-store-metadata-migration.js +++ b/src/migration/triple-store-metadata-migration.js @@ -2,7 +2,7 @@ import { formatAssertion } from 'assertion-tools'; import path from 'path'; import BaseMigration from './base-migration.js'; -import { SCHEMA_CONTEXT, TRIPLE_STORE_REPOSITORIES } from '../constants/constants.js'; +import { SCHEMA_CONTEXT, TRIPLE_STORE } from '../constants/constants.js'; class TripleStoreMetadataMigration extends BaseMigration { constructor( @@ -29,8 +29,8 @@ class TripleStoreMetadataMigration extends BaseMigration { } async updatePublicCurrentMetadata() { - const currentRepository = TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT; - const historyRepository = TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY; + const currentRepository = TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT; + const historyRepository = TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY; const migrationFolderPath = this.fileService.getMigrationFolderPath(); const migrationInfoFileName = `${this.migrationName}_${currentRepository}`; const migrationInfoPath = path.join(migrationFolderPath, migrationInfoFileName); @@ -76,8 +76,8 @@ class TripleStoreMetadataMigration extends BaseMigration { } async updatePrivateCurrentMetadata() { - const currentRepository = TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT; - const historyRepository = TRIPLE_STORE_REPOSITORIES.PRIVATE_HISTORY; + const currentRepository = TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT; + const historyRepository = TRIPLE_STORE.REPOSITORIES.PRIVATE_HISTORY; const migrationFolderPath = this.fileService.getMigrationFolderPath(); const migrationInfoFileName = `${this.migrationName}_${currentRepository}`; const migrationInfoPath = path.join(migrationFolderPath, migrationInfoFileName); @@ -511,7 +511,7 @@ class TripleStoreMetadataMigration extends BaseMigration { await this._updateMigrationInfoFile(currentRepository, migrationInfoCopy); - if (currentRepository === TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT) { + if (currentRepository === TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT) { const privateAssertionId = this.dataService.getPrivateAssertionId(publicAssertion); if (privateAssertionId) { @@ -576,7 +576,7 @@ class TripleStoreMetadataMigration extends BaseMigration { assertion: [{ '@id': `assertion:${latestPublicAssertionId}` }], }; - if (currentRepository === TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT) { + if (currentRepository === TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT) { const latestPrivateAssertionId = this.dataService.getPrivateAssertionId(latestPublicAssertion); if (latestPrivateAssertionId) { diff --git a/src/migration/ual-extension-triple-store-migration.js b/src/migration/ual-extension-triple-store-migration.js index 4709c6133b..821619cd84 100644 --- a/src/migration/ual-extension-triple-store-migration.js +++ b/src/migration/ual-extension-triple-store-migration.js @@ -1,6 +1,6 @@ /* eslint-disable no-await-in-loop */ import BaseMigration from './base-migration.js'; -import { TRIPLE_STORE_REPOSITORIES } from '../constants/constants.js'; +import { TRIPLE_STORE } from '../constants/constants.js'; const CHAIN_IDS = { development: 31337, @@ -23,7 +23,7 @@ class UalExtensionTripleStoreMigration extends BaseMigration { const chunkSize = 10000; - for (const repository in TRIPLE_STORE_REPOSITORIES) { + for (const repository in TRIPLE_STORE.REPOSITORIES) { const getUalListQuery = ` PREFIX schema: SELECT DISTINCT ?subject ?object @@ -32,7 +32,7 @@ class UalExtensionTripleStoreMigration extends BaseMigration { }`; const ualList = await this.tripleStoreService.select( - TRIPLE_STORE_REPOSITORIES[repository], + TRIPLE_STORE.REPOSITORIES[repository], getUalListQuery, ); @@ -65,7 +65,7 @@ class UalExtensionTripleStoreMigration extends BaseMigration { } }`; await this.tripleStoreService.queryVoid( - TRIPLE_STORE_REPOSITORIES[repository], + TRIPLE_STORE.REPOSITORIES[repository], insertQuery, ); this.logger.info( diff --git a/src/modules/module-config-validation.js b/src/modules/module-config-validation.js index fc2cd00619..580fb48a39 100644 --- a/src/modules/module-config-validation.js +++ b/src/modules/module-config-validation.js @@ -1,4 +1,4 @@ -import { REQUIRED_MODULES, TRIPLE_STORE_REPOSITORIES } from '../constants/constants.js'; +import { REQUIRED_MODULES, TRIPLE_STORE } from '../constants/constants.js'; class ModuleConfigValidation { constructor(ctx) { @@ -47,7 +47,7 @@ class ModuleConfigValidation { occurences[repository] += 1; } } - for (const repository of Object.values(TRIPLE_STORE_REPOSITORIES)) { + for (const repository of Object.values(TRIPLE_STORE.REPOSITORIES)) { if (occurences[repository] !== 1) throw Error(`Exactly one config for repository ${repository} needs to be defined.`); } diff --git a/src/modules/triple-store/implementation/ot-triple-store.js b/src/modules/triple-store/implementation/ot-triple-store.js index f15649d437..74ac5aa2ec 100644 --- a/src/modules/triple-store/implementation/ot-triple-store.js +++ b/src/modules/triple-store/implementation/ot-triple-store.js @@ -1,11 +1,6 @@ import { QueryEngine as Engine } from '@comunica/query-sparql'; import { setTimeout } from 'timers/promises'; -import { - SCHEMA_CONTEXT, - TRIPLE_STORE_CONNECT_MAX_RETRIES, - TRIPLE_STORE_CONNECT_RETRY_FREQUENCY, - MEDIA_TYPES, -} from '../../../constants/constants.js'; +import { SCHEMA_CONTEXT, TRIPLE_STORE, MEDIA_TYPES } from '../../../constants/constants.js'; class OtTripleStore { async initialize(config, logger) { @@ -75,18 +70,20 @@ class OtTripleStore { const ensureConnectionPromises = Object.keys(this.repositories).map(async (repository) => { let ready = await this.healthCheck(repository); let retries = 0; - while (!ready && retries < TRIPLE_STORE_CONNECT_MAX_RETRIES) { + while (!ready && retries < TRIPLE_STORE.CONNECT.MAX_RETRIES) { retries += 1; this.logger.warn( `Cannot connect to Triple store (${this.getName()}), repository: ${repository}, located at: ${ this.repositories[repository].url - } retry number: ${retries}/${TRIPLE_STORE_CONNECT_MAX_RETRIES}. Retrying in ${TRIPLE_STORE_CONNECT_RETRY_FREQUENCY} seconds.`, + } retry number: ${retries}/${TRIPLE_STORE.CONNECT.MAX_RETRIES}. Retrying in ${ + TRIPLE_STORE.CONNECT.RETRY_FREQUENCY + } seconds.`, ); /* eslint-disable no-await-in-loop */ - await setTimeout(TRIPLE_STORE_CONNECT_RETRY_FREQUENCY * 1000); + await setTimeout(TRIPLE_STORE.CONNECT.RETRY_FREQUENCY * 1000); ready = await this.healthCheck(repository); } - if (retries === TRIPLE_STORE_CONNECT_MAX_RETRIES) { + if (retries === TRIPLE_STORE.CONNECT.MAX_RETRIES) { this.logger.error( `Triple Store (${this.getName()}) not available, max retries reached.`, ); diff --git a/src/service/blockchain-event-listener-service.js b/src/service/blockchain-event-listener-service.js index d89014aca1..6fce3d722e 100644 --- a/src/service/blockchain-event-listener-service.js +++ b/src/service/blockchain-event-listener-service.js @@ -3,7 +3,7 @@ import { CONTENT_ASSET_HASH_FUNCTION_ID, CONTRACTS, CONTRACT_EVENT_FETCH_INTERVALS, - TRIPLE_STORE_REPOSITORIES, + TRIPLE_STORE, NODE_ENVIRONMENTS, PENDING_STORAGE_REPOSITORIES, CONTRACT_EVENTS, @@ -523,8 +523,8 @@ class BlockchainEventListenerService { // eslint-disable-next-line no-await-in-loop await Promise.all([ this.pendingStorageService.moveAndDeletePendingState( - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, - TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY, PENDING_STORAGE_REPOSITORIES.PUBLIC, blockchain, contract, @@ -535,8 +535,8 @@ class BlockchainEventListenerService { stateIndex, ), this.pendingStorageService.moveAndDeletePendingState( - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, - TRIPLE_STORE_REPOSITORIES.PRIVATE_HISTORY, + TRIPLE_STORE.REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE.REPOSITORIES.PRIVATE_HISTORY, PENDING_STORAGE_REPOSITORIES.PRIVATE, blockchain, contract, diff --git a/src/service/get-service.js b/src/service/get-service.js index 8ed3e84017..aa29a2b24d 100644 --- a/src/service/get-service.js +++ b/src/service/get-service.js @@ -6,7 +6,7 @@ import { ERROR_TYPE, OPERATIONS, OPERATION_REQUEST_STATUS, - TRIPLE_STORE_REPOSITORIES, + TRIPLE_STORE, PARANET_NODES_ACCESS_POLICIES, } from '../constants/constants.js'; @@ -103,8 +103,8 @@ class GetService extends OperationService { if (!paranetLatestAsset) { repository = paranetNodesAccessPolicy === 'OPEN' - ? TRIPLE_STORE_REPOSITORIES.PUBLIC_HISTORY - : TRIPLE_STORE_REPOSITORIES.PRIVATE_HISTORY; + ? TRIPLE_STORE.REPOSITORIES.PUBLIC_HISTORY + : TRIPLE_STORE.REPOSITORIES.PRIVATE_HISTORY; publicAssertionId = assertionId; } else { const paranetUAL = this.ualService.deriveUAL( @@ -154,7 +154,7 @@ class GetService extends OperationService { ); await this.tripleStoreService.localStoreAsset( - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, assertionId, responseData.nquads, blockchain, diff --git a/src/service/triple-store-service.js b/src/service/triple-store-service.js index 920d0ab7a3..03cc21c835 100644 --- a/src/service/triple-store-service.js +++ b/src/service/triple-store-service.js @@ -1,6 +1,6 @@ import { formatAssertion } from 'assertion-tools'; -import { SCHEMA_CONTEXT, TRIPLE_STORE_REPOSITORIES, MEDIA_TYPES } from '../constants/constants.js'; +import { SCHEMA_CONTEXT, TRIPLE_STORE, MEDIA_TYPES } from '../constants/constants.js'; class TripleStoreService { constructor(ctx) { @@ -444,11 +444,11 @@ class TripleStoreService { async queryVoidAllRepositories(query) { const queryPromises = []; - for (const repository in TRIPLE_STORE_REPOSITORIES) { + for (const repository in TRIPLE_STORE.REPOSITORIES) { queryPromises.push( this.tripleStoreModuleManager.queryVoid( this.repositoryImplementations[repository], - TRIPLE_STORE_REPOSITORIES[repository], + TRIPLE_STORE.REPOSITORIES[repository], query, ), ); diff --git a/test/unit/modules/triple-store/triple-store.test.js b/test/unit/modules/triple-store/triple-store.test.js index 9209cf8bc3..21b0e75cf5 100644 --- a/test/unit/modules/triple-store/triple-store.test.js +++ b/test/unit/modules/triple-store/triple-store.test.js @@ -2,7 +2,7 @@ import chai from 'chai'; import { readFile } from 'fs/promises'; import { formatAssertion, calculateRoot } from 'assertion-tools'; -import { TRIPLE_STORE_REPOSITORIES } from '../../../src/constants/constants.js'; +import { TRIPLE_STORE } from '../../../src/constants/constants.js'; import Logger from '../../../src/logger/logger.js'; import TripleStoreModuleManager from '../../../src/modules/triple-store/triple-store-module-manager.js'; import DataService from '../../../src/service/data-service.js'; @@ -22,14 +22,14 @@ async function _insertAndGet(content) { await tripleStoreModuleManager.insertAssertion( implementationName, - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, assertionId, assertion.join('\n'), ); const nquads = await tripleStoreModuleManager.getAssertion( implementationName, - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + TRIPLE_STORE.REPOSITORIES.PUBLIC_CURRENT, assertionId, ); From deb9a27e04b256d6ff207dd583a7c69a1535fc7b Mon Sep 17 00:00:00 2001 From: Zvonimir Sculac Date: Fri, 4 Oct 2024 12:59:32 +0200 Subject: [PATCH 6/8] Create NETWORK_API constant --- src/constants/constants.js | 20 +++++++++---------- .../network/implementation/libp2p-service.js | 16 +++++++-------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index d78c36a24b..c531670074 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -133,18 +133,18 @@ export const MEDIA_TYPES = { // TODO: Make this 20 not only in const export const MIN_NODE_VERSION = 16; -export const NETWORK_API_RATE_LIMIT = { - TIME_WINDOW_MILLS: 1 * 60 * 1000, - MAX_NUMBER: 100, -}; - -export const NETWORK_API_SPAM_DETECTION = { - TIME_WINDOW_MILLS: 1 * 60 * 1000, - MAX_NUMBER: 150, +export const NETWORK_API = { + RATE_LIMIT: { + TIME_WINDOW_MILLS: 1 * 60 * 1000, + MAX_NUMBER: 100, + }, + SPAM_DETECTION: { + TIME_WINDOW_MILLS: 1 * 60 * 1000, + MAX_NUMBER: 150, + }, + BLACK_LIST_TIME_WINDOW_MINUTES: 60, }; -export const NETWORK_API_BLACK_LIST_TIME_WINDOW_MINUTES = 60; - export const HIGH_TRAFFIC_OPERATIONS_NUMBER_PER_HOUR = 16000; export const SHARDING_TABLE_CHECK_COMMAND_FREQUENCY_MINUTES = 30; diff --git a/src/modules/network/implementation/libp2p-service.js b/src/modules/network/implementation/libp2p-service.js index 0e44653ad8..854a797c3e 100644 --- a/src/modules/network/implementation/libp2p-service.js +++ b/src/modules/network/implementation/libp2p-service.js @@ -16,10 +16,8 @@ import { mkdir, writeFile, readFile, stat } from 'fs/promises'; import ip from 'ip'; import { TimeoutController } from 'timeout-abort-controller'; import { - NETWORK_API_RATE_LIMIT, - NETWORK_API_SPAM_DETECTION, + NETWORK_API, NETWORK_MESSAGE_TYPES, - NETWORK_API_BLACK_LIST_TIME_WINDOW_MINUTES, LIBP2P_KEY, NODE_ENVIRONMENTS, BYTES_IN_MEGABYTE, @@ -172,13 +170,13 @@ class Libp2pService { _initializeRateLimiters() { const basicRateLimiter = new InMemoryRateLimiter({ - interval: NETWORK_API_RATE_LIMIT.TIME_WINDOW_MILLS, - maxInInterval: NETWORK_API_RATE_LIMIT.MAX_NUMBER, + interval: NETWORK_API.RATE_LIMIT.TIME_WINDOW_MILLS, + maxInInterval: NETWORK_API.RATE_LIMIT.MAX_NUMBER, }); const spamDetection = new InMemoryRateLimiter({ - interval: NETWORK_API_SPAM_DETECTION.TIME_WINDOW_MILLS, - maxInInterval: NETWORK_API_SPAM_DETECTION.MAX_NUMBER, + interval: NETWORK_API.SPAM_DETECTION.TIME_WINDOW_MILLS, + maxInInterval: NETWORK_API.SPAM_DETECTION.MAX_NUMBER, }); this.rateLimiter = { @@ -582,7 +580,7 @@ class Libp2pService { if (this.blackList[peerIdString]) { const remainingMinutes = Math.floor( - NETWORK_API_BLACK_LIST_TIME_WINDOW_MINUTES - + NETWORK_API.BLACK_LIST_TIME_WINDOW_MINUTES - (Date.now() - this.blackList[peerIdString]) / (1000 * 60), ); @@ -599,7 +597,7 @@ class Libp2pService { if (await this.rateLimiter.spamDetection.limit(peerIdString)) { this.blackList[peerIdString] = Date.now(); this.logger.debug( - `Blocking request from ${peerIdString}. Spammer detected and blacklisted for ${NETWORK_API_BLACK_LIST_TIME_WINDOW_MINUTES} minutes.`, + `Blocking request from ${peerIdString}. Spammer detected and blacklisted for ${NETWORK_API.BLACK_LIST_TIME_WINDOW_MINUTES} minutes.`, ); return true; From 98118ee1a676b1eeb86a628b72578c95b63a7f20 Mon Sep 17 00:00:00 2001 From: Zvonimir Sculac Date: Fri, 4 Oct 2024 13:26:34 +0200 Subject: [PATCH 7/8] Create PARANET constant --- ot-node.js | 4 +-- src/commands/paranet/paranet-sync-command.js | 23 +++++++--------- .../paranet/start-paranet-sync-commands.js | 4 +-- ...1_0_0-handle-store-paranet-init-command.js | 4 +-- .../publish-paranet-validate-asset.command.js | 4 +-- src/constants/constants.js | 26 +++++++++---------- src/service/get-service.js | 4 +-- 7 files changed, 32 insertions(+), 37 deletions(-) diff --git a/ot-node.js b/ot-node.js index ce912b549c..4effb4bdeb 100644 --- a/ot-node.js +++ b/ot-node.js @@ -5,7 +5,7 @@ import { createRequire } from 'module'; import { execSync } from 'child_process'; import DependencyInjection from './src/service/dependency-injection.js'; import Logger from './src/logger/logger.js'; -import { MIN_NODE_VERSION, PARANET_ACCESS_POLICY } from './src/constants/constants.js'; +import { MIN_NODE_VERSION, PARANET } from './src/constants/constants.js'; import FileService from './src/service/file-service.js'; import OtnodeUpdateCommand from './src/commands/common/otnode-update-command.js'; import OtAutoUpdater from './src/modules/auto-updater/implementation/ot-auto-updater.js'; @@ -416,7 +416,7 @@ class OTNode { blockchain, paranetId, ); - if (nodesAccessPolicy === PARANET_ACCESS_POLICY.CURATED) { + if (nodesAccessPolicy === PARANET.ACCESS_POLICY.CURATED) { // eslint-disable-next-line no-await-in-loop const identityId = await blockchainModuleManager.getIdentityId(blockchain); // eslint-disable-next-line no-await-in-loop diff --git a/src/commands/paranet/paranet-sync-command.js b/src/commands/paranet/paranet-sync-command.js index 8754abb563..4ae6b75f95 100644 --- a/src/commands/paranet/paranet-sync-command.js +++ b/src/commands/paranet/paranet-sync-command.js @@ -4,14 +4,11 @@ import { setTimeout } from 'timers/promises'; import Command from '../command.js'; import { ERROR_TYPE, - PARANET_SYNC_FREQUENCY_MILLS, OPERATION_ID_STATUS, CONTENT_ASSET_HASH_FUNCTION_ID, - PARANET_SYNC_PARAMETERS, TRIPLE_STORE, - PARANET_SYNC_KA_COUNT, + PARANET, OPERATION_STATUS, - PARANET_NODES_ACCESS_POLICIES, } from '../../constants/constants.js'; class ParanetSyncCommand extends Command { @@ -33,7 +30,7 @@ class ParanetSyncCommand extends Command { command.data; const paranetNodesAccessPolicy = - PARANET_NODES_ACCESS_POLICIES[paranetMetadata.nodesAccessPolicy]; + PARANET.NODES_ACCESS_POLICIES[paranetMetadata.nodesAccessPolicy]; this.logger.info( `Paranet sync: Starting paranet sync for paranet: ${paranetUAL} (${paranetId}), operation ID: ${operationId}`, @@ -57,15 +54,15 @@ class ParanetSyncCommand extends Command { if (cachedMissedKaCount > 0) { this.logger.info( `Paranet sync: Missed KA count is ${cachedMissedKaCount} syncing ${ - cachedMissedKaCount > PARANET_SYNC_KA_COUNT - ? PARANET_SYNC_KA_COUNT + cachedMissedKaCount > PARANET.SYNC_KA_COUNT + ? PARANET.SYNC_KA_COUNT : cachedMissedKaCount } assets, for paranet: ${paranetUAL}, operation ID: ${operationId}!`, ); const missedParanetAssets = await this.repositoryModuleManager.getMissedParanetAssetsRecords( paranetUAL, - PARANET_SYNC_KA_COUNT, + PARANET.SYNC_KA_COUNT, ); const promises = []; @@ -185,14 +182,14 @@ class ParanetSyncCommand extends Command { for ( let i = cachedKaCount + cachedMissedKaCount; i <= contractKaCount; - i += PARANET_SYNC_KA_COUNT + i += PARANET.SYNC_KA_COUNT ) { const nextKaArray = await this.blockchainModuleManager.getParanetKnowledgeAssetsWithPagination( blockchain, paranetId, i, - PARANET_SYNC_KA_COUNT, + PARANET.SYNC_KA_COUNT, ); if (!nextKaArray.length) break; kaToUpdate.push(...nextKaArray); @@ -411,11 +408,11 @@ class ParanetSyncCommand extends Command { let attempt = 0; let getResult; do { - await setTimeout(PARANET_SYNC_PARAMETERS.GET_RESULT_POLLING_INTERVAL_MILLIS); + await setTimeout(PARANET.SYNC_PARAMETERS.GET_RESULT_POLLING_INTERVAL_MILLIS); getResult = await this.operationIdService.getOperationIdRecord(operationId); attempt += 1; } while ( - attempt < PARANET_SYNC_PARAMETERS.GET_RESULT_POLLING_MAX_ATTEMPTS && + attempt < PARANET.SYNC_PARAMETERS.GET_RESULT_POLLING_MAX_ATTEMPTS && getResult?.status !== OPERATION_ID_STATUS.FAILED && getResult?.status !== OPERATION_ID_STATUS.COMPLETED ); @@ -470,7 +467,7 @@ class ParanetSyncCommand extends Command { name: 'paranetSyncCommands', data: {}, transactional: false, - period: PARANET_SYNC_FREQUENCY_MILLS, + period: PARANET.SYNC_FREQUENCY_MILLS, }; Object.assign(command, map); return command; diff --git a/src/commands/paranet/start-paranet-sync-commands.js b/src/commands/paranet/start-paranet-sync-commands.js index 192fbbac0e..ea7176a70a 100644 --- a/src/commands/paranet/start-paranet-sync-commands.js +++ b/src/commands/paranet/start-paranet-sync-commands.js @@ -1,5 +1,5 @@ import Command from '../command.js'; -import { ERROR_TYPE, PARANET_SYNC_FREQUENCY_MILLS } from '../../constants/constants.js'; +import { ERROR_TYPE, PARANET } from '../../constants/constants.js'; class StartParanetSyncCommands extends Command { constructor(ctx) { @@ -42,7 +42,7 @@ class StartParanetSyncCommands extends Command { this.commandExecutor.add({ name: 'paranetSyncCommand', data: commandData, - period: PARANET_SYNC_FREQUENCY_MILLS, + period: PARANET.SYNC_FREQUENCY_MILLS, }), ); }); diff --git a/src/commands/protocols/publish-paranet/receiver/v1.0.0/v1_0_0-handle-store-paranet-init-command.js b/src/commands/protocols/publish-paranet/receiver/v1.0.0/v1_0_0-handle-store-paranet-init-command.js index 9cf79e50d4..5ea3fec0ea 100644 --- a/src/commands/protocols/publish-paranet/receiver/v1.0.0/v1_0_0-handle-store-paranet-init-command.js +++ b/src/commands/protocols/publish-paranet/receiver/v1.0.0/v1_0_0-handle-store-paranet-init-command.js @@ -4,7 +4,7 @@ import { ERROR_TYPE, OPERATION_ID_STATUS, NETWORK_MESSAGE_TYPES, - PARANET_ACCESS_POLICY, + PARANET, } from '../../../../../constants/constants.js'; class HandleStoreParanetInitCommand extends HandleProtocolMessageCommand { @@ -58,7 +58,7 @@ class HandleStoreParanetInitCommand extends HandleProtocolMessageCommand { blockchain, paranetId, ); - if (nodesAccessPolicy === PARANET_ACCESS_POLICY.CURATED) { + if (nodesAccessPolicy === PARANET.ACCESS_POLICY.CURATED) { const identityId = await this.blockchainModuleManager.getIdentityId(blockchain); const isCuratedNode = await this.blockchainModuleManager.isCuratedNode( blockchain, diff --git a/src/commands/protocols/publish-paranet/sender/publish-paranet-validate-asset.command.js b/src/commands/protocols/publish-paranet/sender/publish-paranet-validate-asset.command.js index f285107888..716067aae9 100644 --- a/src/commands/protocols/publish-paranet/sender/publish-paranet-validate-asset.command.js +++ b/src/commands/protocols/publish-paranet/sender/publish-paranet-validate-asset.command.js @@ -5,7 +5,7 @@ import { OPERATION_ID_STATUS, LOCAL_STORE_TYPES, EVM_ZERO, - PARANET_ACCESS_POLICY, + PARANET, } from '../../../../constants/constants.js'; class PublishParanetValidateAssetCommand extends ValidateAssetCommand { @@ -57,7 +57,7 @@ class PublishParanetValidateAssetCommand extends ValidateAssetCommand { blockchain, paranetId, ); - if (nodesAccessPolicy === PARANET_ACCESS_POLICY.CURATED) { + if (nodesAccessPolicy === PARANET.ACCESS_POLICY.CURATED) { const identityId = await this.blockchainModuleManager.getIdentityId(blockchain); const isCuratedNode = await this.blockchainModuleManager.isCuratedNode( blockchain, diff --git a/src/constants/constants.js b/src/constants/constants.js index c531670074..7a4b3385a0 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -99,11 +99,18 @@ export const DEFAULT_GET_STATE = GET_STATES.LATEST; // TODO: Fix this and whereve it is used export const CONTENT_ASSET_HASH_FUNCTION_ID = 1; -export const PARANET_SYNC_KA_COUNT = 50; - -export const PARANET_ACCESS_POLICY = { - OPEN: 0, - CURATED: 1, +export const PARANET = { + SYNC_KA_COUNT: 50, + SYNC_FREQUENCY_MILLS: 5 * 60 * 1000, + NODES_ACCESS_POLICIES: ['OPEN', 'CURATED'], + ACCESS_POLICY: { + OPEN: 0, + CURATED: 1, + }, + SYNC_PARAMETERS: { + GET_RESULT_POLLING_INTERVAL_MILLIS: 1 * 1000, + GET_RESULT_POLLING_MAX_ATTEMPTS: 30, + }, }; export const PENDING_STORAGE_REPOSITORIES = { @@ -149,8 +156,6 @@ export const HIGH_TRAFFIC_OPERATIONS_NUMBER_PER_HOUR = 16000; export const SHARDING_TABLE_CHECK_COMMAND_FREQUENCY_MINUTES = 30; -export const PARANET_SYNC_FREQUENCY_MILLS = 5 * 60 * 1000; - export const SEND_TELEMETRY_COMMAND_FREQUENCY_MINUTES = 15; export const PEER_RECORD_UPDATE_DELAY = 30 * 60 * 1000; // 30 minutes @@ -210,11 +215,6 @@ export const COMMAND_RETRIES = { SUBMIT_UPDATE_COMMIT: 5, }; -export const PARANET_SYNC_PARAMETERS = { - GET_RESULT_POLLING_INTERVAL_MILLIS: 1 * 1000, - GET_RESULT_POLLING_MAX_ATTEMPTS: 30, -}; - export const COMMAND_TX_GAS_INCREASE_FACTORS = { SUBMIT_UPDATE_COMMIT: 1.2, }; @@ -264,8 +264,6 @@ export const NETWORK_MESSAGE_TYPES = { }, }; -export const PARANET_NODES_ACCESS_POLICIES = ['OPEN', 'CURATED']; - export const NETWORK_MESSAGE_TIMEOUT_MILLS = { PUBLISH: { INIT: 60 * 1000, diff --git a/src/service/get-service.js b/src/service/get-service.js index aa29a2b24d..04bf429556 100644 --- a/src/service/get-service.js +++ b/src/service/get-service.js @@ -7,7 +7,7 @@ import { OPERATIONS, OPERATION_REQUEST_STATUS, TRIPLE_STORE, - PARANET_NODES_ACCESS_POLICIES, + PARANET, } from '../constants/constants.js'; class GetService extends OperationService { @@ -95,7 +95,7 @@ class GetService extends OperationService { ); const paranetNodesAccessPolicy = - PARANET_NODES_ACCESS_POLICIES[paranetMetadata.nodesAccessPolicy]; + PARANET.NODES_ACCESS_POLICIES[paranetMetadata.nodesAccessPolicy]; let repository; let publicAssertionId; From 7a25dbd13382d62e1b3afbb06857f7486dfd2f0e Mon Sep 17 00:00:00 2001 From: Zvonimir Sculac Date: Fri, 4 Oct 2024 13:34:32 +0200 Subject: [PATCH 8/8] Create ARCHIVE constant --- .../blockchain-event-cleaner-command.js | 4 +-- .../cleaners/commands-cleaner-command.js | 4 +-- src/commands/cleaners/get-cleaner-command.js | 4 +-- .../cleaners/get-response-cleaner-command.js | 4 +-- .../cleaners/publish-cleaner-command.js | 4 +-- .../publish-response-cleaner-command.js | 4 +-- .../cleaners/update-cleaner-command.js | 4 +-- .../update-response-cleaner-command.js | 4 +-- src/constants/constants.js | 26 +++++++------------ 9 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/commands/cleaners/blockchain-event-cleaner-command.js b/src/commands/cleaners/blockchain-event-cleaner-command.js index ea0017793a..1183b3cbd5 100644 --- a/src/commands/cleaners/blockchain-event-cleaner-command.js +++ b/src/commands/cleaners/blockchain-event-cleaner-command.js @@ -2,7 +2,7 @@ import { PROCESSED_BLOCKCHAIN_EVENTS_CLEANUP_TIME_MILLS, REPOSITORY_ROWS_FOR_REMOVAL_MAX_NUMBER, PROCESSED_BLOCKCHAIN_EVENTS_CLEANUP_TIME_DELAY, - ARCHIVE_BLOCKCHAIN_EVENTS_FOLDER, + ARCHIVE, } from '../../constants/constants.js'; import CleanerCommand from './cleaner-command.js'; @@ -15,7 +15,7 @@ class BlockchainEventCleanerCommand extends CleanerCommand { } getArchiveFolderName() { - return ARCHIVE_BLOCKCHAIN_EVENTS_FOLDER; + return ARCHIVE.BLOCKCHAIN_EVENTS_FOLDER; } async deleteRows(ids) { diff --git a/src/commands/cleaners/commands-cleaner-command.js b/src/commands/cleaners/commands-cleaner-command.js index 746d182331..21a4f403ce 100644 --- a/src/commands/cleaners/commands-cleaner-command.js +++ b/src/commands/cleaners/commands-cleaner-command.js @@ -1,6 +1,6 @@ import { FINALIZED_COMMAND_CLEANUP_TIME_MILLS, - ARCHIVE_COMMANDS_FOLDER, + ARCHIVE, REPOSITORY_ROWS_FOR_REMOVAL_MAX_NUMBER, } from '../../constants/constants.js'; import CleanerCommand from './cleaner-command.js'; @@ -14,7 +14,7 @@ class CommandsCleanerCommand extends CleanerCommand { } getArchiveFolderName() { - return ARCHIVE_COMMANDS_FOLDER; + return ARCHIVE.COMMANDS_FOLDER; } async deleteRows(ids) { diff --git a/src/commands/cleaners/get-cleaner-command.js b/src/commands/cleaners/get-cleaner-command.js index 3991623871..ebbefefd4e 100644 --- a/src/commands/cleaners/get-cleaner-command.js +++ b/src/commands/cleaners/get-cleaner-command.js @@ -4,7 +4,7 @@ import { OPERATIONS, GET_CLEANUP_TIME_DELAY, GET_CLEANUP_TIME_MILLS, - ARCHIVE_GET_FOLDER, + ARCHIVE, } from '../../constants/constants.js'; class GetCleanerCommand extends CleanerCommand { @@ -17,7 +17,7 @@ class GetCleanerCommand extends CleanerCommand { } getArchiveFolderName() { - return ARCHIVE_GET_FOLDER; + return ARCHIVE.GET_FOLDER; } async deleteRows(ids) { diff --git a/src/commands/cleaners/get-response-cleaner-command.js b/src/commands/cleaners/get-response-cleaner-command.js index d79e90ba02..04e73876ac 100644 --- a/src/commands/cleaners/get-response-cleaner-command.js +++ b/src/commands/cleaners/get-response-cleaner-command.js @@ -4,7 +4,7 @@ import { OPERATIONS, GET_RESPONSE_CLEANUP_TIME_DELAY, GET_RESPONSE_CLEANUP_TIME_MILLS, - ARCHIVE_GET_RESPONSES_FOLDER, + ARCHIVE, } from '../../constants/constants.js'; class GetResponseCleanerCommand extends CleanerCommand { @@ -17,7 +17,7 @@ class GetResponseCleanerCommand extends CleanerCommand { } getArchiveFolderName() { - return ARCHIVE_GET_RESPONSES_FOLDER; + return ARCHIVE.GET_RESPONSES_FOLDER; } async deleteRows(ids) { diff --git a/src/commands/cleaners/publish-cleaner-command.js b/src/commands/cleaners/publish-cleaner-command.js index cfa93ea85e..939fbec652 100644 --- a/src/commands/cleaners/publish-cleaner-command.js +++ b/src/commands/cleaners/publish-cleaner-command.js @@ -4,7 +4,7 @@ import { OPERATIONS, PUBLISH_CLEANUP_TIME_DELAY, PUBLISH_CLEANUP_TIME_MILLS, - ARCHIVE_PUBLISH_FOLDER, + ARCHIVE, } from '../../constants/constants.js'; class PublishCleanerCommand extends CleanerCommand { @@ -17,7 +17,7 @@ class PublishCleanerCommand extends CleanerCommand { } getArchiveFolderName() { - return ARCHIVE_PUBLISH_FOLDER; + return ARCHIVE.PUBLISH_FOLDER; } async deleteRows(ids) { diff --git a/src/commands/cleaners/publish-response-cleaner-command.js b/src/commands/cleaners/publish-response-cleaner-command.js index 85ff500af5..9b54a783fa 100644 --- a/src/commands/cleaners/publish-response-cleaner-command.js +++ b/src/commands/cleaners/publish-response-cleaner-command.js @@ -4,7 +4,7 @@ import { OPERATIONS, PUBLISH_RESPONSE_CLEANUP_TIME_DELAY, PUBLISH_RESPONSE_CLEANUP_TIME_MILLS, - ARCHIVE_PUBLISH_RESPONSES_FOLDER, + ARCHIVE, } from '../../constants/constants.js'; class PublishResponseCleanerCommand extends CleanerCommand { @@ -17,7 +17,7 @@ class PublishResponseCleanerCommand extends CleanerCommand { } getArchiveFolderName() { - return ARCHIVE_PUBLISH_RESPONSES_FOLDER; + return ARCHIVE.PUBLISH_RESPONSES_FOLDER; } async deleteRows(ids) { diff --git a/src/commands/cleaners/update-cleaner-command.js b/src/commands/cleaners/update-cleaner-command.js index 9f57fae2e4..d2929e146e 100644 --- a/src/commands/cleaners/update-cleaner-command.js +++ b/src/commands/cleaners/update-cleaner-command.js @@ -4,7 +4,7 @@ import { OPERATIONS, UPDATE_CLEANUP_TIME_DELAY, UPDATE_CLEANUP_TIME_MILLS, - ARCHIVE_UPDATE_FOLDER, + ARCHIVE, } from '../../constants/constants.js'; class UpdateCleanerCommand extends CleanerCommand { @@ -17,7 +17,7 @@ class UpdateCleanerCommand extends CleanerCommand { } getArchiveFolderName() { - return ARCHIVE_UPDATE_FOLDER; + return ARCHIVE.UPDATE_FOLDER; } async deleteRows(ids) { diff --git a/src/commands/cleaners/update-response-cleaner-command.js b/src/commands/cleaners/update-response-cleaner-command.js index d5066e7263..939eadec93 100644 --- a/src/commands/cleaners/update-response-cleaner-command.js +++ b/src/commands/cleaners/update-response-cleaner-command.js @@ -4,7 +4,7 @@ import { OPERATIONS, UPDATE_RESPONSE_CLEANUP_TIME_DELAY, UPDATE_RESPONSE_CLEANUP_TIME_MILLS, - ARCHIVE_UPDATE_RESPONSES_FOLDER, + ARCHIVE, } from '../../constants/constants.js'; class UpdateResponseCleanerCommand extends CleanerCommand { @@ -17,7 +17,7 @@ class UpdateResponseCleanerCommand extends CleanerCommand { } getArchiveFolderName() { - return ARCHIVE_UPDATE_RESPONSES_FOLDER; + return ARCHIVE.UPDATE_RESPONSES_FOLDER; } async deleteRows(ids) { diff --git a/src/constants/constants.js b/src/constants/constants.js index 7a4b3385a0..60d0ba0ddf 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -516,22 +516,16 @@ export const OPERATION_ID_FILES_FOR_REMOVAL_MAX_NUMBER = 100; export const REPOSITORY_ROWS_FOR_REMOVAL_MAX_NUMBER = 1000; -export const ARCHIVE_COMMANDS_FOLDER = 'commands'; - -export const ARCHIVE_BLOCKCHAIN_EVENTS_FOLDER = 'blockchain_events'; - -export const ARCHIVE_GET_FOLDER = 'get'; - -export const ARCHIVE_GET_RESPONSES_FOLDER = 'get_responses'; - -export const ARCHIVE_PUBLISH_FOLDER = 'publish'; - -export const ARCHIVE_PUBLISH_RESPONSES_FOLDER = 'publish_responses'; - -export const ARCHIVE_UPDATE_FOLDER = 'update'; - -export const ARCHIVE_UPDATE_RESPONSES_FOLDER = 'update_responses'; - +export const ARCHIVE = { + COMMANDS_FOLDER: 'commands', + BLOCKCHAIN_EVENTS_FOLDER: 'blockchain_events', + GET_FOLDER: 'get', + GET_RESPONSES_FOLDER: 'get_responses', + PUBLISH_FOLDER: 'publish', + PUBLISH_RESPONSES_FOLDER: 'publish_responses', + UPDATE_FOLDER: 'update', + UPDATE_RESPONSES_FOLDER: 'update_responses', +}; /** * How many commands will run in parallel * @type {number}