fix: add fee retry loop to redemption flow (Bug #9)#389
fix: add fee retry loop to redemption flow (Bug #9)#389JohnnyLawDGB wants to merge 1 commit intoDigiByte-Core:feature/digidollar-v1from
Conversation
Redemption transactions fail with "Insufficient fee inputs for calculated fee" because the initial 0.1 DGB fee estimate is too low for redemptions with multiple inputs (collateral + DD UTXOs + fee UTXOs). The txbuilder calculates the actual fee after constructing the transaction, but if the pre-selected fee UTXOs don't cover it, the build fails with no recovery. Add a retry loop (max 3 attempts) to both redemption code paths: - src/rpc/digidollar.cpp (wallet RPC handler, position_id-based) - src/wallet/digidollarwallet.cpp (direct wallet call, timelock-based) On "Insufficient fee inputs" failure, re-select fee UTXOs using result.totalFees + 20% margin, then retry. Non-fee errors return immediately without retry. Also fix the timelock-based RedeemDigiDollar to populate params.feeAmounts (was passing nullptr to SelectFeeCoins), matching the transfer flow pattern. Tested on testnet19 — 3 consecutive redemptions all succeed on attempt 2 after automatic fee retry: Redemption 1: 10,000 cents, 240,731 tDGB unlocked (fee: 0.280 tDGB) Redemption 2: 10,000 cents, 240,731 tDGB unlocked (fee: 0.215 tDGB) Redemption 3: 10,001 cents, 240,755 tDGB unlocked (fee: 0.248 tDGB) Debug log proof (attempt 1 fails, retry succeeds): BuildRedemptionTransaction attempt 1: success=0, error='Insufficient fee inputs' Fee shortfall on attempt 1, retrying with 25872000 sats (actual 21560000 + 20%) BuildRedemptionTransaction attempt 2: success=1 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for digging into this and for the solid testing on testnet19 — the debug log proof is great work. We've been working on the same Bug #9 issue on our end, and we've actually addressed the root cause directly rather than adding a retry loop. Here's what happened: The core problem was that the fee estimation was hardcoded at Our fix replaces the hardcoded value with a proper calculation everywhere: This means the first attempt should already have enough fee selected, so the retry loop shouldn't be needed. The retry approach works as a bandaid, but it still starts with the wrong estimate and always fails on attempt 1 before recovering — your own logs show this ("attempt 1 returned success=0" on all 3 redemptions). However — you caught a real bug that we missed. The We've incorporated that fix into our RC24 branch with credit to you in the commit message ( Going to close this PR since the underlying fee estimation has been properly fixed, but thank you for the contribution — the nullptr fix is real and is now part of RC24. |
SelectFeeCoins was called with nullptr for the amounts output in the wallet's direct RedeemDigiDollar() method, leaving params.feeAmounts empty. BuildRedemptionTransaction needs per-UTXO amounts to correctly construct fee inputs. The RPC path already did this correctly. Credit: JohnnyLawDGB (identified in PR #389)
Summary
result.totalFees + 20%margin, then retries the buildRedeemDigiDollarto populateparams.feeAmounts(was passingnullptrtoSelectFeeCoins)Root Cause
Redemption transactions with multiple inputs (1 collateral + 2+ DD UTXOs + fee UTXOs) require more than the 0.1 DGB fee estimate. The txbuilder calculates the actual fee after constructing the transaction, but if pre-selected fee UTXOs don't cover it, the build fails with no recovery path.
Files Changed
src/rpc/digidollar.cppsrc/wallet/digidollarwallet.cppfeeAmountspopulation + add retry loop to direct wallet callTestnet Verification (testnet19, block ~98,400)
Three consecutive redemptions all succeed after automatic fee retry:
1b1a69dd...6c97a7c3...f66e9e76...e00a5145...75b3b386...a69f5a59...Debug Log Proof
Test plan
digidollar_wallet_tests(131 cases),digidollar_redeem_tests(23 cases)🤖 Generated with Claude Code