Skip to content

Commit

Permalink
topology: listincoming: apply channel balances to public channels
Browse files Browse the repository at this point in the history
Since the receivable data is available from listpeerchannels, use that
for a more accurate inbound channel capacity.
  • Loading branch information
endothermicdev committed Aug 25, 2023
1 parent 6a0f81b commit e693f01
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions plugins/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand All @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit e693f01

Please sign in to comment.