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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-06-26 14:07:01 +09:30
parent c1a111b68c
commit 2b7915359c
2 changed files with 14 additions and 3 deletions

View File

@ -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])

View File

@ -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",