Skip to content

Commit

Permalink
lightningd: obey first hop channel id.
Browse files Browse the repository at this point in the history
Reported-by: Warren Togami
Changelog-Changed: `sendpay` and `sendonion` now obey the first hop "channel" short_channel_id, if specified.
Changelog-Deprecated: `sendpay` and `sendonion` could take a bogus first hop "channel" short_channel_id
  • Loading branch information
rustyrussell authored and niftynei committed Aug 9, 2022
1 parent 9543204 commit 054339e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "config.h"
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
#include <common/bolt12_merkle.h>
#include <common/configdir.h>
Expand Down Expand Up @@ -827,19 +828,26 @@ static struct command_result *check_offer_usage(struct command *cmd,
}

static struct channel *find_channel_for_htlc_add(struct lightningd *ld,
const struct node_id *node)
const struct node_id *node,
const struct short_channel_id *scid)
{
struct channel *channel;
struct peer *peer = peer_by_id(ld, node);
if (!peer)
return NULL;

list_for_each(&peer->channels, channel, list) {
if (channel_can_add_htlc(channel)) {
return channel;
channel = find_channel_by_scid(peer, scid);
if (channel && channel_can_add_htlc(channel))
return channel;

/* We used to ignore scid: now all-zero means "any" */
if (!channel && (deprecated_apis || memeqzero(scid, sizeof(*scid)))) {
list_for_each(&peer->channels, channel, list) {
if (channel_can_add_htlc(channel)) {
return channel;
}
}
}

return NULL;
}

Expand Down Expand Up @@ -1032,7 +1040,8 @@ send_payment_core(struct lightningd *ld,
if (offer_err)
return offer_err;

channel = find_channel_for_htlc_add(ld, &first_hop->node_id);
channel = find_channel_for_htlc_add(ld, &first_hop->node_id,
&first_hop->scid);
if (!channel) {
struct json_stream *data
= json_stream_fail(cmd, PAY_TRY_OTHER_ROUTE,
Expand Down

0 comments on commit 054339e

Please sign in to comment.