Add config option to set maximum total routing fee - #2417

Merged
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee
Sep 26, 2023
Merged

Add config option to set maximum total routing fee#2417
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee

Conversation

@tnull

@tnulltnull commented Jul 14, 2023

Copy link
Copy Markdown
Contributor

Fixes#2339.
Closes#2596.
Based on #2555.

Currently, users have no means to upper-bound the total fees accruing when finding a route. Here, we add a corresponding field to PaymentParameters which is used to limit the candidate set during path finding.

To this end, we exclude any candidate hops if we find that using them would let the aggregated path routing fees exceed max_total_routeing_fee_msat. Moreover, we return an error if the aggregated fees over all paths of the selected route would surpass max_total_routeing_fee_msat.

@tnull
tnull marked this pull request as draft July 14, 2023 15:08
@tnull

tnull commented Jul 14, 2023

Copy link
Copy Markdown
ContributorAuthor

Drafting for now as I'm not super happy that we only filter on a per-path basis and then fail entirely if the aggregate route surpasses the routing fee limit. So far experimented with the approach we took for the minimal_value_contribution, i.e., having static per-path quotas, but discarded this as it would for example limit the per-path total fee to max_total_routing_fee_msat/max_path_count, i.e., to only 10% of the given value by default.

I think it's not super bad currently as we already pre-sort and filter routes by their cost/value ratio, which however also includes the penalty. Considering whether it would make sense to, whenever max_total_routing_fee_msat is set, add yet another pre-filtering step that only takes total fees into account to decrease the chances of unnecessarily returning an empty route.

This also currently doesn't account for retries. We might need to track the 'used' fees in a structure similar to InFlightHtlcs.

@codecov-commenter

codecov-commenter commented Jul 14, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (7e7e7a0) 88.83% compared to head (77afeac) 89.68%.
Report is 35 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2417 +/- ##
==========================================
+ Coverage 88.83% 89.68% +0.85% 
==========================================
Files 113 113 Lines 84489 89980 +5491 Branches 84489 89980 +5491 ==========================================
+ Hits 75052 80696 +5644 + Misses 7205 7055 -150 + Partials 2232 2229 -3 
FilesCoverage Δ
lightning/src/ln/blinded_payment_tests.rs100.00% <100.00%> (ø)
lightning/src/ln/functional_test_utils.rs93.62% <ø> (+2.45%)⬆️
lightning/src/ln/channelmanager.rs87.68% <50.00%> (+6.55%)⬆️
lightning-invoice/src/payment.rs77.30% <33.33%> (-0.26%)⬇️
lightning/src/ln/payment_tests.rs98.06% <98.60%> (+0.01%)⬆️
lightning/src/ln/outbound_payment.rs90.03% <92.94%> (+1.23%)⬆️
lightning/src/routing/router.rs93.73% <93.22%> (+0.10%)⬆️

... and 17 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, I think. I agree we should clean it up later to more aggressively find paths even though our first choice was fee-limited out, but this is certainly better than not having fee limiting.

Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as a first step, given where we're at with the release!

Comment threadlightning/src/routing/router.rs Outdated

@alecchendevalecchendev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from ed0ade8 to da559d3CompareJuly 18, 2023 12:28
@tnull
tnull marked this pull request as ready for review July 18, 2023 12:42
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from c34a4a9 to be27e7fCompareJuly 18, 2023 14:07
Comment threadlightning/src/ln/outbound_payment.rs
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/ln/outbound_payment.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from eaa9435 to 63ed69bCompareJuly 18, 2023 14:36
Comment threadlightning/src/ln/outbound_payment.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 63ed69b to 804abe6CompareJuly 18, 2023 17:20
@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM after squash

@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 804abe6 to 97f07fbCompareJuly 18, 2023 20:41
@tnull

Copy link
Copy Markdown
ContributorAuthor

LGTM after squash

Squashed fixups without further changes.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 97f07fb to 90ef352CompareJuly 20, 2023 13:46
@tnull

Copy link
Copy Markdown
ContributorAuthor

Rebased on main to get rid of the CI failure.

@tnulltnull removed this from the 0.0.116 milestone Jul 21, 2023

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should land this to get the API in place for a second alpha, but we should get some of these comments fixed (at least the total-fee final check one) for 0.0.117.

// subtracting the used fee from the total fee budget.
route_params.max_total_routing_fee_msat = route_params
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
route_params.final_value_msat = pending_amt_unsent;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression, but this is wrong - this includes any overpayment amount, ensuring we overpay again when we go to retry, rather than just recalculating the amount sent against the intended amount. Lets definitely fix this ASAP.

@tnulltnullSep 27, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nevermind my previous reply): Tacked a corresponding commit onto #2575.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking about this once more, I think my previous comment was kinda correct: if we find a route and need to overpay for some of the paths, we may reduce the value of the others to meet the final value, i.e., the route's split is essentially determined at this time. If now some of the overpaid paths fail and we start to only retry the net. value (excluding overpaid amounts), the sum of all paths might not meet the expected final value. I suspect this is no issue if we have infinite auto-retries as we'd retry until the expected value is met, but if we're limited we probably will run out of retry attempts sooner than expected/necessary. Not sure how we'd want to resolve this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Right, then we seem to be on the same page that per-path accounting doesn't make sense, but only to account for the overpayment for the whole route.

I think what you propose unfortunately doesn't work as is though as for the immediate/legacy retry case we'd recursively reduce final_value_msat while we don't do this in the newer auto-retry case where we'd leave final_value_msat static, but account for for the pending amounts differently. In d7ab0ef I solved this by taking the min, but this seems to be pretty hacky.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/ln/payment_tests.rs
}

#[test]
fn mpp_retry_overpay() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is nice but isn't what I was mostly interested about. I'm really curious to test overpaying the final recipient and ensuring the route_params' final_value_msat is correct, not just the remaining fees.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, had understood above request slightly differently. IIUC, this might now more or less be covered by the new test introduced in #2604?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test tests the router end of it, but I'm really worried about the outbound_payment part overpaying.

@TheBlueMatt
TheBlueMatt merged commit 1ac53ed into lightningdevkit:mainSep 26, 2023
@TheBlueMattTheBlueMatt mentioned this pull request Sep 26, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt added a commit that referenced this pull request Sep 28, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
benthecarman added a commit to benthecarman/rust-lightning that referenced this pull request Nov 8, 2023
In lightningdevkit#2417 support for setting a max fee was added but it is not exposed
when using the `pay_invoice` utility functions. This makes it so the
user can pass in that parameter. One downside is that this removes the
defualt value form before.
Sign up for freeto 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.

Add another test for max_total_routing_fee_msat Allow to set maximum total fees during routing

6 participants

@tnull@codecov-commenter@valentinewallace@TheBlueMatt@jkczyz@alecchendev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Add config option to set maximum total routing fee - #2417

Merged
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee
Sep 26, 2023
Merged

