From a49453667281747f3b5a35dfbf95ea55486a25ad Mon Sep 17 00:00:00 2001 From: Kithmini Gunawardhana Date: Thu, 26 Sep 2024 12:26:23 +0530 Subject: [PATCH 1/2] Added lease expiry in instance termination catchup (#428) --- mb-xrpl/lib/message-board.js | 39 +++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/mb-xrpl/lib/message-board.js b/mb-xrpl/lib/message-board.js index 4d75ea7..8eab5d3 100644 --- a/mb-xrpl/lib/message-board.js +++ b/mb-xrpl/lib/message-board.js @@ -678,7 +678,7 @@ class MessageBoard { await this.#queueAction(async (submissionRefs) => { submissionRefs.refs ??= [{}]; - // Check again wether the transaction is validated before retry. + // Check again whether the transaction is validated before retry. const txHash = submissionRefs?.refs[0]?.submissionResult?.result?.tx_json?.hash; if (txHash) { const txResponse = await this.hostClient.xrplApi.getTransactionValidatedResults(txHash); @@ -1160,7 +1160,40 @@ class MessageBoard { } } else { - console.log("No relevant instance was found to perform the lease termination"); + const uriInfo = evernode.UtilHelpers.decodeLeaseTokenUri(hostingToken.URI); + await this.#queueAction(async (submissionRefs) => { + submissionRefs.refs ??= [{}]; + // Check again wether the transaction is validated before retry. + const txHash = submissionRefs?.refs[0]?.submissionResult?.result?.tx_json?.hash; + if (txHash) { + const txResponse = await this.hostClient.xrplApi.getTransactionValidatedResults(txHash); + if (txResponse && txResponse.code === "tesSUCCESS") { + console.log('Transaction is validated and success, Retry skipped!') + return; + } + } + console.log(`Expire the terminated instance ${hostingToken.index} lease.`); + await this.hostClient.expireLease(hostingToken.index, { submissionRef: submissionRefs?.refs[0] }); + }); + + + await this.#queueAction(async (submissionRefs) => { + submissionRefs.refs ??= [{}]; + // Check again wether the transaction is validated before retry. + const txHash = submissionRefs?.refs[0]?.submissionResult?.result?.tx_json?.hash; + if (txHash) { + const txResponse = await this.hostClient.xrplApi.getTransactionValidatedResults(txHash); + if (txResponse && txResponse.code === "tesSUCCESS") { + console.log('Transaction is validated and success, Retry skipped!') + return; + } + } + console.log(`Re-created lease offer for the terminated instance ${hostingToken.index}.`); + await this.hostClient.offerLease(uriInfo.leaseIndex, + uriInfo.leaseAmount, + appenv.TOS_HASH, + uriInfo.outboundIP, { submissionRef: submissionRefs?.refs[0] }); + }); } } else { @@ -1195,7 +1228,7 @@ class MessageBoard { async recreateLeaseOffer(uriTokenId, leaseIndex, outboundIP, noLeaseRecord = false) { await this.#queueAction(async (submissionRefs) => { submissionRefs.refs ??= [{}, {}]; - // Check again wether the transaction is validated before retry. + // Check again whether the transaction is validated before retry. const txHash1 = submissionRefs?.refs[0]?.submissionResult?.result?.tx_json?.hash; let retry = true; if (txHash1) { From 5c24dc7977dde56df4775daba9f246b609da2267 Mon Sep 17 00:00:00 2001 From: Chalith Desaman Date: Fri, 27 Sep 2024 15:16:57 +0530 Subject: [PATCH 2/2] Bug fixes and memory release (#429) --- dependencies/user-uninstall.sh | 19 ++++++++++-- installer/jshelper/package-lock.json | 8 +++--- installer/jshelper/package.json | 2 +- installer/sashimono-install.sh | 43 +++++++++++++++++++--------- installer/setup.sh | 5 +++- mb-xrpl/lib/appenv.js | 2 +- mb-xrpl/package-lock.json | 8 +++--- mb-xrpl/package.json | 2 +- reputationd | 2 +- src/version.hpp | 2 +- 10 files changed, 62 insertions(+), 31 deletions(-) diff --git a/dependencies/user-uninstall.sh b/dependencies/user-uninstall.sh index 1ffdbfb..99f9943 100755 --- a/dependencies/user-uninstall.sh +++ b/dependencies/user-uninstall.sh @@ -11,8 +11,6 @@ instance_name=$6 prefix="sashi" max_kill_attempts=5 - - # Check whether this is a valid sashimono username. [ ${#user} -lt 24 ] || [ ${#user} -gt 32 ] || [[ ! "$user" =~ ^$prefix[0-9]+$ ]] && echo "ARGS,UNINST_ERR" && exit 1 @@ -35,6 +33,15 @@ cleanup_script=$user_dir/uninstall_cleanup.sh gp_udp_port_count=2 gp_tcp_port_count=2 +function cgrulesengd_servicename() { + # Find the cgroups rules engine service. + local cgrulesengd_filepath=$(grep "ExecStart.*=.*/cgrulesengd$" /etc/systemd/system/*.service | head -1 | awk -F : ' { print $1 } ') + if [ -n "$cgrulesengd_filepath" ]; then + local cgrulesengd_filename=$(basename $cgrulesengd_filepath) + echo "${cgrulesengd_filename%.*}" + fi +} + echo "Uninstalling user '$user'." echo "Stopping and cleaning hpfs systemd services." @@ -150,7 +157,13 @@ rm -r /home/"${user:?}" # Even though we are creating a group specifically, # It'll be automatically deleted when we delete the user. +cgrulesengd_service=$(cgrulesengd_servicename) +if [ ! -z "$cgrulesengd_service" ]; then + echo "Restarting the '$cgrulesengd_service' service..." + systemctl restart $cgrulesengd_service +fi + [ -d /home/"$user" ] && echo "NOT_CLEAN,UNINST_ERR" && exit 1 echo "UNINST_SUC" -exit 0 \ No newline at end of file +exit 0 diff --git a/installer/jshelper/package-lock.json b/installer/jshelper/package-lock.json index aaf6558..7b5abc5 100644 --- a/installer/jshelper/package-lock.json +++ b/installer/jshelper/package-lock.json @@ -6,7 +6,7 @@ "": { "name": "evernode-setup-helper", "dependencies": { - "evernode-js-client": "0.6.58", + "evernode-js-client": "0.6.60", "ip6addr": "0.2.5", "ripple-keypairs": "1.3.1" } @@ -405,9 +405,9 @@ } }, "node_modules/evernode-js-client": { - "version": "0.6.58", - "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.58.tgz", - "integrity": "sha512-kPapQWgZenrTFFIzHFrKFuugNUqSWjh7AZGNeZKPRTnLjMsvmujsNVGcdPm7nhsFIzp1La3O0ePnS3lZ4h1SgQ==", + "version": "0.6.60", + "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.60.tgz", + "integrity": "sha512-nw7DxGLEHthy/dneQkQgi4o4Yu6sb09OjTPcHwhD5vnVDiOjDkUm8fshmIcjnwIW2Nhq0atGblSRq+UYvPkblQ==", "dependencies": { "elliptic": "6.5.4", "libsodium-wrappers": "0.7.10", diff --git a/installer/jshelper/package.json b/installer/jshelper/package.json index 2d798a0..5ccc361 100644 --- a/installer/jshelper/package.json +++ b/installer/jshelper/package.json @@ -4,7 +4,7 @@ "build": "ncc build index.js --minify -o dist" }, "dependencies": { - "evernode-js-client": "0.6.58", + "evernode-js-client": "0.6.60", "ip6addr": "0.2.5", "ripple-keypairs": "1.3.1" } diff --git a/installer/sashimono-install.sh b/installer/sashimono-install.sh index dfaeca8..a851262 100755 --- a/installer/sashimono-install.sh +++ b/installer/sashimono-install.sh @@ -190,6 +190,27 @@ function set_cpu_info() { [ -z $cpu_mhz ] && cpu_mhz=$(lscpu | grep -i "^CPU MHz:" | sed 's/CPU MHz://g' | sed 's/\.[0-9]*//g' | xargs) } +function setup_certbot_renewal() { + # We need to place our script in certbook deploy hooks dir. + local deploy_hooks_dir="/etc/letsencrypt/renewal-hooks/deploy" + [ "$UPGRADE" == "0" ] && ! [ -d $deploy_hooks_dir ] && echo "$deploy_hooks_dir not found" && return 1 + + # Setup deploy hook (update contract certs on certbot SSL auto-renewal) + local deploy_hook="/etc/letsencrypt/renewal-hooks/deploy/sashimono-$inetaddr.sh" + + if [ "$UPGRADE" == "0" ] || [ -f $deploy_hook ]; then + echo "Setting up certbot deploy hook $deploy_hook" + echo "#!/bin/sh +# This script is placed by Sashimono for automatic updataing of contract SSL certs. +# Domain name: $inetaddr +certname=\$(basename \$RENEWED_LINEAGE) +[ \"\$certname\" = \"$inetaddr\" ] && evernode applyssl \$RENEWED_LINEAGE/privkey.pem \$RENEWED_LINEAGE/cert.pem \$RENEWED_LINEAGE/fullchain.pem" >$deploy_hook + chmod +x $deploy_hook + fi + + return 0 +} + function setup_certbot() { stage "Setting up letsencrypt certbot" @@ -220,24 +241,14 @@ function setup_certbot() { ufw allow http comment sashimono-certbot # Setup the certificates. If there're already certificates skip this. - if [ ! -f /etc/letsencrypt/live/$inetaddr/privkey.pem ] || [ ! -f /etc/letsencrypt/live/$inetaddr/fullchain.pem ]; then + if [ ! -f /etc/letsencrypt/live/$inetaddr/privkey.pem ] || [ ! -f /etc/letsencrypt/live/$inetaddr/fullchain.pem ] || [ ! -f /etc/letsencrypt/live/$inetaddr/cert.pem ]; then echo "Running certbot certonly" call_third_party "certbot certonly -n -d $inetaddr --agree-tos --email $email_address --standalone" "setup certificates" || return 1 fi - # We need to place our script in certbook deploy hooks dir. - local deploy_hooks_dir="/etc/letsencrypt/renewal-hooks/deploy" - ! [ -d $deploy_hooks_dir ] && echo "$deploy_hooks_dir not found" && return 1 + setup_certbot_renewal || return 1 - # Setup deploy hook (update contract certs on certbot SSL auto-renewal) - local deploy_hook="/etc/letsencrypt/renewal-hooks/deploy/sashimono-$inetaddr.sh" - echo "Setting up certbot deploy hook $deploy_hook" - echo "#!/bin/sh -# This script is placed by Sashimono for automatic updataing of contract SSL certs. -# Domain name: $inetaddr -certname=\$(basename \$RENEWED_LINEAGE) -[ \"\$certname\" = \"$inetaddr\" ] && evernode applyssl \$RENEWED_LINEAGE/privkey.pem \$RENEWED_LINEAGE/fullchain.pem" >$deploy_hook - chmod +x $deploy_hook + return 0 } function setup_tls_certs() { @@ -247,7 +258,8 @@ function setup_tls_certs() { ! setup_certbot && echo "Error when setting up letsencrypt SSL certificate." && abort cp /etc/letsencrypt/live/$inetaddr/privkey.pem $SASHIMONO_DATA/contract_template/cfg/tlskey.pem - cp /etc/letsencrypt/live/$inetaddr/fullchain.pem $SASHIMONO_DATA/contract_template/cfg/tlscert.pem + cp /etc/letsencrypt/live/$inetaddr/cert.pem $SASHIMONO_DATA/contract_template/cfg/tlscert.pem + cat /etc/letsencrypt/live/$inetaddr/fullchain.pem >>$SASHIMONO_DATA/contract_template/cfg/tlscert.pem elif [ "$tls_key_file" == "self" ]; then # If user has not provided certs we generate self-signed ones. @@ -484,6 +496,9 @@ chmod -R +x $SASHIMONO_BIN # Setup tls certs used for contract instance websockets. [ "$UPGRADE" == "0" ] && setup_tls_certs +# Update renewal of tls certs used for contract instance websockets. +[ "$UPGRADE" == "1" ] && setup_certbot_renewal + # Copy Blake3 and update linker library cache. [ ! -f /usr/local/lib/libblake3.so ] && cp "$script_dir"/libblake3.so /usr/local/lib/ && ldconfig diff --git a/installer/setup.sh b/installer/setup.sh index 614c7c9..acd7120 100755 --- a/installer/setup.sh +++ b/installer/setup.sh @@ -28,7 +28,7 @@ root_user="root" repo_owner="EvernodeXRPL" - repo_name="evernode-test-resources" + repo_name="evernode-resources" desired_branch="main" # Reputation modes : 0 - "none", 1 - "OneToOne", 2 - "OneToMany" @@ -1593,6 +1593,9 @@ WantedBy=timers.target" >/etc/systemd/system/$EVERNODE_AUTO_UPDATE_SERVICE.timer if [ "$latest_installer_script_version" != "$current_installer_script_version" ]; then # This is added temporary to remove auto updater. This can later be removed. remove_evernode_auto_updater + + inetaddr=$(jq -r ".hp.host_address | select( . != null )" "$SASHIMONO_CONFIG") + install_evernode 1 fi diff --git a/mb-xrpl/lib/appenv.js b/mb-xrpl/lib/appenv.js index bc85d58..8c65cd6 100644 --- a/mb-xrpl/lib/appenv.js +++ b/mb-xrpl/lib/appenv.js @@ -45,7 +45,7 @@ appenv = { ORPHAN_PRUNE_SCHEDULER_INTERVAL_HOURS: 2, SASHIMONO_SCHEDULER_INTERVAL_SECONDS: 2, SASHI_CLI_PATH: appenv.IS_DEV_MODE ? "../build/sashi" : "/usr/bin/sashi", - MB_VERSION: '0.12.0', + MB_VERSION: '0.12.1', TOS_HASH: '0801677EBCB2F76EF97D531549D8B27DB2C7A4A8EE7F60032AE40184247F0810', // This is the sha256 hash of EVERNODE-HOSTING-PRINCIPLES.pdf. NETWORK: 'mainnet', REPUTATIOND_CONFIG_PATH: path.join(appenv.DATA_DIR, '../') + "reputationd/reputationd.cfg", diff --git a/mb-xrpl/package-lock.json b/mb-xrpl/package-lock.json index c9db30f..495abfa 100644 --- a/mb-xrpl/package-lock.json +++ b/mb-xrpl/package-lock.json @@ -6,7 +6,7 @@ "": { "name": "mb-xrpl", "dependencies": { - "evernode-js-client": "0.6.59", + "evernode-js-client": "0.6.60", "ip6addr": "0.2.5", "sqlite3": "5.1.7" }, @@ -1115,9 +1115,9 @@ } }, "node_modules/evernode-js-client": { - "version": "0.6.59", - "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.59.tgz", - "integrity": "sha512-IXT5T2fAG//Z9kHlSp/wZyWjvfs7+bmJVTCkD3RfLbZjqIviB/ydigGtf631Js5Q1jyIMu5F+EFpd08XS8S4jw==", + "version": "0.6.60", + "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.60.tgz", + "integrity": "sha512-nw7DxGLEHthy/dneQkQgi4o4Yu6sb09OjTPcHwhD5vnVDiOjDkUm8fshmIcjnwIW2Nhq0atGblSRq+UYvPkblQ==", "dependencies": { "elliptic": "6.5.4", "libsodium-wrappers": "0.7.10", diff --git a/mb-xrpl/package.json b/mb-xrpl/package.json index ba1ad1c..18c9e21 100644 --- a/mb-xrpl/package.json +++ b/mb-xrpl/package.json @@ -5,7 +5,7 @@ "build": "npm run lint && ncc build app.js --minify -o dist" }, "dependencies": { - "evernode-js-client": "0.6.59", + "evernode-js-client": "0.6.60", "ip6addr": "0.2.5", "sqlite3": "5.1.7" }, diff --git a/reputationd b/reputationd index 5a57d18..ed57e1b 160000 --- a/reputationd +++ b/reputationd @@ -1 +1 @@ -Subproject commit 5a57d183ab05538b0ecb917fc1979dd56850ddcf +Subproject commit ed57e1b0b977d1a77cc87306be9fb1c291bb9f4b diff --git a/src/version.hpp b/src/version.hpp index 1096495..bb21579 100644 --- a/src/version.hpp +++ b/src/version.hpp @@ -6,7 +6,7 @@ namespace version { // Sashimono agent version. Written to new configs. - constexpr const char *AGENT_VERSION = "0.12.0"; + constexpr const char *AGENT_VERSION = "0.12.1"; // Minimum compatible config version (this will be used to validate configs). constexpr const char *MIN_CONFIG_VERSION = "0.5.0";