From a98ccac7774297f255f0a4f585384609af87c3d6 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 12 Dec 2021 14:27:00 +0100 Subject: [PATCH] pay: Disable channels that are not in normal state Since we have the exact state of the channels from the `listpeers` response we can filter out the ones that are not yet normal or not anymore. This is more of a safety net, given that the `gossip_store` should contain local disables, but better not be racy :-) Changelog-None --- plugins/libplugin-pay.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 0a3c32546..ae82c1497 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -2310,7 +2310,7 @@ local_channel_hints_listpeers(struct command *cmd, const char *buffer, const jsmntok_t *toks, struct payment *p) { const jsmntok_t *peers, *peer, *channels, *channel, *spendsats, *scid, - *dir, *connected, *max_htlc, *htlcs; + *dir, *connected, *max_htlc, *htlcs, *state; size_t i, j; peers = json_get_member(buffer, toks, "peers"); @@ -2331,13 +2331,19 @@ local_channel_hints_listpeers(struct command *cmd, const char *buffer, dir = json_get_member(buffer, channel, "direction"); max_htlc = json_get_member(buffer, channel, "max_accepted_htlcs"); htlcs = json_get_member(buffer, channel, "htlcs"); + state = json_get_member(buffer, channel, "state"); if (spendsats == NULL || scid == NULL || dir == NULL || - max_htlc == NULL || + max_htlc == NULL || state == NULL || max_htlc->type != JSMN_PRIMITIVE || htlcs == NULL || htlcs->type != JSMN_ARRAY) continue; + /* Filter out local channels if they are + * either a) disconnected, or b) not in normal + * state. */ json_to_bool(buffer, connected, &h.enabled); + h.enabled &= json_tok_streq(buffer, state, "CHANNELD_NORMAL"); + json_to_short_channel_id(buffer, scid, &h.scid.scid); json_to_int(buffer, dir, &h.scid.dir);