Skip to content

Commit 5b4f340

Browse files
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.
1 parent 60b8164 commit 5b4f340

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

contrib/devtools/utxo_snapshot.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ if (( GENERATE_AT_HEIGHT < PRUNED )); then
3636
exit 1
3737
fi
3838

39+
# Check current block height to ensure the node has synchronized past the required block
40+
CURRENT_BLOCK_HEIGHT=$(${BITCOIN_CLI_CALL} getblockcount)
41+
PIVOT_BLOCK_HEIGHT=$(( GENERATE_AT_HEIGHT + 1 ))
42+
43+
if (( PIVOT_BLOCK_HEIGHT > CURRENT_BLOCK_HEIGHT )); then
44+
(>&2 echo "Error: The node has not yet synchronized to block height ${PIVOT_BLOCK_HEIGHT}.")
45+
(>&2 echo "Please wait until the node has synchronized past this block height and try again.")
46+
exit 1
47+
fi
48+
3949
# Early exit if file at OUTPUT_PATH already exists
4050
if [[ -e "$OUTPUT_PATH" ]]; then
4151
(>&2 echo "Error: $OUTPUT_PATH already exists or is not a valid path.")

0 commit comments

Comments
 (0)