fix: cap spending max at quoted lsp fee balance - #1179
Draft
jvsena42 wants to merge 2 commits into
Draft
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Fixes #899
This PR fixes the maximum Savings → Spending transfer failing with an insufficient funds error.
Description
Sizing a max transfer takes two LSP fee quotes. The first prices the whole available balance and yields the balance left after fees; the second re-prices at that lower balance and comes back cheaper, because the Blocktank service fee grows with the client balance. The spending max was then derived from the available balance minus that second, cheaper quote — producing a client balance higher than the one the quote actually priced.
The order built at that max therefore costs more than the user has. In the reported case the gap was a single satoshi: the order came to 265,727 against a spendable balance of 265,726. Confirming it fell past the drain shortcut and attempted an ordinary send it could not fund, surfacing the raw Lightning error.
The max is now capped at the balance the fee was quoted for, which is always affordable because the second quote never exceeds the first. The same sizing path backs the hardware wallet transfer limits, so both are covered.
Preview
QA Notes
Reproducing needs the whole on-chain balance transferred at once — the gap only appears at exactly Max.
Manual Tests
regression:Transfer → Spending → tap ¼ → Continue → swipe to confirm: still funds normally.regression:on-chain balance above the LSP max channel size → Transfer → Spending: Max still caps at the LSP limit rather than collapsing to zero.Automated Checks
TransferViewModelTest.kt: reproduces the reported quote pair and asserts the max stays within what the order will cost. Confirmed it fails against master without the fix.just compile,just test, andjust lintall pass, with only pre-existing detekt findings in untouched files.