Repository navigation
feat(wallet): size the Max-send fee reserve from real UTXO count - #861
Conversation
Max / all-funds core sends reserved a flat 100,000-duff fee headroom (WalletBalance.maxSendable). The real fee is ~1-2k duffs, so Max left the difference (~0.001 DASH) behind as change and never emptied the wallet. Add SwiftDashSDKTransactionSender.maxSendFeeReserveDuffs(), which sizes the reserve from the BIP44 account's actual spendable-UTXO count using the same 1 duff/byte model as estimatedSignalFee, plus a 50% safety margin so it can never under-reserve (which would make the Max send fail to build). It falls back to the flat reserve when the account can't be enumerated, so behaviour is never worse than before. Expose SwiftDashSDKWalletState.feeAwareMaxSendable() and route every core-send Max/all-funds call site through it (CrowdNode keeps its own deposit-cap fee logic). Verified on device (testnet): Max now fills the full spendable balance and the confirm builds successfully.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
llbartekll
left a comment
There was a problem hiding this comment.
The account lookup needs to include the BIP44 standard tag. is the whole Standard family and can contain both BIP44 () and BIP32 () account 0. Picking the first match without checking can therefore count UTXOs from the wrong account and compute an incorrect Max reserve. Please mirror here and require (and preferably use instead of the literal 0).
llbartekll
left a comment
There was a problem hiding this comment.
Clarification with the exact symbols: typeTag == 0 covers the whole Standard family. Account 0 may exist as both BIP44 (standardTag == 0) and BIP32 (standardTag == 1). Please make the lookup require $0.standardTag == Self.bip44StandardTag and use Self.bip44AccountIndex instead of the literal 0, matching addressUtxos(script:).
typeTag == 0 is the whole Standard family; account 0 can exist as both BIP44 (standardTag 0) and BIP32 (standardTag 1). Matching on typeTag+index alone could pick the BIP32 account and size the reserve from the wrong UTXO set. Require standardTag == bip44StandardTag and use bip44AccountIndex, mirroring addressUtxos(script:).
Issue being fixed or feature implemented
"Max" / all-funds core sends did not empty the wallet — they left ~0.001 DASH behind as change.
Root cause: the Max amount is
WalletBalance.maxSendable = spendable − sendFeeReserveDuffs, andsendFeeReserveDuffsis a flat 100,000-duff reserve. The actual fee is size-based (~1–2k duffs at 1 duff/byte), so the send returnedreserve − actual_fee(~98k duffs) as change. Confirmed on-chain earlier: an 11-input Max send charged 1,740 duffs but left a 98,260-duff change output (= 100,000 − 1,740, exact).Funds were never lost (change went to the wallet's own address), but Max was misleading — the resulting balance was not zero.
What was done?
SwiftDashSDKTransactionSender.maxSendFeeReserveDuffs()— sizes the reserve from the BIP44 account's real spendable-UTXO count using the same 1 duff/byte model asestimatedSignalFee, plus a +50% safety margin so it can never under-reserve (an under-estimate would make the Max send fail to build).sendFeeReserveDuffs, i.e. the previous behaviour — never worse, only tighter when it can be.SwiftDashSDKWalletState.feeAwareMaxSendable()and routed every core-send Max/all-funds call site through it (Send, InternalTransfer, SwapConvert, OrderPreview, ContactProfile, BuyCredits, DashSpendPay).TX_FEE_PER_INPUT) — out of scope.How Has This Been Tested?
Verified on device (testnet, dashpay scheme): a Max send now fills the full spendable balance (reserve dropped from the flat 100,000 to a few hundred duffs) and the confirm builds successfully — the +50% margin covered the real fee without under-reserving. Recommend a follow-up check that the post-send transparent balance settles to ~0. Note:
maxSendFeeReserveDuffs()performs a UTXO enumeration on each read; it's a synchronous DB read but worth an eye on the per-keystroke affordability checks.Breaking Changes
None.
Checklist:
For repository code-owners and collaborators only