From 7a651c62fa80f827369eecbc379552bc2b4397c4 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 30 Jan 2018 00:39:48 +0100 Subject: [PATCH] gossip: Pull up the check for new channels before checking the txout We drop all but the first announcement, so any work that is done for a channel that we already know is wasted. Pulling this up duplicates some of the work but allows us to skip the costly txout check. Signed-off-by: Christian Decker --- gossipd/routing.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gossipd/routing.c b/gossipd/routing.c index 768bfbb32..46d6c4e3d 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -545,6 +545,7 @@ const struct short_channel_id *handle_channel_announcement( const char *tag; secp256k1_ecdsa_signature node_signature_1, node_signature_2; secp256k1_ecdsa_signature bitcoin_signature_1, bitcoin_signature_2; + struct node_connection *c0, *c1; pending = tal(rstate, struct pending_cannouncement); pending->updates[0] = NULL; @@ -619,10 +620,16 @@ const struct short_channel_id *handle_channel_announcement( /* FIXME: Handle duplicates as per BOLT #7 */ - if (find_pending_cannouncement(rstate, &pending->short_channel_id) != NULL) { - /* Drop it like it's hot */ + c0 = get_connection(rstate, &pending->node_id_2, &pending->node_id_1); + c1 = get_connection(rstate, &pending->node_id_1, &pending->node_id_2); + + /* If we know the channels, or we have already a pending check, then skip */ + if ((c0 != NULL && c1 != NULL) || + find_pending_cannouncement(rstate, &pending->short_channel_id) != + NULL) { return tal_free(pending); } + list_add_tail(&rstate->pending_cannouncement, &pending->list); return &pending->short_channel_id; }