From f85425d1066ff3450cf63916e8240cd90b6c301f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 23 Mar 2022 09:29:20 +1030 Subject: [PATCH] lightningd: don't assume a single channel per peer. Signed-off-by: Rusty Russell --- lightningd/routehint.c | 20 ++++++++++++++++---- lightningd/test/run-invoice-select-inchan.c | 7 ++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lightningd/routehint.c b/lightningd/routehint.c index a9879e3a3..29a1439bc 100644 --- a/lightningd/routehint.c +++ b/lightningd/routehint.c @@ -99,14 +99,25 @@ routehint_candidates(const tal_t *ctx, if (!peer) { log_debug(ld->log, "%s: unknown peer", type_to_string(tmpctx, - struct short_channel_id, - &r->short_channel_id)); + struct node_id, + &r->pubkey)); continue; } - /* Does it have a channel in state CHANNELD_NORMAL */ - candidate.c = peer_normal_channel(peer); + /* Check channel is in CHANNELD_NORMAL */ + candidate.c = find_channel_by_scid(peer, &r->short_channel_id); if (!candidate.c) { + log_debug(ld->log, "%s: channel not found in peer %s", + type_to_string(tmpctx, + struct short_channel_id, + &r->short_channel_id), + type_to_string(tmpctx, + struct node_id, + &r->pubkey)); + continue; + } + + if (candidate.c->state != CHANNELD_NORMAL) { log_debug(ld->log, "%s: abnormal channel", type_to_string(tmpctx, struct short_channel_id, @@ -120,6 +131,7 @@ routehint_candidates(const tal_t *ctx, * capacity ceiling. We *could* do multiple HTLCs, * but presumably that would defeat the spirit of the * limit anyway */ + /* FIXME: Present max capacity of multiple channels? */ candidate.capacity = channel_amount_receivable(candidate.c); if (amount_msat_greater(candidate.capacity, htlc_max)) candidate.capacity = htlc_max; diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index dec7c3a72..17e3c9d1b 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -191,6 +191,10 @@ u8 *featurebits_or(const tal_t *ctx UNNEEDED, const u8 *f1 TAKES UNNEEDED, const struct channel *find_channel_by_id(const struct peer *peer UNNEEDED, const struct channel_id *cid UNNEEDED) { fprintf(stderr, "find_channel_by_id called!\n"); abort(); } +/* Generated stub for find_channel_by_scid */ +struct channel *find_channel_by_scid(const struct peer *peer UNNEEDED, + const struct short_channel_id *scid UNNEEDED) +{ fprintf(stderr, "find_channel_by_scid called!\n"); abort(); } /* Generated stub for find_plugin_for_command */ struct plugin *find_plugin_for_command(struct lightningd *ld UNNEEDED, const char *cmd_name UNNEEDED) @@ -585,9 +589,6 @@ struct command_result *param_u64(struct command *cmd UNNEEDED, const char *name /* Generated stub for peer_active_channel */ struct channel *peer_active_channel(struct peer *peer UNNEEDED) { fprintf(stderr, "peer_active_channel called!\n"); abort(); } -/* Generated stub for peer_normal_channel */ -struct channel *peer_normal_channel(struct peer *peer UNNEEDED) -{ fprintf(stderr, "peer_normal_channel called!\n"); abort(); } /* Generated stub for peer_restart_dualopend */ void peer_restart_dualopend(struct peer *peer UNNEEDED, struct peer_fd *peer_fd UNNEEDED,