From 6663e5aa17285db7add69d59309e2ab4f1a5bbc7 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Thu, 1 Feb 2024 10:29:10 +0100 Subject: [PATCH 1/8] Remove sha256Blob --- src/migration/pull-sharding-table-migration.js | 6 ------ .../20240201100000-remove-sha256Blob.js | 17 +++++++++++++++++ .../implementation/sequelize/models/shard.js | 3 --- .../sequelize/repositories/shard-repository.js | 4 +--- .../blockchain-event-listener-service.js | 4 ---- src/service/sharding-table-service.js | 3 --- 6 files changed, 18 insertions(+), 19 deletions(-) create mode 100644 src/modules/repository/implementation/sequelize/migrations/20240201100000-remove-sha256Blob.js diff --git a/src/migration/pull-sharding-table-migration.js b/src/migration/pull-sharding-table-migration.js index 968cc8b9d9..6455a88dc2 100644 --- a/src/migration/pull-sharding-table-migration.js +++ b/src/migration/pull-sharding-table-migration.js @@ -67,11 +67,6 @@ class PullBlockchainShardingTableMigration extends BaseMigration { const sha256 = await this.hashingService.callHashFunction(1, nodeId); - const cleanHexString = sha256.startsWith('0x') - ? sha256.slice(2) - : sha256; - const sha256Blob = Buffer.from(cleanHexString, 'hex'); - return { peerId: nodeId, blockchainId, @@ -86,7 +81,6 @@ class PullBlockchainShardingTableMigration extends BaseMigration { 'ether', ), sha256, - sha256Blob, }; }), ), diff --git a/src/modules/repository/implementation/sequelize/migrations/20240201100000-remove-sha256Blob.js b/src/modules/repository/implementation/sequelize/migrations/20240201100000-remove-sha256Blob.js new file mode 100644 index 0000000000..25618e1d51 --- /dev/null +++ b/src/modules/repository/implementation/sequelize/migrations/20240201100000-remove-sha256Blob.js @@ -0,0 +1,17 @@ +export async function up({ context: { queryInterface } }) { + const tableInfo = await queryInterface.describeTable('shard'); + + if (tableInfo.sha256_blob) { + await queryInterface.removeColumn('shard', 'sha256_blob'); + } +} + +export async function down({ context: { queryInterface, Sequelize } }) { + const tableInfo = await queryInterface.describeTable('shard'); + + if (!tableInfo.sha256_blob) { + await queryInterface.addColumn('shard', 'sha256_blob', { + type: Sequelize.BLOB, + }); + } +} diff --git a/src/modules/repository/implementation/sequelize/models/shard.js b/src/modules/repository/implementation/sequelize/models/shard.js index 7e5b884e29..cd14aa539f 100644 --- a/src/modules/repository/implementation/sequelize/models/shard.js +++ b/src/modules/repository/implementation/sequelize/models/shard.js @@ -26,9 +26,6 @@ export default (sequelize, DataTypes) => { type: DataTypes.STRING, allowNull: false, }, - sha256Blob: { - type: DataTypes.BLOB, - }, }, { underscored: true }, ); diff --git a/src/modules/repository/implementation/sequelize/repositories/shard-repository.js b/src/modules/repository/implementation/sequelize/repositories/shard-repository.js index 25a2051633..86fb01460b 100644 --- a/src/modules/repository/implementation/sequelize/repositories/shard-repository.js +++ b/src/modules/repository/implementation/sequelize/repositories/shard-repository.js @@ -19,7 +19,7 @@ class ShardRepository { }); } - async createPeerRecord(peerId, blockchainId, ask, stake, lastSeen, sha256, sha256Blob) { + async createPeerRecord(peerId, blockchainId, ask, stake, lastSeen, sha256) { return this.model.create( { peerId, @@ -28,7 +28,6 @@ class ShardRepository { stake, lastSeen, sha256, - sha256Blob, }, { ignoreDuplicates: true, @@ -42,7 +41,6 @@ class ShardRepository { blockchainId, }, attributes: ['peerId', 'blockchainId', 'ask', 'stake', 'lastSeen', 'sha256'], - order: [['sha256Blob', 'ASC']], }; if (filterLastSeen) { diff --git a/src/service/blockchain-event-listener-service.js b/src/service/blockchain-event-listener-service.js index afb4b889d9..89adb006f7 100644 --- a/src/service/blockchain-event-listener-service.js +++ b/src/service/blockchain-event-listener-service.js @@ -312,9 +312,6 @@ class BlockchainEventListenerService { nodeId, ); - const cleanHexString = sha256.startsWith('0x') ? sha256.slice(2) : sha256; - const sha256Blob = Buffer.from(cleanHexString, 'hex'); - this.logger.trace(`Adding peer id: ${nodeId} to sharding table.`); return { peerId: nodeId, @@ -329,7 +326,6 @@ class BlockchainEventListenerService { ), lastSeen: new Date(0), sha256, - sha256Blob, }; }), ); diff --git a/src/service/sharding-table-service.js b/src/service/sharding-table-service.js index d6fd6e5718..4a5a3ff8cf 100644 --- a/src/service/sharding-table-service.js +++ b/src/service/sharding-table-service.js @@ -93,8 +93,6 @@ class ShardingTableService { ); const sha256 = await this.hashingService.callHashFunction(1, nodeId); - const cleanHexString = sha256.startsWith('0x') ? sha256.slice(2) : sha256; - const sha256Blob = Buffer.from(cleanHexString, 'hex'); return { peerId: nodeId, blockchainId, @@ -109,7 +107,6 @@ class ShardingTableService { 'ether', ), sha256, - sha256Blob, }; }), ), From b3da277d74872932d0ca8841a522755ee6e08274 Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Thu, 1 Feb 2024 11:53:30 +0100 Subject: [PATCH 2/8] Updated epoch check command, added listening on scoring contract events --- .../protocols/common/epoch-check-command.js | 50 ++++++++++++------ .../v1-0-0-handle-update-request-command.js | 4 +- src/constants/constants.js | 6 ++- .../blockchain/implementation/web3-service.js | 9 ++-- .../blockchain-event-listener-service.js | 51 ++++++++++++++++--- 5 files changed, 88 insertions(+), 32 deletions(-) diff --git a/src/commands/protocols/common/epoch-check-command.js b/src/commands/protocols/common/epoch-check-command.js index 477a3b9747..0b144995a5 100644 --- a/src/commands/protocols/common/epoch-check-command.js +++ b/src/commands/protocols/common/epoch-check-command.js @@ -37,11 +37,11 @@ class EpochCheckCommand extends Command { !migrationExecuted ) { this.logger.info( - 'Epoch check command will be postponed until ual extension triple store migration is completed', + 'Epoch check: command will be postponed until ual extension triple store migration is completed', ); return Command.repeat(); } - this.logger.info('Starting epoch check command'); + this.logger.info('Epoch check: Starting epoch check command'); const operationId = this.operationIdService.generateId(); await Promise.all( @@ -77,7 +77,7 @@ class EpochCheckCommand extends Command { const [r0, r2, totalNodesNumber, minStake, maxStake] = await Promise.all([ this.blockchainModuleManager.getR0(blockchain), this.blockchainModuleManager.getR2(blockchain), - this.blockchainModuleManager.getShardingTableLength(blockchain), + this.repositoryModuleManager.getPeersCount(blockchain), this.blockchainModuleManager.getMinimumStake(blockchain), this.blockchainModuleManager.getMaximumStake(blockchain), ]); @@ -129,11 +129,18 @@ class EpochCheckCommand extends Command { blockchain, commitWindowDurationPerc, ); - + this.logger.info( + `Epoch check: Found ${eligibleAgreementForSubmitCommit.length} eligible agreements for submit commit for blockchain: ${blockchain}`, + ); const scheduleSubmitCommitCommands = []; const updateServiceAgreementsLastCommitEpoch = []; for (const serviceAgreement of eligibleAgreementForSubmitCommit) { - if (scheduleSubmitCommitCommands.length >= maxTransactions) break; + if (scheduleSubmitCommitCommands.length >= maxTransactions) { + this.logger.warn( + `Epoch check: not scheduling new commits. Submit commit command length: ${scheduleSubmitCommitCommands.length}, max number of transactions: ${maxTransactions} for blockchain: ${blockchain}`, + ); + break; + } const neighbourhood = await this.shardingTableService.findNeighbourhood( blockchain, @@ -156,7 +163,10 @@ class EpochCheckCommand extends Command { } if (!neighbourhoodEdges && serviceAgreement.scoreFunctionId === 2) { - throw Error('Unable to find neighbourhood edges for asset'); + this.logger.warn( + `Epoch check: unable to find neighbourhood edges for agreement id: ${serviceAgreement.agreementId} for blockchain: ${blockchain}`, + ); + continue; } try { @@ -182,28 +192,28 @@ class EpochCheckCommand extends Command { if (rank == null) { this.logger.trace( - `Node not in R2: ${r2} for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Skipping scheduling submitCommitCommand.`, + `Epoch check: Node not in R2: ${r2} for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Skipping scheduling submitCommitCommand for blockchain: ${blockchain}`, ); continue; } if (rank >= r0) { this.logger.trace( - `Calculated rank: ${ + `Epoch check: Calculated rank: ${ rank + 1 }. Node not in R0: ${r0} for the Service Agreement with the ID: ${ serviceAgreement.agreementId - }. Skipping scheduling submitCommitCommand.`, + }. Skipping scheduling submitCommitCommand for blockchain: ${blockchain}`, ); continue; } this.logger.trace( - `Calculated rank: ${ + `Epoch check: Calculated rank: ${ rank + 1 }. Node in R0: ${r0} for the Service Agreement with the ID: ${ serviceAgreement.agreementId - }. Scheduling submitCommitCommand.`, + }. Scheduling submitCommitCommand for blockchain: ${blockchain}`, ); const closestNode = neighbourhood[0]; scheduleSubmitCommitCommands.push( @@ -215,7 +225,7 @@ class EpochCheckCommand extends Command { ); } catch (error) { this.logger.warn( - `Failed to schedule submitCommitCommand for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Error message: ${error.message}.`, + `Epoch check: Failed to schedule submitCommitCommand for the Service Agreement with the ID: ${serviceAgreement.agreementId} for blockchain: ${blockchain}. Error message: ${error.message}.`, ); continue; } @@ -239,10 +249,18 @@ class EpochCheckCommand extends Command { blockchain, proofWindowDurationPerc, ); + this.logger.info( + `Epoch check: Found ${eligibleAgreementsForSubmitProofs.length} eligible agreements for submit proof for blockchain: ${blockchain}`, + ); const scheduleSubmitProofCommands = []; const updateServiceAgreementsLastProofEpoch = []; for (const serviceAgreement of eligibleAgreementsForSubmitProofs) { - if (scheduleSubmitProofCommands.length >= maxTransactions) break; + if (scheduleSubmitProofCommands.length >= maxTransactions) { + this.logger.warn( + `Epoch check: not scheduling new proofs. Submit proofs command length: ${scheduleSubmitProofCommands.length}, max number of transactions: ${maxTransactions} for blockchain: ${blockchain}`, + ); + break; + } try { const eligibleForReward = await this.isEligibleForRewards( @@ -254,7 +272,7 @@ class EpochCheckCommand extends Command { ); if (eligibleForReward) { this.logger.trace( - `Node is eligible for rewards for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Scheduling submitProofsCommand.`, + `Epoch check: Node is eligible for rewards for the Service Agreement with the ID: ${serviceAgreement.agreementId} for blockchain: ${blockchain}. Scheduling submitProofsCommand.`, ); scheduleSubmitProofCommands.push( @@ -262,7 +280,7 @@ class EpochCheckCommand extends Command { ); } else { this.logger.trace( - `Node is not eligible for rewards for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Skipping scheduling submitProofsCommand.`, + `Epoch check: Node is not eligible for rewards for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Skipping scheduling submitProofsCommand for blockchain: ${blockchain}`, ); } updateServiceAgreementsLastProofEpoch.push( @@ -273,7 +291,7 @@ class EpochCheckCommand extends Command { ); } catch (error) { this.logger.warn( - `Failed to schedule submitProofsCommand for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Error message: ${error.message}.`, + `Epoch check: Failed to schedule submitProofsCommand for the Service Agreement with the ID: ${serviceAgreement.agreementId} for blockchain: ${blockchain}. Error message: ${error.message}.`, ); continue; } diff --git a/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js b/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js index daf2576398..4a2ab745c1 100644 --- a/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js +++ b/src/commands/protocols/update/receiver/v1.0.0/v1-0-0-handle-update-request-command.js @@ -96,9 +96,7 @@ class HandleUpdateRequestCommand extends HandleProtocolMessageCommand { throw Error('Unable to find neighbourhood edges for asset'); } - const totalNodesNumber = await this.blockchainModuleManager.getShardingTableLength( - blockchain, - ); + const totalNodesNumber = await this.repositoryModuleManager.getPeersCount(blockchain); const minStake = await this.blockchainModuleManager.getMinimumStake(blockchain); const maxStake = await this.blockchainModuleManager.getMaximumStake(blockchain); diff --git a/src/constants/constants.js b/src/constants/constants.js index 47af51d9c5..ddb44ab5bc 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -576,8 +576,8 @@ export const CONTRACTS = { SERVICE_AGREEMENT_V1_CONTRACT: 'ServiceAgreementV1Contract', PARAMETERS_STORAGE_CONTRACT: 'ParametersStorageContract', IDENTITY_STORAGE_CONTRACT: 'IdentityStorageContract', - Log2PLDSF: 'Log2PLDSF', - LINEAR_SUM: 'LinearSum', + Log2PLDSF_CONTRACT: 'Log2PLDSFContract', + LINEAR_SUM_CONTRACT: 'LinearSumContract', }; export const CONTRACT_EVENTS = { @@ -588,6 +588,8 @@ export const CONTRACT_EVENTS = { COMMIT_MANAGER_V1: ['StateFinalized'], SERVICE_AGREEMENT_V1: ['ServiceAgreementV1Extended', 'ServiceAgreementV1Terminated'], PARAMETERS_STORAGE: ['ParameterChanged'], + Log2PLDSF: ['ParameterChanged'], + LINEAR_SUM: ['ParameterChanged'], }; export const NODE_ENVIRONMENTS = { diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index db44d6ce73..9db13b47de 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -710,9 +710,10 @@ class Web3Service { ) { const contract = this[contractName]; if (!contract) { - throw new Error( - `Error while getting all past events. Unknown contract: ${contractName}`, - ); + // this will happen when we have different set of contracts on different blockchains + // eg LinearSum contract is available on gnosis but not on NeuroWeb, so the node should not fetch events + // from LinearSum contract on NeuroWeb blockchain + return []; } let fromBlock; @@ -1294,7 +1295,7 @@ class Web3Service { this.scoringFunctionsContracts[2], 'getParameters', [], - CONTRACTS.LINEAR_SUM, + CONTRACTS.LINEAR_SUM_CONTRACT, ); return { distanceScaleFactor: BigNumber.from(linearSumParams[0]), diff --git a/src/service/blockchain-event-listener-service.js b/src/service/blockchain-event-listener-service.js index afb4b889d9..aca8db13f2 100644 --- a/src/service/blockchain-event-listener-service.js +++ b/src/service/blockchain-event-listener-service.js @@ -88,6 +88,18 @@ class BlockchainEventListenerService { currentBlock, CONTRACT_EVENTS.PARAMETERS_STORAGE, ), + this.getContractEvents( + blockchainId, + CONTRACTS.Log2PLDSF_CONTRACT, + currentBlock, + CONTRACT_EVENTS.Log2PLDSF, + ), + this.getContractEvents( + blockchainId, + CONTRACTS.LINEAR_SUM_CONTRACT, + currentBlock, + CONTRACT_EVENTS.LINEAR_SUM, + ), ]; if (!devEnvironment) { @@ -239,13 +251,38 @@ class BlockchainEventListenerService { async handleParameterChangedEvents(blockEvents) { for (const event of blockEvents) { - const { parameterName, parameterValue } = JSON.parse(event.data); - this.blockchainModuleManager.setContractCallCache( - event.blockchainId, - CONTRACTS.PARAMETERS_STORAGE_CONTRACT, - parameterName, - parameterValue, - ); + const { blockchainId, contract, data } = event; + const { parameterName, parameterValue } = JSON.parse(data); + switch (contract) { + case CONTRACTS.Log2PLDSF_CONTRACT: + this.blockchainModuleManager.setContractCallCache( + blockchainId, + CONTRACTS.Log2PLDSF_CONTRACT, + parameterName, + null, + ); + break; + case CONTRACTS.LINEAR_SUM_CONTRACT: + this.blockchainModuleManager.setContractCallCache( + blockchainId, + CONTRACTS.LINEAR_SUM_CONTRACT, + parameterName, + null, + ); + break; + case CONTRACTS.PARAMETERS_STORAGE_CONTRACT: + this.blockchainModuleManager.setContractCallCache( + blockchainId, + CONTRACTS.PARAMETERS_STORAGE_CONTRACT, + parameterName, + parameterValue, + ); + break; + default: + this.logger.warn( + `Unable to handle parameter changed event. Unknown contract name ${event.contract}`, + ); + } } } From ac2277a9d80336c1c1f2e7926ea317ffba12ee23 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Thu, 1 Feb 2024 12:21:58 +0100 Subject: [PATCH 3/8] Get peers ordered by sha256 --- .../implementation/sequelize/repositories/shard-repository.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/repository/implementation/sequelize/repositories/shard-repository.js b/src/modules/repository/implementation/sequelize/repositories/shard-repository.js index 86fb01460b..2b66f77b84 100644 --- a/src/modules/repository/implementation/sequelize/repositories/shard-repository.js +++ b/src/modules/repository/implementation/sequelize/repositories/shard-repository.js @@ -41,6 +41,7 @@ class ShardRepository { blockchainId, }, attributes: ['peerId', 'blockchainId', 'ask', 'stake', 'lastSeen', 'sha256'], + order: [['sha256', 'asc']], }; if (filterLastSeen) { From d19ff0b8eb15ac931d0681529b50c15977efcee0 Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Thu, 1 Feb 2024 13:06:15 +0100 Subject: [PATCH 4/8] Updated migration for removing service agreements for chiado --- ot-node.js | 2 +- src/migration/migration-executor.js | 15 +++++++++------ ...ve-service-agreements-for-chiado-migration.js} | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) rename src/migration/{remove-service-agreements-for-chiado-devnet-migration.js => remove-service-agreements-for-chiado-migration.js} (76%) diff --git a/ot-node.js b/ot-node.js index a8916ce8b7..7a64c5f38c 100644 --- a/ot-node.js +++ b/ot-node.js @@ -49,7 +49,7 @@ class OTNode { await this.initializeModules(); - await MigrationExecutor.executeRemoveServiceAgreementsForChiadoDevnetMigration( + await MigrationExecutor.executeRemoveServiceAgreementsForChiadoMigration( this.container, this.logger, this.config, diff --git a/src/migration/migration-executor.js b/src/migration/migration-executor.js index 35c3ccffcd..5a5559f777 100644 --- a/src/migration/migration-executor.js +++ b/src/migration/migration-executor.js @@ -15,7 +15,7 @@ import ServiceAgreementsInvalidDataMigration from './service-agreements-invalid- import UalExtensionUserConfigurationMigration from './ual-extension-user-configuration-migration.js'; import UalExtensionTripleStoreMigration from './ual-extension-triple-store-migration.js'; import MarkStakingEventsAsProcessedMigration from './mark-staking-events-as-processed-migration.js'; -import RemoveServiceAgreementsForChiadoDevnetMigration from './remove-service-agreements-for-chiado-devnet-migration.js'; +import RemoveServiceAgreementsForChiadoMigration from './remove-service-agreements-for-chiado-migration.js'; class MigrationExecutor { static async executePullShardingTableMigration(container, logger, config) { @@ -365,12 +365,15 @@ class MigrationExecutor { } } - static async executeRemoveServiceAgreementsForChiadoDevnetMigration(container, logger, config) { - if (process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVNET) { + static async executeRemoveServiceAgreementsForChiadoMigration(container, logger, config) { + if ( + process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVNET || + process.env.NODE_ENV === NODE_ENVIRONMENTS.TESTNET + ) { const repositoryModuleManager = container.resolve('repositoryModuleManager'); - const migration = new RemoveServiceAgreementsForChiadoDevnetMigration( - 'removeServiceAgreementsForChiadoDevnetMigrationV2', + const migration = new RemoveServiceAgreementsForChiadoMigration( + 'removeServiceAgreementsForChiadoMigrationV2', logger, config, repositoryModuleManager, @@ -380,7 +383,7 @@ class MigrationExecutor { await migration.migrate(); } catch (error) { logger.error( - `Unable to execute remove service agreements for Chiado Devnet migration. Error: ${error.message}`, + `Unable to execute remove service agreements for Chiado migration. Error: ${error.message}`, ); this.exitNode(1); } diff --git a/src/migration/remove-service-agreements-for-chiado-devnet-migration.js b/src/migration/remove-service-agreements-for-chiado-migration.js similarity index 76% rename from src/migration/remove-service-agreements-for-chiado-devnet-migration.js rename to src/migration/remove-service-agreements-for-chiado-migration.js index 7c8dab87c5..680931b4f2 100644 --- a/src/migration/remove-service-agreements-for-chiado-devnet-migration.js +++ b/src/migration/remove-service-agreements-for-chiado-migration.js @@ -2,7 +2,7 @@ import BaseMigration from './base-migration.js'; const GNOSIS_DEVNET_CHAIN_ID = 'gnosis:10200'; -class RemoveServiceAgreementsForChiadoDevnetMigration extends BaseMigration { +class RemoveServiceAgreementsForChiadoMigration extends BaseMigration { constructor(migrationName, logger, config, repositoryModuleManager) { super(migrationName, logger, config); this.repositoryModuleManager = repositoryModuleManager; @@ -15,4 +15,4 @@ class RemoveServiceAgreementsForChiadoDevnetMigration extends BaseMigration { } } -export default RemoveServiceAgreementsForChiadoDevnetMigration; +export default RemoveServiceAgreementsForChiadoMigration; From 3c186f4ce669580430db7625ab2e7ebdd59d7dd8 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Thu, 1 Feb 2024 14:29:42 +0100 Subject: [PATCH 5/8] Fixed LinearSum score calculation --- src/constants/constants.js | 2 +- src/service/proximity-scoring-service.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index ddb44ab5bc..79a666d1d0 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -18,7 +18,7 @@ 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 HASH_RING_SIZE = BigNumber.from(2).pow(256); +export const HASH_RING_SIZE = BigNumber.from(2).pow(256).sub(1); export const STAKE_UINT256_MULTIPLIER_BN = UINT256_MAX_BN.div(500000000); diff --git a/src/service/proximity-scoring-service.js b/src/service/proximity-scoring-service.js index ade26896ec..4e06f6197a 100644 --- a/src/service/proximity-scoring-service.js +++ b/src/service/proximity-scoring-service.js @@ -143,10 +143,9 @@ class ProximityScoringService { const idealMaxDistanceInNeighborhood = HASH_RING_SIZE.div(nodesNumber).mul( Math.ceil(r2 / 2), ); - const divisor = - maxNeighborhoodDistance <= idealMaxDistanceInNeighborhood - ? maxNeighborhoodDistance - : idealMaxDistanceInNeighborhood; + const divisor = maxNeighborhoodDistance.lte(idealMaxDistanceInNeighborhood) + ? maxNeighborhoodDistance + : idealMaxDistanceInNeighborhood; const maxMultiplier = UINT256_MAX_BN.div(distance); From bf36e12d6b4f07ff4587c18ae269b74eb2363280 Mon Sep 17 00:00:00 2001 From: Nikola Todorovic Date: Thu, 1 Feb 2024 14:32:54 +0100 Subject: [PATCH 6/8] Update src/service/blockchain-event-listener-service.js --- src/service/blockchain-event-listener-service.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/service/blockchain-event-listener-service.js b/src/service/blockchain-event-listener-service.js index 087854f6cd..d49436ae87 100644 --- a/src/service/blockchain-event-listener-service.js +++ b/src/service/blockchain-event-listener-service.js @@ -255,6 +255,8 @@ class BlockchainEventListenerService { const { parameterName, parameterValue } = JSON.parse(data); switch (contract) { case CONTRACTS.Log2PLDSF_CONTRACT: + // This invalidates contracts parameter + // TODO: Create function for contract call cache invalidation this.blockchainModuleManager.setContractCallCache( blockchainId, CONTRACTS.Log2PLDSF_CONTRACT, From 6c03295abddf92c0b1a101ae4b9365773fab7d02 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Thu, 1 Feb 2024 14:36:09 +0100 Subject: [PATCH 7/8] Use ehters constant for uin256 max value --- src/constants/constants.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index 79a666d1d0..24b9539962 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -8,7 +8,7 @@ export const FALLBACK_PROVIDER_QUORUM = 1; export const RPC_PROVIDER_STALL_TIMEOUT = 60 * 1000; -export const UINT256_MAX_BN = BigNumber.from(2).pow(256).sub(1); +export const UINT256_MAX_BN = ethers.constants.MaxUint256; export const UINT128_MAX_BN = BigNumber.from(2).pow(128).sub(1); @@ -18,7 +18,7 @@ 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 HASH_RING_SIZE = BigNumber.from(2).pow(256).sub(1); +export const HASH_RING_SIZE = ethers.constants.MaxUint256; export const STAKE_UINT256_MULTIPLIER_BN = UINT256_MAX_BN.div(500000000); From 01bb1acca5bd37080e3b28cb29c55013562a3dad Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Thu, 1 Feb 2024 14:55:09 +0100 Subject: [PATCH 8/8] Update commit hash for dkg-evm-module --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 53ac11e5c1..4a1dfdf078 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8563,7 +8563,7 @@ }, "node_modules/dkg-evm-module": { "version": "4.2.0", - "resolved": "git+ssh://git@github.com/OriginTrail/dkg-evm-module.git#940afd112685cfd20aad52f13274b1ce47bff409", + "resolved": "git+ssh://git@github.com/OriginTrail/dkg-evm-module.git#5fcbdfba99d8b8b9d23d9e2277f73a1bfa70c50c", "license": "Apache-2.0", "dependencies": { "@openzeppelin/contracts": "^4.9.3", @@ -27985,7 +27985,7 @@ "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==" }, "dkg-evm-module": { - "version": "git+ssh://git@github.com/OriginTrail/dkg-evm-module.git#940afd112685cfd20aad52f13274b1ce47bff409", + "version": "git+ssh://git@github.com/OriginTrail/dkg-evm-module.git#5fcbdfba99d8b8b9d23d9e2277f73a1bfa70c50c", "from": "dkg-evm-module@github:OriginTrail/dkg-evm-module#release/delegations", "requires": { "@openzeppelin/contracts": "^4.9.3",