Add config option to set maximum total routing fee#2417
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee

Conversation

@tnull

@tnulltnull commented Jul 14, 2023

Copy link
Copy Markdown
Contributor

Fixes#2339.
Closes#2596.
Based on #2555.

Currently, users have no means to upper-bound the total fees accruing when finding a route. Here, we add a corresponding field to PaymentParameters which is used to limit the candidate set during path finding.

To this end, we exclude any candidate hops if we find that using them would let the aggregated path routing fees exceed max_total_routeing_fee_msat. Moreover, we return an error if the aggregated fees over all paths of the selected route would surpass max_total_routeing_fee_msat.

@tnull
tnull marked this pull request as draft July 14, 2023 15:08
@tnull

tnull commented Jul 14, 2023

Copy link
Copy Markdown
ContributorAuthor

Drafting for now as I'm not super happy that we only filter on a per-path basis and then fail entirely if the aggregate route surpasses the routing fee limit. So far experimented with the approach we took for the minimal_value_contribution, i.e., having static per-path quotas, but discarded this as it would for example limit the per-path total fee to max_total_routing_fee_msat/max_path_count, i.e., to only 10% of the given value by default.

I think it's not super bad currently as we already pre-sort and filter routes by their cost/value ratio, which however also includes the penalty. Considering whether it would make sense to, whenever max_total_routing_fee_msat is set, add yet another pre-filtering step that only takes total fees into account to decrease the chances of unnecessarily returning an empty route.

This also currently doesn't account for retries. We might need to track the 'used' fees in a structure similar to InFlightHtlcs.

@codecov-commenter

codecov-commenter commented Jul 14, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (7e7e7a0) 88.83% compared to head (77afeac) 89.68%.
Report is 35 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2417 +/- ##
==========================================
+ Coverage 88.83% 89.68% +0.85% 
==========================================
Files 113 113 Lines 84489 89980 +5491 Branches 84489 89980 +5491 ==========================================
+ Hits 75052 80696 +5644 + Misses 7205 7055 -150 + Partials 2232 2229 -3 
FilesCoverage Δ
lightning/src/ln/blinded_payment_tests.rs100.00% <100.00%> (ø)
lightning/src/ln/functional_test_utils.rs93.62% <ø> (+2.45%)⬆️
lightning/src/ln/channelmanager.rs87.68% <50.00%> (+6.55%)⬆️
lightning-invoice/src/payment.rs77.30% <33.33%> (-0.26%)⬇️
lightning/src/ln/payment_tests.rs98.06% <98.60%> (+0.01%)⬆️
lightning/src/ln/outbound_payment.rs90.03% <92.94%> (+1.23%)⬆️
lightning/src/routing/router.rs93.73% <93.22%> (+0.10%)⬆️

... and 17 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, I think. I agree we should clean it up later to more aggressively find paths even though our first choice was fee-limited out, but this is certainly better than not having fee limiting.

Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as a first step, given where we're at with the release!

Comment threadlightning/src/routing/router.rs Outdated

@alecchendevalecchendev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from ed0ade8 to da559d3CompareJuly 18, 2023 12:28
@tnull
tnull marked this pull request as ready for review July 18, 2023 12:42
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from c34a4a9 to be27e7fCompareJuly 18, 2023 14:07
Comment threadlightning/src/ln/outbound_payment.rs
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/ln/outbound_payment.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from eaa9435 to 63ed69bCompareJuly 18, 2023 14:36
Comment threadlightning/src/ln/outbound_payment.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 63ed69b to 804abe6CompareJuly 18, 2023 17:20
@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM after squash

@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 804abe6 to 97f07fbCompareJuly 18, 2023 20:41
@tnull

Copy link
Copy Markdown
ContributorAuthor

LGTM after squash

Squashed fixups without further changes.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 97f07fb to 90ef352CompareJuly 20, 2023 13:46
@tnull

Copy link
Copy Markdown
ContributorAuthor

Rebased on main to get rid of the CI failure.

@tnulltnull removed this from the 0.0.116 milestone Jul 21, 2023

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should land this to get the API in place for a second alpha, but we should get some of these comments fixed (at least the total-fee final check one) for 0.0.117.

// subtracting the used fee from the total fee budget.
route_params.max_total_routing_fee_msat = route_params
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
route_params.final_value_msat = pending_amt_unsent;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression, but this is wrong - this includes any overpayment amount, ensuring we overpay again when we go to retry, rather than just recalculating the amount sent against the intended amount. Lets definitely fix this ASAP.

@tnulltnullSep 27, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nevermind my previous reply): Tacked a corresponding commit onto #2575.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking about this once more, I think my previous comment was kinda correct: if we find a route and need to overpay for some of the paths, we may reduce the value of the others to meet the final value, i.e., the route's split is essentially determined at this time. If now some of the overpaid paths fail and we start to only retry the net. value (excluding overpaid amounts), the sum of all paths might not meet the expected final value. I suspect this is no issue if we have infinite auto-retries as we'd retry until the expected value is met, but if we're limited we probably will run out of retry attempts sooner than expected/necessary. Not sure how we'd want to resolve this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Right, then we seem to be on the same page that per-path accounting doesn't make sense, but only to account for the overpayment for the whole route.

I think what you propose unfortunately doesn't work as is though as for the immediate/legacy retry case we'd recursively reduce final_value_msat while we don't do this in the newer auto-retry case where we'd leave final_value_msat static, but account for for the pending amounts differently. In d7ab0ef I solved this by taking the min, but this seems to be pretty hacky.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/ln/payment_tests.rs
}

#[test]
fn mpp_retry_overpay() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is nice but isn't what I was mostly interested about. I'm really curious to test overpaying the final recipient and ensuring the route_params' final_value_msat is correct, not just the remaining fees.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, had understood above request slightly differently. IIUC, this might now more or less be covered by the new test introduced in #2604?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test tests the router end of it, but I'm really worried about the outbound_payment part overpaying.

@TheBlueMatt
TheBlueMatt merged commit 1ac53ed into lightningdevkit:mainSep 26, 2023
@TheBlueMattTheBlueMatt mentioned this pull request Sep 26, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt added a commit that referenced this pull request Sep 28, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
benthecarman added a commit to benthecarman/rust-lightning that referenced this pull request Nov 8, 2023
In lightningdevkit#2417 support for setting a max fee was added but it is not exposed
when using the `pay_invoice` utility functions. This makes it so the
user can pass in that parameter. One downside is that this removes the
defualt value form before.
Sign up for freeto 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.

Add another test for max_total_routing_fee_msat Allow to set maximum total fees during routing

6 participants

@tnull@codecov-commenter@valentinewallace@TheBlueMatt@jkczyz@alecchendev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add config option to set maximum total routing fee - #2417

Merged
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee
Sep 26, 2023
Merged

Add config option to set maximum total routing fee#2417
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee

Conversation

@tnull

