Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libplugin-pay: use map for channel hints (on top of #7494) #7648

Conversation

JssDWt
Copy link
Contributor

@JssDWt JssDWt commented Sep 6, 2024

libplugin-pay: use map for channel hints (on top of #7494)

Description

This commit fixes a "FIXME: This is slow" in the pay plugin. For nodes with many channels this is a tremendous improvement in pay performance. PR #7611 improves payment performance from 15 seconds to 13.5 seconds on one of our nodes. This commit improves payment performance from 13.5 seconds to 5.7 seconds.

Changes Made

  • Feature: Brief description of the new feature or functionality added.
  • Bug Fix: Brief description of the bug fixed and how it was resolved.
  • Refactor: Any code improvements or refactoring done without changing the functionality.

Checklist

Ensure the following tasks are completed before submitting the PR:

  • Changelog has been added in relevant commit/s.
  • Tests have been added or updated to cover the changes.
  • Documentation has been updated as needed.
  • Any relevant comments or TODOs have been addressed or removed.

Additional Notes

This PR builds on top of #7494
This is a replacement of #7636, because that PR conflicts with #7494

@JssDWt JssDWt force-pushed the jssdwt-channel-hint-map-7494 branch from 5857c5e to 79bc332 Compare September 6, 2024 14:02
@cdecker cdecker force-pushed the 202407-pay-channel-hint-update branch from c362f12 to 6b068c5 Compare September 6, 2024 15:29
We relax constraints from the `channel_hint` through a linear refill.
We need to know the overall channel capacity, i.e., the amount_msat
that the channel was funded with, in order to relax the channel_hint
to refill over time.
We attach the hints to the plugin, so they get shared across multiple
payments.
We're getting serious about how we manage the channel_hints, so let's
give them a proper home.
Keeping it in `amount_msat` made the comparisons easier, but it was
the wrong type for this.
If we have a large channel, fail to send through a small amount, and
then add a `channel_hint`, then it can happen that the call to
`channel_hint_set_update` is already late enough that it refills the
1msat we removed from the attempted amount, thus making the edge we
just excluded eligible again, which can lead into an infinite loop.

We slow down the updating of the channel_hints to once every
hysteresis timeout. This allows us to set tight constraints, while not
incurring in the accidental relaxation issue.
Making sure that we don't accidentally create an endless loop.
We were using `channel_hint` to temporarily tweak the graph inside of
a payment. However, these ad-hoc `channel_hints` are stickier than
their predecessors, in that they outlive the payment attempt itself,
and interfere with later ones.

Changelog-Changed: pay: Discarding an overly long or expensive route does not blocklist channels anymore.
I'm not sure how this ever worked, and it must've been racy: we
initiate a number of payments, then proceed to disconnect and
reconnect repeatedly. If a payment is attempted inbetween the
`disconnect` and `connect` the payment will fail. Removing it since it
most likely was just a sledgehammer test that we didn't know how to
fine-tune.

Changelog-None
It was failing because the channel_hint from one attempt would prevent
us from retrying. By changing the amounts so that the channel_hints do
not concern them (value smaller than estimate) we can make things work
as before again.
We were ignoring more reliable information because of the
stricter-is-better logic. This meant that we were also ignoring local
channel information, despite knowing better.

By simplifying the logic to pick the one with the newer timestamp we
ensure that later observations always trump earlier ones. There is a
bit of interplay between the relaxation of the constraints updating
the timestamp, and comparing to real observation timestamps, but that
should not impact us for local channels.
@cdecker cdecker force-pushed the 202407-pay-channel-hint-update branch from 6b068c5 to 1e833ba Compare September 6, 2024 15:29
@JssDWt JssDWt marked this pull request as ready for review September 9, 2024 07:57
@JssDWt JssDWt marked this pull request as draft September 9, 2024 07:57
This commit fixes a "FIXME: This is slow" in the pay plugin. For
nodes with many channels this is a tremendous improvement in pay
performance. PR ElementsProject#7611 improves payment performance from 15 seconds to
13.5 seconds on one of our nodes. This commit improves payment
performance from 13.5 seconds to 5.7 seconds.

Changelog-Fixed: Improved pathfinding speed for large nodes.
@JssDWt JssDWt force-pushed the jssdwt-channel-hint-map-7494 branch from 79bc332 to aaff2f3 Compare September 9, 2024 08:08
@JssDWt JssDWt marked this pull request as ready for review September 9, 2024 08:08
Copy link
Collaborator

@endothermicdev endothermicdev left a comment

Choose a reason for hiding this comment

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

Nit: The changelog entry should probably start with the subject, i.e., "Pay plugin:"
I have not reviewed the base branch, but this PR looks good when #7494 is ready.
ACK aaff2f3

@cdecker cdecker added this to the v24.08.1 milestone Sep 18, 2024
@ShahanaFarooqui ShahanaFarooqui modified the milestones: v24.08.1, v24.08.2 Sep 20, 2024
@cdecker cdecker force-pushed the 202407-pay-channel-hint-update branch 4 times, most recently from 05c2d1a to d0b2f3c Compare October 7, 2024 09:38
@cdecker cdecker deleted the branch ElementsProject:202407-pay-channel-hint-update October 7, 2024 12:05
@cdecker cdecker closed this Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants