From d5a28bcc40599d8b6c2e9032d1a1e73d1da8e9f2 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 25 Jan 2023 16:51:04 -0300 Subject: [PATCH 1/8] add `ZCASH_RPC_COOKIE_FILE` env var --- zebra-utils/zcash-rpc-diff | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/zebra-utils/zcash-rpc-diff b/zebra-utils/zcash-rpc-diff index 818dac6da32..915660c1724 100755 --- a/zebra-utils/zcash-rpc-diff +++ b/zebra-utils/zcash-rpc-diff @@ -16,6 +16,7 @@ function usage() # Override the commands used by this script using these environmental variables: ZCASH_CLI="${ZCASH_CLI:-zcash-cli}" +ZCASH_RPC_COOKIE_FILE="${ZCASH_RPC_COOKIE_FILE:-.cookie}" DIFF="${DIFF:-diff --unified --color=always}" JQ="${JQ:-jq}" @@ -41,7 +42,7 @@ ZEBRAD=$(cat "$ZEBRAD_RELEASE_INFO" | grep '"subversion"' | cut -d: -f2 | cut -d tr 'A-Z' 'a-z' | sed 's/magicbean/zcashd/ ; s/zebra$/zebrad/') echo "Checking second node release info..." -$ZCASH_CLI getinfo > "$ZCASHD_RELEASE_INFO" +$ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" getinfo > "$ZCASHD_RELEASE_INFO" ZCASHD=$(cat "$ZCASHD_RELEASE_INFO" | grep '"subversion"' | cut -d: -f2 | cut -d/ -f2 | \ tr 'A-Z' 'a-z' | sed 's/magicbean/zcashd/ ; s/zebra$/zebrad/') @@ -60,7 +61,7 @@ ZEBRAD_NET=$(cat "$ZEBRAD_BLOCKCHAIN_INFO" | grep '"chain"' | cut -d: -f2 | tr - ZEBRAD_HEIGHT=$(cat "$ZEBRAD_BLOCKCHAIN_INFO" | grep '"blocks"' | cut -d: -f2 | tr -d ' ,"') echo "Checking $ZCASHD network and tip height..." -$ZCASH_CLI getblockchaininfo > "$ZCASHD_BLOCKCHAIN_INFO" +$ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" getblockchaininfo > "$ZCASHD_BLOCKCHAIN_INFO" ZCASHD_NET=$(cat "$ZCASHD_BLOCKCHAIN_INFO" | grep '"chain"' | cut -d: -f2 | tr -d ' ,"') ZCASHD_HEIGHT=$(cat "$ZCASHD_BLOCKCHAIN_INFO" | grep '"blocks"' | cut -d: -f2 | tr -d ' ,"') @@ -93,7 +94,7 @@ time $ZCASH_CLI -rpcport="$ZEBRAD_RPC_PORT" "$@" > "$ZEBRAD_RESPONSE" echo echo "Querying $ZCASHD $ZCASHD_NET chain at height >=$ZCASHD_HEIGHT..." -time $ZCASH_CLI "$@" > "$ZCASHD_RESPONSE" +time $ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" "$@" > "$ZCASHD_RESPONSE" echo echo @@ -136,7 +137,7 @@ echo "Querying $ZEBRAD $ZEBRAD_NET chain at height >=$ZEBRAD_HEIGHT..." $ZCASH_CLI -rpcport="$ZEBRAD_RPC_PORT" "$@" > "$ZEBRAD_CHECK_RESPONSE" echo "Querying $ZCASHD $ZCASHD_NET chain at height >=$ZCASHD_HEIGHT..." -$ZCASH_CLI "$@" > "$ZCASHD_CHECK_RESPONSE" +$ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" "$@" > "$ZCASHD_CHECK_RESPONSE" echo From de68004025f1fae47493eacf840f5427ab983f1e Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 25 Jan 2023 17:06:57 -0300 Subject: [PATCH 2/8] get details when `getrawmempool` call differs --- zebra-utils/zcash-rpc-diff | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/zebra-utils/zcash-rpc-diff b/zebra-utils/zcash-rpc-diff index 915660c1724..11ec165eb4f 100755 --- a/zebra-utils/zcash-rpc-diff +++ b/zebra-utils/zcash-rpc-diff @@ -120,6 +120,8 @@ EXIT_STATUS=$? if [ "$1" == "getaddressutxos" ]; then set "getaddressbalance" "$2" +elif [ "$1" == "getrawmempool" ]; then + set "getrawmempool" else exit $EXIT_STATUS fi @@ -193,6 +195,37 @@ if [ "$1" == "getaddressbalance" ]; then fi fi +if [ "$1" == "getrawmempool" ] && [ $CHECK_EXIT_STATUS != 0 ]; then + echo + echo "Obtaining transaction details" + echo + + set TRANSACTION_ID + set TRANSACTION_HEX + set TRANSACTION_DECODED + + while IFS= read -r line + do + if [ "$line" != "[" ] && [ "$line" != "]" ]; then + if [[ "${line:0-1}" == "," ]]; then + TRANSACTION_ID="${line:3:-2}" + else + TRANSACTION_ID="${line:3:-1}" + fi + + TRANSACTION_HEX=`$ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" -rpcport="$ZEBRAD_RPC_PORT" getrawtransaction $TRANSACTION_ID 0` + + echo "## Displaying transaction $TRANSACTION_ID" + echo + + TRANSACTION_DECODED=`$ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" decoderawtransaction $TRANSACTION_HEX` + + echo $TRANSACTION_DECODED | $JQ + echo + fi + done < "$ZEBRAD_RESPONSE" +fi + if [ $EXIT_STATUS -ne 0 ]; then exit $EXIT_STATUS else From 6a11abe07e9ed08498f3aec9ce87dabd8914b326 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 25 Jan 2023 17:22:24 -0300 Subject: [PATCH 3/8] remove non needed cookie file argument in zebra call --- zebra-utils/zcash-rpc-diff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra-utils/zcash-rpc-diff b/zebra-utils/zcash-rpc-diff index 11ec165eb4f..1635d939eb2 100755 --- a/zebra-utils/zcash-rpc-diff +++ b/zebra-utils/zcash-rpc-diff @@ -213,7 +213,7 @@ if [ "$1" == "getrawmempool" ] && [ $CHECK_EXIT_STATUS != 0 ]; then TRANSACTION_ID="${line:3:-1}" fi - TRANSACTION_HEX=`$ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" -rpcport="$ZEBRAD_RPC_PORT" getrawtransaction $TRANSACTION_ID 0` + TRANSACTION_HEX=`$ZCASH_CLI -rpcport="$ZEBRAD_RPC_PORT" getrawtransaction $TRANSACTION_ID 0` echo "## Displaying transaction $TRANSACTION_ID" echo From b94ed8f3fdce8508f3be826fad650be0ab077365 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Sat, 28 Jan 2023 09:55:53 -0300 Subject: [PATCH 4/8] replace cookie args with extra agrs --- zebra-utils/zcash-rpc-diff | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/zebra-utils/zcash-rpc-diff b/zebra-utils/zcash-rpc-diff index 1635d939eb2..ee15f48b8ae 100755 --- a/zebra-utils/zcash-rpc-diff +++ b/zebra-utils/zcash-rpc-diff @@ -16,9 +16,12 @@ function usage() # Override the commands used by this script using these environmental variables: ZCASH_CLI="${ZCASH_CLI:-zcash-cli}" -ZCASH_RPC_COOKIE_FILE="${ZCASH_RPC_COOKIE_FILE:-.cookie}" DIFF="${DIFF:-diff --unified --color=always}" JQ="${JQ:-jq}" +# Zcashd authentification modes: +# - Use `-rpccookiefile=your/cookie/file` for a cookie file. +# - Use `-rpcpassword=your-password` for a password. +ZCASHD_EXTRA_ARGS="${ZCASHD_EXTRA_ARGS:-}" if [ $# -lt 2 ]; then usage @@ -42,7 +45,7 @@ ZEBRAD=$(cat "$ZEBRAD_RELEASE_INFO" | grep '"subversion"' | cut -d: -f2 | cut -d tr 'A-Z' 'a-z' | sed 's/magicbean/zcashd/ ; s/zebra$/zebrad/') echo "Checking second node release info..." -$ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" getinfo > "$ZCASHD_RELEASE_INFO" +$ZCASH_CLI $ZCASHD_EXTRA_ARGS getinfo > "$ZCASHD_RELEASE_INFO" ZCASHD=$(cat "$ZCASHD_RELEASE_INFO" | grep '"subversion"' | cut -d: -f2 | cut -d/ -f2 | \ tr 'A-Z' 'a-z' | sed 's/magicbean/zcashd/ ; s/zebra$/zebrad/') @@ -61,7 +64,7 @@ ZEBRAD_NET=$(cat "$ZEBRAD_BLOCKCHAIN_INFO" | grep '"chain"' | cut -d: -f2 | tr - ZEBRAD_HEIGHT=$(cat "$ZEBRAD_BLOCKCHAIN_INFO" | grep '"blocks"' | cut -d: -f2 | tr -d ' ,"') echo "Checking $ZCASHD network and tip height..." -$ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" getblockchaininfo > "$ZCASHD_BLOCKCHAIN_INFO" +$ZCASH_CLI $ZCASHD_EXTRA_ARGS getblockchaininfo > "$ZCASHD_BLOCKCHAIN_INFO" ZCASHD_NET=$(cat "$ZCASHD_BLOCKCHAIN_INFO" | grep '"chain"' | cut -d: -f2 | tr -d ' ,"') ZCASHD_HEIGHT=$(cat "$ZCASHD_BLOCKCHAIN_INFO" | grep '"blocks"' | cut -d: -f2 | tr -d ' ,"') @@ -94,7 +97,7 @@ time $ZCASH_CLI -rpcport="$ZEBRAD_RPC_PORT" "$@" > "$ZEBRAD_RESPONSE" echo echo "Querying $ZCASHD $ZCASHD_NET chain at height >=$ZCASHD_HEIGHT..." -time $ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" "$@" > "$ZCASHD_RESPONSE" +time $ZCASH_CLI $ZCASHD_EXTRA_ARGS "$@" > "$ZCASHD_RESPONSE" echo echo @@ -139,7 +142,7 @@ echo "Querying $ZEBRAD $ZEBRAD_NET chain at height >=$ZEBRAD_HEIGHT..." $ZCASH_CLI -rpcport="$ZEBRAD_RPC_PORT" "$@" > "$ZEBRAD_CHECK_RESPONSE" echo "Querying $ZCASHD $ZCASHD_NET chain at height >=$ZCASHD_HEIGHT..." -$ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" "$@" > "$ZCASHD_CHECK_RESPONSE" +$ZCASH_CLI $ZCASHD_EXTRA_ARGS "$@" > "$ZCASHD_CHECK_RESPONSE" echo @@ -218,7 +221,7 @@ if [ "$1" == "getrawmempool" ] && [ $CHECK_EXIT_STATUS != 0 ]; then echo "## Displaying transaction $TRANSACTION_ID" echo - TRANSACTION_DECODED=`$ZCASH_CLI -rpccookiefile="$ZCASH_RPC_COOKIE_FILE" decoderawtransaction $TRANSACTION_HEX` + TRANSACTION_DECODED=`$ZCASH_CLI $ZCASHD_EXTRA_ARGS decoderawtransaction $TRANSACTION_HEX` echo $TRANSACTION_DECODED | $JQ echo From 83ceaaff1dce3f0a339d11942e7dcae099636eb5 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Sat, 28 Jan 2023 10:41:07 -0300 Subject: [PATCH 5/8] read hex from file --- zebra-utils/zcash-rpc-diff | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/zebra-utils/zcash-rpc-diff b/zebra-utils/zcash-rpc-diff index ee15f48b8ae..c0090ea8d38 100755 --- a/zebra-utils/zcash-rpc-diff +++ b/zebra-utils/zcash-rpc-diff @@ -204,7 +204,7 @@ if [ "$1" == "getrawmempool" ] && [ $CHECK_EXIT_STATUS != 0 ]; then echo set TRANSACTION_ID - set TRANSACTION_HEX + set TRANSACTION_HEX_FILE set TRANSACTION_DECODED while IFS= read -r line @@ -216,12 +216,16 @@ if [ "$1" == "getrawmempool" ] && [ $CHECK_EXIT_STATUS != 0 ]; then TRANSACTION_ID="${line:3:-1}" fi - TRANSACTION_HEX=`$ZCASH_CLI -rpcport="$ZEBRAD_RPC_PORT" getrawtransaction $TRANSACTION_ID 0` + TRANSACTION_HEX_FILE="$ZCASH_RPC_TMP_DIR/$ZEBRAD-$ZEBRAD_NET-$ZEBRAD_HEIGHT-TRANSACTION_HEX-$TRANSACTION_ID.json" + + $ZCASH_CLI -rpcport="$ZEBRAD_RPC_PORT" getrawtransaction $TRANSACTION_ID 0 > $TRANSACTION_HEX_FILE echo "## Displaying transaction $TRANSACTION_ID" echo - TRANSACTION_DECODED=`$ZCASH_CLI $ZCASHD_EXTRA_ARGS decoderawtransaction $TRANSACTION_HEX` + # read the proposal data from a file, to avoid command-line length limits + TRANSACTION_DECODED=`cat "$TRANSACTION_HEX_FILE" | \ + $ZCASH_CLI $ZCASHD_EXTRA_ARGS -stdin decoderawtransaction` echo $TRANSACTION_DECODED | $JQ echo From dd1d35c81169335fe5fd496239f453118ac88034 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Sat, 28 Jan 2023 10:51:04 -0300 Subject: [PATCH 6/8] use jq for transactions loop --- zebra-utils/zcash-rpc-diff | 40 +++++++++++++++----------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/zebra-utils/zcash-rpc-diff b/zebra-utils/zcash-rpc-diff index c0090ea8d38..89c9df9474f 100755 --- a/zebra-utils/zcash-rpc-diff +++ b/zebra-utils/zcash-rpc-diff @@ -207,30 +207,22 @@ if [ "$1" == "getrawmempool" ] && [ $CHECK_EXIT_STATUS != 0 ]; then set TRANSACTION_HEX_FILE set TRANSACTION_DECODED - while IFS= read -r line - do - if [ "$line" != "[" ] && [ "$line" != "]" ]; then - if [[ "${line:0-1}" == "," ]]; then - TRANSACTION_ID="${line:3:-2}" - else - TRANSACTION_ID="${line:3:-1}" - fi - - TRANSACTION_HEX_FILE="$ZCASH_RPC_TMP_DIR/$ZEBRAD-$ZEBRAD_NET-$ZEBRAD_HEIGHT-TRANSACTION_HEX-$TRANSACTION_ID.json" - - $ZCASH_CLI -rpcport="$ZEBRAD_RPC_PORT" getrawtransaction $TRANSACTION_ID 0 > $TRANSACTION_HEX_FILE - - echo "## Displaying transaction $TRANSACTION_ID" - echo - - # read the proposal data from a file, to avoid command-line length limits - TRANSACTION_DECODED=`cat "$TRANSACTION_HEX_FILE" | \ - $ZCASH_CLI $ZCASHD_EXTRA_ARGS -stdin decoderawtransaction` - - echo $TRANSACTION_DECODED | $JQ - echo - fi - done < "$ZEBRAD_RESPONSE" + ZEBRAD_TRANSACTION_IDS=$(cat "$ZEBRAD_RESPONSE" | $JQ -r 'join(" ")') + for TRANSACTION_ID in $ZEBRAD_TRANSACTION_IDS; do + TRANSACTION_HEX_FILE="$ZCASH_RPC_TMP_DIR/$ZEBRAD-$ZEBRAD_NET-$ZEBRAD_HEIGHT-TRANSACTION_HEX-$TRANSACTION_ID.json" + + $ZCASH_CLI -rpcport="$ZEBRAD_RPC_PORT" getrawtransaction $TRANSACTION_ID 0 > $TRANSACTION_HEX_FILE + + echo "## Displaying transaction $TRANSACTION_ID" + echo + + # read the proposal data from a file, to avoid command-line length limits + TRANSACTION_DECODED=`cat "$TRANSACTION_HEX_FILE" | \ + $ZCASH_CLI $ZCASHD_EXTRA_ARGS -stdin decoderawtransaction` + + echo $TRANSACTION_DECODED | $JQ + echo + done fi if [ $EXIT_STATUS -ne 0 ]; then From 04e5b5722012fe0eaf7fe74370a1bb96262cdf1b Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Sat, 28 Jan 2023 11:36:23 -0300 Subject: [PATCH 7/8] dump transactions from the zcashd mempool --- zebra-utils/zcash-rpc-diff | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/zebra-utils/zcash-rpc-diff b/zebra-utils/zcash-rpc-diff index 89c9df9474f..6032e405d84 100755 --- a/zebra-utils/zcash-rpc-diff +++ b/zebra-utils/zcash-rpc-diff @@ -199,21 +199,23 @@ if [ "$1" == "getaddressbalance" ]; then fi if [ "$1" == "getrawmempool" ] && [ $CHECK_EXIT_STATUS != 0 ]; then - echo - echo "Obtaining transaction details" - echo - set TRANSACTION_ID set TRANSACTION_HEX_FILE set TRANSACTION_DECODED ZEBRAD_TRANSACTION_IDS=$(cat "$ZEBRAD_RESPONSE" | $JQ -r 'join(" ")') + ZCASHD_TRANSACTION_IDS=$(cat "$ZCASHD_RESPONSE" | $JQ -r 'join(" ")') + + echo + echo "# Dumping transactions from zebrad mempool" + echo + for TRANSACTION_ID in $ZEBRAD_TRANSACTION_IDS; do TRANSACTION_HEX_FILE="$ZCASH_RPC_TMP_DIR/$ZEBRAD-$ZEBRAD_NET-$ZEBRAD_HEIGHT-TRANSACTION_HEX-$TRANSACTION_ID.json" $ZCASH_CLI -rpcport="$ZEBRAD_RPC_PORT" getrawtransaction $TRANSACTION_ID 0 > $TRANSACTION_HEX_FILE - echo "## Displaying transaction $TRANSACTION_ID" + echo "## Displaying transaction $TRANSACTION_ID from zebrad" echo # read the proposal data from a file, to avoid command-line length limits @@ -223,6 +225,27 @@ if [ "$1" == "getrawmempool" ] && [ $CHECK_EXIT_STATUS != 0 ]; then echo $TRANSACTION_DECODED | $JQ echo done + + echo + echo "# Dumping transactions from zcashd mempool" + echo + + for TRANSACTION_ID in $ZCASHD_TRANSACTION_IDS; do + TRANSACTION_HEX_FILE="$ZCASH_RPC_TMP_DIR/$ZCASHD-$ZCASHD_NET-$ZCASHD_HEIGHT-TRANSACTION_HEX-$TRANSACTION_ID.json" + + $ZCASH_CLI $ZCASHD_EXTRA_ARGS getrawtransaction $TRANSACTION_ID 0 > $TRANSACTION_HEX_FILE + + echo "## Displaying transaction $TRANSACTION_ID from zcashd" + echo + + # read the proposal data from a file, to avoid command-line length limits + TRANSACTION_DECODED=`cat "$TRANSACTION_HEX_FILE" | \ + $ZCASH_CLI $ZCASHD_EXTRA_ARGS -stdin decoderawtransaction` + + echo $TRANSACTION_DECODED | $JQ + echo + done + fi if [ $EXIT_STATUS -ne 0 ]; then From 3eded4c036e1c48a9eaf21a0bde0d4ee11b4432e Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 1 Feb 2023 09:15:02 -0300 Subject: [PATCH 8/8] apply suggestions from code review Co-authored-by: teor --- zebra-utils/zcash-rpc-diff | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zebra-utils/zcash-rpc-diff b/zebra-utils/zcash-rpc-diff index 6032e405d84..2a89a4a9cc5 100755 --- a/zebra-utils/zcash-rpc-diff +++ b/zebra-utils/zcash-rpc-diff @@ -18,7 +18,7 @@ function usage() ZCASH_CLI="${ZCASH_CLI:-zcash-cli}" DIFF="${DIFF:-diff --unified --color=always}" JQ="${JQ:-jq}" -# Zcashd authentification modes: +# Zcashd authentication modes: # - Use `-rpccookiefile=your/cookie/file` for a cookie file. # - Use `-rpcpassword=your-password` for a password. ZCASHD_EXTRA_ARGS="${ZCASHD_EXTRA_ARGS:-}" @@ -124,6 +124,7 @@ EXIT_STATUS=$? if [ "$1" == "getaddressutxos" ]; then set "getaddressbalance" "$2" elif [ "$1" == "getrawmempool" ]; then + # Call `getrawmempool` again as a dummy request (this script isn't set up to do multiple cross-check calls) set "getrawmempool" else exit $EXIT_STATUS @@ -211,7 +212,7 @@ if [ "$1" == "getrawmempool" ] && [ $CHECK_EXIT_STATUS != 0 ]; then echo for TRANSACTION_ID in $ZEBRAD_TRANSACTION_IDS; do - TRANSACTION_HEX_FILE="$ZCASH_RPC_TMP_DIR/$ZEBRAD-$ZEBRAD_NET-$ZEBRAD_HEIGHT-TRANSACTION_HEX-$TRANSACTION_ID.json" + TRANSACTION_HEX_FILE="$ZCASH_RPC_TMP_DIR/$ZEBRAD-$ZEBRAD_NET-$ZEBRAD_HEIGHT-$TRANSACTION_ID.json" $ZCASH_CLI -rpcport="$ZEBRAD_RPC_PORT" getrawtransaction $TRANSACTION_ID 0 > $TRANSACTION_HEX_FILE @@ -248,6 +249,8 @@ if [ "$1" == "getrawmempool" ] && [ $CHECK_EXIT_STATUS != 0 ]; then fi +echo "Full RPC output is in $ZCASH_RPC_TMP_DIR" + if [ $EXIT_STATUS -ne 0 ]; then exit $EXIT_STATUS else