From e693f01949e68bb2c92acf50372bf7b026466a80 Mon Sep 17 00:00:00 2001 From: Alex Myers Date: Fri, 25 Aug 2023 15:25:25 -0500 Subject: [PATCH] topology: listincoming: apply channel balances to public channels Since the receivable data is available from listpeerchannels, use that for a more accurate inbound channel capacity. --- plugins/topology.c | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/plugins/topology.c b/plugins/topology.c index 6d2567f55ac0..984518e01e72 100644 --- a/plugins/topology.c +++ b/plugins/topology.c @@ -514,30 +514,6 @@ static struct command_result *json_listnodes(struct command *cmd, return command_finished(cmd, js); } -/* What is capacity of peer attached to chan #n? */ -static struct amount_msat peer_capacity(const struct gossmap *gossmap, - const struct gossmap_node *me, - const struct gossmap_node *peer, - const struct gossmap_chan *ourchan) -{ - struct amount_msat capacity = AMOUNT_MSAT(0); - - for (size_t i = 0; i < peer->num_chans; i++) { - int dir; - struct gossmap_chan *c; - c = gossmap_nth_chan(gossmap, peer, i, &dir); - if (c == ourchan) - continue; - if (!c->half[!dir].enabled) - continue; - if (!amount_msat_add( - &capacity, capacity, - amount_msat(fp16_to_u64(c->half[!dir].htlc_max)))) - continue; - } - return capacity; -} - struct chanliquidity { struct short_channel_id scid; struct amount_msat receivable; @@ -644,6 +620,7 @@ static struct command_result *listprivateinbound_done(struct command *cmd, struct gossmap_node *peer; struct short_channel_id scid; const u8 *peer_features; + struct amount_msat htlc_max; ourchan = gossmap_nth_chan(gossmap, me, i, &dir); /* Entirely missing? Ignore. */ @@ -654,6 +631,8 @@ static struct command_result *listprivateinbound_done(struct command *cmd, * channel is disabled, so we still use them. */ peer = gossmap_nth_node(gossmap, ourchan, !dir); scid = gossmap_chan_scid(gossmap, ourchan); + htlc_max = amount_msat(fp16_to_u64(ourchan->half[!dir] + .htlc_max)); json_object_start(js, NULL); gossmap_node_get_id(gossmap, peer, &peer_id); @@ -664,14 +643,13 @@ static struct command_result *listprivateinbound_done(struct command *cmd, json_add_amount_msat(js, "htlc_min_msat", amount_msat(fp16_to_u64(ourchan->half[!dir] .htlc_min))); - json_add_amount_msat(js, "htlc_max_msat", - amount_msat(fp16_to_u64(ourchan->half[!dir] - .htlc_max))); + json_add_amount_msat(js, "htlc_max_msat", htlc_max); json_add_u32(js, "fee_proportional_millionths", ourchan->half[!dir].proportional_fee); json_add_u32(js, "cltv_expiry_delta", ourchan->half[!dir].delay); json_add_amount_msat(js, "incoming_capacity_msat", - peer_capacity(gossmap, me, peer, ourchan)); + max_receivable(&scid, &htlc_max, + liquidity)); json_add_bool(js, "public", !ourchan->private); peer_features = gossmap_node_get_features(tmpctx, gossmap, peer); if (peer_features)