Skip to content

Commit 3f6cd59

Browse files
whitslackendothermicdev
authored andcommitted
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: #7972
1 parent ae320cd commit 3f6cd59

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

gossipd/gossmap_manage.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,12 @@ const char *gossmap_manage_channel_announcement(const tal_t *ctx,
588588
return NULL;
589589
}
590590

591+
/* Already known? */
592+
if (gossmap_find_chan(gossmap, &scid)
593+
|| map_get(&gm->pending_ann_map, scid)
594+
|| map_get(&gm->early_ann_map, scid))
595+
return NULL;
596+
591597
warn = sigcheck_channel_announcement(ctx, &node_id_1, &node_id_2,
592598
&bitcoin_key_1, &bitcoin_key_2,
593599
&node_signature_1, &node_signature_2,
@@ -596,10 +602,6 @@ const char *gossmap_manage_channel_announcement(const tal_t *ctx,
596602
if (warn)
597603
return warn;
598604

599-
/* Already known? */
600-
if (gossmap_find_chan(gossmap, &scid))
601-
return NULL;
602-
603605
pca = tal(gm, struct pending_cannounce);
604606
pca->scriptpubkey = scriptpubkey_p2wsh(pca,
605607
bitcoin_redeem_2of2(tmpctx,
@@ -613,9 +615,7 @@ const char *gossmap_manage_channel_announcement(const tal_t *ctx,
613615
/* Are we supposed to add immediately without checking with lightningd?
614616
* Unless we already got it from a peer and we're processing now!
615617
*/
616-
if (known_amount
617-
&& !map_get(&gm->pending_ann_map, scid)
618-
&& !map_get(&gm->early_ann_map, scid)) {
618+
if (known_amount) {
619619
/* Set with timestamp 0 (we will update once we have a channel_update) */
620620
gossip_store_add(gm->gs, announce, 0);
621621
gossip_store_add(gm->gs,

0 commit comments

Comments
 (0)