Skip to content

fix: auto-consolidate fragmented UTXOs when minting DigiDollar#391

Merged
DigiSwarm merged 1 commit intoDigiByte-Core:feature/digidollar-v1from
JohnnyLawDGB:fix/utxo-consolidation-mint
Mar 11, 2026
Merged

fix: auto-consolidate fragmented UTXOs when minting DigiDollar#391
DigiSwarm merged 1 commit intoDigiByte-Core:feature/digidollar-v1from
JohnnyLawDGB:fix/utxo-consolidation-mint

Conversation

@JohnnyLawDGB
Copy link

Summary

  • When mintdigidollar fails due to UTXO fragmentation (>400 small UTXOs), the RPC now automatically creates a consolidation transaction and retries the mint
  • Fixes the "Too many small UTXOs" error that miners/pool operators encounter when their wallets are full of small mining reward UTXOs
  • Response includes consolidation_txid and utxos_consolidated fields when auto-consolidation occurred

Root Cause

SelectCoins in txbuilder.cpp has a MAX_TX_INPUTS = 400 limit to keep transactions under MAX_STANDARD_TX_WEIGHT. When a wallet has many small UTXOs (e.g., 500 x 600 DGB from mining), the top 400 UTXOs may not cover the collateral requirement (e.g., 400 × 600 = 240,000 < 246,000 needed for tier 0).

Fix

In the mintdigidollar RPC handler (src/rpc/digidollar.cpp):

  1. First attempt: normal BuildMintTransaction
  2. If it fails with "Too many small UTXOs":
    • Create a consolidation tx using the wallet's standard CreateTransaction (which has its own weight-aware coin selection)
    • Broadcast the consolidation tx
    • Re-gather available UTXOs (now includes the unconfirmed consolidated output)
    • Retry BuildMintTransaction with the new UTXO set
  3. Both transactions chain in the mempool (parent-child)

Test plan

  • Reproduced bug: created wallet with 500 × 600 DGB UTXOs, mintdigidollar 10000 0 failed with "Too many small UTXOs"
  • Applied fix, same wallet successfully mints with auto-consolidation
  • Response includes consolidation_txid and utxos_consolidated: true
  • DD position created correctly (10,000 cents, tier 0, health_ratio 999)
  • Wallet UTXO count reduced from 500 → 49 after consolidation + mint
  • Normal minting (no fragmentation) unaffected — consolidation path not triggered
  • Edge case: wallet with insufficient total DGB returns clear error
  • Edge case: wallet with extreme fragmentation (>1700 UTXOs where even consolidation hits weight limits)

🤖 Generated with Claude Code

When a wallet has too many small UTXOs (>400) to cover collateral in a
single transaction, mintdigidollar now automatically creates a
consolidation transaction using the wallet's standard coin selection,
then retries the mint using the consolidated output.

This fixes the "Too many small UTXOs" error that miners and pool
operators encounter when their wallet contains hundreds of small
mining reward UTXOs that individually don't cover the collateral
requirement within the 400-input transaction limit.

The consolidation is transparent — the response includes
consolidation_txid and utxos_consolidated fields when auto-
consolidation was performed. Both the consolidation and mint
transactions are broadcast together and chain in the mempool.

Tested with 500 x 600 DGB UTXOs (300,000 DGB total) where tier 0
minting requires ~246,000 DGB collateral. Without this fix, the mint
fails because 400 x 600 = 240,000 < 246,000. With this fix, the
wallet auto-consolidates and the mint succeeds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DigiSwarm
Copy link

Nice work Johnny. Verified this is a real issue — SelectCoins hits MAX_TX_INPUTS = 400 at line 78 of txbuilder.cpp, returns false, and miners with 500+ small UTXOs physically cannot fit enough inputs to meet collateral. The auto-consolidation approach using the wallet's standard CreateTransaction is clean.

Code review notes:

  • Consolidation target math is correct (collateral + 10% + 0.1 DGB fee buffer)
  • GetNewChangeDestination(BECH32) avoids address reuse ✅
  • The unconfirmed consolidation output chains correctly in mempool (parent-child) — low risk on DGB's 15-sec blocks
  • Error messages are clear with manual fallback instructions
  • Optional response fields (consolidation_txid, utxos_consolidated) are clean UX

Two unchecked edge cases from the test plan:

  1. Insufficient total DGB — handled by the consolidationTarget > totalAvailable check, throws clear error ✅
  2. Extreme fragmentation (>1700 UTXOs) — CreateTransaction itself would reject oversized consolidation tx. Error message might be confusing but it's a rare edge case.

One minor note: If the consolidation tx gets evicted from mempool before confirmation, the chained mint tx becomes orphaned. Practically zero risk on DigiByte but worth documenting.

Approved. Merging into feature/digidollar-v1. 🚀

@DigiSwarm DigiSwarm merged commit eb07fb7 into DigiByte-Core:feature/digidollar-v1 Mar 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants