Skip to content

fix: budget for up to 3 inputs in on-chain required amount estimate#929

Open
dangershony wants to merge 1 commit into
mainfrom
fix/onchain-required-multi-utxo-padding
Open

fix: budget for up to 3 inputs in on-chain required amount estimate#929
dangershony wants to merge 1 commit into
mainfrom
fix/onchain-required-multi-utxo-padding

Conversation

@dangershony

Copy link
Copy Markdown
Member

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).

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.
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