@tnulltnull commented Jul 14, 2023

Copy link
Copy Markdown
Contributor

Fixes#2339.
Closes#2596.
Based on #2555.

Currently, users have no means to upper-bound the total fees accruing when finding a route. Here, we add a corresponding field to PaymentParameters which is used to limit the candidate set during path finding.

To this end, we exclude any candidate hops if we find that using them would let the aggregated path routing fees exceed max_total_routeing_fee_msat. Moreover, we return an error if the aggregated fees over all paths of the selected route would surpass max_total_routeing_fee_msat.

@tnull
tnull marked this pull request as draft July 14, 2023 15:08
@tnull

tnull commented Jul 14, 2023

Copy link
Copy Markdown
ContributorAuthor

Drafting for now as I'm not super happy that we only filter on a per-path basis and then fail entirely if the aggregate route surpasses the routing fee limit. So far experimented with the approach we took for the minimal_value_contribution, i.e., having static per-path quotas, but discarded this as it would for example limit the per-path total fee to max_total_routing_fee_msat/max_path_count, i.e., to only 10% of the given value by default.

I think it's not super bad currently as we already pre-sort and filter routes by their cost/value ratio, which however also includes the penalty. Considering whether it would make sense to, whenever max_total_routing_fee_msat is set, add yet another pre-filtering step that only takes total fees into account to decrease the chances of unnecessarily returning an empty route.

This also currently doesn't account for retries. We might need to track the 'used' fees in a structure similar to InFlightHtlcs.

@codecov-commenter

codecov-commenter commented Jul 14, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (7e7e7a0) 88.83% compared to head (77afeac) 89.68%.
Report is 35 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2417 +/- ##
==========================================
+ Coverage 88.83% 89.68% +0.85% 
==========================================
Files 113 113 Lines 84489 89980 +5491 Branches 84489 89980 +5491 ==========================================
+ Hits 75052 80696 +5644 + Misses 7205 7055 -150 + Partials 2232 2229 -3 
FilesCoverage Δ
lightning/src/ln/blinded_payment_tests.rs100.00% <100.00%> (ø)
lightning/src/ln/functional_test_utils.rs93.62% <ø> (+2.45%)⬆️
lightning/src/ln/channelmanager.rs87.68% <50.00%> (+6.55%)⬆️
lightning-invoice/src/payment.rs77.30% <33.33%> (-0.26%)⬇️
lightning/src/ln/payment_tests.rs98.06% <98.60%> (+0.01%)⬆️
lightning/src/ln/outbound_payment.rs90.03% <92.94%> (+1.23%)⬆️
lightning/src/routing/router.rs93.73% <93.22%> (+0.10%)⬆️

... and 17 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, I think. I agree we should clean it up later to more aggressively find paths even though our first choice was fee-limited out, but this is certainly better than not having fee limiting.

Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as a first step, given where we're at with the release!

Comment threadlightning/src/routing/router.rs Outdated

@alecchendevalecchendev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from ed0ade8 to da559d3CompareJuly 18, 2023 12:28
@tnull
tnull marked this pull request as ready for review July 18, 2023 12:42
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from c34a4a9 to be27e7fCompareJuly 18, 2023 14:07
Comment threadlightning/src/ln/outbound_payment.rs
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/ln/outbound_payment.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from eaa9435 to 63ed69bCompareJuly 18, 2023 14:36
Comment threadlightning/src/ln/outbound_payment.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 63ed69b to 804abe6CompareJuly 18, 2023 17:20
@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM after squash

@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 804abe6 to 97f07fbCompareJuly 18, 2023 20:41
@tnull

Copy link
Copy Markdown
ContributorAuthor

LGTM after squash

Squashed fixups without further changes.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 97f07fb to 90ef352CompareJuly 20, 2023 13:46
@tnull

Copy link
Copy Markdown
ContributorAuthor

Rebased on main to get rid of the CI failure.

@tnulltnull removed this from the 0.0.116 milestone Jul 21, 2023

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should land this to get the API in place for a second alpha, but we should get some of these comments fixed (at least the total-fee final check one) for 0.0.117.

// subtracting the used fee from the total fee budget.
route_params.max_total_routing_fee_msat = route_params
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
route_params.final_value_msat = pending_amt_unsent;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression, but this is wrong - this includes any overpayment amount, ensuring we overpay again when we go to retry, rather than just recalculating the amount sent against the intended amount. Lets definitely fix this ASAP.

@tnulltnullSep 27, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nevermind my previous reply): Tacked a corresponding commit onto #2575.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking about this once more, I think my previous comment was kinda correct: if we find a route and need to overpay for some of the paths, we may reduce the value of the others to meet the final value, i.e., the route's split is essentially determined at this time. If now some of the overpaid paths fail and we start to only retry the net. value (excluding overpaid amounts), the sum of all paths might not meet the expected final value. I suspect this is no issue if we have infinite auto-retries as we'd retry until the expected value is met, but if we're limited we probably will run out of retry attempts sooner than expected/necessary. Not sure how we'd want to resolve this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Right, then we seem to be on the same page that per-path accounting doesn't make sense, but only to account for the overpayment for the whole route.

I think what you propose unfortunately doesn't work as is though as for the immediate/legacy retry case we'd recursively reduce final_value_msat while we don't do this in the newer auto-retry case where we'd leave final_value_msat static, but account for for the pending amounts differently. In d7ab0ef I solved this by taking the min, but this seems to be pretty hacky.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/ln/payment_tests.rs
}

#[test]
fn mpp_retry_overpay() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is nice but isn't what I was mostly interested about. I'm really curious to test overpaying the final recipient and ensuring the route_params' final_value_msat is correct, not just the remaining fees.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, had understood above request slightly differently. IIUC, this might now more or less be covered by the new test introduced in #2604?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test tests the router end of it, but I'm really worried about the outbound_payment part overpaying.

@TheBlueMatt
TheBlueMatt merged commit 1ac53ed into lightningdevkit:mainSep 26, 2023
@TheBlueMattTheBlueMatt mentioned this pull request Sep 26, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt added a commit that referenced this pull request Sep 28, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
benthecarman added a commit to benthecarman/rust-lightning that referenced this pull request Nov 8, 2023
In lightningdevkit#2417 support for setting a max fee was added but it is not exposed
when using the `pay_invoice` utility functions. This makes it so the
user can pass in that parameter. One downside is that this removes the
defualt value form before.
Sign up for freeto 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.

Add another test for max_total_routing_fee_msat Allow to set maximum total fees during routing

6 participants

@tnull@codecov-commenter@valentinewallace@TheBlueMatt@jkczyz@alecchendev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add config option to set maximum total routing fee - #2417

Merged
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee
Sep 26, 2023
Merged

Add config option to set maximum total routing fee#2417
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee

Conversation

@tnull

@tnulltnull commented Jul 14, 2023

Copy link
Copy Markdown
Contributor

