Skip to content

Commit

Permalink
Add error handling to utxo_snapshot.sh
Browse files Browse the repository at this point in the history
Resolves bitcoin#27841
  • Loading branch information
hazeycode committed Jun 9, 2023
1 parent c0c43de commit 63a510f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions contrib/devtools/utxo_snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand All @@ -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}"

0 comments on commit 63a510f

Please sign in to comment.