Skip to content

Commit a0ed611

Browse files
rustyrussellcdecker
authored andcommitted
gossipd: make sure to mark node_announcement dying if we fast-path remove last channel.
Normally, channels are marked dying, the 12 blocks later, removed. But for local channels, we can access any spliced channel already, so we remove them immediately from our local gossip. This left a hole in our logic, if that channel was the last one keeping a node_announcement alive. Solution is to unify with the "moved node_announcement" path. Signed-off-by: Rusty Russell <[email protected]>
1 parent f57d1f4 commit a0ed611

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

gossipd/gossmap_manage.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static bool all_node_channels_dying(struct gossmap *gossmap,
243243
* - Suppress future lookups in case we receive another channel_update.
244244
* - Put deleted tombstone in gossip_store.
245245
* - Mark records deleted in gossip_store.
246-
* - See if node_announcement(s) need to be removed, or moved.
246+
* - See if node_announcement(s) need to be removed, marked dying, or moved.
247247
*/
248248
static void remove_channel(struct gossmap_manage *gm,
249249
struct gossmap *gossmap,
@@ -272,8 +272,6 @@ static void remove_channel(struct gossmap_manage *gm,
272272
/* Check for node_announcements which should no longer be there */
273273
for (int dir = 0; dir < 2; dir++) {
274274
struct gossmap_node *node;
275-
const u8 *nannounce;
276-
u32 timestamp;
277275
u64 offset;
278276

279277
node = gossmap_nth_node(gossmap, chan, dir);
@@ -289,18 +287,26 @@ static void remove_channel(struct gossmap_manage *gm,
289287
}
290288

291289
/* Maybe this was the last channel_announcement which preceeded node_announcement? */
292-
if (chan->cann_off > node->nann_off)
293-
continue;
294-
295-
if (any_cannounce_preceeds_offset(gossmap, node, chan, node->nann_off))
296-
continue;
290+
if (chan->cann_off < node->nann_off
291+
&& any_cannounce_preceeds_offset(gossmap, node, chan, node->nann_off)) {
292+
const u8 *nannounce;
293+
u32 timestamp;
297294

298-
/* To maintain order, delete and re-add node_announcement */
299-
nannounce = gossmap_node_get_announce(tmpctx, gossmap, node);
300-
timestamp = gossip_store_get_timestamp(gm->daemon->gs, node->nann_off);
295+
/* To maintain order, delete and re-add node_announcement */
296+
nannounce = gossmap_node_get_announce(tmpctx, gossmap, node);
297+
timestamp = gossip_store_get_timestamp(gm->daemon->gs, node->nann_off);
301298

302-
gossip_store_del(gm->daemon->gs, node->nann_off, WIRE_NODE_ANNOUNCEMENT);
303-
offset = gossip_store_add(gm->daemon->gs, nannounce, timestamp);
299+
gossip_store_del(gm->daemon->gs, node->nann_off, WIRE_NODE_ANNOUNCEMENT);
300+
offset = gossip_store_add(gm->daemon->gs, nannounce, timestamp);
301+
} else {
302+
/* Are all remaining channels dying but we weren't?
303+
* Can happen if we removed this channel immediately
304+
* for our own channels, without marking them
305+
* dying. */
306+
if (gossmap_chan_is_dying(gossmap, chan))
307+
continue;
308+
offset = node->nann_off;
309+
}
304310

305311
/* Be sure to set DYING flag when we move (ignore current
306312
* channel, we haven't reloaded gossmap yet!) */

0 commit comments

Comments
 (0)