Fixes#2339.
Closes#2596.
Based on #2555.

Currently, users have no means to upper-bound the total fees accruing when finding a route. Here, we add a corresponding field to PaymentParameters which is used to limit the candidate set during path finding.

To this end, we exclude any candidate hops if we find that using them would let the aggregated path routing fees exceed max_total_routeing_fee_msat. Moreover, we return an error if the aggregated fees over all paths of the selected route would surpass max_total_routeing_fee_msat.

@tnull
tnull marked this pull request as draft July 14, 2023 15:08
@tnull

tnull commented Jul 14, 2023

Copy link
Copy Markdown
ContributorAuthor

Drafting for now as I'm not super happy that we only filter on a per-path basis and then fail entirely if the aggregate route surpasses the routing fee limit. So far experimented with the approach we took for the minimal_value_contribution, i.e., having static per-path quotas, but discarded this as it would for example limit the per-path total fee to max_total_routing_fee_msat/max_path_count, i.e., to only 10% of the given value by default.

I think it's not super bad currently as we already pre-sort and filter routes by their cost/value ratio, which however also includes the penalty. Considering whether it would make sense to, whenever max_total_routing_fee_msat is set, add yet another pre-filtering step that only takes total fees into account to decrease the chances of unnecessarily returning an empty route.

This also currently doesn't account for retries. We might need to track the 'used' fees in a structure similar to InFlightHtlcs.

@codecov-commenter

codecov-commenter commented Jul 14, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (7e7e7a0) 88.83% compared to head (77afeac) 89.68%.
Report is 35 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2417 +/- ##
==========================================
+ Coverage 88.83% 89.68% +0.85% 
==========================================
Files 113 113 Lines 84489 89980 +5491 Branches 84489 89980 +5491 ==========================================
+ Hits 75052 80696 +5644 + Misses 7205 7055 -150 + Partials 2232 2229 -3 
FilesCoverage Δ
lightning/src/ln/blinded_payment_tests.rs100.00% <100.00%> (ø)
lightning/src/ln/functional_test_utils.rs93.62% <ø> (+2.45%)⬆️
lightning/src/ln/channelmanager.rs87.68% <50.00%> (+6.55%)⬆️
lightning-invoice/src/payment.rs77.30% <33.33%> (-0.26%)⬇️
lightning/src/ln/payment_tests.rs98.06% <98.60%> (+0.01%)⬆️
lightning/src/ln/outbound_payment.rs90.03% <92.94%> (+1.23%)⬆️
lightning/src/routing/router.rs93.73% <93.22%> (+0.10%)⬆️

... and 17 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, I think. I agree we should clean it up later to more aggressively find paths even though our first choice was fee-limited out, but this is certainly better than not having fee limiting.

Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as a first step, given where we're at with the release!

Comment threadlightning/src/routing/router.rs Outdated

@alecchendevalecchendev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from ed0ade8 to da559d3CompareJuly 18, 2023 12:28
@tnull
tnull marked this pull request as ready for review July 18, 2023 12:42
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from c34a4a9 to be27e7fCompareJuly 18, 2023 14:07
Comment threadlightning/src/ln/outbound_payment.rs
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/ln/outbound_payment.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from eaa9435 to 63ed69bCompareJuly 18, 2023 14:36
Comment threadlightning/src/ln/outbound_payment.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 63ed69b to 804abe6CompareJuly 18, 2023 17:20
@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM after squash

@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 804abe6 to 97f07fbCompareJuly 18, 2023 20:41
@tnull

Copy link
Copy Markdown
ContributorAuthor

LGTM after squash

Squashed fixups without further changes.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 97f07fb to 90ef352CompareJuly 20, 2023 13:46
@tnull

Copy link
Copy Markdown
ContributorAuthor

Rebased on main to get rid of the CI failure.

@tnulltnull removed this from the 0.0.116 milestone Jul 21, 2023

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should land this to get the API in place for a second alpha, but we should get some of these comments fixed (at least the total-fee final check one) for 0.0.117.

// subtracting the used fee from the total fee budget.
route_params.max_total_routing_fee_msat = route_params
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
route_params.final_value_msat = pending_amt_unsent;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression, but this is wrong - this includes any overpayment amount, ensuring we overpay again when we go to retry, rather than just recalculating the amount sent against the intended amount. Lets definitely fix this ASAP.

@tnulltnullSep 27, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nevermind my previous reply): Tacked a corresponding commit onto #2575.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking about this once more, I think my previous comment was kinda correct: if we find a route and need to overpay for some of the paths, we may reduce the value of the others to meet the final value, i.e., the route's split is essentially determined at this time. If now some of the overpaid paths fail and we start to only retry the net. value (excluding overpaid amounts), the sum of all paths might not meet the expected final value. I suspect this is no issue if we have infinite auto-retries as we'd retry until the expected value is met, but if we're limited we probably will run out of retry attempts sooner than expected/necessary. Not sure how we'd want to resolve this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Right, then we seem to be on the same page that per-path accounting doesn't make sense, but only to account for the overpayment for the whole route.

I think what you propose unfortunately doesn't work as is though as for the immediate/legacy retry case we'd recursively reduce final_value_msat while we don't do this in the newer auto-retry case where we'd leave final_value_msat static, but account for for the pending amounts differently. In d7ab0ef I solved this by taking the min, but this seems to be pretty hacky.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/ln/payment_tests.rs
}

#[test]
fn mpp_retry_overpay() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is nice but isn't what I was mostly interested about. I'm really curious to test overpaying the final recipient and ensuring the route_params' final_value_msat is correct, not just the remaining fees.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, had understood above request slightly differently. IIUC, this might now more or less be covered by the new test introduced in #2604?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test tests the router end of it, but I'm really worried about the outbound_payment part overpaying.

@TheBlueMatt
TheBlueMatt merged commit 1ac53ed into lightningdevkit:mainSep 26, 2023
@TheBlueMattTheBlueMatt mentioned this pull request Sep 26, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt added a commit that referenced this pull request Sep 28, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
benthecarman added a commit to benthecarman/rust-lightning that referenced this pull request Nov 8, 2023
In lightningdevkit#2417 support for setting a max fee was added but it is not exposed
when using the `pay_invoice` utility functions. This makes it so the
user can pass in that parameter. One downside is that this removes the
defualt value form before.
Sign up for freeto 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.

Add another test for max_total_routing_fee_msat Allow to set maximum total fees during routing

6 participants

@tnull@codecov-commenter@valentinewallace@TheBlueMatt@jkczyz@alecchendev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Add config option to set maximum total routing fee - #2417

Merged
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee
Sep 26, 2023
Merged

Add config option to set maximum total routing fee#2417
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee

Conversation

@tnull

@tnulltnull commented Jul 14, 2023

Copy link
Copy Markdown
Contributor

Fixes#2339.
Closes#2596.
Based on #2555.

