From c4ea79cc5c1c871581d26b851be6b2b812d7172a Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 25 Mar 2018 18:30:47 +0200 Subject: [PATCH] Revert gossip: Track whether we read a message from store or peer Messages from peers and messages from the gossip_store now have completely different entrypoints, so we don't need to trace their origin around the message handling code any longer. --- gossipd/gossip.c | 12 ++++++------ gossipd/routing.c | 39 ++++++++++++++------------------------- gossipd/routing.h | 9 +++------ 3 files changed, 23 insertions(+), 37 deletions(-) diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 61b725573..ee2f8f525 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -477,7 +477,7 @@ static void send_node_announcement(struct daemon *daemon) * from the HSM, create the real announcement and forward it to * gossipd so it can take care of forwarding it. */ nannounce = create_node_announcement(NULL, daemon, &sig, timestamp); - err = handle_node_announcement(daemon->rstate, take(nannounce), true); + err = handle_node_announcement(daemon->rstate, take(nannounce)); if (err) status_failed(STATUS_FAIL_INTERNAL_ERROR, "rejected own node announcement: %s", @@ -495,7 +495,7 @@ static u8 *handle_gossip_msg(struct daemon *daemon, const u8 *msg, bool store) case WIRE_CHANNEL_ANNOUNCEMENT: { const struct short_channel_id *scid; /* If it's OK, tells us the short_channel_id to lookup */ - err = handle_channel_announcement(rstate, msg, &scid, store); + err = handle_channel_announcement(rstate, msg, &scid); if (err) return err; else if (scid) @@ -506,13 +506,13 @@ static u8 *handle_gossip_msg(struct daemon *daemon, const u8 *msg, bool store) } case WIRE_NODE_ANNOUNCEMENT: - err = handle_node_announcement(rstate, msg, store); + err = handle_node_announcement(rstate, msg); if (err) return err; break; case WIRE_CHANNEL_UPDATE: - err = handle_channel_update(rstate, msg, store); + err = handle_channel_update(rstate, msg); if (err) return err; break; @@ -1370,7 +1370,7 @@ static void gossip_send_keepalive_update(struct routing_state *rstate, status_trace("Sending keepalive channel_update for %s", type_to_string(tmpctx, struct short_channel_id, &scid)); - err = handle_channel_update(rstate, update, true); + err = handle_channel_update(rstate, update); if (err) status_failed(STATUS_FAIL_INTERNAL_ERROR, "rejected keepalive channel_update: %s", @@ -1954,7 +1954,7 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn, strerror(errno)); } - err = handle_channel_update(daemon->rstate, msg, true); + err = handle_channel_update(daemon->rstate, msg); if (err) status_failed(STATUS_FAIL_INTERNAL_ERROR, "rejected disabling channel_update: %s", diff --git a/gossipd/routing.c b/gossipd/routing.c index c2c6e0a94..9932a9187 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -50,9 +50,6 @@ struct pending_cannouncement { /* Only ever replace with newer updates */ u32 update_timestamps[2]; - - /* Was this from a peer and should be stored? */ - bool store; }; struct pending_node_announce { @@ -551,8 +548,7 @@ static void add_pending_node_announcement(struct routing_state *rstate, struct p } static void process_pending_node_announcement(struct routing_state *rstate, - struct pubkey *nodeid, - bool store) + struct pubkey *nodeid) { struct pending_node_announce *pna = pending_node_map_get(rstate->pending_node_map, &nodeid->pubkey); if (!pna) @@ -565,7 +561,7 @@ static void process_pending_node_announcement(struct routing_state *rstate, type_to_string(pna, struct pubkey, nodeid)); /* Should not error, since we processed it before */ - err = handle_node_announcement(rstate, pna->node_announcement, store); + err = handle_node_announcement(rstate, pna->node_announcement); if (err) status_failed(STATUS_FAIL_INTERNAL_ERROR, "pending node_announcement %s malformed %s?", @@ -632,8 +628,7 @@ void routing_add_channel_announcement(struct routing_state *rstate, u8 *handle_channel_announcement(struct routing_state *rstate, const u8 *announce TAKES, - const struct short_channel_id **scid, - bool store) + const struct short_channel_id **scid) { struct pending_cannouncement *pending; struct bitcoin_blkid chain_hash; @@ -645,7 +640,6 @@ u8 *handle_channel_announcement(struct routing_state *rstate, pending = tal(rstate, struct pending_cannouncement); pending->updates[0] = NULL; pending->updates[1] = NULL; - pending->store = store; pending->announce = tal_dup_arr(pending, u8, announce, tal_len(announce), 0); pending->update_timestamps[0] = pending->update_timestamps[1] = 0; @@ -768,7 +762,7 @@ ignored: static void process_pending_channel_update(struct routing_state *rstate, const struct short_channel_id *scid, - const u8 *cupdate, bool store) + const u8 *cupdate) { u8 *err; @@ -776,7 +770,7 @@ static void process_pending_channel_update(struct routing_state *rstate, return; /* FIXME: We don't remember who sent us updates, so can't error them */ - err = handle_channel_update(rstate, cupdate, store); + err = handle_channel_update(rstate, cupdate); if (err) { status_trace("Pending channel_update for %s: %s", type_to_string(tmpctx, struct short_channel_id, scid), @@ -832,19 +826,18 @@ bool handle_pending_cannouncement(struct routing_state *rstate, return false; } - if (pending->store) - gossip_store_add_channel_announcement(rstate->store, pending->announce, satoshis); + gossip_store_add_channel_announcement(rstate->store, pending->announce, satoshis); routing_add_channel_announcement(rstate, pending->announce, satoshis); local = pubkey_eq(&pending->node_id_1, &rstate->local_id) || pubkey_eq(&pending->node_id_2, &rstate->local_id); /* Did we have an update waiting? If so, apply now. */ - process_pending_channel_update(rstate, scid, pending->updates[0], pending->store); - process_pending_channel_update(rstate, scid, pending->updates[1], pending->store); + process_pending_channel_update(rstate, scid, pending->updates[0]); + process_pending_channel_update(rstate, scid, pending->updates[1]); - process_pending_node_announcement(rstate, &pending->node_id_1, pending->store); - process_pending_node_announcement(rstate, &pending->node_id_2, pending->store); + process_pending_node_announcement(rstate, &pending->node_id_1); + process_pending_node_announcement(rstate, &pending->node_id_2); tal_free(pending); return local; @@ -936,8 +929,7 @@ void routing_add_channel_update(struct routing_state *rstate, take(update)); } -u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, - bool store) +u8 *handle_channel_update(struct routing_state *rstate, const u8 *update) { u8 *serialized; struct half_chan *c; @@ -1100,8 +1092,7 @@ void routing_add_node_announcement(struct routing_state *rstate, const u8 *msg T take(msg)); } -u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann, - bool store) +u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann) { u8 *serialized; struct sha256_double hash; @@ -1225,9 +1216,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann, status_trace("Received node_announcement for node %s", type_to_string(tmpctx, struct pubkey, &node_id)); - /* FIXME: remove store guard */ - if (store) - gossip_store_add_node_announcement(rstate->store, serialized); + gossip_store_add_node_announcement(rstate->store, serialized); routing_add_node_announcement(rstate, serialized); return NULL; } @@ -1385,7 +1374,7 @@ void routing_failure(struct routing_state *rstate, (int) failcode); return; } - err = handle_channel_update(rstate, channel_update, true); + err = handle_channel_update(rstate, channel_update); if (err) { status_unusual("routing_failure: " "bad channel_update %s", diff --git a/gossipd/routing.h b/gossipd/routing.h index 102ebd43b..32ca3c7a8 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -200,8 +200,7 @@ struct chan *new_chan(struct routing_state *rstate, */ u8 *handle_channel_announcement(struct routing_state *rstate, const u8 *announce TAKES, - const struct short_channel_id **scid, - bool store); + const struct short_channel_id **scid); /** * handle_pending_cannouncement -- handle channel_announce once we've @@ -217,12 +216,10 @@ bool handle_pending_cannouncement(struct routing_state *rstate, const u8 *txscript); /* Returns NULL if all OK, otherwise an error for the peer which sent. */ -u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, - bool store); +u8 *handle_channel_update(struct routing_state *rstate, const u8 *update); /* Returns NULL if all OK, otherwise an error for the peer which sent. */ -u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node, - bool store); +u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node); /* Set values on the struct node_connection */ void set_connection_values(struct chan *chan,