Skip to content

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

Open
JohnnyLawDGB wants to merge 1 commit intoDigiByte-Core:feature/digidollar-v1from
JohnnyLawDGB:fix/utxo-consolidation-mint
Open

fix: auto-consolidate fragmented UTXOs when minting DigiDollar#391
JohnnyLawDGB wants to merge 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>
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.

1 participant