From 30c1ab424f340fb7d3fb1453f0e14e67e7e82a8f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 11 Apr 2018 08:33:24 +0930 Subject: [PATCH] gossipd: reorder handle_node_announcement I found the logic a bit confusing, so this reworks to bunch the "no node" cases together. Signed-off-by: Rusty Russell --- gossipd/routing.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/gossipd/routing.c b/gossipd/routing.c index a68da88a1..30e7cdf3c 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -1195,38 +1195,39 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann) /* Beyond this point it's not malformed, so safe if we make it * pending and requeue later. */ node = get_node(rstate, &node_id); - if (node && !node_has_public_channels(node)) - node = NULL; - /* Check if we are currently verifying the txout for a - * matching channel */ - pna = pending_node_map_get(rstate->pending_node_map, &node_id.pubkey); - if (!node && pna) { - if (pna->timestamp < timestamp) { + /* BOLT #7: + * + * - if `node_id` is NOT previously known from a `channel_announcement` + * message, OR if `timestamp` is NOT greater than the last-received + * `node_announcement` from this `node_id`: + * - SHOULD ignore the message. + */ + if (!node || !node_has_public_channels(node)) { + /* Check if we are currently verifying the txout for a + * matching channel */ + pna = pending_node_map_get(rstate->pending_node_map, + &node_id.pubkey); + if (!pna) { + SUPERVERBOSE("Node not found, was the node_announcement " + "for node %s preceded by at least " + "channel_announcement?", + type_to_string(tmpctx, struct pubkey, + &node_id)); + } else if (pna->timestamp < timestamp) { SUPERVERBOSE( "Deferring node_announcement for node %s", type_to_string(tmpctx, struct pubkey, &node_id)); pna->timestamp = timestamp; tal_free(pna->node_announcement); - pna->node_announcement = tal_dup_arr(pna, u8, node_ann, tal_len(node_ann), 0); + pna->node_announcement = tal_dup_arr(pna, u8, node_ann, + tal_len(node_ann), + 0); } return NULL; } - /* BOLT #7: - * - * - if `node_id` is NOT previously known from a - * `channel_announcement` message, OR if `timestamp` is NOT greater - * than the last-received `node_announcement` from this `node_id`: - * - SHOULD ignore the message. - */ - if (!node) { - SUPERVERBOSE("Node not found, was the node_announcement for " - "node %s preceded by at least " - "channel_announcement?", - type_to_string(tmpctx, struct pubkey, &node_id)); - return NULL; - } else if (node->last_timestamp >= timestamp) { + if (node->last_timestamp >= timestamp) { SUPERVERBOSE("Ignoring node announcement, it's outdated."); return NULL; }