From af742bdde6c04ec287c8bf20f4ed777fefc521c5 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Mon, 21 Aug 2023 16:16:54 +0100 Subject: [PATCH 1/9] Removed fixed gas limit for blockchain functions --- src/constants/constants.js | 6 ------ src/modules/blockchain/implementation/web3-service.js | 11 ++--------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index 9c807292ea..867b5b384d 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -492,12 +492,6 @@ export const CONTRACT_EVENT_FETCH_INTERVALS = { DEVELOPMENT: 4 * 1000, }; -export const FIXED_GAS_LIMIT_METHODS = { - submitCommit: 600000, - submitUpdateCommit: 600000, - sendProof: 500000, -}; - export const BLOCK_TIME_MILLIS = { OTP: 12_000, HARDHAT: 5_000, diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index e003f881d8..f1e02e680f 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -8,7 +8,6 @@ import { DEFAULT_BLOCKCHAIN_EVENT_SYNC_PERIOD_IN_MILLS, MAXIMUM_NUMBERS_OF_BLOCKS_TO_FETCH, TRANSACTION_QUEUE_CONCURRENCY, - FIXED_GAS_LIMIT_METHODS, TRANSACTION_POLLING_TIMEOUT_MILLIS, TRANSACTION_CONFIRMATIONS, BLOCK_TIME_MILLIS, @@ -348,13 +347,7 @@ class Web3Service { while (result === undefined) { try { /* eslint-disable no-await-in-loop */ - let gasLimit; - - if (FIXED_GAS_LIMIT_METHODS[functionName]) { - gasLimit = FIXED_GAS_LIMIT_METHODS[functionName]; - } else { - gasLimit = await contractInstance.estimateGas[functionName](...args); - } + const gasLimit = await contractInstance.estimateGas[functionName](...args); const gas = gasLimit ?? this.convertToWei(900, 'kwei'); @@ -383,7 +376,7 @@ class Web3Service { (error.message.includes(`timeout exceeded`) || error.message.includes(`Pool(TooLowPriority`)) ) { - gasPrice = Math.ceil(gasPrice * 1.2); + gasPrice += 1; this.logger.warn( `Retrying to execute smart contract function ${functionName} with gasPrice: ${gasPrice}`, ); From 4a7854c4d5cc9d49f9aa24ff8447be1a1bf1d967 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Tue, 22 Aug 2023 08:05:43 +0100 Subject: [PATCH 2/9] Changed gasPrice handling to use BigNumber --- src/modules/blockchain/implementation/web3-service.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index f1e02e680f..8e059503c7 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -1,4 +1,4 @@ -import { ethers } from 'ethers'; +import { BigNumber, ethers } from 'ethers'; import axios from 'axios'; import async from 'async'; import { setTimeout as sleep } from 'timers/promises'; @@ -348,7 +348,6 @@ class Web3Service { try { /* eslint-disable no-await-in-loop */ const gasLimit = await contractInstance.estimateGas[functionName](...args); - const gas = gasLimit ?? this.convertToWei(900, 'kwei'); this.logger.info( @@ -376,7 +375,7 @@ class Web3Service { (error.message.includes(`timeout exceeded`) || error.message.includes(`Pool(TooLowPriority`)) ) { - gasPrice += 1; + gasPrice = BigNumber.from(gasPrice).add(1); this.logger.warn( `Retrying to execute smart contract function ${functionName} with gasPrice: ${gasPrice}`, ); From 3099d147a25fc1f10ef7fd28f742cde8765cc762 Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Mon, 4 Sep 2023 11:31:01 +0200 Subject: [PATCH 3/9] Updated check for root hash --- src/service/validation-service.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/service/validation-service.js b/src/service/validation-service.js index a6cd284152..0786db76d0 100644 --- a/src/service/validation-service.js +++ b/src/service/validation-service.js @@ -34,7 +34,6 @@ class ValidationService { this.validateAssertionId(assertion, assertionId); // TODO: get assertion data in one call - await this.validateAssertionSize(blockchain, assertionId, assertion); await this.validateTriplesNumber(blockchain, assertionId, assertion); await this.validateChunkSize(blockchain, assertionId, assertion); @@ -56,7 +55,8 @@ class ValidationService { } const assertionSize = assertionMetadata.getAssertionSizeInBytes(assertion); if (blockchainAssertionSize !== assertionSize) { - throw Error( + // todo after corrective component is implemented, update this logic + this.logger.warn( `Invalid assertion size, value read from blockchain: ${blockchainAssertionSize}, calculated: ${assertionSize}`, ); } @@ -90,7 +90,8 @@ class ValidationService { const calculatedAssertionId = this.validationModuleManager.calculateRoot(assertion); if (assertionId !== calculatedAssertionId) { - throw Error( + // todo after corrective component is implemented, update this logic + this.logger.warn( `Invalid assertion id. Received value: ${assertionId}, calculated: ${calculatedAssertionId}`, ); } From 845b39432af11834c247f6676fc27432143b7347 Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Mon, 4 Sep 2023 11:45:05 +0200 Subject: [PATCH 4/9] Unit tests updated --- test/unit/service/validation-service.test.js | 90 ++++++++++---------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/test/unit/service/validation-service.test.js b/test/unit/service/validation-service.test.js index 7cb77e625e..69dafd7e39 100644 --- a/test/unit/service/validation-service.test.js +++ b/test/unit/service/validation-service.test.js @@ -49,22 +49,23 @@ describe('Validation service test', async () => { }); it('Tries to validate assertion but fails due to assertion size mismatch', async () => { - let errorThrown = false; - try { - await validationService.validateAssertion( - '0xde58cc52a5ce3a04ae7a05a13176226447ac02489252e4d37a72cbe0aea46b42', - 'hardhat', - { - '@context': 'https://schema.org', - '@id': 'https://tesla.modelX/2321', - '@type': 'Car', - name: 'Tesla Model X', - }, - ); - } catch (error) { - errorThrown = true; - } - expect(errorThrown).to.be.true; + // todo after corrective component is implemented, update this logic + // let errorThrown = false; + // try { + // await validationService.validateAssertion( + // '0xde58cc52a5ce3a04ae7a05a13176226447ac02489252e4d37a72cbe0aea46b42', + // 'hardhat', + // { + // '@context': 'https://schema.org', + // '@id': 'https://tesla.modelX/2321', + // '@type': 'Car', + // name: 'Tesla Model X', + // }, + // ); + // } catch (error) { + // errorThrown = true; + // } + // expect(errorThrown).to.be.true; }); it('Tries to validate assertion but fails due to triple number mismatch', async () => { @@ -136,34 +137,35 @@ describe('Validation service test', async () => { }); it('Tries to validate assertion but fails due to validation manager returning wrong assertion id', async () => { + // todo after corrective component is implemented, update this logic // Will lead to mismatch with passed assertion id - validationService.validationModuleManager.calculateRoot = (assertion) => ''; - - let errorThrown = false; - try { - await validationService.validateAssertion( - '0xde58cc52a5ce3a04ae7a05a13176226447ac02489252e4d37a72cbe0aea46b42', - 'hardhat', - { - '@context': 'https://schema.org', - '@id': 'https://tesla.modelX/2321', - '@type': 'Car', - name: 'Tesla Model X', - brand: { - '@type': 'Brand', - name: 'Tesla', - }, - model: 'Model X', - manufacturer: { - '@type': 'Organization', - name: 'Tesla, Inc.', - }, - fuelType: 'Electric', - }, - ); - } catch (error) { - errorThrown = true; - } - expect(errorThrown).to.be.true; + // validationService.validationModuleManager.calculateRoot = (assertion) => ''; + // + // let errorThrown = false; + // try { + // await validationService.validateAssertion( + // '0xde58cc52a5ce3a04ae7a05a13176226447ac02489252e4d37a72cbe0aea46b42', + // 'hardhat', + // { + // '@context': 'https://schema.org', + // '@id': 'https://tesla.modelX/2321', + // '@type': 'Car', + // name: 'Tesla Model X', + // brand: { + // '@type': 'Brand', + // name: 'Tesla', + // }, + // model: 'Model X', + // manufacturer: { + // '@type': 'Organization', + // name: 'Tesla, Inc.', + // }, + // fuelType: 'Electric', + // }, + // ); + // } catch (error) { + // errorThrown = true; + // } + // expect(errorThrown).to.be.true; }); }); From 4b1fccf0f46d47bb9ad30de8d8634c5669f434a3 Mon Sep 17 00:00:00 2001 From: Niks988 Date: Mon, 4 Sep 2023 14:26:05 +0200 Subject: [PATCH 5/9] bugfix - npm command improved with proper installation version --- installer/installer.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/installer/installer.sh b/installer/installer.sh index ba6a78771b..b9d090e96d 100755 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -87,7 +87,7 @@ install_prereqs() { rm -rf setup_$NODEJS_VER.x perform_step apt update "Updating Ubuntu package repository" perform_step apt-get install nodejs -y "Installing node.js" - perform_step npm install -g npm "Installing npm" + perform_step npm install -g npm@^8 "Installing npm" perform_step install_firewall "Configuring firewall" perform_step apt remove unattended-upgrades -y "Remove unattended upgrades" } @@ -263,9 +263,9 @@ install_node() { perform_step touch $CONFIG_DIR/.origintrail_noderc "Configuring node config file" perform_step $(jq --null-input --arg tripleStore "$tripleStore" '{"logLevel": "trace", "auth": {"ipWhitelist": ["::1", "127.0.0.1"]}}' > $CONFIG_DIR/.origintrail_noderc) "Adding loglevel and auth values to node config file" - perform_step $(jq --arg tripleStore "$tripleStore" --arg tripleStoreUrl "$tripleStoreUrl" '.modules.tripleStore.implementation[$tripleStore] |= + perform_step $(jq --arg tripleStore "$tripleStore" --arg tripleStoreUrl "$tripleStoreUrl" '.modules.tripleStore.implementation[$tripleStore] |= { - "enabled": "true", + "enabled": "true", "config": { "repositories": { "privateCurrent": { @@ -293,24 +293,24 @@ install_node() { "password": "" } } - } + } } + .' $CONFIG_DIR/.origintrail_noderc > $CONFIG_DIR/origintrail_noderc_tmp) "Adding node wallets to node config file 1/2" perform_step mv $CONFIG_DIR/origintrail_noderc_tmp $CONFIG_DIR/.origintrail_noderc "Adding node wallets to node config file 2/2" - - perform_step $(jq --arg blockchain "otp" --arg evmOperationalWallet "$EVM_OPERATIONAL_WALLET" --arg evmOperationalWalletPrivateKey "$EVM_OPERATIONAL_PRIVATE_KEY" --arg evmManagementWallet "$EVM_MANAGEMENT_WALLET" --arg evmManagementWallet "$SHARES_TOKEN_NAME" --arg evmManagementWallet "$SHARES_TOKEN_SYMBOL" --arg sharesTokenName "$SHARES_TOKEN_NAME" --arg sharesTokenSymbol "$SHARES_TOKEN_SYMBOL" '.modules.blockchain.implementation[$blockchain].config |= - { - "evmOperationalWalletPublicKey": $evmOperationalWallet, - "evmOperationalWalletPrivateKey": $evmOperationalWalletPrivateKey, - "evmManagementWalletPublicKey": $evmManagementWallet, - "sharesTokenName": $sharesTokenName, + + perform_step $(jq --arg blockchain "otp" --arg evmOperationalWallet "$EVM_OPERATIONAL_WALLET" --arg evmOperationalWalletPrivateKey "$EVM_OPERATIONAL_PRIVATE_KEY" --arg evmManagementWallet "$EVM_MANAGEMENT_WALLET" --arg evmManagementWallet "$SHARES_TOKEN_NAME" --arg evmManagementWallet "$SHARES_TOKEN_SYMBOL" --arg sharesTokenName "$SHARES_TOKEN_NAME" --arg sharesTokenSymbol "$SHARES_TOKEN_SYMBOL" '.modules.blockchain.implementation[$blockchain].config |= + { + "evmOperationalWalletPublicKey": $evmOperationalWallet, + "evmOperationalWalletPrivateKey": $evmOperationalWalletPrivateKey, + "evmManagementWalletPublicKey": $evmManagementWallet, + "sharesTokenName": $sharesTokenName, "sharesTokenSymbol": $sharesTokenSymbol } + .' $CONFIG_DIR/.origintrail_noderc > $CONFIG_DIR/origintrail_noderc_tmp) "Adding node wallets to node config file 1/2" - + perform_step mv $CONFIG_DIR/origintrail_noderc_tmp $CONFIG_DIR/.origintrail_noderc "Adding node wallets to node config file 2/2" perform_step cp $OTNODE_DIR/installer/data/otnode.service /lib/systemd/system/ "Copying otnode service file" - + systemctl daemon-reload perform_step systemctl enable otnode "Enabling otnode" perform_step systemctl start otnode "Starting otnode" @@ -411,4 +411,4 @@ If the logs do not show and the screen hangs, press ctrl+c to exit the installat " read -p "Press enter to continue..." -journalctl -u otnode --output cat -fn 200 \ No newline at end of file +journalctl -u otnode --output cat -fn 200 From e922299db3e8944138e83a22bd2babc6ebdb6550 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Wed, 6 Sep 2023 14:00:17 +0100 Subject: [PATCH 6/9] Reverted back gasPrice increase by 20% on retry --- src/modules/blockchain/implementation/web3-service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index 8e059503c7..5759b4d1bf 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -1,4 +1,4 @@ -import { BigNumber, ethers } from 'ethers'; +import { ethers } from 'ethers'; import axios from 'axios'; import async from 'async'; import { setTimeout as sleep } from 'timers/promises'; @@ -375,7 +375,7 @@ class Web3Service { (error.message.includes(`timeout exceeded`) || error.message.includes(`Pool(TooLowPriority`)) ) { - gasPrice = BigNumber.from(gasPrice).add(1); + gasPrice = Math.ceil(gasPrice * 1.2); this.logger.warn( `Retrying to execute smart contract function ${functionName} with gasPrice: ${gasPrice}`, ); From 270ccf10a2ab5bc197930734a0f1aff760b31693 Mon Sep 17 00:00:00 2001 From: NZT48 Date: Thu, 7 Sep 2023 15:29:09 +0200 Subject: [PATCH 7/9] Round small assertions to 1KB --- src/service/sharding-table-service.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/service/sharding-table-service.js b/src/service/sharding-table-service.js index a1200c0deb..87688c0a42 100644 --- a/src/service/sharding-table-service.js +++ b/src/service/sharding-table-service.js @@ -152,6 +152,7 @@ class ShardingTableService { firstAssertionId, hashFunctionId, ) { + const kbSize = assertionSize < BYTES_IN_KILOBYTE ? BYTES_IN_KILOBYTE : assertionSize; const peerRecords = await this.findNeighbourhood( blockchainId, this.blockchainModuleManager.encodePacked( @@ -177,20 +178,13 @@ class ShardingTableService { const r0 = await this.blockchainModuleManager.getR0(blockchainId); - const minBidSuggestion = this.blockchainModuleManager - .toBigNumber(blockchainId, '1') - .mul(epochsNumber) - .mul(r0); - const bidSuggestion = this.blockchainModuleManager .toBigNumber(blockchainId, this.blockchainModuleManager.convertToWei(blockchainId, ask)) - .mul(assertionSize) + .mul(kbSize) .mul(epochsNumber) .mul(r0) .div(BYTES_IN_KILOBYTE); - return bidSuggestion.lte(minBidSuggestion) - ? minBidSuggestion.toString() - : bidSuggestion.toString(); + return bidSuggestion.toString(); } async findEligibleNodes(neighbourhood, bid, r1, r0) { From 1a9fd378a300e6b8eff0608d24c28fba068c9a88 Mon Sep 17 00:00:00 2001 From: NZT48 Date: Thu, 7 Sep 2023 15:30:23 +0200 Subject: [PATCH 8/9] Bump version to 6.0.15 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index cf09c0f316..ffc9ae1c34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.0.14", + "version": "6.0.15", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.0.14", + "version": "6.0.15", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index c10bb71d29..2c8c7ec700 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.0.14", + "version": "6.0.15", "description": "OTNode V6", "main": "index.js", "type": "module", From b68134911185b74a1b7f270411cb4657029c7b33 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Sep 2023 13:52:57 +0000 Subject: [PATCH 9/9] Bump protobufjs from 6.11.3 to 6.11.4 Bumps [protobufjs](https://github.com/protobufjs/protobuf.js) from 6.11.3 to 6.11.4. - [Release notes](https://github.com/protobufjs/protobuf.js/releases) - [Changelog](https://github.com/protobufjs/protobuf.js/blob/master/CHANGELOG.md) - [Commits](https://github.com/protobufjs/protobuf.js/commits) --- updated-dependencies: - dependency-name: protobufjs dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index ffc9ae1c34..28d3231823 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15569,9 +15569,9 @@ "dev": true }, "node_modules/protobufjs": { - "version": "6.11.3", - "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.11.3.tgz", - "integrity": "sha512-xL96WDdCZYdU7Slin569tFX712BxsxslWwAfAhCYjQKGTq7dAU91Lomy6nLLhh/dyGhk/YH4TwTSRxTzhuHyZg==", + "version": "6.11.4", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.11.4.tgz", + "integrity": "sha512-5kQWPaJHi1WoCpjTGszzQ32PG2F4+wRY6BmAT4Vfw56Q2FZ4YZzK20xUYQH4YkfehY1e6QSICrJquM6xXZNcrw==", "hasInstallScript": true, "dependencies": { "@protobufjs/aspromise": "^1.1.2", @@ -31816,9 +31816,9 @@ "dev": true }, "protobufjs": { - "version": "6.11.3", - "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.11.3.tgz", - "integrity": "sha512-xL96WDdCZYdU7Slin569tFX712BxsxslWwAfAhCYjQKGTq7dAU91Lomy6nLLhh/dyGhk/YH4TwTSRxTzhuHyZg==", + "version": "6.11.4", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.11.4.tgz", + "integrity": "sha512-5kQWPaJHi1WoCpjTGszzQ32PG2F4+wRY6BmAT4Vfw56Q2FZ4YZzK20xUYQH4YkfehY1e6QSICrJquM6xXZNcrw==", "requires": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2",