Currently, users have no means to upper-bound the total fees accruing when finding a route. Here, we add a corresponding field to PaymentParameters which is used to limit the candidate set during path finding.

To this end, we exclude any candidate hops if we find that using them would let the aggregated path routing fees exceed max_total_routeing_fee_msat. Moreover, we return an error if the aggregated fees over all paths of the selected route would surpass max_total_routeing_fee_msat.

@tnull
tnull marked this pull request as draft July 14, 2023 15:08
@tnull

tnull commented Jul 14, 2023

Copy link
Copy Markdown
ContributorAuthor

Drafting for now as I'm not super happy that we only filter on a per-path basis and then fail entirely if the aggregate route surpasses the routing fee limit. So far experimented with the approach we took for the minimal_value_contribution, i.e., having static per-path quotas, but discarded this as it would for example limit the per-path total fee to max_total_routing_fee_msat/max_path_count, i.e., to only 10% of the given value by default.

I think it's not super bad currently as we already pre-sort and filter routes by their cost/value ratio, which however also includes the penalty. Considering whether it would make sense to, whenever max_total_routing_fee_msat is set, add yet another pre-filtering step that only takes total fees into account to decrease the chances of unnecessarily returning an empty route.

This also currently doesn't account for retries. We might need to track the 'used' fees in a structure similar to InFlightHtlcs.

@codecov-commenter

codecov-commenter commented Jul 14, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (7e7e7a0) 88.83% compared to head (77afeac) 89.68%.
Report is 35 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2417 +/- ##
==========================================
+ Coverage 88.83% 89.68% +0.85% 
==========================================
Files 113 113 Lines 84489 89980 +5491 Branches 84489 89980 +5491 ==========================================
+ Hits 75052 80696 +5644 + Misses 7205 7055 -150 + Partials 2232 2229 -3 
FilesCoverage Δ
lightning/src/ln/blinded_payment_tests.rs100.00% <100.00%> (ø)
lightning/src/ln/functional_test_utils.rs93.62% <ø> (+2.45%)⬆️
lightning/src/ln/channelmanager.rs87.68% <50.00%> (+6.55%)⬆️
lightning-invoice/src/payment.rs77.30% <33.33%> (-0.26%)⬇️
lightning/src/ln/payment_tests.rs98.06% <98.60%> (+0.01%)⬆️
lightning/src/ln/outbound_payment.rs90.03% <92.94%> (+1.23%)⬆️
lightning/src/routing/router.rs93.73% <93.22%> (+0.10%)⬆️

... and 17 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, I think. I agree we should clean it up later to more aggressively find paths even though our first choice was fee-limited out, but this is certainly better than not having fee limiting.

Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as a first step, given where we're at with the release!

Comment threadlightning/src/routing/router.rs Outdated

@alecchendevalecchendev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from ed0ade8 to da559d3CompareJuly 18, 2023 12:28
@tnull
tnull marked this pull request as ready for review July 18, 2023 12:42
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from c34a4a9 to be27e7fCompareJuly 18, 2023 14:07
Comment threadlightning/src/ln/outbound_payment.rs
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/ln/outbound_payment.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from eaa9435 to 63ed69bCompareJuly 18, 2023 14:36
Comment threadlightning/src/ln/outbound_payment.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 63ed69b to 804abe6CompareJuly 18, 2023 17:20
@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM after squash

@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 804abe6 to 97f07fbCompareJuly 18, 2023 20:41
@tnull

Copy link
Copy Markdown
ContributorAuthor

LGTM after squash

Squashed fixups without further changes.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 97f07fb to 90ef352CompareJuly 20, 2023 13:46
@tnull

Copy link
Copy Markdown
ContributorAuthor

Rebased on main to get rid of the CI failure.

@tnulltnull removed this from the 0.0.116 milestone Jul 21, 2023

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should land this to get the API in place for a second alpha, but we should get some of these comments fixed (at least the total-fee final check one) for 0.0.117.

// subtracting the used fee from the total fee budget.
route_params.max_total_routing_fee_msat = route_params
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
route_params.final_value_msat = pending_amt_unsent;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression, but this is wrong - this includes any overpayment amount, ensuring we overpay again when we go to retry, rather than just recalculating the amount sent against the intended amount. Lets definitely fix this ASAP.

@tnulltnullSep 27, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nevermind my previous reply): Tacked a corresponding commit onto #2575.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking about this once more, I think my previous comment was kinda correct: if we find a route and need to overpay for some of the paths, we may reduce the value of the others to meet the final value, i.e., the route's split is essentially determined at this time. If now some of the overpaid paths fail and we start to only retry the net. value (excluding overpaid amounts), the sum of all paths might not meet the expected final value. I suspect this is no issue if we have infinite auto-retries as we'd retry until the expected value is met, but if we're limited we probably will run out of retry attempts sooner than expected/necessary. Not sure how we'd want to resolve this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Right, then we seem to be on the same page that per-path accounting doesn't make sense, but only to account for the overpayment for the whole route.

I think what you propose unfortunately doesn't work as is though as for the immediate/legacy retry case we'd recursively reduce final_value_msat while we don't do this in the newer auto-retry case where we'd leave final_value_msat static, but account for for the pending amounts differently. In d7ab0ef I solved this by taking the min, but this seems to be pretty hacky.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/ln/payment_tests.rs
}

#[test]
fn mpp_retry_overpay() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is nice but isn't what I was mostly interested about. I'm really curious to test overpaying the final recipient and ensuring the route_params' final_value_msat is correct, not just the remaining fees.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, had understood above request slightly differently. IIUC, this might now more or less be covered by the new test introduced in #2604?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test tests the router end of it, but I'm really worried about the outbound_payment part overpaying.

@TheBlueMatt
TheBlueMatt merged commit 1ac53ed into lightningdevkit:mainSep 26, 2023
@TheBlueMattTheBlueMatt mentioned this pull request Sep 26, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt added a commit that referenced this pull request Sep 28, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
benthecarman added a commit to benthecarman/rust-lightning that referenced this pull request Nov 8, 2023
In lightningdevkit#2417 support for setting a max fee was added but it is not exposed
when using the `pay_invoice` utility functions. This makes it so the
user can pass in that parameter. One downside is that this removes the
defualt value form before.
Sign up for freeto 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.

Add another test for max_total_routing_fee_msat Allow to set maximum total fees during routing

6 participants

@tnull@codecov-commenter@valentinewallace@TheBlueMatt@jkczyz@alecchendev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add config option to set maximum total routing fee - #2417

Merged
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee
Sep 26, 2023
Merged

Add config option to set maximum total routing fee#2417
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee

Conversation

@tnull

@tnulltnull commented Jul 14, 2023

Copy link
Copy Markdown
Contributor

Fixes#2339.
Closes#2596.
Based on #2555.

Currently, users have no means to upper-bound the total fees accruing when finding a route. Here, we add a corresponding field to PaymentParameters which is used to limit the candidate set during path finding.

