From 8b42b99cd842904a6274ee7f7e5b462210f15275 Mon Sep 17 00:00:00 2001 From: Dulana Peiris <57042272+du1ana@users.noreply.github.com> Date: Tue, 30 Jan 2024 14:26:03 +0530 Subject: [PATCH 1/2] Handle reg token not accepted in installation (#341) --- examples/client/client.js | 2 +- installer/jshelper/index.js | 28 ++++++++++++++++++++++++++++ installer/sashimono-uninstall.sh | 2 +- mb-xrpl/lib/setup.js | 2 +- src/sqlite.cpp | 2 +- test/vm-cluster/cluster.sh | 4 ++-- 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/examples/client/client.js b/examples/client/client.js index 2790687..e4d7440 100644 --- a/examples/client/client.js +++ b/examples/client/client.js @@ -57,7 +57,7 @@ async function main() { hpc.on(HotPocket.events.contractOutput, (r) => { r.outputs.forEach(output => { - // If bson.deserialize error occured it'll be caught by this try catch. + // If bson.deserialize error occurred it'll be caught by this try catch. try { const result = bson.deserialize(output); diff --git a/installer/jshelper/index.js b/installer/jshelper/index.js index 84e0407..6de6674 100644 --- a/installer/jshelper/index.js +++ b/installer/jshelper/index.js @@ -61,6 +61,34 @@ const funcs = { return { success: false, result: "Account not found." }; await hostClient.connect(); + + if (validateFor === "register" || validateFor === "re-register") { + // Check whether is there any missed NFT sell offers + try { + const registryAcc = new evernode.XrplAccount(hostClient.config.registryAddress, null); + const regUriToken = await hostClient.getRegistrationUriToken(); + + if (!regUriToken) { + const regInfo = await hostClient.getHostInfo(accountAddress); + + if (regInfo) { + const sellOffer = (await registryAcc.getURITokens()).find(o => o.index == regInfo.uriTokenId && o.Amount); + + if (sellOffer) { + await hostClient.disconnect(); + await xrplApi.disconnect(); + return { success: true }; + } + } + } + + } catch (e) { + await hostClient.disconnect(); + await xrplApi.disconnect(); + return { success: false, result: 'Error occurred in missed sell offers check.' }; + } + } + const registered = await hostClient.isRegistered(); // For register validation the host should not be registered in evernode. // For other validations host should be registered in evernode. diff --git a/installer/sashimono-uninstall.sh b/installer/sashimono-uninstall.sh index 1eadd63..e810363 100755 --- a/installer/sashimono-uninstall.sh +++ b/installer/sashimono-uninstall.sh @@ -134,7 +134,7 @@ if [ -f $SASHIMONO_BIN/docker-registry-uninstall.sh ]; then fi # Delete binaries except message board and sashimnono uninstall script. -# We keep uninstall script so user can uninstall again if error occured at later steps. +# We keep uninstall script so user can uninstall again if error occurred at later steps. # We'll remove these after deregistration. echo "Deleting binaries..." find $SASHIMONO_BIN -mindepth 1 ! \( -regex "^$MB_XRPL_BIN\(/.*\)?" -o -path $SASHIMONO_BIN/sashimono-uninstall.sh \) -delete diff --git a/mb-xrpl/lib/setup.js b/mb-xrpl/lib/setup.js index 4d99c19..7993359 100644 --- a/mb-xrpl/lib/setup.js +++ b/mb-xrpl/lib/setup.js @@ -214,7 +214,7 @@ class Setup { await hostClient.disconnect(); } catch { - throw 'Error occured when retrieving account info.'; + throw 'Error occurred when retrieving account info.'; } } } diff --git a/src/sqlite.cpp b/src/sqlite.cpp index 22b5222..fd784d5 100644 --- a/src/sqlite.cpp +++ b/src/sqlite.cpp @@ -91,7 +91,7 @@ namespace sqlite char *err_msg; if (sqlite3_exec(db, sql.data(), callback, (callback != NULL ? (void *)callback_first_arg : NULL), &err_msg) != SQLITE_OK) { - LOG_ERROR << "SQL error occured: " << err_msg; + LOG_ERROR << "SQL error occurred: " << err_msg; sqlite3_free(err_msg); return -1; } diff --git a/test/vm-cluster/cluster.sh b/test/vm-cluster/cluster.sh index ffb5b3f..5ccf233 100755 --- a/test/vm-cluster/cluster.sh +++ b/test/vm-cluster/cluster.sh @@ -208,7 +208,7 @@ if [ $mode == "reconfig" ]; then fi if ! sshskp $sshuser@$hostaddr $command ; then - printf "$PRINTFORMAT" "$nodeno" "Error occured reconfiguring sashimono." + printf "$PRINTFORMAT" "$nodeno" "Error occurred reconfiguring sashimono." else # Remove host info if reinstall. if [ ! -z $reinstall ] && [ $reinstall == "R" ]; then @@ -402,7 +402,7 @@ if [ $mode == "docker-pull" ]; then command="$contractpath && $user && $dpull" if ! sshskp $sshuser@$hostaddr $command 1>/dev/null; then - printf "$PRINTFORMAT" "$nodeno" "Error occured pulling $image." + printf "$PRINTFORMAT" "$nodeno" "Error occurred pulling $image." else printf "$PRINTFORMAT" "$nodeno" "Successfully pulled $image." fi From bc8240471f661576b613661d8a0f17f093f35e22 Mon Sep 17 00:00:00 2001 From: Kithmini Gunawardhana Date: Tue, 30 Jan 2024 14:27:26 +0530 Subject: [PATCH 2/2] Configuring extra fee. (#340) --- installer/sashimono-install.sh | 3 ++- installer/setup.sh | 40 +++++++++++++++++++++++++++++++--- mb-xrpl/app.js | 8 ++++--- mb-xrpl/lib/setup.js | 16 ++++++++++---- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/installer/sashimono-install.sh b/installer/sashimono-install.sh index 5dfbc8a..7c0c033 100755 --- a/installer/sashimono-install.sh +++ b/installer/sashimono-install.sh @@ -24,6 +24,7 @@ tls_cabundle_file=${17} description=${18} ipv6_subnet=${19} ipv6_net_interface=${20} +extra_txn_fee=${21} script_dir=$(dirname "$(realpath "$0")") desired_slirp4netns_version="1.2.1" @@ -262,7 +263,7 @@ if [ "$NO_MB" == "" ]; then stage "Configuring host Xahau account" echo "Using registry: $EVERNODE_REGISTRY_ADDRESS" - ! sudo -u $MB_XRPL_USER MB_DATA_DIR=$MB_XRPL_DATA node $MB_XRPL_BIN new $xrpl_account_address $xrpl_account_secret_path $EVERNODE_GOVERNOR_ADDRESS $inetaddr $lease_amount $rippled_server $ipv6_subnet $ipv6_net_interface $NETWORK && echo "XRPLACC_FAILURE" && rollback + ! sudo -u $MB_XRPL_USER MB_DATA_DIR=$MB_XRPL_DATA node $MB_XRPL_BIN new $xrpl_account_address $xrpl_account_secret_path $EVERNODE_GOVERNOR_ADDRESS $inetaddr $lease_amount $rippled_server $ipv6_subnet $ipv6_net_interface $NETWORK $extra_txn_fee && echo "XRPLACC_FAILURE" && rollback doreg=1 fi diff --git a/installer/setup.sh b/installer/setup.sh index 91b6528..97eb195 100755 --- a/installer/setup.sh +++ b/installer/setup.sh @@ -737,6 +737,21 @@ function set_lease_amount() { lease_amount=$amount } +function set_extra_fee() { + local fee=0 + if confirm "Do you want to set an extra transaction fee to consider in case of network congestion?" "n" ; then + while true ; do + read -ep "Specify the affordable extra transaction fee (in XAH Drops): " fee &1 \ + $tls_key_file $tls_cert_file $tls_cabundle_file $description $ipv6_subnet $ipv6_net_interface $extra_txn_fee 2>&1 \ | tee -a $logfile | stdbuf --output=L grep "STAGE\|ERROR" \ | while read line ; do [[ $line =~ ^STAGE[[:space:]]-p(.*)$ ]] && echo -e \\e[1A\\e[K"${line:9}" || echo ${line:6} ; done \ && remove_evernode_alias && install_failure @@ -1364,7 +1379,7 @@ function reconfig_sashi() { function reconfig_mb() { echomult "Configuaring message board...\n" - ! sudo -u $MB_XRPL_USER MB_DATA_DIR=$MB_XRPL_DATA node $MB_XRPL_BIN reconfig $lease_amount $alloc_instcount $rippled_server $ipv6_subnet $ipv6_net_interface && + ! sudo -u $MB_XRPL_USER MB_DATA_DIR=$MB_XRPL_DATA node $MB_XRPL_BIN reconfig $lease_amount $alloc_instcount $rippled_server $ipv6_subnet $ipv6_net_interface $extra_txn_fee && echo "There was an error in updating message board configuration." && return 1 return 0 } @@ -1381,6 +1396,7 @@ function config() { rippled_server='-' ipv6_subnet='-' ipv6_net_interface='-' + extra_txn_fee='-' local saconfig="$SASHIMONO_DATA/sa.cfg" local max_instance_count=$(jq '.system.max_instance_count' $saconfig) @@ -1391,6 +1407,7 @@ function config() { local mbconfig="$MB_XRPL_DATA/mb-xrpl.cfg" local cfg_lease_amount=$(jq '.xrpl.leaseAmount' $mbconfig) local cfg_rippled_server=$(jq -r '.xrpl.rippledServer' $mbconfig) + local cfg_extra_txn_fee=$(jq '.xrpl.affordableExtraFee' $mbconfig) local cfg_ipv6_subnet=$(jq -r '.networking.ipv6.subnet' $mbconfig) local cfg_ipv6_net_interface=$(jq -r '.networking.ipv6.interface' $mbconfig) @@ -1563,8 +1580,23 @@ function config() { echomult "Invalid arguments.\n Usage: evernode config instance [ipv6]\n" && exit 1 fi + elif [ "$sub_mode" == "extrafee" ] ; then + + local fee=${2} # Affordable extra transaction fee to consider in txn failures. + [ -z $fee ] && echomult "Your affordable extra transaction fee: $cfg_extra_txn_fee XAH Drops.\n" && exit 0 + + ! validate_positive_decimal $fee && + echomult "Invalid fee amount.\n Usage: evernode config extrafee | evernode config extrafee \n" && + exit 1 + extra_txn_fee=$fee + [[ $cfg_extra_txn_fee == $extra_txn_fee ]] && echomult "Affordable extra transaction fee is already configured!\n" && exit 0 + + echomult "Using affordable extra transaction fee $extra_txn_fee XAH Drops." + + update_mb=1 + else - echomult "Invalid arguments.\n Usage: evernode config [resources|leaseamt|rippled|email|instance] [arguments]\n" && exit 1 + echomult "Invalid arguments.\n Usage: evernode config [resources|leaseamt|rippled|email|instance|extrafee] [arguments]\n" && exit 1 fi local mb_user_id=$(id -u "$MB_XRPL_USER") @@ -1685,6 +1717,8 @@ if [ "$mode" == "install" ]; then set_lease_amount echo -e "Lease amount set as $lease_amount EVRs per Moment.\n" + set_extra_fee + # TODO - CHECKPOINT - 02 set_host_xrpl_account $operation echo -e "\nAccount setup is complete." diff --git a/mb-xrpl/app.js b/mb-xrpl/app.js index 6a3bea2..d9f9083 100644 --- a/mb-xrpl/app.js +++ b/mb-xrpl/app.js @@ -23,8 +23,9 @@ async function main() { const ipv6Subnet = (process.argv[9] === '-') ? null : process.argv[9]; const ipv6NetInterface = (process.argv[10] === '-') ? null : process.argv[10]; const network = process.argv.length > 11 ? process.argv[11] : appenv.NETWORK; + const affordableExtraFee = process.argv.length > 12 ? process.argv[12] : 0; const setup = new Setup(); - setup.newConfig(accountAddress, accountSecretPath, governorAddress, parseFloat(leaseAmount), rippledServer, ipv6Subnet, ipv6NetInterface, network); + setup.newConfig(accountAddress, accountSecretPath, governorAddress, parseFloat(leaseAmount), rippledServer, ipv6Subnet, ipv6NetInterface, network, parseInt(affordableExtraFee)); if (appenv.IS_DEV_MODE) { await setup.prepareHostAccount(domain); @@ -49,12 +50,13 @@ async function main() { else if (process.argv.length >= 3 && process.argv[2] === 'upgrade') { await new Setup().upgrade(); } - else if ((process.argv.length === 8) && process.argv[2] === 'reconfig') { + else if ((process.argv.length === 9) && process.argv[2] === 'reconfig') { if (process.argv[5] == '-') process.argv[5] = null; if (process.argv[6] == '-') process.argv[6] = null; if (process.argv[7] == '-') process.argv[7] = null; + if (process.argv[8] == '-') process.argv[8] = null; - await new Setup().changeConfig(process.argv[3], process.argv[5], process.argv[4], process.argv[6], process.argv[7]); + await new Setup().changeConfig(process.argv[3], process.argv[5], process.argv[4], process.argv[6], process.argv[7], process.argv[8]); } else if (process.argv.length === 4 && process.argv[2] === 'delete') { await new Setup().deleteInstance(process.argv[3]); diff --git a/mb-xrpl/lib/setup.js b/mb-xrpl/lib/setup.js index 7993359..2534edd 100644 --- a/mb-xrpl/lib/setup.js +++ b/mb-xrpl/lib/setup.js @@ -51,7 +51,7 @@ class Setup { ConfigHelper.writeConfig(cfg, appenv.CONFIG_PATH); } - newConfig(address = "", secretPath = "", governorAddress = "", leaseAmount = 0, rippledServer = null, ipv6Subnet = null, ipv6NetInterface = null, network = "") { + newConfig(address = "", secretPath = "", governorAddress = "", leaseAmount = 0, rippledServer = null, ipv6Subnet = null, ipv6NetInterface = null, network = "", affordableExtraFee = 0) { const baseConfig = { version: appenv.MB_VERSION, xrpl: { @@ -60,7 +60,8 @@ class Setup { secretPath: secretPath, governorAddress: governorAddress, rippledServer: rippledServer || appenv.DEFAULT_RIPPLED_SERVER, - leaseAmount: leaseAmount + leaseAmount: leaseAmount, + affordableExtraFee: affordableExtraFee } }; @@ -332,7 +333,7 @@ class Setup { } // Change the message board configurations. - async changeConfig(leaseAmount, rippledServer, totalInstanceCount, ipv6Subnet, ipv6NetInterface) { + async changeConfig(leaseAmount, rippledServer, totalInstanceCount, ipv6Subnet, ipv6NetInterface, affordableExtraFee) { // Update the configuration. const cfg = this.#getConfig(); @@ -343,16 +344,21 @@ class Setup { throw 'Provided Rippled Server is invalid'; else if (totalInstanceCount && isNaN(totalInstanceCount)) throw 'Maximum instance count should be a number'; + else if (affordableExtraFee && isNaN(affordableExtraFee)) + throw 'Affordable txn fee should be a number'; const leaseAmountParsed = leaseAmount ? parseFloat(leaseAmount) : 0; const totalInstanceCountParsed = totalInstanceCount ? parseInt(totalInstanceCount) : 0; + const affordableExtraFeeParsed = affordableExtraFee ? parseInt(affordableExtraFee) : 0; + // Return if not changed. if (!totalInstanceCount && (!leaseAmount || cfg.xrpl.leaseAmount == leaseAmount) && (!rippledServer || cfg.xrpl.rippledServer == rippledServer) && (!ipv6Subnet) && - (!ipv6NetInterface)) + (!ipv6NetInterface) && + (!affordableExtraFee || cfg.xrpl.affordableExtraFee == affordableExtraFee)) return; await this.recreateLeases(leaseAmountParsed, totalInstanceCountParsed, rippledServer, ipv6Subnet, ipv6NetInterface, cfg); @@ -361,6 +367,8 @@ class Setup { cfg.xrpl.leaseAmount = leaseAmountParsed; if (rippledServer) cfg.xrpl.rippledServer = rippledServer; + if (affordableExtraFeeParsed) + cfg.xrpl.affordableExtraFee = affordableExtraFeeParsed; this.#saveConfig(cfg); }