c-lightning: MaxFeePercent is ignored for invoices that carry an amount - #186
Open
atharrva01 wants to merge 1 commit into
Open
c-lightning: MaxFeePercent is ignored for invoices that carry an amount#186atharrva01 wants to merge 1 commit into
atharrva01 wants to merge 1 commit into
Conversation
Before the move to xpay, MaxFeePercent was passed to the 'pay' command as its native 'maxfeepercent' argument for every invoice, with 'exemptfee' left at its 5000msat default. A payment was accepted when its fee fell below either the percentage or 5000msat. xpay takes only an absolute 'maxfee', so the percentage is now converted to one. That conversion was guarded on 'explicitAmount is not null', which only holds for invoices that carry no amount, so for a normal invoice 'maxfee' was left null and xpay applied its own default instead of the configured ceiling. Derive the percentage from the amount actually being paid, and floor it at exemptfee's default so small payments keep the allowance 'pay' gave them.
Author
|
hi @NicolasDorier , would love ur thoughts on this |
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.
Follow up to #183, and to the chat discussion about keeping the same behaviour we had with the old
payAPI.What the old behaviour was
Before the move to xpay,
MaxFeePercentwas passed straight topayas its nativemaxfeepercentargument, for every invoice:exemptfeewas left null, so c-lightning's 5000msat default applied. Per thepaydocs,exemptfee"allows themaxfeepercentcheck to be skipped on fees that are smaller thanexemptfee". So the effective ceiling was max(5000msat, percentage).What changed
xpay takes only an absolute
maxfee, so the percentage now has to be converted into one. That conversion is guarded onexplicitAmount is not null:explicitAmountis only set when the invoice carries no amount, since xpay acceptsamount_msatonly in that case. So for a normal amount-carrying invoice the branch never runs,maxfeegoes out as null, and xpay applies its own default of "5000msat, or 1% (whatever is greater)" instead of the configured ceiling.#183 corrected the unit of that computation but kept the guard, and noted the gap at the time.
Fix
Derive the percentage from the amount actually being paid (the explicit amount when we supply one, ie. keysend or a bolt11 without an amount, otherwise the amount on the invoice) and floor it at
exemptfee's default so small payments keep the allowancepaygave them:Without the floor a 100 sat payment at 0.5% would drop from a 5000msat allowance to 500msat, which is tighter than
payever was.Tests
Three cases in the harness #183 added, all backend-free (an in-process TCP server stands in for lightningd and captures the outgoing request):
PayMaxFeePercentIsSentInMilliSatoshi: existing, unchanged.PayMaxFeePercentIsAppliedToInvoiceAmount: amount-carrying invoice, 1% of 250,000 sat, assertsmaxfeeis 2,500,000 msat. Fails before this change (maxfeeis null).PayMaxFeePercentKeepsExemptFeeFloorOnSmallPayments: 100 sat at 0.5%, asserts the 5000msat floor wins over the 500msat percentage.Also verified end to end against a live node. Setup is
cln -> lnd -> cln_deston regtest with CLN v26.06.1, the middle hop charging 20,000msat base so the route costs 20,250msat. Paying a 250,000 sat invoice withMaxFeePercentlow enough that the ceiling falls back to the 5000msat floor:maxfeesentOk, fee paid 20,250 msatError, "Could not find route without excessive cost"Worth noting for anyone reproducing this that it needs three nodes. With two the channel is direct, there is no routing fee, and
maxfeenever binds. The percentage used above is deliberately small so the ceiling lands under a cheap regtest route; on mainnet the same gap shows up whenever the configured percentage is below the 1% xpay assumes, e.g. a caller asking for 0.5% currently gets 1%.Notes
Reachable from the Greenfield pay-invoice endpoint, which is the only place
MaxFeePercentis set in btcpayserver.MaxFeeFlatis unaffected; it was already applied unconditionally.