To this end, we exclude any candidate hops if we find that using them would let the aggregated path routing fees exceed max_total_routeing_fee_msat. Moreover, we return an error if the aggregated fees over all paths of the selected route would surpass max_total_routeing_fee_msat.

@tnull
tnull marked this pull request as draft July 14, 2023 15:08
@tnull

tnull commented Jul 14, 2023

Copy link
Copy Markdown
ContributorAuthor

Drafting for now as I'm not super happy that we only filter on a per-path basis and then fail entirely if the aggregate route surpasses the routing fee limit. So far experimented with the approach we took for the minimal_value_contribution, i.e., having static per-path quotas, but discarded this as it would for example limit the per-path total fee to max_total_routing_fee_msat/max_path_count, i.e., to only 10% of the given value by default.

I think it's not super bad currently as we already pre-sort and filter routes by their cost/value ratio, which however also includes the penalty. Considering whether it would make sense to, whenever max_total_routing_fee_msat is set, add yet another pre-filtering step that only takes total fees into account to decrease the chances of unnecessarily returning an empty route.

This also currently doesn't account for retries. We might need to track the 'used' fees in a structure similar to InFlightHtlcs.

@codecov-commenter

codecov-commenter commented Jul 14, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (7e7e7a0) 88.83% compared to head (77afeac) 89.68%.
Report is 35 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2417 +/- ##
==========================================
+ Coverage 88.83% 89.68% +0.85% 
==========================================
Files 113 113 Lines 84489 89980 +5491 Branches 84489 89980 +5491 ==========================================
+ Hits 75052 80696 +5644 + Misses 7205 7055 -150 + Partials 2232 2229 -3 
FilesCoverage Δ
lightning/src/ln/blinded_payment_tests.rs100.00% <100.00%> (ø)
lightning/src/ln/functional_test_utils.rs93.62% <ø> (+2.45%)⬆️
lightning/src/ln/channelmanager.rs87.68% <50.00%> (+6.55%)⬆️
lightning-invoice/src/payment.rs77.30% <33.33%> (-0.26%)⬇️
lightning/src/ln/payment_tests.rs98.06% <98.60%> (+0.01%)⬆️
lightning/src/ln/outbound_payment.rs90.03% <92.94%> (+1.23%)⬆️
lightning/src/routing/router.rs93.73% <93.22%> (+0.10%)⬆️

... and 17 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, I think. I agree we should clean it up later to more aggressively find paths even though our first choice was fee-limited out, but this is certainly better than not having fee limiting.

Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as a first step, given where we're at with the release!

Comment threadlightning/src/routing/router.rs Outdated

@alecchendevalecchendev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from ed0ade8 to da559d3CompareJuly 18, 2023 12:28
@tnull
tnull marked this pull request as ready for review July 18, 2023 12:42
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from c34a4a9 to be27e7fCompareJuly 18, 2023 14:07
Comment threadlightning/src/ln/outbound_payment.rs
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/ln/outbound_payment.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from eaa9435 to 63ed69bCompareJuly 18, 2023 14:36
Comment threadlightning/src/ln/outbound_payment.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 63ed69b to 804abe6CompareJuly 18, 2023 17:20
@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM after squash

@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 804abe6 to 97f07fbCompareJuly 18, 2023 20:41
@tnull

Copy link
Copy Markdown
ContributorAuthor

LGTM after squash

Squashed fixups without further changes.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 97f07fb to 90ef352CompareJuly 20, 2023 13:46
@tnull

Copy link
Copy Markdown
ContributorAuthor

Rebased on main to get rid of the CI failure.

@tnulltnull removed this from the 0.0.116 milestone Jul 21, 2023

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should land this to get the API in place for a second alpha, but we should get some of these comments fixed (at least the total-fee final check one) for 0.0.117.

// subtracting the used fee from the total fee budget.
route_params.max_total_routing_fee_msat = route_params
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
route_params.final_value_msat = pending_amt_unsent;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression, but this is wrong - this includes any overpayment amount, ensuring we overpay again when we go to retry, rather than just recalculating the amount sent against the intended amount. Lets definitely fix this ASAP.

@tnulltnullSep 27, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nevermind my previous reply): Tacked a corresponding commit onto #2575.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking about this once more, I think my previous comment was kinda correct: if we find a route and need to overpay for some of the paths, we may reduce the value of the others to meet the final value, i.e., the route's split is essentially determined at this time. If now some of the overpaid paths fail and we start to only retry the net. value (excluding overpaid amounts), the sum of all paths might not meet the expected final value. I suspect this is no issue if we have infinite auto-retries as we'd retry until the expected value is met, but if we're limited we probably will run out of retry attempts sooner than expected/necessary. Not sure how we'd want to resolve this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Right, then we seem to be on the same page that per-path accounting doesn't make sense, but only to account for the overpayment for the whole route.

I think what you propose unfortunately doesn't work as is though as for the immediate/legacy retry case we'd recursively reduce final_value_msat while we don't do this in the newer auto-retry case where we'd leave final_value_msat static, but account for for the pending amounts differently. In d7ab0ef I solved this by taking the min, but this seems to be pretty hacky.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/ln/payment_tests.rs
}

#[test]
fn mpp_retry_overpay() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is nice but isn't what I was mostly interested about. I'm really curious to test overpaying the final recipient and ensuring the route_params' final_value_msat is correct, not just the remaining fees.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, had understood above request slightly differently. IIUC, this might now more or less be covered by the new test introduced in #2604?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test tests the router end of it, but I'm really worried about the outbound_payment part overpaying.

@TheBlueMatt
TheBlueMatt merged commit 1ac53ed into lightningdevkit:mainSep 26, 2023
@TheBlueMattTheBlueMatt mentioned this pull request Sep 26, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt added a commit that referenced this pull request Sep 28, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
benthecarman added a commit to benthecarman/rust-lightning that referenced this pull request Nov 8, 2023
In lightningdevkit#2417 support for setting a max fee was added but it is not exposed
when using the `pay_invoice` utility functions. This makes it so the
user can pass in that parameter. One downside is that this removes the
defualt value form before.
Sign up for freeto 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.

Add another test for max_total_routing_fee_msat Allow to set maximum total fees during routing

6 participants

@tnull@codecov-commenter@valentinewallace@TheBlueMatt@jkczyz@alecchendev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add config option to set maximum total routing fee - #2417

Merged
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee
Sep 26, 2023
Merged

Add config option to set maximum total routing fee#2417
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee

Conversation

@tnull

@tnulltnull commented Jul 14, 2023

Copy link
Copy Markdown
Contributor

Fixes#2339.
Closes#2596.
Based on #2555.

Currently, users have no means to upper-bound the total fees accruing when finding a route. Here, we add a corresponding field to PaymentParameters which is used to limit the candidate set during path finding.

