Repository navigation
fix(utxo): stop swallowing stale-mempool cleanup errors after committed spends - #8519
Merged
Merged
Conversation
Scottcjn
force-pushed
the
fix/utxo-mempool-cleanup-surface-errors
branch
from
September 24, 2026 22:18
40c34d6 to
1f39ab0
Compare
Contributor
|
| Metric | Value |
|---|---|
| Trust Score | 36/100 |
| Certificate ID | BCOS-2e687bd4 |
| Tier | L2 (not met) |
What does this mean?
The BCOS (Beacon Certified Open Source) engine scans for:
- SPDX license header compliance
- Known CVE vulnerabilities (OSV database)
- Static analysis findings (Semgrep)
- SBOM completeness
- Dependency freshness
- Test infrastructure evidence
- Review attestation tier
BCOS v2 Engine - Free & Open Source (MIT) - Elyan Labs
…ed spends After apply_transaction() spends inputs it evicts mempool txs that depend on the spent boxes. Every failure in that cleanup was swallowed twice: _evict_stale_data_input_txs() caught all exceptions and returned 0, and apply_transaction() wrapped the call in `except Exception: pass`. Stale dependents could silently stay in the pool with no log or signal. Now: - The helper raises instead of returning 0, and is atomic: BEGIN IMMEDIATE on its own connection, a SAVEPOINT on a caller's connection, so a mid-eviction failure can no longer commit claim-row DELETEs while leaving the mempool row behind (orphaned, unclaimed inputs). - apply_transaction() never rolls back a spend over a cleanup failure; it logs at ERROR with tx_id + spent box ids and increments a process-local counter (mempool_eviction_failure_count()). - Fail closed on the caller-connection path: if SQLite aborted the caller's whole transaction during eviction (spend gone), or the savepoint rollback itself failed, apply_transaction() raises instead of returning True for a spend that is not there. A RELEASE failure after a successful ROLLBACK TO (or after a successful eviction) is only logged: the caller's writes are intact and its COMMIT closes the leftover savepoint. - Defense in depth: a mempool row whose tx_data_json spends a spent box is evicted even if its utxo_mempool_inputs claim rows are missing; non-dict / malformed rows no longer abort the whole scan. Reported by @expertedgevault-rgb (#2819). Signed-off-by: Scott <scottbphone12@gmail.com> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Scottcjn
force-pushed
the
fix/utxo-mempool-cleanup-surface-errors
branch
from
September 24, 2026 22:45
1f39ab0 to
07c0826
Compare
Owner
Author
|
Changes after the outside review (amended into the single signed-off commit, now
UTXO suite: before ( |
Contributor
RTC RewardThis merged PR earned 5 RTC — sent to |
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.
Reported by @expertedgevault-rgb (#2819).
Problem
After
apply_transaction()spends inputs it evicts mempool txs that depend on the spent boxes (as inputs ordata_inputs). Every failure there was swallowed twice:_evict_stale_data_input_txs()caught all exceptions and returned0, andapply_transaction()wrapped the call inexcept Exception: pass. Stale dependents could stay in the pool with no log, counter, or return signal.Two more problems showed up while writing the tests (caller-connection path, which
/utxo/transferuses):apply_transaction()still returnedTruefor a spend that had been rolled back. The endpoint would then carry on with its dual-write account writes.Fix (only
node/utxo_db.pychanges)BEGIN IMMEDIATE. On a caller's connection it uses aSAVEPOINT, so the caller's spend writes are never touched.ERRORwith thetx_idand spent box ids, and it incrementsmempool_eviction_failure_count()(process-local).apply_transaction()raises instead of returningTrue.tx_data_jsonspends a spent box is evicted even when its claim rows are missing. Non-dict rows no longer abort the scan.Tests
New
tests/test_utxo_mempool_eviction_failure_surfaced.py(17 tests). Failures are injected with real SQLite triggers (RAISE(ABORT)/RAISE(ROLLBACK)) plus one monkeypatch.tests/*utxo*,node/test_utxo*,node/tests/*utxo*): before 343 passed / 21 failed, after 360 passed / 21 failed. The 21 failures are identical before and after (existing PoC tests).Merge considerations
True. This only happens when SQLite has aborted the transaction or the savepoint rollback failed./metricsor health yet. That can be a follow-up.🤖 Generated with Claude Code