From 94bd50926f56297c3491eca3feed7e034d9dd2fd Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 3 Jun 2021 18:41:57 +0200 Subject: [PATCH] pay: Do not attempt to filter routehints if we can't find outselves There are a couple of ways this can happen, but we shouldn't crash. Fixed #4488 Fixes #4533 Changelog-Fixed: pay: Fixed an issue when filtering routehints when we can't find ourselves in the local network view. --- plugins/libplugin-pay.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 6769b4a7447a..b1081d8f898c 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -2334,8 +2334,16 @@ static struct route_info **filter_routehints(struct gossmap *map, { const size_t max_hops = ROUTING_MAX_HOPS / 2; char *mods = tal_strdup(tmpctx, ""); - for (size_t i = 0; i < tal_count(hints); i++) { - struct gossmap_node *entrynode, *src; + struct gossmap_node *src = gossmap_find_node(map, p->local_id); + + if (src == NULL) { + tal_append_fmt(&mods, + "Could not locate ourselves in the gossip map, " + "leaving routehints untouched. "); + } + + for (size_t i = 0; i < tal_count(hints) && src != NULL; i++) { + struct gossmap_node *entrynode; u32 distance; /* Trim any routehint > 10 hops */ @@ -2367,8 +2375,6 @@ static struct route_info **filter_routehints(struct gossmap *map, /* If routehint entrypoint is unreachable there's no * point in keeping it. */ entrynode = gossmap_find_node(map, &hints[i][0].pubkey); - src = gossmap_find_node(map, p->local_id); - if (entrynode == NULL) { tal_append_fmt(&mods, "Removed routehint %zu because "