To this end, we exclude any candidate hops if we find that using them would let the aggregated path routing fees exceed max_total_routeing_fee_msat. Moreover, we return an error if the aggregated fees over all paths of the selected route would surpass max_total_routeing_fee_msat.

@tnull
tnull marked this pull request as draft July 14, 2023 15:08
@tnull

tnull commented Jul 14, 2023

Copy link
Copy Markdown
ContributorAuthor

Drafting for now as I'm not super happy that we only filter on a per-path basis and then fail entirely if the aggregate route surpasses the routing fee limit. So far experimented with the approach we took for the minimal_value_contribution, i.e., having static per-path quotas, but discarded this as it would for example limit the per-path total fee to max_total_routing_fee_msat/max_path_count, i.e., to only 10% of the given value by default.

I think it's not super bad currently as we already pre-sort and filter routes by their cost/value ratio, which however also includes the penalty. Considering whether it would make sense to, whenever max_total_routing_fee_msat is set, add yet another pre-filtering step that only takes total fees into account to decrease the chances of unnecessarily returning an empty route.

This also currently doesn't account for retries. We might need to track the 'used' fees in a structure similar to InFlightHtlcs.

@codecov-commenter

codecov-commenter commented Jul 14, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (7e7e7a0) 88.83% compared to head (77afeac) 89.68%.
Report is 35 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2417 +/- ##
==========================================
+ Coverage 88.83% 89.68% +0.85% 
==========================================
Files 113 113 Lines 84489 89980 +5491 Branches 84489 89980 +5491 ==========================================
+ Hits 75052 80696 +5644 + Misses 7205 7055 -150 + Partials 2232 2229 -3 
FilesCoverage Δ
lightning/src/ln/blinded_payment_tests.rs100.00% <100.00%> (ø)
lightning/src/ln/functional_test_utils.rs93.62% <ø> (+2.45%)⬆️
lightning/src/ln/channelmanager.rs87.68% <50.00%> (+6.55%)⬆️
lightning-invoice/src/payment.rs77.30% <33.33%> (-0.26%)⬇️
lightning/src/ln/payment_tests.rs98.06% <98.60%> (+0.01%)⬆️
lightning/src/ln/outbound_payment.rs90.03% <92.94%> (+1.23%)⬆️
lightning/src/routing/router.rs93.73% <93.22%> (+0.10%)⬆️

... and 17 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, I think. I agree we should clean it up later to more aggressively find paths even though our first choice was fee-limited out, but this is certainly better than not having fee limiting.

Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as a first step, given where we're at with the release!

Comment threadlightning/src/routing/router.rs Outdated

@alecchendevalecchendev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from ed0ade8 to da559d3CompareJuly 18, 2023 12:28
@tnull
tnull marked this pull request as ready for review July 18, 2023 12:42
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from c34a4a9 to be27e7fCompareJuly 18, 2023 14:07
Comment threadlightning/src/ln/outbound_payment.rs
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/ln/outbound_payment.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from eaa9435 to 63ed69bCompareJuly 18, 2023 14:36
Comment threadlightning/src/ln/outbound_payment.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 63ed69b to 804abe6CompareJuly 18, 2023 17:20
@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM after squash

@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 804abe6 to 97f07fbCompareJuly 18, 2023 20:41
@tnull

Copy link
Copy Markdown
ContributorAuthor

LGTM after squash

Squashed fixups without further changes.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 97f07fb to 90ef352CompareJuly 20, 2023 13:46
@tnull

Copy link
Copy Markdown
ContributorAuthor

Rebased on main to get rid of the CI failure.

@tnulltnull removed this from the 0.0.116 milestone Jul 21, 2023

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should land this to get the API in place for a second alpha, but we should get some of these comments fixed (at least the total-fee final check one) for 0.0.117.

// subtracting the used fee from the total fee budget.
route_params.max_total_routing_fee_msat = route_params
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
route_params.final_value_msat = pending_amt_unsent;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression, but this is wrong - this includes any overpayment amount, ensuring we overpay again when we go to retry, rather than just recalculating the amount sent against the intended amount. Lets definitely fix this ASAP.

@tnulltnullSep 27, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nevermind my previous reply): Tacked a corresponding commit onto #2575.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking about this once more, I think my previous comment was kinda correct: if we find a route and need to overpay for some of the paths, we may reduce the value of the others to meet the final value, i.e., the route's split is essentially determined at this time. If now some of the overpaid paths fail and we start to only retry the net. value (excluding overpaid amounts), the sum of all paths might not meet the expected final value. I suspect this is no issue if we have infinite auto-retries as we'd retry until the expected value is met, but if we're limited we probably will run out of retry attempts sooner than expected/necessary. Not sure how we'd want to resolve this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Right, then we seem to be on the same page that per-path accounting doesn't make sense, but only to account for the overpayment for the whole route.

I think what you propose unfortunately doesn't work as is though as for the immediate/legacy retry case we'd recursively reduce final_value_msat while we don't do this in the newer auto-retry case where we'd leave final_value_msat static, but account for for the pending amounts differently. In d7ab0ef I solved this by taking the min, but this seems to be pretty hacky.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/ln/payment_tests.rs
}

#[test]
fn mpp_retry_overpay() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is nice but isn't what I was mostly interested about. I'm really curious to test overpaying the final recipient and ensuring the route_params' final_value_msat is correct, not just the remaining fees.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, had understood above request slightly differently. IIUC, this might now more or less be covered by the new test introduced in #2604?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test tests the router end of it, but I'm really worried about the outbound_payment part overpaying.

@TheBlueMatt
TheBlueMatt merged commit 1ac53ed into lightningdevkit:mainSep 26, 2023
@TheBlueMattTheBlueMatt mentioned this pull request Sep 26, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt added a commit that referenced this pull request Sep 28, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
benthecarman added a commit to benthecarman/rust-lightning that referenced this pull request Nov 8, 2023
In lightningdevkit#2417 support for setting a max fee was added but it is not exposed
when using the `pay_invoice` utility functions. This makes it so the
user can pass in that parameter. One downside is that this removes the
defualt value form before.
Sign up for freeto 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.

Add another test for max_total_routing_fee_msat Allow to set maximum total fees during routing

6 participants

@tnull@codecov-commenter@valentinewallace@TheBlueMatt@jkczyz@alecchendev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Add config option to set maximum total routing fee - #2417

Merged
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee
Sep 26, 2023
Merged

Add config option to set maximum total routing fee#2417
TheBlueMatt merged 8 commits into
lightningdevkit:mainfrom
tnull:2023-07-max-total-fee

Conversation

@tnull

@tnulltnull commented Jul 14, 2023

Copy link
Copy Markdown
Contributor

Fixes#2339.
Closes#2596.
Based on #2555.

Currently, users have no means to upper-bound the total fees accruing when finding a route. Here, we add a corresponding field to PaymentParameters which is used to limit the candidate set during path finding.

