From 650443e4d50eb55f1fc1fd96b388d78e8dd80c64 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 5 Jan 2023 12:11:36 +0100 Subject: [PATCH] ld: Add a couple of logging statements when forwarding We were debugging a number of issues related to the forwarding logic, when using public scids on private channels, and we noticed that we are very verbose everywhere, except where it counts, i.e., what decisions are being taken. So we add a couple of debug logs, and a final info one that tells the operator which resolution was chosen in the end. --- lightningd/peer_htlcs.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 6adbd248d..f188f943b 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -1205,18 +1205,42 @@ static struct channel_id *calc_forwarding_channel(struct lightningd *ld, return NULL; if (p->forward_channel) { + log_debug(hp->channel->log, + "Looking up channel by scid=%s to forward htlc_id=%" PRIu64, + type_to_string(tmpctx, struct short_channel_id, + p->forward_channel), + hp->hin->key.id); + c = any_channel_by_scid(ld, p->forward_channel, false); - if (!c) + + if (!c) { + log_unusual(hp->channel->log, "No peer channel with scid=%s", + type_to_string(tmpctx, struct short_channel_id, + p->forward_channel)); return NULL; + } + peer = c->peer; } else { struct node_id id; - if (!p->forward_node_id) + if (!p->forward_node_id) { + log_unusual(hp->channel->log, + "Neither forward_channel nor " + "forward_node_id was set in payload"); return NULL; + } node_id_from_pubkey(&id, p->forward_node_id); peer = peer_by_id(ld, &id); - if (!peer) + + log_debug(hp->channel->log, "Looking up peer by node_id=%s", + type_to_string(tmpctx, struct node_id, &id)); + + if (!peer) { + log_unusual( + hp->channel->log, "No peer with node_id=%s", + type_to_string(tmpctx, struct node_id, &id)); return NULL; + } c = NULL; } @@ -1239,6 +1263,14 @@ static struct channel_id *calc_forwarding_channel(struct lightningd *ld, channel_scid_or_local_alias(best))); } + log_debug(hp->channel->log, + "Decided to forward htlc_id=%" PRIu64 + " over channel with scid=%s with peer %s", + hp->hin->key.id, + type_to_string(tmpctx, struct short_channel_id, + channel_scid_or_local_alias(best)), + type_to_string(tmpctx, struct node_id, &best->peer->id)); + return tal_dup(hp, struct channel_id, &best->cid); }