Skip to content

feat: recheck on-chain required amount against actual UTXO count#930

Draft
dangershony wants to merge 1 commit into
mainfrom
feat/onchain-dynamic-utxo-recheck
Draft

feat: recheck on-chain required amount against actual UTXO count#930
dangershony wants to merge 1 commit into
mainfrom
feat/onchain-dynamic-utxo-recheck

Conversation

@dangershony

Copy link
Copy Markdown
Member

Problem

Follow-up to #923 and companion to #929 (this one targeted at the next release).

The estimate shown to the user assumes a fixed number of inputs, but the signing path (AddInputsFromAddressAndSignTransaction) spends all UTXOs on the funding address and pays ~68 vB per input. If the payment arrives as multiple UTXOs (two separate sends, exchange withdrawal splits, RBF leftovers), the paid amount can no longer cover the miner fee — MonitorAddressForFunds declares the payment received, then BuildInvestmentDraft fails with "Insufficient funds".

#929 mitigates this with a static 3-input buffer; this PR makes the flow correct for any UTXO count.

Fix

  • PaymentFlowConfig.OnChainRequiredForUtxoCount — optional delegate that recomputes the required total for the actual number of detected UTXOs.
  • EstimateOnChainRequired overload accepting an inputCount (existing signature delegates with count 1, so fix: budget for up to 3 inputs in on-chain required amount estimate #929's padding merges cleanly on top).
  • PaymentFlowViewModel.PayToOnChainAddressAsync — after funds arrive, recheck against the actual UTXO count; if short, show the exact shortfall ("Payment arrived in N parts — please send X sats more") and keep monitoring for the top-up instead of proceeding to a signing failure.
  • InvestPageViewModel wires the delegate (invest flow only; deploy is unaffected as it doesn't restrict signing to the funding address).

Lightning/Boltz claims always deliver a single UTXO, so the recheck loop is a no-op on that path.

Known caveat

The top-up monitor reuses MonitorAddressForFunds, which (via the mempool polling service) tracks unconfirmed UTXOs. If the first payment confirms before the top-up arrives, the aggregate check may need revisiting — worth verifying with a signet UAT run before merging. Marked as draft for the next release accordingly.

…r funds arrive

The signing transaction for on-chain invoice payments spends ALL UTXOs on the
funding address and pays ~68 vB per input. If the user's payment arrives as
multiple UTXOs (two separate sends, exchange withdrawal splits, RBF leftovers),
the originally displayed amount no longer covers the miner fee, and
BuildInvestmentDraft fails with 'Insufficient funds' after the payment was
declared received.

Add PaymentFlowConfig.OnChainRequiredForUtxoCount: after MonitorAddressForFunds
succeeds, recompute the required amount for the actual detected UTXO count. If
the received total is short, tell the user the exact shortfall and keep
monitoring for the top-up instead of proceeding to a signing failure.

Also add an EstimateOnChainRequired overload that accepts an input count.
@dangershony

Copy link
Copy Markdown
Member Author

I am not convinced this commit should go in

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