fix(utxo): ensure ROLLBACK on ValueError in spend_box (BUG-2)#6308
Open
crowniteto wants to merge 2 commits into
Open
fix(utxo): ensure ROLLBACK on ValueError in spend_box (BUG-2)#6308crowniteto wants to merge 2 commits into
crowniteto wants to merge 2 commits into
Conversation
spend_box() had individual ROLLBACK calls before each ValueError raise, but the 'except ValueError: raise' path bypassed the general 'except Exception' handler. If a future code path adds a new ValueError without the explicit ROLLBACK, the transaction would leak. Now the 'except ValueError' handler also does ROLLBACK (idempotent in SQLite), making the pattern safe against future additions. 3 regression tests passing. Addresses review feedback on PR Scottcjn#6146.
jaxint
approved these changes
May 25, 2026
Contributor
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Great work on this PR. 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Split follow-up from PR #6146 review feedback. Addresses BUG-2.
BUG-2: spend_box ROLLBACK leak on ValueError
Problem:
spend_box()had individualROLLBACKcalls before eachValueErrorraise, but theexcept ValueError: raisepath bypassed the generalexcept Exceptionhandler. If a future code path adds a newValueErrorwithout the explicit ROLLBACK, the transaction would leak.Fix: The
except ValueErrorhandler now also does ROLLBACK before re-raising. Since ROLLBACK is idempotent in SQLite (a no-op on an already-rolled-back transaction), this makes the pattern safe against future additions without any behavioral change.Tests
3 regression tests:
test_spend_nonexistent_returns_nonetest_double_spend_raises_and_releases_lock: Verifies DB is usable after ValueErrortest_spend_box_success