From 7c505ee7b21d5e882397d60d2be4eef771f718a2 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Thu, 4 Jul 2024 13:07:38 +0200 Subject: [PATCH 1/4] OriginTrail Testnet Release v6.5.0 (#3233) * OriginTrail Testnet prerelease v6.5.0 (#3225) * Resolving sequelize timeout errors * Hotfix version updated * Updated Simulation script for LinearSum, updated dkg-evm-module package (#3215) * Add support for BASE blockchain (#3216) * Default config update * Fix package path for base integration * Add base-service implementation * Add Hub contracts for devnet and testnet * Version bump * Fix baseTokenTicker in BaseService * Update dkg.js version. Add typesrcipt dependecy for hardhat support * Set version to 6.5.0 * OriginTrail Devnet prerelease v6.5.0 (#3218) * Updated Simulation script for LinearSum, updated dkg-evm-module package (#3215) * Add support for BASE blockchain (#3216) * Default config update * Fix package path for base integration * Add base-service implementation * Add Hub contracts for devnet and testnet * Version bump * Fix baseTokenTicker in BaseService * Update dkg.js version. Add typesrcipt dependecy for hardhat support * Set version to 6.5.0 --------- Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> * Fix/get gas price in scripts (#3219) * Update getGasPrice in set-stake * Update set-ask getGasPrice * Version update --------- Co-authored-by: djordjekovac Co-authored-by: Nikola Todorovic Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> * OriginTrail Testnet Prerelease v6.5.0 (#3232) * Updated Simulation script for LinearSum, updated dkg-evm-module package (#3215) * Add support for BASE blockchain (#3216) * Default config update * Fix package path for base integration * Add base-service implementation * Add Hub contracts for devnet and testnet * Version bump * Fix baseTokenTicker in BaseService * Update dkg.js version. Add typesrcipt dependecy for hardhat support * Set version to 6.5.0 * OriginTrail Devnet prerelease v6.5.0 (#3218) * Updated Simulation script for LinearSum, updated dkg-evm-module package (#3215) * Add support for BASE blockchain (#3216) * Default config update * Fix package path for base integration * Add base-service implementation * Add Hub contracts for devnet and testnet * Version bump * Fix baseTokenTicker in BaseService * Update dkg.js version. Add typesrcipt dependecy for hardhat support * Set version to 6.5.0 --------- Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> * Fix/get gas price in scripts (#3219) * Update getGasPrice in set-stake * Update set-ask getGasPrice * Version update * OriginTrail Devnet Release v6.5.0 (#3231) * branch fix 2 --------- Co-authored-by: djordjekovac Co-authored-by: Nikola Todorovic Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> --------- Co-authored-by: djordjekovac Co-authored-by: Nikola Todorovic Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> --- config/config.json | 2 +- installer/installer.sh | 346 +++++++++++++++++------------------------ package-lock.json | 4 +- package.json | 2 +- scripts/set-ask.js | 17 +- scripts/set-stake.js | 17 +- 6 files changed, 164 insertions(+), 224 deletions(-) diff --git a/config/config.json b/config/config.json index cbc91c4b3..6f687077a 100644 --- a/config/config.json +++ b/config/config.json @@ -817,7 +817,7 @@ "package": "./blockchain/implementation/base/base-service.js", "config": { - "hubContractAddress": "", + "hubContractAddress": "0xaBfcf2ad1718828E7D3ec20435b0d0b5EAfbDf2c", "operatorFee": 0 } } diff --git a/installer/installer.sh b/installer/installer.sh index 364dad676..77754cc11 100755 --- a/installer/installer.sh +++ b/installer/installer.sh @@ -283,7 +283,7 @@ install_node() { # Change directory to ot-node/current cd $OTNODE_DIR - # Request node env with strict input validation + # Request node environment with strict input validation while true; do read -p "Please select node environment: (Default: Mainnet) [T]estnet [M]ainnet [E]xit " choice case "$choice" in @@ -295,142 +295,79 @@ install_node() { done echo "NODE_ENV=$nodeEnv" >> $OTNODE_DIR/.env -# Blockchains prompt based on the selected environment -if [ "$nodeEnv" == "mainnet" ]; then - blockchain_prompt=("OriginTrail Parachain" "Gnosis" "Both") -elif [ "$nodeEnv" == "testnet" ]; then - blockchain_prompt=("OriginTrail Parachain" "Gnosis" "Both") -fi - - -# Ask user which blockchain to connect to with strict input validation -while true; do - read -p "Please select the blockchain you want to connect your node to: - 1. ${blockchain_prompt[0]} - 2. ${blockchain_prompt[1]} - 3. ${blockchain_prompt[2]} - Your choice: " blockchain_choice - - case "$blockchain_choice" in - [1]* ) blockchain="${blockchain_prompt[0]}"; break;; - [2]* ) blockchain="${blockchain_prompt[1]}"; break;; - [3]* ) blockchain="${blockchain_prompt[2]}"; break;; - [eE]* ) text_color $RED "Installer stopped by user"; exit;; - * ) text_color $RED "Invalid choice. Please enter a valid number."; continue;; - esac -done - - -# Function to validate Operator Fees input -validate_operator_fees() { - local blockchain=$1 - local operator_fee_variable="${blockchain}_OPERATOR_FEES" - - read -p "Enter Operator Fees (0% - 100%) for $blockchain: " OPERATOR_FEES - if (( OPERATOR_FEES >= 0 && OPERATOR_FEES <= 100 )); then - text_color $GREEN "Operator Fees for $blockchain: $OPERATOR_FEES" - eval "${operator_fee_variable}=$OPERATOR_FEES" + # Set blockchain options based on the selected environment + if [ "$nodeEnv" == "mainnet" ]; then + blockchain_options=("OriginTrail Parachain" "Gnosis" "Base") + otp_blockchain_id=2043 + gnosis_blockchain_id=100 + base_blockchain_id=8453 else - text_color $RED "Please enter Operator Fees in the range of 0% - 100%. Try again." - validate_operator_fees $blockchain + blockchain_options=("OriginTrail Parachain" "Gnosis" "Base-Sepolia") + otp_blockchain_id=20430 + gnosis_blockchain_id=10200 + base_blockchain_id=84532 fi -} - - -# Case statement to handle blockchain-specific configurations -case "$blockchain" in - "OriginTrail Parachain" | "Gnosis" ) - - - if [ "$blockchain" == "OriginTrail Parachain" ]; then - blockchain="OTP" - fi - - - # Input wallets for the selected blockchain - request_operational_wallet_keys $blockchain - EVM_OP_WALLET_KEYS_BLOCKCHAIN=$OP_WALLET_KEYS_JSON - - read -p "Enter your EVM management wallet address for $blockchain: " EVM_MANAGEMENT_WALLET - text_color $GREEN "EVM management wallet address for $blockchain: $EVM_MANAGEMENT_WALLET" - - read -p "Enter your profile shares token name for $blockchain: " SHARES_TOKEN_NAME - text_color $GREEN "Profile shares token name for $blockchain: $SHARES_TOKEN_NAME" - - read -p "Enter your profile shares token symbol for $blockchain: " SHARES_TOKEN_SYMBOL - text_color $GREEN "Profile shares token symbol for $blockchain: $SHARES_TOKEN_SYMBOL" - - # Prompt and validate Operator Fees for the first blockchain - validate_operator_fees $blockchain - eval "OPERATOR_FEE=\$${blockchain}_OPERATOR_FEES" - - if [ "$blockchain" == "Gnosis" ]; then - read -p "Enter your Gnosis RPC endpoint: " GNOSIS_RPC_ENDPOINT - text_color $GREEN "Gnosis RPC endpoint: $GNOSIS_RPC_ENDPOINT" - fi + # Ask user which blockchains to connect to + selected_blockchains=() + checkbox_states=() + for _ in "${blockchain_options[@]}"; do + checkbox_states+=("[ ]") + done - ;; - "Both" ) - if [ "$nodeEnv" == "mainnet" ]; then - blockchain1="OTP" - blockchain2="Gnosis" - elif [ "$nodeEnv" == "testnet" ]; then - blockchain1="OTP" - blockchain2="Gnosis" + while true; do + clear # Clear the screen for a cleaner display + echo "Please select the blockchains you want to connect your node to:" + for i in "${!blockchain_options[@]}"; do + echo " ${checkbox_states[$i]} $((i+1)). ${blockchain_options[$i]}" + done + echo " [ ] $((${#blockchain_options[@]}+1)). All Blockchains" + echo " Enter 'd' to finish selection" + + # Use read -n 1 to read a single character without requiring Enter + read -n 1 -p "Enter the number to toggle selection (1-$((${#blockchain_options[@]}+1))): " choice + echo # Add a newline after the selection + + if [[ "$choice" == "d" ]]; then + if [ ${#selected_blockchains[@]} -eq 0 ]; then + text_color $RED "You must select at least one blockchain. Please try again." + read -n 1 -p "Press any key to continue..." + continue + else + break + fi + elif [[ "$choice" =~ ^[1-${#blockchain_options[@]}]$ ]]; then + index=$((choice-1)) + if [[ "${checkbox_states[$index]}" == "[ ]" ]]; then + checkbox_states[$index]="[x]" + selected_blockchains+=("${blockchain_options[$index]}") + else + checkbox_states[$index]="[ ]" + selected_blockchains=(${selected_blockchains[@]/${blockchain_options[$index]}}) + fi + elif [[ "$choice" == "$((${#blockchain_options[@]}+1))" ]]; then + if [[ "${checkbox_states[-1]}" == "[ ]" ]]; then + for i in "${!checkbox_states[@]}"; do + checkbox_states[$i]="[x]" + done + selected_blockchains=("${blockchain_options[@]}") + else + for i in "${!checkbox_states[@]}"; do + checkbox_states[$i]="[ ]" + done + selected_blockchains=() + fi + else + text_color $RED "Invalid choice. Please enter a number between 1 and $((${#blockchain_options[@]}+1))." + read -n 1 -p "Press any key to continue..." fi + done - # Input wallets for the first blockchain - request_operational_wallet_keys $blockchain1 - EVM_OP_WALLET_KEYS_BLOCKCHAIN1=$OP_WALLET_KEYS_JSON - - read -p "Enter your EVM management wallet address for $blockchain1: " EVM_MANAGEMENT_WALLET - text_color $GREEN "EVM management wallet address for $blockchain1: $EVM_MANAGEMENT_WALLET" - - read -p "Enter your profile shares token name for $blockchain1: " SHARES_TOKEN_NAME - text_color $GREEN "Profile shares token name for $blockchain1: $SHARES_TOKEN_NAME" - - read -p "Enter your profile shares token symbol for $blockchain1: " SHARES_TOKEN_SYMBOL - text_color $GREEN "Profile shares token symbol for $blockchain1: $SHARES_TOKEN_SYMBOL" - - # Prompt and validate Operator Fees for the first blockchain - validate_operator_fees $blockchain1 - OPERATOR_FEES_1=$OTP_OPERATOR_FEES - - # Input wallets for the second blockchain - request_operational_wallet_keys $blockchain2 - EVM_OP_WALLET_KEYS_BLOCKCHAIN2=$OP_WALLET_KEYS_JSON - - read -p "Enter your EVM management wallet address for $blockchain2: " EVM_MANAGEMENT_WALLET_2 - text_color $GREEN "EVM management wallet address for $blockchain2: $EVM_MANAGEMENT_WALLET_2" - - read -p "Enter your profile shares token name for $blockchain2: " SHARES_TOKEN_NAME_2 - text_color $GREEN "Profile shares token name for $blockchain2: $SHARES_TOKEN_NAME_2" - - read -p "Enter your profile shares token symbol for $blockchain2: " SHARES_TOKEN_SYMBOL_2 - text_color $GREEN "Profile shares token symbol for $blockchain2: $SHARES_TOKEN_SYMBOL_2" - - # Prompt and validate Operator Fees for the second blockchain - validate_operator_fees $blockchain2 - OPERATOR_FEES_2=$Gnosis_OPERATOR_FEES - - - read -p "Enter your Gnosis RPC endpoint: " GNOSIS_RPC_ENDPOINT - text_color $GREEN "Gnosis RPC endpoint: $GNOSIS_RPC_ENDPOINT" - - ;; - * ) - text_color $RED "Invalid blockchain choice. Exiting installer." - exit;; -esac - - -perform_step npm ci --omit=dev --ignore-scripts "Executing npm install" - -CONFIG_DIR=$OTNODE_DIR/.. -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" + text_color $GREEN "Final blockchain selection: ${selected_blockchains[*]}" + CONFIG_DIR=$OTNODE_DIR/.. + perform_step touch $CONFIG_DIR/.origintrail_noderc "Configuring node config file" + perform_step $(jq --null-input '{"logLevel": "trace", "auth": {"ipWhitelist": ["::1", "127.0.0.1"]}, "modules": {"blockchain": {"implementation": {}}}}' > $CONFIG_DIR/.origintrail_noderc) "Adding initial config to node config file" perform_step $(jq --arg tripleStore "$tripleStore" --arg tripleStoreUrl "$tripleStoreUrl" '.modules.tripleStore.implementation[$tripleStore] |= { @@ -463,88 +400,89 @@ perform_step $(jq --null-input --arg tripleStore "$tripleStore" '{"logLevel": "t } } } - } + .' $CONFIG_DIR/.origintrail_noderc > $CONFIG_DIR/origintrail_noderc_tmp) "Adding node wallets to node config file 1/2" + } + .' $CONFIG_DIR/.origintrail_noderc > $CONFIG_DIR/origintrail_noderc_tmp) "Adding triple store config to node config file" - perform_step mv $CONFIG_DIR/origintrail_noderc_tmp $CONFIG_DIR/.origintrail_noderc "Adding node wallets to node config file 2/2" + perform_step mv $CONFIG_DIR/origintrail_noderc_tmp $CONFIG_DIR/.origintrail_noderc "Finalizing initial node config file" -# Set blockchain IDs based on the environment -if [ "$nodeEnv" == "mainnet" ]; then - otp_blockchain_id=2043 - gnosis_blockchain_id=100 -else - otp_blockchain_id=20430 - gnosis_blockchain_id=10200 -fi + # Function to validate operator fees + validate_operator_fees() { + local blockchain=$1 + while true; do + read -p "Enter your operator fee for $blockchain (0-100): " OPERATOR_FEE + if [[ "$OPERATOR_FEE" =~ ^[0-9]+$ ]] && [ "$OPERATOR_FEE" -ge 0 ] && [ "$OPERATOR_FEE" -le 100 ]; then + text_color $GREEN "Operator fee for $blockchain: $OPERATOR_FEE" + break + else + text_color $RED "Invalid input. Please enter a number between 0 and 100." + fi + done + } -# Check if "Both" blockchains are selected -if [ "$blockchain" == "Both" ]; then - perform_step $(jq --arg otp_blockchain_id "$otp_blockchain_id" --argjson EVM_OP_WALLET_KEYS_BLOCKCHAIN1 "$EVM_OP_WALLET_KEYS_BLOCKCHAIN1" --argjson EVM_OP_WALLET_KEYS_BLOCKCHAIN2 "$EVM_OP_WALLET_KEYS_BLOCKCHAIN2" --arg EVM_MANAGEMENT_WALLET "$EVM_MANAGEMENT_WALLET" --arg SHARES_TOKEN_NAME "$SHARES_TOKEN_NAME" --arg SHARES_TOKEN_SYMBOL "$SHARES_TOKEN_SYMBOL" --argjson OPERATOR_FEES_1 "$OPERATOR_FEES_1" --argjson OPERATOR_FEES_2 "$OPERATOR_FEES_2" --arg gnosis_blockchain_id "$gnosis_blockchain_id" --arg EVM_OPERATIONAL_WALLET_2 "$EVM_OPERATIONAL_WALLET_2" --arg EVM_OPERATIONAL_PRIVATE_KEY_2 "$EVM_OPERATIONAL_PRIVATE_KEY_2" --arg EVM_MANAGEMENT_WALLET_2 "$EVM_MANAGEMENT_WALLET_2" --arg SHARES_TOKEN_NAME_2 "$SHARES_TOKEN_NAME_2" --arg SHARES_TOKEN_SYMBOL_2 "$SHARES_TOKEN_SYMBOL_2" --arg GNOSIS_RPC_ENDPOINT "$GNOSIS_RPC_ENDPOINT" ' - .modules.blockchain.implementation += { - "otp:'$otp_blockchain_id'": { - "enabled": true, - "config": { - "operationalWallets": $EVM_OP_WALLET_KEYS_BLOCKCHAIN1, - "evmManagementWalletPublicKey": $EVM_MANAGEMENT_WALLET, - "sharesTokenName": $SHARES_TOKEN_NAME, - "sharesTokenSymbol": $SHARES_TOKEN_SYMBOL, - "operatorFee": $OPERATOR_FEES_1 - } - }, - "gnosis:'$gnosis_blockchain_id'": { - "enabled": true, - "config": { - "operationalWallets": $EVM_OP_WALLET_KEYS_BLOCKCHAIN2, - "evmManagementWalletPublicKey": $EVM_MANAGEMENT_WALLET_2, - "sharesTokenName": $SHARES_TOKEN_NAME_2, - "sharesTokenSymbol": $SHARES_TOKEN_SYMBOL_2, - "operatorFee": $OPERATOR_FEES_2, - "rpcEndpoints": [$GNOSIS_RPC_ENDPOINT] - } - } - }' $CONFIG_DIR/.origintrail_noderc > $CONFIG_DIR/origintrail_noderc_tmp) "Adding node wallets to node config file 1/2 for Both" -else + # Function to configure a blockchain + configure_blockchain() { + local blockchain=$1 + local blockchain_id=$2 + + request_operational_wallet_keys $blockchain + local EVM_OP_WALLET_KEYS=$OP_WALLET_KEYS_JSON + + read -p "Enter your EVM management wallet address for $blockchain: " EVM_MANAGEMENT_WALLET + text_color $GREEN "EVM management wallet address for $blockchain: $EVM_MANAGEMENT_WALLET" + read -p "Enter your profile shares token name for $blockchain: " SHARES_TOKEN_NAME + text_color $GREEN "Profile shares token name for $blockchain: $SHARES_TOKEN_NAME" + + read -p "Enter your profile shares token symbol for $blockchain: " SHARES_TOKEN_SYMBOL + text_color $GREEN "Profile shares token symbol for $blockchain: $SHARES_TOKEN_SYMBOL" - # Single blockchain selected - if [ "$blockchain" = "OriginTrail Parachain" ] || [ "$blockchain" = "OTP" ]; then - blockchain="otp" - blockchain_id="$otp_blockchain_id" - elif [ "$blockchain" = "Gnosis" ]; then - blockchain="gnosis" - blockchain_id="$gnosis_blockchain_id" - fi - ADD_GNOSIS_RPC="false" - if [ "$blockchain" = "gnosis" ]; then - ADD_GNOSIS_RPC="true" - fi - - blockchain_arg="$blockchain:$blockchain_id" - - jq --arg blockchain_arg "$blockchain_arg" \ - --argjson EVM_OP_WALLET_KEYS_BLOCKCHAIN "$EVM_OP_WALLET_KEYS_BLOCKCHAIN" \ - --arg EVM_MANAGEMENT_WALLET "$EVM_MANAGEMENT_WALLET" \ - --arg SHARES_TOKEN_NAME "$SHARES_TOKEN_NAME" \ - --arg SHARES_TOKEN_SYMBOL "$SHARES_TOKEN_SYMBOL" \ - --argjson ADD_GNOSIS_RPC "$ADD_GNOSIS_RPC" \ - --argjson OPERATOR_FEE $OPERATOR_FEE \ - --arg GNOSIS_RPC_ENDPOINT "$GNOSIS_RPC_ENDPOINT" ' - (.modules.blockchain.implementation += { - ($blockchain_arg): { - "enabled": true, - "config": { - "operationalWallets": $EVM_OP_WALLET_KEYS_BLOCKCHAIN, - "evmManagementWalletPublicKey": $EVM_MANAGEMENT_WALLET, - "sharesTokenName": $SHARES_TOKEN_NAME, - "sharesTokenSymbol": $SHARES_TOKEN_SYMBOL, - "operatorFee": $OPERATOR_FEE + validate_operator_fees $blockchain + local RPC_ENDPOINT="" + if [ "$blockchain" == "gnosis" ] || [ "$blockchain" == "base" ]; then + read -p "Enter your $blockchain RPC endpoint: " RPC_ENDPOINT + text_color $GREEN "$blockchain RPC endpoint: $RPC_ENDPOINT" + fi + + local jq_filter=$(cat < "$CONFIG_DIR/origintrail_noderc_tmp" -fi +EOF + ) + + if [ -n "$RPC_ENDPOINT" ]; then + jq_filter+=" | .modules.blockchain.implementation[\"$blockchain:$blockchain_id\"].config.rpcEndpoints = [\"$RPC_ENDPOINT\"]" + fi + + jq "$jq_filter" $CONFIG_DIR/.origintrail_noderc > $CONFIG_DIR/origintrail_noderc_tmp + mv $CONFIG_DIR/origintrail_noderc_tmp $CONFIG_DIR/.origintrail_noderc + } + + # Configure selected blockchains + for blockchain in "${selected_blockchains[@]}"; do + case "$blockchain" in + "OriginTrail Parachain") + configure_blockchain "otp" $otp_blockchain_id + ;; + "Gnosis") + configure_blockchain "gnosis" $gnosis_blockchain_id + ;; + "Base" | "Base-Sepolia") + configure_blockchain "base" $base_blockchain_id + ;; + esac + done + + # Now execute npm install after configuring wallets + perform_step npm ci --omit=dev --ignore-scripts "Executing npm install" - 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 diff --git a/package-lock.json b/package-lock.json index 52cecb7e7..135deab96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.5.0+hotfix.1", + "version": "6.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.5.0+hotfix.1", + "version": "6.5.0", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index d285095ae..bb88a9c32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.5.0+hotfix.1", + "version": "6.5.0", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/scripts/set-ask.js b/scripts/set-ask.js index 756927e96..bb2b8734d 100644 --- a/scripts/set-ask.js +++ b/scripts/set-ask.js @@ -22,15 +22,16 @@ const devEnvironment = process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST; async function getGasPrice(gasPriceOracleLink, hubContractAddress, provider) { - if (!gasPriceOracleLink) { - return devEnvironment ? undefined : 8; - } try { - if ( - hubContractAddress === '0x6C861Cb69300C34DfeF674F7C00E734e840C29C0' || - hubContractAddress === '0x144eDa5cbf8926327cb2cceef168A121F0E4A299' - ) { - return provider.getGasPrice(); + if (!gasPriceOracleLink) { + if ( + hubContractAddress === '0x6C861Cb69300C34DfeF674F7C00E734e840C29C0' || + hubContractAddress === '0x144eDa5cbf8926327cb2cceef168A121F0E4A299' || + hubContractAddress === '0xaBfcf2ad1718828E7D3ec20435b0d0b5EAfbDf2c' + ) { + return provider.getGasPrice(); + } + return devEnvironment ? undefined : 8; } let gasPrice; const response = await axios.get(gasPriceOracleLink); diff --git a/scripts/set-stake.js b/scripts/set-stake.js index 671c814ef..cfc4a235d 100644 --- a/scripts/set-stake.js +++ b/scripts/set-stake.js @@ -29,15 +29,16 @@ const devEnvironment = process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST; async function getGasPrice(gasPriceOracleLink, hubContractAddress, provider) { - if (!gasPriceOracleLink) { - return devEnvironment ? undefined : 8; - } try { - if ( - hubContractAddress === '0x6C861Cb69300C34DfeF674F7C00E734e840C29C0' || - hubContractAddress === '0x144eDa5cbf8926327cb2cceef168A121F0E4A299' - ) { - return provider.getGasPrice(); + if (!gasPriceOracleLink) { + if ( + hubContractAddress === '0x6C861Cb69300C34DfeF674F7C00E734e840C29C0' || + hubContractAddress === '0x144eDa5cbf8926327cb2cceef168A121F0E4A299' || + hubContractAddress === '0xaBfcf2ad1718828E7D3ec20435b0d0b5EAfbDf2c' + ) { + return provider.getGasPrice(); + } + return devEnvironment ? undefined : 8; } let gasPrice; const response = await axios.get(gasPriceOracleLink); From 05d2aba1e5d7544d93f960124e46e06424a68973 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Thu, 18 Jul 2024 11:20:34 +0200 Subject: [PATCH 2/4] OriginTrail Testnet Prerelease v6.5.1 (#3244) * Updated Simulation script for LinearSum, updated dkg-evm-module package (#3215) * Add support for BASE blockchain (#3216) * Default config update * Fix package path for base integration * Add base-service implementation * Add Hub contracts for devnet and testnet * Version bump * Fix baseTokenTicker in BaseService * Update dkg.js version. Add typesrcipt dependecy for hardhat support * Set version to 6.5.0 * OriginTrail Devnet prerelease v6.5.0 (#3218) * Updated Simulation script for LinearSum, updated dkg-evm-module package (#3215) * Add support for BASE blockchain (#3216) * Default config update * Fix package path for base integration * Add base-service implementation * Add Hub contracts for devnet and testnet * Version bump * Fix baseTokenTicker in BaseService * Update dkg.js version. Add typesrcipt dependecy for hardhat support * Set version to 6.5.0 --------- Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> * Fix/get gas price in scripts (#3219) * Update getGasPrice in set-stake * Update set-ask getGasPrice * Version update * OriginTrail Devnet Release v6.5.0 (#3231) * branch fix 2 * OriginTrail Devnet Release v6.5.1 (#3243) * OriginTrail Devnet prerelease v6.5.0 (#3217) * Updated Simulation script for LinearSum, updated dkg-evm-module package (#3215) * Add support for BASE blockchain (#3216) * Default config update * Fix package path for base integration * Add base-service implementation * Add Hub contracts for devnet and testnet * Version bump * Fix baseTokenTicker in BaseService * Update dkg.js version. Add typesrcipt dependecy for hardhat support * Set version to 6.5.0 --------- Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> * OriginTrail Devnet Preelease v6.5.0 (#3230) * Update installer.sh (#3224) - Added base blockchain integration. Co-authored-by: Mihajlo Pavlovic * Base mainnet integration (#3229) * Add hub contract * Update set scripts * Remove hotfix * Update package-lock --------- Co-authored-by: Samuel Wamala <35219064+swamala@users.noreply.github.com> * OriginTrail Devnet Preelease v6.5.1 (#3242) * Update installer.sh (#3224) - Added base blockchain integration. Co-authored-by: Mihajlo Pavlovic * Base mainnet integration (#3229) * Add hub contract * Update set scripts * Remove hotfix * Update package-lock * Fixed removal of the AbortSignal event listener (#3227) * Increasing number of service agreements considered in command and command executor (#3241) * Increase number of service agreements for commits fetched from DB * Increase number of service agreements for commits fetched from DB * Increse limit and command queue pararelism * Add dynamic scaling factor when scheduling commits and proofs * Migration to remove duplicate service agreements (#3240) * Add findDuplicateServiceAgreement function * Expand query in findDuplicateServiceAgreement function * Add RemoveDuplicateServiceAgreementMigration * Fix migration queries * Migration tested and working * version bump * Add default connection pool to node (#3238) * Prune corrupted service agreement (#3237) * Add removeServiceAgreementsByBlockchainAndContract function * Change removeServiceAgreementsByBlockchainAndContract to remove all service agreements except ones with given contract * Add service agreement pruning migration * Fix epoch check scaling factor --------- Co-authored-by: Samuel Wamala <35219064+swamala@users.noreply.github.com> Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> --------- Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> Co-authored-by: Nikola Todorovic Co-authored-by: Samuel Wamala <35219064+swamala@users.noreply.github.com> --------- Co-authored-by: djordjekovac Co-authored-by: Nikola Todorovic Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> Co-authored-by: Samuel Wamala <35219064+swamala@users.noreply.github.com> --- config/config.json | 45 ++++++++++++-- ot-node.js | 13 ++++ package-lock.json | 4 +- package.json | 2 +- .../blockchain-epoch-check-command.js | 7 ++- src/constants/constants.js | 2 +- src/migration/migration-executor.js | 60 +++++++++++++++++++ ...e-duplicate-service-agreement-migration.js | 43 +++++++++++++ .../service-agreement-pruning-migration.js | 35 +++++++++++ .../network/implementation/libp2p-service.js | 19 +++--- .../service-agreement-repository.js | 37 +++++++++++- .../repository/repository-module-manager.js | 19 ++++++ 12 files changed, 264 insertions(+), 22 deletions(-) create mode 100644 src/migration/remove-duplicate-service-agreement-migration.js create mode 100644 src/migration/service-agreement-pruning-migration.js diff --git a/config/config.json b/config/config.json index 6f687077a..64d5fb3f0 100644 --- a/config/config.json +++ b/config/config.json @@ -77,7 +77,14 @@ "port": "3306", "host": "localhost", "dialect": "mysql", - "logging": false + "logging": false, + "pool": { + "max": 120, + "min": 0, + "acquire": 60000, + "idle": 10000, + "evict": 1000 + } } } } @@ -260,7 +267,14 @@ "port": "3306", "host": "localhost", "dialect": "mysql", - "logging": false + "logging": false, + "pool": { + "max": 120, + "min": 0, + "acquire": 60000, + "idle": 10000, + "evict": 1000 + } } } } @@ -413,7 +427,14 @@ "port": "3306", "host": "localhost", "dialect": "mysql", - "logging": false + "logging": false, + "pool": { + "max": 120, + "min": 0, + "acquire": 60000, + "idle": 10000, + "evict": 1000 + } } } } @@ -597,7 +618,14 @@ "port": "3306", "host": "localhost", "dialect": "mysql", - "logging": false + "logging": false, + "pool": { + "max": 120, + "min": 0, + "acquire": 60000, + "idle": 10000, + "evict": 1000 + } } } } @@ -781,7 +809,14 @@ "port": "3306", "host": "localhost", "dialect": "mysql", - "logging": false + "logging": false, + "pool": { + "max": 120, + "min": 0, + "acquire": 60000, + "idle": 10000, + "evict": 1000 + } } } } diff --git a/ot-node.js b/ot-node.js index 5614b42e3..4900e328d 100644 --- a/ot-node.js +++ b/ot-node.js @@ -89,6 +89,19 @@ class OTNode { this.logger, this.config, ); + + + MigrationExecutor.executeServiceAgreementPruningMigration( + this.container, + this.logger, + this.config, + ); + + MigrationExecutor.executeRemoveDuplicateServiceAgreementMigration( + this.container, + this.logger, + this.config, + ); } checkNodeVersion() { diff --git a/package-lock.json b/package-lock.json index 135deab96..bc8afa769 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.5.0", + "version": "6.5.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.5.0", + "version": "6.5.1", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index bb88a9c32..e7f54dafa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.5.0", + "version": "6.5.1", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/commands/protocols/common/epoch-check/blockchain-epoch-check-command.js b/src/commands/protocols/common/epoch-check/blockchain-epoch-check-command.js index baea3a9ec..7932f684c 100644 --- a/src/commands/protocols/common/epoch-check/blockchain-epoch-check-command.js +++ b/src/commands/protocols/common/epoch-check/blockchain-epoch-check-command.js @@ -51,10 +51,15 @@ class BlockchainEpochCheckCommand extends Command { command.period, ); + const numberOfBlockchains = this.blockchainModuleManager.getImplementationNames().length; + // We don't expect to have this many transactions in one epoch check window. // This is just to make sure we don't schedule too many commands and block the queue // TODO: find general solution for all commands scheduling blockchain transactions - totalTransactions = Math.min(totalTransactions, COMMAND_QUEUE_PARALLELISM * 0.3); + totalTransactions = Math.min( + totalTransactions, + Math.floor(COMMAND_QUEUE_PARALLELISM / numberOfBlockchains), + ); const transactionQueueLength = this.blockchainModuleManager.getTotalTransactionQueueLength(blockchain); diff --git a/src/constants/constants.js b/src/constants/constants.js index ea771a96f..e06bf467a 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -555,7 +555,7 @@ export const ARCHIVE_UPDATE_RESPONSES_FOLDER = 'update_responses'; * How many commands will run in parallel * @type {number} */ -export const COMMAND_QUEUE_PARALLELISM = 100; +export const COMMAND_QUEUE_PARALLELISM = 150; export const GET_LATEST_SERVICE_AGREEMENT_BATCH_SIZE = 50; diff --git a/src/migration/migration-executor.js b/src/migration/migration-executor.js index 0c84318a6..a3e2635ec 100644 --- a/src/migration/migration-executor.js +++ b/src/migration/migration-executor.js @@ -18,6 +18,8 @@ import MarkStakingEventsAsProcessedMigration from './mark-staking-events-as-proc import RemoveServiceAgreementsForChiadoMigration from './remove-service-agreements-for-chiado-migration.js'; import MultipleOpWalletsUserConfigurationMigration from './multiple-op-wallets-user-configuration-migration.js'; import GetOldServiceAgreementsMigration from './get-old-service-agreements-migration.js'; +import ServiceAgreementPruningMigration from './service-agreement-pruning-migration.js'; +import RemoveDuplicateServiceAgreementMigration from './remove-duplicate-service-agreement-migration.js'; class MigrationExecutor { static async executePullShardingTableMigration(container, logger, config) { @@ -442,6 +444,64 @@ class MigrationExecutor { } } + static async executeServiceAgreementPruningMigration(container, logger, config) { + if ( + process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT || + process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST + ) + return; + + const repositoryModuleManager = container.resolve('repositoryModuleManager'); + const blockchainModuleManager = container.resolve('blockchainModuleManager'); + const serviceAgreementService = container.resolve('serviceAgreementService'); + + const migration = new ServiceAgreementPruningMigration( + 'serviceAgreementPruningMigration', + logger, + config, + repositoryModuleManager, + blockchainModuleManager, + serviceAgreementService, + ); + if (!(await migration.migrationAlreadyExecuted())) { + try { + await migration.migrate(); + } catch (error) { + logger.error( + `Unable to execute service agreement pruning migration. Error: ${error.message}`, + ); + } + } + } + + static async executeRemoveDuplicateServiceAgreementMigration(container, logger, config) { + if ( + process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT || + process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST + ) + return; + + const repositoryModuleManager = container.resolve('repositoryModuleManager'); + const blockchainModuleManager = container.resolve('blockchainModuleManager'); + + const migration = new RemoveDuplicateServiceAgreementMigration( + 'removeDuplicateServiceAgreementMigration', + logger, + config, + repositoryModuleManager, + blockchainModuleManager, + ); + if (!(await migration.migrationAlreadyExecuted())) { + try { + await migration.migrate(); + } catch (error) { + logger.error( + `Unable to execute service agreement pruning migration. Error: ${error.message}`, + ); + } + } + } + static exitNode(code = 0) { process.exit(code); } diff --git a/src/migration/remove-duplicate-service-agreement-migration.js b/src/migration/remove-duplicate-service-agreement-migration.js new file mode 100644 index 000000000..8e646606c --- /dev/null +++ b/src/migration/remove-duplicate-service-agreement-migration.js @@ -0,0 +1,43 @@ +import BaseMigration from './base-migration.js'; + +class RemoveDuplicateServiceAgreementMigration extends BaseMigration { + constructor(migrationName, logger, config, repositoryModuleManager, blockchainModuleManager) { + super(migrationName, logger, config); + this.repositoryModuleManager = repositoryModuleManager; + this.blockchainModuleManager = blockchainModuleManager; + } + + async executeMigration() { + const blockchainIds = this.blockchainModuleManager.getImplementationNames(); + + for (const blockchainId of blockchainIds) { + const incorrectServiceAgreementId = []; + const duplicateTokenIdsRestult = + // eslint-disable-next-line no-await-in-loop + await this.repositoryModuleManager.findDuplicateServiceAgreements(blockchainId); + const duplicateTokenIds = duplicateTokenIdsRestult.map((t) => t.dataValues.token_id); + const findDuplicateServiceAgreements = + // eslint-disable-next-line no-await-in-loop + await this.repositoryModuleManager.findServiceAgreementsByTokenIds( + duplicateTokenIds, + blockchainId, + ); + for (const serviceAgreement of findDuplicateServiceAgreements) { + const blockchainAssertionId = + // eslint-disable-next-line no-await-in-loop + await this.blockchainModuleManager.getAssertionIdByIndex( + blockchainId, + serviceAgreement.assetStorageContractAddress, + serviceAgreement.tokenId, + serviceAgreement.stateIndex, + ); + if (serviceAgreement.assertionId !== blockchainAssertionId) { + incorrectServiceAgreementId.push(serviceAgreement.agreementId); + } + } + // eslint-disable-next-line no-await-in-loop + await this.repositoryModuleManager.removeServiceAgreements(incorrectServiceAgreementId); + } + } +} +export default RemoveDuplicateServiceAgreementMigration; diff --git a/src/migration/service-agreement-pruning-migration.js b/src/migration/service-agreement-pruning-migration.js new file mode 100644 index 000000000..2e7853c75 --- /dev/null +++ b/src/migration/service-agreement-pruning-migration.js @@ -0,0 +1,35 @@ +import BaseMigration from './base-migration.js'; + +class ServiceAgreementPruningMigration extends BaseMigration { + constructor( + migrationName, + logger, + config, + repositoryModuleManager, + blockchainModuleManager, + serviceAgreementService, + ) { + super(migrationName, logger, config); + this.repositoryModuleManager = repositoryModuleManager; + this.blockchainModuleManager = blockchainModuleManager; + this.serviceAgreementService = serviceAgreementService; + } + + async executeMigration() { + const blockchainIds = this.blockchainModuleManager.getImplementationNames(); + + // eslint-disable-next-line no-await-in-loop + for (const blockchainId of blockchainIds) { + const assetStorageContractAddresses = + // eslint-disable-next-line no-await-in-loop + await this.blockchainModuleManager.getAssetStorageContractAddresses(blockchainId); + + // eslint-disable-next-line no-await-in-loop + await this.repositoryModuleManager.removeServiceAgreementsByBlockchainAndContract( + blockchainId, + assetStorageContractAddresses[0], + ); + } + } +} +export default ServiceAgreementPruningMigration; diff --git a/src/modules/network/implementation/libp2p-service.js b/src/modules/network/implementation/libp2p-service.js index 6ea134353..19d1eeb9d 100644 --- a/src/modules/network/implementation/libp2p-service.js +++ b/src/modules/network/implementation/libp2p-service.js @@ -397,18 +397,17 @@ class Libp2pService { let readResponseStart; let readResponseEnd; let response; + const abortSignalEventListener = async () => { + stream.abort(); + response = null; + }; const timeoutController = new TimeoutController(timeout); try { readResponseStart = Date.now(); - timeoutController.signal.addEventListener( - 'abort', - async () => { - stream.abort(); - response = null; - }, - { once: true }, - ); + timeoutController.signal.addEventListener('abort', abortSignalEventListener, { + once: true, + }); response = await this._readMessageFromStream( stream, @@ -420,12 +419,12 @@ class Libp2pService { throw Error('Message timed out!'); } - timeoutController.signal.removeEventListener('abort'); + timeoutController.signal.removeEventListener('abort', abortSignalEventListener); timeoutController.clear(); readResponseEnd = Date.now(); } catch (error) { - timeoutController.signal.removeEventListener('abort'); + timeoutController.signal.removeEventListener('abort', abortSignalEventListener); timeoutController.clear(); readResponseEnd = Date.now(); diff --git a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js index 062a6876e..6857a46a5 100644 --- a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js +++ b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js @@ -190,7 +190,7 @@ class ServiceAgreementRepository { ['scoreFunctionId', 'DESC'], [Sequelize.col('timeLeftInSubmitCommitWindow'), 'ASC'], ], - limit: 100, + limit: 500, raw: true, }); } @@ -249,7 +249,7 @@ class ServiceAgreementRepository { ['scoreFunctionId', 'DESC'], [Sequelize.col('timeLeftInSubmitProofWindow'), 'ASC'], ], - limit: 100, + limit: 500, raw: true, }); } @@ -286,6 +286,39 @@ class ServiceAgreementRepository { }, }); } + + + async removeServiceAgreementsByBlockchainAndContract(blockchainId, contract) { + await this.model.destroy({ + where: { + blockchainId, + assetStorageContractAddress: { + [Sequelize.Op.ne]: contract, + }, + }, + }); + } + + async findDuplicateServiceAgreements(blockchainId) { + return this.model.findAll({ + attributes: ['token_id', [Sequelize.fn('COUNT', Sequelize.col('*')), 'count']], + where: { + blockchain_id: `${blockchainId}`, + }, + group: ['token_id'], + having: Sequelize.literal('count > 1'), + }); + } + + async findServiceAgreementsByTokenIds(tokenIds, blockchainId) { + return this.model.findAll({ + where: { + tokenId: { [Sequelize.Op.in]: tokenIds }, + blockchainId, + }, + order: [['token_id']], + }); + } } export default ServiceAgreementRepository; diff --git a/src/modules/repository/repository-module-manager.js b/src/modules/repository/repository-module-manager.js index 30ad35a16..33f6ffb44 100644 --- a/src/modules/repository/repository-module-manager.js +++ b/src/modules/repository/repository-module-manager.js @@ -403,6 +403,14 @@ class RepositoryModuleManager extends BaseModuleManager { } } + async removeServiceAgreementsByBlockchainAndContract(blockchainId, contract) { + if (this.initialized) { + return this.getRepository( + 'service_agreement', + ).removeServiceAgreementsByBlockchainAndContract(blockchainId, contract); + } + } + async getEligibleAgreementsForSubmitCommit( timestampSeconds, blockchain, @@ -473,6 +481,17 @@ class RepositoryModuleManager extends BaseModuleManager { ); } + async findDuplicateServiceAgreements(blockchainId) { + return this.getRepository('service_agreement').findDuplicateServiceAgreements(blockchainId); + } + + async findServiceAgreementsByTokenIds(tokenIds, blockchainId) { + return this.getRepository('service_agreement').findServiceAgreementsByTokenIds( + tokenIds, + blockchainId, + ); + } + async createParanetRecord(name, description, paranetId, blockchainId) { this.getRepository('paranet').createParanetRecord( name, From 834060f0773a2fd9eaf3a02b219510d152b5bb7f Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Thu, 18 Jul 2024 13:50:38 +0200 Subject: [PATCH 3/4] OriginTrail Devnet Release v6.5.1 Hotfix 1 (#3247) * OriginTrail Devnet prerelease v6.5.0 (#3217) * Updated Simulation script for LinearSum, updated dkg-evm-module package (#3215) * Add support for BASE blockchain (#3216) * Default config update * Fix package path for base integration * Add base-service implementation * Add Hub contracts for devnet and testnet * Version bump * Fix baseTokenTicker in BaseService * Update dkg.js version. Add typesrcipt dependecy for hardhat support * Set version to 6.5.0 --------- Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> * OriginTrail Devnet Preelease v6.5.0 (#3230) * Update installer.sh (#3224) - Added base blockchain integration. Co-authored-by: Mihajlo Pavlovic * Base mainnet integration (#3229) * Add hub contract * Update set scripts * Remove hotfix * Update package-lock --------- Co-authored-by: Samuel Wamala <35219064+swamala@users.noreply.github.com> * OriginTrail Devnet Preelease v6.5.1 (#3242) * Update installer.sh (#3224) - Added base blockchain integration. Co-authored-by: Mihajlo Pavlovic * Base mainnet integration (#3229) * Add hub contract * Update set scripts * Remove hotfix * Update package-lock * Fixed removal of the AbortSignal event listener (#3227) * Increasing number of service agreements considered in command and command executor (#3241) * Increase number of service agreements for commits fetched from DB * Increase number of service agreements for commits fetched from DB * Increse limit and command queue pararelism * Add dynamic scaling factor when scheduling commits and proofs * Migration to remove duplicate service agreements (#3240) * Add findDuplicateServiceAgreement function * Expand query in findDuplicateServiceAgreement function * Add RemoveDuplicateServiceAgreementMigration * Fix migration queries * Migration tested and working * version bump * Add default connection pool to node (#3238) * Prune corrupted service agreement (#3237) * Add removeServiceAgreementsByBlockchainAndContract function * Change removeServiceAgreementsByBlockchainAndContract to remove all service agreements except ones with given contract * Add service agreement pruning migration * Fix epoch check scaling factor --------- Co-authored-by: Samuel Wamala <35219064+swamala@users.noreply.github.com> Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> * OriginTrail Devnet prerelease v6.5.1 Hotfix 1 (#3246) * Update installer.sh (#3224) - Added base blockchain integration. Co-authored-by: Mihajlo Pavlovic * Base mainnet integration (#3229) * Add hub contract * Update set scripts * Remove hotfix * Update package-lock * Fixed removal of the AbortSignal event listener (#3227) * Increasing number of service agreements considered in command and command executor (#3241) * Increase number of service agreements for commits fetched from DB * Increase number of service agreements for commits fetched from DB * Increse limit and command queue pararelism * Add dynamic scaling factor when scheduling commits and proofs * Migration to remove duplicate service agreements (#3240) * Add findDuplicateServiceAgreement function * Expand query in findDuplicateServiceAgreement function * Add RemoveDuplicateServiceAgreementMigration * Fix migration queries * Migration tested and working * version bump * Add default connection pool to node (#3238) * Prune corrupted service agreement (#3237) * Add removeServiceAgreementsByBlockchainAndContract function * Change removeServiceAgreementsByBlockchainAndContract to remove all service agreements except ones with given contract * Add service agreement pruning migration * Fix epoch check scaling factor * Migration fixes --------- Co-authored-by: Samuel Wamala <35219064+swamala@users.noreply.github.com> Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> --------- Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> Co-authored-by: Nikola Todorovic Co-authored-by: Samuel Wamala <35219064+swamala@users.noreply.github.com> --- ot-node.js | 13 ++++++------ package-lock.json | 4 ++-- package.json | 2 +- src/migration/migration-executor.js | 2 +- .../service-agreement-pruning-migration.js | 21 ++++++++++++++----- .../service-agreement-repository.js | 19 +++++++++++++---- .../repository/repository-module-manager.js | 8 +++++++ 7 files changed, 49 insertions(+), 20 deletions(-) diff --git a/ot-node.js b/ot-node.js index 4900e328d..754425752 100644 --- a/ot-node.js +++ b/ot-node.js @@ -78,6 +78,12 @@ class OTNode { this.config, ); + await MigrationExecutor.executeServiceAgreementPruningMigration( + this.container, + this.logger, + this.config, + ); + await this.initializeRouters(); await this.startNetworkModule(); this.startTelemetryModule(); @@ -90,13 +96,6 @@ class OTNode { this.config, ); - - MigrationExecutor.executeServiceAgreementPruningMigration( - this.container, - this.logger, - this.config, - ); - MigrationExecutor.executeRemoveDuplicateServiceAgreementMigration( this.container, this.logger, diff --git a/package-lock.json b/package-lock.json index bc8afa769..4004d3ae0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.5.1", + "version": "6.5.1+hotfix.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.5.1", + "version": "6.5.1+hotfix.1", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index e7f54dafa..e72debf9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.5.1", + "version": "6.5.1+hotfix.1", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/migration/migration-executor.js b/src/migration/migration-executor.js index a3e2635ec..77469b986 100644 --- a/src/migration/migration-executor.js +++ b/src/migration/migration-executor.js @@ -496,7 +496,7 @@ class MigrationExecutor { await migration.migrate(); } catch (error) { logger.error( - `Unable to execute service agreement pruning migration. Error: ${error.message}`, + `Unable to execute remove duplicate service agreement migration. Error: ${error.message}`, ); } } diff --git a/src/migration/service-agreement-pruning-migration.js b/src/migration/service-agreement-pruning-migration.js index 2e7853c75..c29ba4de1 100644 --- a/src/migration/service-agreement-pruning-migration.js +++ b/src/migration/service-agreement-pruning-migration.js @@ -24,11 +24,22 @@ class ServiceAgreementPruningMigration extends BaseMigration { // eslint-disable-next-line no-await-in-loop await this.blockchainModuleManager.getAssetStorageContractAddresses(blockchainId); - // eslint-disable-next-line no-await-in-loop - await this.repositoryModuleManager.removeServiceAgreementsByBlockchainAndContract( - blockchainId, - assetStorageContractAddresses[0], - ); + const countOfServiceAgreementsToBeRemoved = + // eslint-disable-next-line no-await-in-loop + await this.repositoryModuleManager.getCountOfServiceAgreementsByBlockchainAndContract( + blockchainId, + assetStorageContractAddresses[0], + ); + + // removeServiceAgreementsByBlockchainAndContract deletes in batches od 100_000 + const numberOfIteration = Math.ceil(countOfServiceAgreementsToBeRemoved / 100_000); + for (let i = 0; i < numberOfIteration; i += 1) { + // eslint-disable-next-line no-await-in-loop + await this.repositoryModuleManager.removeServiceAgreementsByBlockchainAndContract( + blockchainId, + assetStorageContractAddresses[0], + ); + } } } } diff --git a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js index 6857a46a5..1c3a6725c 100644 --- a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js +++ b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js @@ -287,9 +287,8 @@ class ServiceAgreementRepository { }); } - - async removeServiceAgreementsByBlockchainAndContract(blockchainId, contract) { - await this.model.destroy({ + async getCountOfServiceAgreementsByBlockchainAndContract(blockchainId, contract) { + await this.model.count({ where: { blockchainId, assetStorageContractAddress: { @@ -298,7 +297,19 @@ class ServiceAgreementRepository { }, }); } - + + async removeServiceAgreementsByBlockchainAndContract(blockchainId, contract) { + const query = ` + DELETE FROM service_agreement + WHERE blockchain_id = '${blockchainId}' + AND asset_storage_contract_address = '${contract}' + LIMIT 100000; + `; + await this.model.query(query, { + type: Sequelize.QueryTypes.DELETE, + }); + } + async findDuplicateServiceAgreements(blockchainId) { return this.model.findAll({ attributes: ['token_id', [Sequelize.fn('COUNT', Sequelize.col('*')), 'count']], diff --git a/src/modules/repository/repository-module-manager.js b/src/modules/repository/repository-module-manager.js index 33f6ffb44..eea9d4983 100644 --- a/src/modules/repository/repository-module-manager.js +++ b/src/modules/repository/repository-module-manager.js @@ -403,6 +403,14 @@ class RepositoryModuleManager extends BaseModuleManager { } } + async getCountOfServiceAgreementsByBlockchainAndContract(blockchainId, contract) { + if (this.initialized) { + return this.getRepository( + 'service_agreement', + ).getCountOfServiceAgreementsByBlockchainAndContract(blockchainId, contract); + } + } + async removeServiceAgreementsByBlockchainAndContract(blockchainId, contract) { if (this.initialized) { return this.getRepository( From 9d3d9a4ef5d057f4268e988084c87948c9e0b0f8 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Fri, 19 Jul 2024 11:46:33 +0200 Subject: [PATCH 4/4] OriginTrail Devnet Prerelease v6.5.1 Hotfix 2 (#3251) * Update installer.sh (#3224) - Added base blockchain integration. Co-authored-by: Mihajlo Pavlovic * Base mainnet integration (#3229) * Add hub contract * Update set scripts * Remove hotfix * Update package-lock * Fixed removal of the AbortSignal event listener (#3227) * Increasing number of service agreements considered in command and command executor (#3241) * Increase number of service agreements for commits fetched from DB * Increase number of service agreements for commits fetched from DB * Increse limit and command queue pararelism * Add dynamic scaling factor when scheduling commits and proofs * Migration to remove duplicate service agreements (#3240) * Add findDuplicateServiceAgreement function * Expand query in findDuplicateServiceAgreement function * Add RemoveDuplicateServiceAgreementMigration * Fix migration queries * Migration tested and working * version bump * Add default connection pool to node (#3238) * Prune corrupted service agreement (#3237) * Add removeServiceAgreementsByBlockchainAndContract function * Change removeServiceAgreementsByBlockchainAndContract to remove all service agreements except ones with given contract * Add service agreement pruning migration * Fix epoch check scaling factor * Migration fixes * Fix/service agreement prunning migration fix (#3250) * Fix missing return in getCountOfServiceAgreementsByBlockchainAndContract * Add commnet for removeServiceAgreementsByBlockchainAndContract * Version bump --------- Co-authored-by: Samuel Wamala <35219064+swamala@users.noreply.github.com> Co-authored-by: Uladzislau Hubar <71610423+u-hubar@users.noreply.github.com> --- package-lock.json | 4 ++-- package.json | 2 +- .../sequelize/repositories/service-agreement-repository.js | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4004d3ae0..4e48f8bd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.5.1+hotfix.1", + "version": "6.5.1+hotfix.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.5.1+hotfix.1", + "version": "6.5.1+hotfix.2", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index e72debf9c..4b5d7d5a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.5.1+hotfix.1", + "version": "6.5.1+hotfix.2", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js index 1c3a6725c..c8fbdc56b 100644 --- a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js +++ b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js @@ -288,7 +288,7 @@ class ServiceAgreementRepository { } async getCountOfServiceAgreementsByBlockchainAndContract(blockchainId, contract) { - await this.model.count({ + return this.model.count({ where: { blockchainId, assetStorageContractAddress: { @@ -298,6 +298,7 @@ class ServiceAgreementRepository { }); } + // Sequelize destroy method doesn't support limit async removeServiceAgreementsByBlockchainAndContract(blockchainId, contract) { const query = ` DELETE FROM service_agreement