From 5b4f34006dbd76223b55b156421f87d2241ac296 Mon Sep 17 00:00:00 2001 From: pablomartin4btc Date: Wed, 21 Aug 2024 12:52:52 -0300 Subject: [PATCH] devtools, utxo-snapshot: Fix block height out of range Handle the Block height out of range error gracefully by checking if the node has synchronized to or beyond the required block height, otherwise without this validation the node would keep the network disabled if the user selected that option. Provide a user-friendly message if the block height is out of range and exit the script cleanly. --- contrib/devtools/utxo_snapshot.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/contrib/devtools/utxo_snapshot.sh b/contrib/devtools/utxo_snapshot.sh index fbb8591965fd0..e8781d94d920f 100755 --- a/contrib/devtools/utxo_snapshot.sh +++ b/contrib/devtools/utxo_snapshot.sh @@ -36,6 +36,16 @@ if (( GENERATE_AT_HEIGHT < PRUNED )); then exit 1 fi +# Check current block height to ensure the node has synchronized past the required block +CURRENT_BLOCK_HEIGHT=$(${BITCOIN_CLI_CALL} getblockcount) +PIVOT_BLOCK_HEIGHT=$(( GENERATE_AT_HEIGHT + 1 )) + +if (( PIVOT_BLOCK_HEIGHT > CURRENT_BLOCK_HEIGHT )); then + (>&2 echo "Error: The node has not yet synchronized to block height ${PIVOT_BLOCK_HEIGHT}.") + (>&2 echo "Please wait until the node has synchronized past this block height and try again.") + exit 1 +fi + # Early exit if file at OUTPUT_PATH already exists if [[ -e "$OUTPUT_PATH" ]]; then (>&2 echo "Error: $OUTPUT_PATH already exists or is not a valid path.")