Skip to content

fix(utxo): mint dual-write reward boxes on the settlement path prod uses - #8485

Merged
Scottcjn merged 2 commits into
mainfrom
fix/rip200-settlement-dualwrite-mint
Sep 19, 2026
Merged

Scottcjn merged 2 commits into
mainfrom
fix/rip200-settlement-dualwrite-mint

Conversation

@Scottcjn

Copy link
Copy Markdown
Owner

This is the last blocker for enabling UTXO dual-write. Found by rehearsing a settlement on a snapshot of the live database.

The gap

finalize_epoch() mints UTXO reward boxes under UTXO_DUAL_WRITE. Production doesn't settle through it. Its cron calls POST /rewards/settle → settle_epoch (= settle_epoch_rip200), which had no UTXO code at all.

Rehearsed on the live DB snapshot with dual-write on:

Path Accounts UTXO minted
finalize_epoch (fixed in #8481/#8394) +1,499,989 µRTC +149,998,900 nRTC ✅ exact
settle_epoch_rip200 (what prod runs) +1,500,000 µRTC 0 ❌

The UTXO model would fall a full epoch pot (1.5 RTC) behind every epoch. It's the safe direction (nothing double-spends), but /utxo/integrity would report the models disagreeing, and the gap would grow daily.

Fix

A bug the tests caught in my own change

settle_epoch_rip200 opens a plain sqlite3.connect, while apply_transaction reads rows by name (row['col']) → TypeError in production. apply_transaction now sets and restores row_factory on a caller connection, which protects every caller.

Verification

  • Rehearsal after the fix (real data, ADM path): 8 boxes minted = exactly the 150,000,000 nRTC credited, all mirrored, 0 mirror>balance, 0 unmirrored boxes.
  • 3 new unit tests (exact mirror, sub-dust skipped, no-op when dual-write is off).
  • 0 regressions (4216 → 4219). fetchall guard 11/11.

Dual-write remains off. This makes enabling it correct when you choose to.

🤖 Generated with Claude Code

finalize_epoch() mints UTXO reward boxes under UTXO_DUAL_WRITE, but
production does not settle through it: cron -> POST /rewards/settle ->
settle_epoch (= settle_epoch_rip200), which had no UTXO code at all.
Rehearsed on a snapshot of the live DB with dual-write on: accounts were
credited 1,500,000 uRTC and ZERO boxes were minted, i.e. the UTXO model
falls a whole epoch pot (1.5 RTC) behind every epoch. Safe direction
(mirror <= balance still holds) but /utxo/integrity would report the
models disagreeing, growing daily.

Mint from epoch_rewards, which BOTH settlement branches write, and hook
both: the standard path and the anti-double-mining path, which returns
early and is the branch production actually takes (rehearsal: ADM).
Values come from the credited uRTC x100, never re-truncated (#8481), and
each box is registered as an account mirror, joined on the mining_reward
tx so a user's /utxo/transfer box at the same height is never tagged
(#8394). Failure raises -> the caller rolls back -> the epoch stays
unsettled, rather than committing a half-mirrored settlement.

utxo_db.apply_transaction: set (and restore) row_factory on a caller
connection. settle_epoch_rip200 opens a plain sqlite3.connect, and the
reads inside apply_transaction use row['col'] -> TypeError. Found by the
new tests, not in review.

Rehearsal after the fix: ADM path minted 8 boxes = exactly the 150,000,000
nRTC credited, all mirrored, 0 mirror>balance, 0 unmirrored.
0 regressions (4216 -> 4219); fetchall guard 11/11.

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 19, 2026
@Scottcjn
Scottcjn merged commit 9fb3fd7 into main Sep 19, 2026
13 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

RTC Reward

This merged PR earned 5 RTC — sent to Scottcjn.

RustChain Bounty Program

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ BCOS v2 Scan Results

Metric Value
Trust Score 36/100
Certificate ID BCOS-2545068b
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

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