fix: budget for up to 3 inputs in on-chain required amount estimate#929
Open
dangershony wants to merge 1 commit into
Open
fix: budget for up to 3 inputs in on-chain required amount estimate#929dangershony wants to merge 1 commit into
dangershony wants to merge 1 commit into
Conversation
The signing path for on-chain invoice payments (AddInputsFromAddressAndSignTransaction) spends ALL UTXOs on the funding address and charges ~68 vB per input. The estimate added in #923 assumed exactly one input, so when a user's payment arrived as multiple UTXOs (two separate sends, exchange withdrawal splits, RBF leftovers) the fee budget fell short and signing failed with 'Insufficient funds' even though the displayed amount was paid in full. Budget for up to 3 inputs (+136 vB). Lightning claims always produce a single UTXO, so this only affects the manual on-chain path. Any surplus is returned to the user's wallet as change, so overestimating costs the user nothing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Follow-up to #923. The on-chain required amount estimate (\EstimateOnChainRequired) assumes the payment arrives as exactly one UTXO (a single ~68 vB P2WPKH input is baked into the 252 vB constant).
But the signing path for on-chain invoice payments (\AddInputsFromAddressAndSignTransaction\ in \WalletOperations.cs) spends all UTXOs on the funding address and charges ~68 vB per input:
\\csharp
var estimatedSize = transaction.GetVirtualSize() + (availableUtxos.Count * 68);
\\
\MonitorAddressForFunds\ aggregates UTXOs at the address, so if the user pays in two separate sends, or their exchange/wallet splits the withdrawal, monitoring declares the amount met — and then signing fails with 'Insufficient funds' because each extra input costs ~68 vB × feerate that was never budgeted.
Lightning claims (Boltz) always produce a single UTXO, so this only affects the manual on-chain path — explaining why the flow works sometimes and fails other times.
Fix
Budget the miner-fee estimate for up to 3 inputs (+136 vB, i.e. ~2,720 sats at 20 sat/vB). Any surplus is returned to the user's own wallet as change, so overestimating costs the user nothing.
A follow-up PR will add a dynamic recheck against the actual UTXO count at the funding address before building the draft (targeted at the next release).