gossipd: check for existing channel announcement before sigcheck

Checking a signature is a CPU-intensive operation that should be performed only
if gossmap doesn't already have the channel announcement in question and we're
not already checking for the announcement's UTxO.

Changelog-Fixed: `gossipd` doesn't waste CPU cycles checking signatures on channel announcements that are already known
Issue: https://github.com/ElementsProject/lightning/issues/7972
This commit is contained in:
Matt Whitlock 2025-06-05 19:22:38 -04:00 committed by Alex Myers
parent ae320cd8d2
commit 3f6cd59dc9

View File

@ -588,6 +588,12 @@ const char *gossmap_manage_channel_announcement(const tal_t *ctx,
return NULL;
}
/* Already known? */
if (gossmap_find_chan(gossmap, &scid)
|| map_get(&gm->pending_ann_map, scid)
|| map_get(&gm->early_ann_map, scid))
return NULL;
warn = sigcheck_channel_announcement(ctx, &node_id_1, &node_id_2,
&bitcoin_key_1, &bitcoin_key_2,
&node_signature_1, &node_signature_2,
@ -596,10 +602,6 @@ const char *gossmap_manage_channel_announcement(const tal_t *ctx,
if (warn)
return warn;
/* Already known? */
if (gossmap_find_chan(gossmap, &scid))
return NULL;
pca = tal(gm, struct pending_cannounce);
pca->scriptpubkey = scriptpubkey_p2wsh(pca,
bitcoin_redeem_2of2(tmpctx,
@ -613,9 +615,7 @@ const char *gossmap_manage_channel_announcement(const tal_t *ctx,
/* Are we supposed to add immediately without checking with lightningd?
* Unless we already got it from a peer and we're processing now!
*/
if (known_amount
&& !map_get(&gm->pending_ann_map, scid)
&& !map_get(&gm->early_ann_map, scid)) {
if (known_amount) {
/* Set with timestamp 0 (we will update once we have a channel_update) */
gossip_store_add(gm->gs, announce, 0);
gossip_store_add(gm->gs,