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

pay: Share channel_hints across payments and plugins #7487

Conversation

cdecker
Copy link
Member

@cdecker cdecker commented Jul 23, 2024

While performing a payment we attempt to get several HTLCs through
from the sender to the destination. Some of these attempts may fail,
due to temporary unavailability, insufficient balance, or many other
reasons. We use channel_hints to track these failures and compile
the observations into a more detailed view of the network.

So far we were just forgetting all of the inferred information once
the payment is done, however this information is useful for later
payments too, as it allows us to skip attempts that are unlikely to
succeed, and essentially continue the exploration where the previous
payments have left off.

The main issue we face is how do we relax the hints over time, such
that we maximize their usefulness by allowing us to skip channels that
are unlikely to succeed, while at the same time minimizing the false
negative rate where we skip a channel that would have worked, based on
the prior observations. We implement it here as a linear decay, in
line with the leaky bucket rate limiting algorithm.

We model the sharing of the channel_hints as notifications since we
might want to share observations across multiple plugins, and maybe
even across multiple nodes, if they are operated by the same
operator. DO NOT accept channel_hint notifications from untrusted
sources, as they can be used directly to steer the route selection.

Changelog-Added: pay: Payments now emit channel_hint_updated notification to share inferred balances and observations across multiple payments.

This is part of the following PR set:

graph TD;
    CLN7487 --> CLN7494 ;
    click CLN7487 "https://github.com/ElementsProject/lightning/pull/7487"
    click CLN7494 "https://github.com/ElementsProject/lightning/pull/7494"
    click CLN7543 "https://github.com/ElementsProject/lightning/pull/7543"
    style CLN7487 fill:#AAFFAA
Loading

@cdecker cdecker force-pushed the 202407-pay-channel-hint-notifications branch 3 times, most recently from 1fa5a3f to 1601835 Compare July 25, 2024 13:29
@cdecker cdecker force-pushed the 202407-pay-channel-hint-notifications branch 3 times, most recently from a22375e to 33a5a0c Compare July 30, 2024 13:23
@cdecker cdecker force-pushed the 202407-pay-channel-hint-notifications branch from 33a5a0c to f6c1cc3 Compare August 5, 2024 10:18
Comment on lines +405 to +422
/*
static struct channel_hint *channel_hint_from_json(const tal_t *ctx,
const char *buffer,
const jsmntok_t *toks)
{
const char *ret;
struct channel_hint *hint = tal(ctx, struct channel_hint);
ret = json_scan(ctx, buffer, toks,
"{timestamp:%,scid:%,capacity_msat:%,enabled:%}",
JSON_SCAN(json_to_u32, &hint->timestamp),
JSON_SCAN(json_to_short_channel_id_dir, &hint->scid),
JSON_SCAN(json_to_msat, &hint->estimated_capacity),
JSON_SCAN(json_to_bool, &hint->enabled));

if (ret != NULL)
hint = tal_free(hint);
return hint;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I could have split this into a later commit, but it seemed like a good idea to have both the writing and reading part of the notification in one commit.

@cdecker cdecker marked this pull request as ready for review August 5, 2024 13:21
The `pay` plugin, as well as other plugins making use of the tree-pay
executor, will now emit their observations as they see them. The
notifications are sent on the `channel_hint_updated` topic, and any
subscriber will get them.

We also added a `timestamp` to the `struct channel_hint`, as these
observations now outlive the `pay` call, and have to be attenuated /
relaxed as they age, until we can eliminate them completely (when the
restriction is equal to the structural information gathered from the
gossip).

Changelog-Added: pay: Payments now emit `channel_hint_updated` notification to share inferred balances and observations across multiple payments.
We were missing the `short_channel_id_dir` helpers.
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

Cosmetics only, given the proximity to release I'm tempted to apply this now and tweak later...

Ack a8504b7

@@ -485,6 +484,16 @@ void json_add_short_channel_id(struct json_stream *response,
short_channel_id_outnum(scid));
}

void json_add_short_channel_id_dir(struct json_stream *response,
const char *fieldname,
struct short_channel_id_dir scidd)
Copy link
Contributor

Choose a reason for hiding this comment

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

scidd is a complex type, so unlike scids it should be passed as "const struct short_channel_id_dir *". This also means the definition doesn't need to be in the header...

@@ -386,6 +386,16 @@ void payment_start(struct payment *p)
payment_start_at_blockheight(p, INVALID_BLOCKHEIGHT);
}

static void channel_hint_to_json(const char *name, const struct channel_hint *hint, struct json_stream *dest)
Copy link
Contributor

Choose a reason for hiding this comment

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

This would normally be called "json_add_channel_hint(struct json_stream *, const char *, const struct channel_hint *)". It's internal, but consistency is nice.

@ShahanaFarooqui
Copy link
Collaborator

@cdecker Can we link this PR as a solution to #7180? Or is it a partial one and should not close the issue yet.

@rustyrussell rustyrussell merged commit aa45e73 into ElementsProject:master Aug 9, 2024
36 checks passed
@cdecker cdecker deleted the 202407-pay-channel-hint-notifications branch August 9, 2024 10:43
@cdecker
Copy link
Member Author

cdecker commented Aug 9, 2024

@cdecker Can we link this PR as a solution to #7180? Or is it a partial one and should not close the issue yet.

Not as a solution, but as a step towards it yes. The channel_hints are being emitted for the benefit of other plugins at the moment, but I have one pending that'll also inject from other plugins into pay if we have external sources of knowledge.

I'd rather mark #7494 as the solution, as it is what was being proposed in the issue.

@nakoshi-satamoto
Copy link

This is not a solution to fixing payment in CLN. I just built 24.08rc3 from source and issues persist. Payments still are no longer supported in CLN. The last funcitonal version is from before version 24.

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