To this end, we exclude any candidate hops if we find that using them would let the aggregated path routing fees exceed max_total_routeing_fee_msat. Moreover, we return an error if the aggregated fees over all paths of the selected route would surpass max_total_routeing_fee_msat.

@tnull
tnull marked this pull request as draft July 14, 2023 15:08
@tnull

tnull commented Jul 14, 2023

Copy link
Copy Markdown
ContributorAuthor

Drafting for now as I'm not super happy that we only filter on a per-path basis and then fail entirely if the aggregate route surpasses the routing fee limit. So far experimented with the approach we took for the minimal_value_contribution, i.e., having static per-path quotas, but discarded this as it would for example limit the per-path total fee to max_total_routing_fee_msat/max_path_count, i.e., to only 10% of the given value by default.

I think it's not super bad currently as we already pre-sort and filter routes by their cost/value ratio, which however also includes the penalty. Considering whether it would make sense to, whenever max_total_routing_fee_msat is set, add yet another pre-filtering step that only takes total fees into account to decrease the chances of unnecessarily returning an empty route.

This also currently doesn't account for retries. We might need to track the 'used' fees in a structure similar to InFlightHtlcs.

@codecov-commenter

codecov-commenter commented Jul 14, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (7e7e7a0) 88.83% compared to head (77afeac) 89.68%.
Report is 35 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2417 +/- ##
==========================================
+ Coverage 88.83% 89.68% +0.85% 
==========================================
Files 113 113 Lines 84489 89980 +5491 Branches 84489 89980 +5491 ==========================================
+ Hits 75052 80696 +5644 + Misses 7205 7055 -150 + Partials 2232 2229 -3 
FilesCoverage Δ
lightning/src/ln/blinded_payment_tests.rs100.00% <100.00%> (ø)
lightning/src/ln/functional_test_utils.rs93.62% <ø> (+2.45%)⬆️
lightning/src/ln/channelmanager.rs87.68% <50.00%> (+6.55%)⬆️
lightning-invoice/src/payment.rs77.30% <33.33%> (-0.26%)⬇️
lightning/src/ln/payment_tests.rs98.06% <98.60%> (+0.01%)⬆️
lightning/src/ln/outbound_payment.rs90.03% <92.94%> (+1.23%)⬆️
lightning/src/routing/router.rs93.73% <93.22%> (+0.10%)⬆️

... and 17 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, I think. I agree we should clean it up later to more aggressively find paths even though our first choice was fee-limited out, but this is certainly better than not having fee limiting.

Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as a first step, given where we're at with the release!

Comment threadlightning/src/routing/router.rs Outdated

@alecchendevalecchendev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from ed0ade8 to da559d3CompareJuly 18, 2023 12:28
@tnull
tnull marked this pull request as ready for review July 18, 2023 12:42
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch 3 times, most recently from c34a4a9 to be27e7fCompareJuly 18, 2023 14:07
Comment threadlightning/src/ln/outbound_payment.rs
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/ln/outbound_payment.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from eaa9435 to 63ed69bCompareJuly 18, 2023 14:36
Comment threadlightning/src/ln/outbound_payment.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/routing/router.rs
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 63ed69b to 804abe6CompareJuly 18, 2023 17:20
@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM after squash

@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 804abe6 to 97f07fbCompareJuly 18, 2023 20:41
@tnull

Copy link
Copy Markdown
ContributorAuthor

LGTM after squash

Squashed fixups without further changes.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs Outdated
@tnull
tnullforce-pushed the 2023-07-max-total-fee branch from 97f07fb to 90ef352CompareJuly 20, 2023 13:46
@tnull

Copy link
Copy Markdown
ContributorAuthor

Rebased on main to get rid of the CI failure.

@tnulltnull removed this from the 0.0.116 milestone Jul 21, 2023

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should land this to get the API in place for a second alpha, but we should get some of these comments fixed (at least the total-fee final check one) for 0.0.117.

// subtracting the used fee from the total fee budget.
route_params.max_total_routing_fee_msat = route_params
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
route_params.final_value_msat = pending_amt_unsent;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression, but this is wrong - this includes any overpayment amount, ensuring we overpay again when we go to retry, rather than just recalculating the amount sent against the intended amount. Lets definitely fix this ASAP.

@tnulltnullSep 27, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nevermind my previous reply): Tacked a corresponding commit onto #2575.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking about this once more, I think my previous comment was kinda correct: if we find a route and need to overpay for some of the paths, we may reduce the value of the others to meet the final value, i.e., the route's split is essentially determined at this time. If now some of the overpaid paths fail and we start to only retry the net. value (excluding overpaid amounts), the sum of all paths might not meet the expected final value. I suspect this is no issue if we have infinite auto-retries as we'd retry until the expected value is met, but if we're limited we probably will run out of retry attempts sooner than expected/necessary. Not sure how we'd want to resolve this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is we don't need to think about paths in this specific case - we tried to send a payment for route.route_params.final_value_msat and we now have route.get_total_amount() - pending_amt_unsent pending. We should retry pending_amt_unsent - (route.get_total_amount() - route.route_params.final_value_msat).

Right, then we seem to be on the same page that per-path accounting doesn't make sense, but only to account for the overpayment for the whole route.

I think what you propose unfortunately doesn't work as is though as for the immediate/legacy retry case we'd recursively reduce final_value_msat while we don't do this in the newer auto-retry case where we'd leave final_value_msat static, but account for for the pending amounts differently. In d7ab0ef I solved this by taking the min, but this seems to be pretty hacky.

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/ln/payment_tests.rs
}

#[test]
fn mpp_retry_overpay() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is nice but isn't what I was mostly interested about. I'm really curious to test overpaying the final recipient and ensuring the route_params' final_value_msat is correct, not just the remaining fees.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, had understood above request slightly differently. IIUC, this might now more or less be covered by the new test introduced in #2604?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test tests the router end of it, but I'm really worried about the outbound_payment part overpaying.

@TheBlueMatt
TheBlueMatt merged commit 1ac53ed into lightningdevkit:mainSep 26, 2023
@TheBlueMattTheBlueMatt mentioned this pull request Sep 26, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 27, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
tnull added a commit to tnull/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Sep 28, 2023
TheBlueMatt added a commit that referenced this pull request Sep 28, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
slanesuke pushed a commit to slanesuke/rust-lightning that referenced this pull request Oct 6, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
optout21 pushed a commit to optout21/rust-lightning that referenced this pull request Nov 4, 2023
benthecarman added a commit to benthecarman/rust-lightning that referenced this pull request Nov 8, 2023
In lightningdevkit#2417 support for setting a max fee was added but it is not exposed
when using the `pay_invoice` utility functions. This makes it so the
user can pass in that parameter. One downside is that this removes the
defualt value form before.
Sign up for freeto 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.

Add another test for max_total_routing_fee_msat Allow to set maximum total fees during routing

6 participants

@tnull@codecov-commenter@valentinewallace@TheBlueMatt@jkczyz@alecchendev