From 5ba0e8f4196e9fd0b515ddc8cbbf098df3b05608 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:02:49 +0200 Subject: [PATCH 1/4] fix: check_network_version script does not clean used docker containers --- scripts/check_network_version.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/check_network_version.sh b/scripts/check_network_version.sh index 400501329c8..fe88553b68d 100755 --- a/scripts/check_network_version.sh +++ b/scripts/check_network_version.sh @@ -38,6 +38,7 @@ function load_masternodes_json() { function grpc_core { docker run \ + --rm \ -v "${REPO}:/repo" \ fullstorydev/grpcurl:latest \ -import-path "/repo/packages/dapi-grpc/protos/core/v0" \ @@ -49,6 +50,7 @@ function grpc_core { function grpc_platform { docker run \ + --rm \ -v "${REPO}:/repo" \ fullstorydev/grpcurl:latest \ -import-path "/repo/packages/dapi-grpc/protos/platform/v0" \ From 15a63d667818febde3ae50d966662ffe41fb14d4 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:25:00 +0200 Subject: [PATCH 2/4] feat(scripts): check_network_version nmap support --- scripts/check_network_version.sh | 70 ++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/scripts/check_network_version.sh b/scripts/check_network_version.sh index fe88553b68d..0ed2cdddaa6 100755 --- a/scripts/check_network_version.sh +++ b/scripts/check_network_version.sh @@ -7,30 +7,26 @@ MASTERNODES="" ALL="" function help() { - if [[ -z "$1" ]]; then - - echo This script connects to all masternodes and tries to detect their version. - echo "" - echo "Usage: $0 [-p | --port ] [-h | --help] [-m | --masternodes ] [-j | --json ] [-w | --mnowatch] [-c | --csv ]" - echo "Options:" - echo " -p, --port Port to connect to (default: $PORT)" - echo " -h, --help Show this help" - echo " -m, --masternodes File with IP addresses of masternodes to check" - echo " -j, --json File with masternodes.json in format generated by mnowatch" - echo " -w, --mnowatch Use mnowatch.org to get masternodes" - echo " -c, --csv Save results to CSV file; default: $CSV" - echo "" - echo "Note: --masternodes, --json, and --mnowatch are mutually exclusive and the latest one takes precedence." - exit 1 - fi + + echo This script connects to all masternodes and tries to detect their version. + echo "" + echo "Usage: $0 [-p | --port ] [-h | --help] [-m | --masternodes ] [-j | --json ] [-w | --mnowatch] [-c | --csv ]" + echo "Options:" + echo " -p, --port Port to connect to (default: $PORT)" + echo " -h, --help Show this help" + echo " -m, --masternodes File with IP addresses of masternodes to check" + echo " -j, --json File with masternodes.json in format generated by mnowatch" + echo " -w, --mnowatch Use mnowatch.org to get masternodes" + echo " -c, --csv Save results to CSV file; default: $CSV" + echo "" + echo "Note: --masternodes, --json, and --mnowatch are mutually exclusive and the latest one takes precedence." + exit 1 } REPO="$(realpath "$(dirname "$0")/..")" function load_masternodes_json() { - # curl https://mnowatch.org/json/?method=emn_details - # TODO: use curl above - jq 'map(select(.platformHTTPPortStatus != "CLOSED"))|map(select(.active_YNU!="N"))|map(select(.status!="P"))' "$1" | + jq 'map(select(.status!="P"))' "$1" | jq -r .[].ip | sort | uniq @@ -56,7 +52,9 @@ function grpc_platform { -import-path "/repo/packages/dapi-grpc/protos/platform/v0" \ -proto platform.proto \ -max-time 30 \ + -connect-timeout 5 \ -keepalive-time 1 \ + -insecure \ "$@" } @@ -73,7 +71,7 @@ function grpc_platform { function detect_platform() { NODE="$1" - err="$(grpc_platform -insecure "$NODE:${PORT}" org.dash.platform.dapi.v0.Platform/getTotalCreditsInPlatform 2>&1)" + err="$(grpc_platform "$NODE:${PORT}" org.dash.platform.dapi.v0.Platform/getTotalCreditsInPlatform 2>&1)" echo "============ $NODE ============" >>/tmp/detect_platform.log echo "$err" >>/tmp/detect_platform.log @@ -83,16 +81,19 @@ function detect_platform() { echo 1.1 ;; *"upstream connect error or disconnect/reset before headers"*) - echo "upstream connect error" + echo "upstream connect error; misconfiguration or drive down" ;; *"connect: connection refused"*) - echo "connection refused" + echo "connection refused; no platform or firewalled" ;; *"Code: Unimplemented"*) - echo "unimplemented" + echo "1.0" + ;; + *"context deadline exceeded"*) + echo "timeout; firewalled?" ;; *) - echo "ERROR" + echo "$err" ;; esac } @@ -125,6 +126,14 @@ function detect_core() { fi } +function run_nmap() { + nmap -n -Pn -p "443,9999,26656,80" -oG - $MASTERNODES +} + +if [[ $# -eq 0 ]]; then + help +fi + # Parse arguments while [[ "$1" == -* ]]; do case "$1" in @@ -154,6 +163,10 @@ while [[ "$1" == -* ]]; do CSV="$2" shift 2 ;; + -h | --help) + help + shift 1 + ;; *) echo "Unknown option: $1" exit 1 @@ -184,16 +197,21 @@ if [[ -z "$MASTERNODES" ]]; then fi # CSV header -echo "'no','masternode','platform','core'" >"$CSV" +echo "'no','masternode','platform','core','tenderdash','ports'" >"$CSV" + +NMAP_RESULTS=$(run_nmap) i=1 for MN in $MASTERNODES; do echo "Checking status of evo node $MN ($i/$COUNT)" PLATFORM="$(detect_platform "$MN")" + PORTS=$(echo "$NMAP_RESULTS" | grep "$MN.*Ports") # CORE="$(detect_core "$MN")" + grep -v 26656/open <<<"$PORTS" >/dev/null + TENDERDASH=$? # Format result as CSV - echo "$i,'$MN','$PLATFORM','$CORE'" >>"$CSV" + echo "$i,'$MN','$PLATFORM','$CORE','$TENDERDASH','$PORTS'" >>"$CSV" i=$((i + 1)) done From 7ee7db8b567c6ae9570ba43cbd58d9a5df6f34ff Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:54:21 +0200 Subject: [PATCH 3/4] chore: script using grpc --- scripts/check_network_version.sh | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/scripts/check_network_version.sh b/scripts/check_network_version.sh index 0ed2cdddaa6..1b833c5b06a 100755 --- a/scripts/check_network_version.sh +++ b/scripts/check_network_version.sh @@ -71,31 +71,14 @@ function grpc_platform { function detect_platform() { NODE="$1" - err="$(grpc_platform "$NODE:${PORT}" org.dash.platform.dapi.v0.Platform/getTotalCreditsInPlatform 2>&1)" - + json="$(grpc_platform "$NODE:${PORT}" org.dash.platform.dapi.v0.Platform/getStatus 2>&1)" echo "============ $NODE ============" >>/tmp/detect_platform.log - echo "$err" >>/tmp/detect_platform.log + echo "$json" >>/tmp/detect_platform.log - case "$err" in - *"decoding error: could not decode"*) - echo 1.1 - ;; - *"upstream connect error or disconnect/reset before headers"*) - echo "upstream connect error; misconfiguration or drive down" - ;; - *"connect: connection refused"*) - echo "connection refused; no platform or firewalled" - ;; - *"Code: Unimplemented"*) - echo "1.0" - ;; - *"context deadline exceeded"*) - echo "timeout; firewalled?" - ;; - *) - echo "$err" - ;; - esac + drive_version="$(echo "$json" | jq -r .v0.version.software.drive 2>/dev/null)" + td_version="$(echo "$json" | jq -r .v0.version.software.tenderdash 2>/dev/null)" + + echo "${drive_version:-unknown}/${td_version:-unknown}" } # Check if core is available by calling getBlockchainStatus From 255bae76b147cd92d08752f656509d0677caefc0 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Mon, 16 Dec 2024 09:42:13 +0100 Subject: [PATCH 4/4] chore: remove deprecated check_network_version.sh --- scripts/check_network_version.sh | 210 ------------------------------- 1 file changed, 210 deletions(-) delete mode 100755 scripts/check_network_version.sh diff --git a/scripts/check_network_version.sh b/scripts/check_network_version.sh deleted file mode 100755 index 1b833c5b06a..00000000000 --- a/scripts/check_network_version.sh +++ /dev/null @@ -1,210 +0,0 @@ -#! /bin/bash - -# Some defaults -PORT=${PORT:-443} -CSV=/tmp/masternodes.csv -MASTERNODES="" -ALL="" - -function help() { - - echo This script connects to all masternodes and tries to detect their version. - echo "" - echo "Usage: $0 [-p | --port ] [-h | --help] [-m | --masternodes ] [-j | --json ] [-w | --mnowatch] [-c | --csv ]" - echo "Options:" - echo " -p, --port Port to connect to (default: $PORT)" - echo " -h, --help Show this help" - echo " -m, --masternodes File with IP addresses of masternodes to check" - echo " -j, --json File with masternodes.json in format generated by mnowatch" - echo " -w, --mnowatch Use mnowatch.org to get masternodes" - echo " -c, --csv Save results to CSV file; default: $CSV" - echo "" - echo "Note: --masternodes, --json, and --mnowatch are mutually exclusive and the latest one takes precedence." - exit 1 -} - -REPO="$(realpath "$(dirname "$0")/..")" - -function load_masternodes_json() { - jq 'map(select(.status!="P"))' "$1" | - jq -r .[].ip | - sort | - uniq -} - -function grpc_core { - docker run \ - --rm \ - -v "${REPO}:/repo" \ - fullstorydev/grpcurl:latest \ - -import-path "/repo/packages/dapi-grpc/protos/core/v0" \ - -proto core.proto \ - -max-time 30 \ - -keepalive-time 1 \ - "$@" -} - -function grpc_platform { - docker run \ - --rm \ - -v "${REPO}:/repo" \ - fullstorydev/grpcurl:latest \ - -import-path "/repo/packages/dapi-grpc/protos/platform/v0" \ - -proto platform.proto \ - -max-time 30 \ - -connect-timeout 5 \ - -keepalive-time 1 \ - -insecure \ - "$@" -} - -# Go to specified IP and fetch SML (subscribeToMasternodeList) - -# MASTERNODES=$( -# grpc_core "$FULLNODE:$PORT" org.dash.platform.dapi.v0.Core/subscribeToMasternodeList | -# jq -r .masternodeListDiff | -# base64 -d | -# grep -aEo '([0-9]{1,3}\.){3}[0-9]{1,3}' | sort | uniq -# ) - -# Try to determine version of the platform -function detect_platform() { - NODE="$1" - - json="$(grpc_platform "$NODE:${PORT}" org.dash.platform.dapi.v0.Platform/getStatus 2>&1)" - echo "============ $NODE ============" >>/tmp/detect_platform.log - echo "$json" >>/tmp/detect_platform.log - - drive_version="$(echo "$json" | jq -r .v0.version.software.drive 2>/dev/null)" - td_version="$(echo "$json" | jq -r .v0.version.software.tenderdash 2>/dev/null)" - - echo "${drive_version:-unknown}/${td_version:-unknown}" -} - -# Check if core is available by calling getBlockchainStatus -# UNUSED -function detect_core() { - NODE="$1" - - err="$(grpc_core -insecure -d '{}' "$NODE:${PORT}" org.dash.platform.dapi.v0.Core/getBlockchainStatus 2>&1)" - - echo "============ $NODE ============" >>/tmp/detect_core.log - echo "$err" >>/tmp/detect_core.log - - version="$(echo "$err" | jq -r .version.agent 2>/dev/null)" - if [[ -z "$version" ]]; then - case "$err" in - *"upstream connect error"*) - echo down - ;; - *"connect: connection refused"*) - echo "connection refused" - ;; - *) - echo "UNKNOWN" - ;; - esac - else - echo "$version" - fi -} - -function run_nmap() { - nmap -n -Pn -p "443,9999,26656,80" -oG - $MASTERNODES -} - -if [[ $# -eq 0 ]]; then - help -fi - -# Parse arguments -while [[ "$1" == -* ]]; do - case "$1" in - -p | --port) - PORT="$2" - shift 2 - ;; - -m | --masternodes) - MASTERNODES=$(cat "$2") - shift 2 - ;; - -j | --json) - MASTERNODES=$(load_masternodes_json "$2") - ALL=$(jq '.|length' "$2") - shift 2 - ;; - -w | --mnowatch) - MN_FILE=$(mktemp /tmp/masternodes.json.XXXXXX) - echo -n Fetching masternodes from mnowatch.org... - curl -s https://mnowatch.org/json/?method=emn_details >"$MN_FILE" - ALL=$(jq '.|length' "$MN_FILE") - MASTERNODES=$(load_masternodes_json "$MN_FILE") - echo " done." - shift - ;; - -c | --csv) - CSV="$2" - shift 2 - ;; - -h | --help) - help - shift 1 - ;; - *) - echo "Unknown option: $1" - exit 1 - ;; - esac -done - -COUNT=$(echo "$MASTERNODES" | wc -l) -if [[ -z "$ALL" ]]; then - ALL=$COUNT -fi - -# Fetch getTotalCreditsInPlatform : -# * can’t connect - no platform, not found - means platform version -# * less than 1.1.0, internal - right version but init chain is not called yet. -# Fetch getBlockchainStatus to get information about Core: -# * can’t connect - no platform or no core -# grpc_core -help -set +e - -# Reset logs -truncate -s 0 /tmp/detect_platform.log -truncate -s 0 /tmp/detect_core.log - -if [[ -z "$MASTERNODES" ]]; then - echo "No masternodes found" - exit 1 -fi - -# CSV header -echo "'no','masternode','platform','core','tenderdash','ports'" >"$CSV" - -NMAP_RESULTS=$(run_nmap) - -i=1 -for MN in $MASTERNODES; do - echo "Checking status of evo node $MN ($i/$COUNT)" - - PLATFORM="$(detect_platform "$MN")" - PORTS=$(echo "$NMAP_RESULTS" | grep "$MN.*Ports") - # CORE="$(detect_core "$MN")" - grep -v 26656/open <<<"$PORTS" >/dev/null - TENDERDASH=$? - # Format result as CSV - echo "$i,'$MN','$PLATFORM','$CORE','$TENDERDASH','$PORTS'" >>"$CSV" - i=$((i + 1)) -done - -echo "Done." - -echo "" -echo "Results saved to $CSV" -echo "" -echo "Some statistics:" -echo "Total evonodes: $ALL" -echo "Potentially correct evo nodes: $COUNT" -echo "Platform versions:" -tail -n +2 "$CSV" | cut -d, -f3 | sort | uniq -c | sort -n