Skip to content

Commit

Permalink
listincoming: deduplicate listed channels
Browse files Browse the repository at this point in the history
Where an unannounced channel with a private update has been added to the
gossip_store, make sure not to add it as both a public and private
channel.
  • Loading branch information
endothermicdev committed Aug 29, 2023
1 parent d68b61e commit c144301
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions plugins/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ static struct amount_msat max_receivable(struct short_channel_id *scid,

static void add_private_channel(struct json_stream *js, const char *buf,
const jsmntok_t *channel,
struct chanliquidity *liquidity)
struct chanliquidity *liquidity,
struct short_channel_id *processed_channels)
{
const jsmntok_t *node_id_tok, *scid_tok, *fee_base_tok;
const jsmntok_t *fee_ppm_tok, *cltv_tok;
Expand All @@ -546,16 +547,30 @@ static void add_private_channel(struct json_stream *js, const char *buf,
u32 fee_base, fee_ppm, cltv_delta;
struct amount_msat htlc_min, htlc_max;
u8 *features;

scid_tok = json_get_member(buf, channel, "short_channel_id");
if (scid_tok) {
json_to_short_channel_id(buf, scid_tok, &scid);
/* check if we've already used this from the gossmap
* public channels */
for (size_t i = 0; i < tal_count(processed_channels); i++) {
if (short_channel_id_eq(&scid, &processed_channels[i]))
return;
}
}

scid_tok = json_get_member(buf, channel, "remote_alias");
if (!scid_tok)
scid_tok = json_get_member(buf, channel, "short_channel_id");
json_to_short_channel_id(buf, scid_tok, &scid);

json_object_start(js, NULL);

node_id_tok = json_get_member(buf, channel, "id");
assert(node_id_tok);
json_to_node_id(buf, node_id_tok, &id);
json_add_node_id(js, "id", &id);

scid_tok = json_get_member(buf, channel, "remote_alias");
assert(scid_tok);
json_to_short_channel_id(buf, scid_tok, &scid);
json_add_short_channel_id(js, "short_channel_id", &scid);

fee_base_tok = json_get_member(buf, channel, "fee_base");
Expand Down Expand Up @@ -605,6 +620,8 @@ static struct command_result *listprivateinbound_done(struct command *cmd,
struct json_stream *js;
struct gossmap_node *me;
struct gossmap *gossmap;
struct short_channel_id *processed_channels = tal_arr(cmd,
struct short_channel_id, 0);
js = jsonrpc_stream_success(cmd);

json_array_start(js, "incoming");
Expand Down Expand Up @@ -658,6 +675,7 @@ static struct command_result *listprivateinbound_done(struct command *cmd,
if (peer_features)
json_add_hex_talarr(js, "peer_features", peer_features);
json_object_end(js);
tal_arr_expand(&processed_channels, scid);
}

public_done:
Expand All @@ -669,10 +687,12 @@ static struct command_result *listprivateinbound_done(struct command *cmd,
size_t i;

json_for_each_arr(i, channel, channels) {
add_private_channel(js, buf, channel, liquidity);
add_private_channel(js, buf, channel, liquidity,
processed_channels);
}

json_array_end(js);
tal_free(processed_channels);

return command_finished(cmd, js);
}
Expand Down

0 comments on commit c144301

Please sign in to comment.