From 2b7915359cfecaa8a4926e36088c321e3896e7e1 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 26 Jun 2022 14:07:01 +0930 Subject: [PATCH] gossmap: handle case where private channel turns into public. Usually we won't see this, since private is deleted. But we could have already read the private channel before that. Handle it properly. (Tested by removing the gossip_store deletion code and making sure this worked). We have to fix up the test, which announces a channel twice! Signed-off-by: Rusty Russell --- common/gossmap.c | 11 +++++++++++ common/test/run-route-specific.c | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/gossmap.c b/common/gossmap.c index 277e87d99..918fb913a 100644 --- a/common/gossmap.c +++ b/common/gossmap.c @@ -398,6 +398,7 @@ static struct gossmap_chan *add_channel(struct gossmap *map, const size_t feature_len_off = 2 + (64 + 64 + 64 + 64); size_t feature_len; size_t plus_scid_off; + struct short_channel_id scid; struct node_id node_id[2]; struct gossmap_node *n[2]; struct gossmap_chan *chan; @@ -409,6 +410,16 @@ static struct gossmap_chan *add_channel(struct gossmap *map, map_nodeid(map, cannounce_off + plus_scid_off + 8, &node_id[0]); map_nodeid(map, cannounce_off + plus_scid_off + 8 + PUBKEY_CMPR_LEN, &node_id[1]); + /* We can have a channel upgrade from private->public, but + * that's the only time we get duplicates */ + scid.u64 = map_be64(map, cannounce_off + plus_scid_off); + chan = gossmap_find_chan(map, &scid); + if (chan) { + assert(chan->private); + assert(!private); + gossmap_remove_chan(map, chan); + } + /* We carefully map pointers to indexes, since new_node can move them! */ n[0] = gossmap_find_node(map, &node_id[0]); if (n[0]) diff --git a/common/test/run-route-specific.c b/common/test/run-route-specific.c index 01d12f94f..3a1488c49 100644 --- a/common/test/run-route-specific.c +++ b/common/test/run-route-specific.c @@ -215,9 +215,9 @@ int main(int argc, char *argv[]) 0, 10, 5); /* {'active': True, 'short_id': '6990:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 0, 'destination': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, */ - add_connection(store_fd, &b, &c, "6990x2x1", - AMOUNT_MSAT(100), AMOUNT_MSAT(1000), - 0, 10, 5); + update_connection(store_fd, &b, &c, "6990x2x1", + AMOUNT_MSAT(100), AMOUNT_MSAT(1000), + 0, 10, 5, false); /* {'active': True, 'short_id': '6989:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'last_update': 1504064344}]} */ update_connection(store_fd, &a, &b, "6989x2x1",