Skip to content

fix(utxo): return 409 ACCOUNT_MIRROR_BOX_NOT_SPENDABLE again, not a misleading 400 - #8468

Merged
Scottcjn merged 2 commits into
mainfrom
fix/utxo-mirror-box-409-not-insufficient
Sep 18, 2026
Merged

Scottcjn merged 2 commits into
mainfrom
fix/utxo-mirror-box-409-not-insufficient

Conversation

@Scottcjn

Copy link
Copy Markdown
Owner

Merge after #8467, which restores CI test collection. Until then this PR's test check stays red for the same reason every PR's does.

Problem

Since #8395, mirror boxes are filtered out inside get_coin_select_candidates(), so the mirror_candidate_ids branch in /utxo/transfer became dead code. A sender whose funds are mirror-locked gets:

{"error": "Insufficient UTXO balance", "balance_rtc": 100.0, "requested_rtc": 99.0}

The balance is higher than the request, yet the response says "insufficient". Funds were never at risk (the box is not spent), but the error is misleading, and two security tests have been failing (hidden, because CI collection was broken).

Fix

This only runs after coin selection has already failed, and it changes no state. It compares wallet-wide totals:

  • 409 ACCOUNT_MIRROR_BOX_NOT_SPENDABLE: spendable (non-mirror) funds fall short, but the mirror-locked funds would cover the request.
  • 400 Insufficient UTXO balance: otherwise. The response now includes spendable_nrtc.

The totals come from SQL SUM over the whole wallet, not the bounded candidate list, so #8395's false-409 can't come back. Only the box IDs echoed in the 409 are capped, at 50. The code passes the repo's fetchall guard without an annotation.

Verification

🤖 Generated with Claude Code

…isleading 400

Since #8395, account-mirror boxes are excluded inside
get_coin_select_candidates() before candidate bounding, so the
mirror_candidate_ids branch in /utxo/transfer can never fire. A sender
whose funds are mirror-locked got 400 "Insufficient UTXO balance" while
the same response reported balance_nrtc >= requested_nrtc.

On a failed selection, decide from wallet totals: if the spendable
(non-mirror) funds fall short but the mirror-locked ones would cover the
request, return the 409 with the box ids; otherwise the plain 400, now
with spendable_nrtc. Totals are wallet-wide (SQL SUM), not the bounded
candidate list, so #8395's false-409 cannot return. No state change: this
only runs after coin selection has already failed.

Fixes the two long-failing tests (test_utxo_dual_write_double_spend,
test_utxo_transfer_spends_account_mirror) and adds a guard that a request
beyond the whole wallet stays a plain 400. Full CI suite (with #8467's
collection fix applied locally): 4012 passed, 0 failed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Scott <scottbphone12@gmail.com>
@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) node Node server related tests Test suite changes size/M PR: 51-200 lines labels Sep 18, 2026
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ BCOS v2 Scan Results

Metric Value
Trust Score 36/100
Certificate ID BCOS-afb3528b
Tier L2 (not met)

BCOS Badge

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

Full report | What is BCOS?


BCOS v2 Engine - Free & Open Source (MIT) - Elyan Labs

@Scottcjn
Scottcjn merged commit a5a2085 into main Sep 18, 2026
12 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

RTC Reward

This merged PR earned 5 RTC — sent to Scottcjn.

RustChain Bounty Program

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) node Node server related size/M PR: 51-200 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants