diff --git a/contrib/devtools/utxo_snapshot.sh b/contrib/devtools/utxo_snapshot.sh index dee25ff67b61e3..2b83c467498add 100755 --- a/contrib/devtools/utxo_snapshot.sh +++ b/contrib/devtools/utxo_snapshot.sh @@ -29,6 +29,15 @@ BITCOIN_CLI_CALL="${*} -rpcclienttimeout=9999999" # Block we'll invalidate/reconsider to rewind/fast-forward the chain. PIVOT_BLOCKHASH=$($BITCOIN_CLI_CALL getblockhash $(( GENERATE_AT_HEIGHT + 1 )) ) +# Trap any errors that occur +trap 'err_handler $?' ERR + +err_handler() { + (>&2 echo "Restoring chain to original height; this may take a while") + ${BITCOIN_CLI_CALL} reconsiderblock "${PIVOT_BLOCKHASH}" + exit $1 +} + (>&2 echo "Rewinding chain back to height ${GENERATE_AT_HEIGHT} (by invalidating ${PIVOT_BLOCKHASH}); this may take a while") ${BITCOIN_CLI_CALL} invalidateblock "${PIVOT_BLOCKHASH}" @@ -40,5 +49,8 @@ else ${BITCOIN_CLI_CALL} dumptxoutset "${OUTPUT_PATH}" fi +# Remove error trap +trap - ERR + (>&2 echo "Restoring chain to original height; this may take a while") ${BITCOIN_CLI_CALL} reconsiderblock "${PIVOT_BLOCKHASH}"