Browse Source

gossip: Track whether we read a message from store or peer

When we read from the gossip_store we set store=false so that we don't duplicate
messages in the store.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
a571bf9d3a
  1. 20
      gossipd/gossip.c
  2. 41
      gossipd/routing.c
  3. 9
      gossipd/routing.h

20
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));
err = handle_node_announcement(daemon->rstate, take(nannounce), true);
if (err)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"rejected own node announcement: %s",
@ -485,7 +485,7 @@ static void send_node_announcement(struct daemon *daemon)
}
/* Returns error if we should send an error. */
static u8 *handle_gossip_msg(struct daemon *daemon, const u8 *msg)
static u8 *handle_gossip_msg(struct daemon *daemon, const u8 *msg, bool store)
{
struct routing_state *rstate = daemon->rstate;
int t = fromwire_peektype(msg);
@ -495,7 +495,7 @@ static u8 *handle_gossip_msg(struct daemon *daemon, const u8 *msg)
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);
err = handle_channel_announcement(rstate, msg, &scid, store);
if (err)
return err;
else if (scid)
@ -506,13 +506,13 @@ static u8 *handle_gossip_msg(struct daemon *daemon, const u8 *msg)
}
case WIRE_NODE_ANNOUNCEMENT:
err = handle_node_announcement(rstate, msg);
err = handle_node_announcement(rstate, msg, store);
if (err)
return err;
break;
case WIRE_CHANNEL_UPDATE:
err = handle_channel_update(rstate, msg);
err = handle_channel_update(rstate, msg, store);
if (err)
return err;
break;
@ -617,7 +617,7 @@ static struct io_plan *peer_msgin(struct io_conn *conn,
case WIRE_CHANNEL_ANNOUNCEMENT:
case WIRE_NODE_ANNOUNCEMENT:
case WIRE_CHANNEL_UPDATE:
err = handle_gossip_msg(peer->daemon, msg);
err = handle_gossip_msg(peer->daemon, msg, true);
if (err)
queue_peer_msg(peer, take(err));
return peer_next_in(conn, peer);
@ -850,7 +850,7 @@ static struct io_plan *owner_msg_in(struct io_conn *conn,
int type = fromwire_peektype(msg);
if (type == WIRE_CHANNEL_ANNOUNCEMENT || type == WIRE_CHANNEL_UPDATE ||
type == WIRE_NODE_ANNOUNCEMENT) {
err = handle_gossip_msg(peer->daemon, dc->msg_in);
err = handle_gossip_msg(peer->daemon, dc->msg_in, true);
if (err)
queue_peer_msg(peer, take(err));
@ -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);
err = handle_channel_update(rstate, update, true);
if (err)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"rejected keepalive channel_update: %s",
@ -1533,7 +1533,7 @@ static bool master_conn_idle(struct io_conn *conn UNUSED,
msg = gossip_store_read_next(tmpctx, daemon->rstate->store);
if (msg) {
handle_gossip_msg(daemon, msg);
handle_gossip_msg(daemon, msg, false);
return true;
} else {
return false;
@ -1954,7 +1954,7 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn,
strerror(errno));
}
err = handle_channel_update(daemon->rstate, msg);
err = handle_channel_update(daemon->rstate, msg, true);
if (err)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"rejected disabling channel_update: %s",

41
gossipd/routing.c

@ -50,6 +50,9 @@ 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 {
@ -548,7 +551,8 @@ 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)
struct pubkey *nodeid,
bool store)
{
struct pending_node_announce *pna = pending_node_map_get(rstate->pending_node_map, &nodeid->pubkey);
if (!pna)
@ -561,7 +565,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);
err = handle_node_announcement(rstate, pna->node_announcement, store);
if (err)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"pending node_announcement %s malformed %s?",
@ -593,7 +597,8 @@ static void destroy_pending_cannouncement(struct pending_cannouncement *pending,
u8 *handle_channel_announcement(struct routing_state *rstate,
const u8 *announce TAKES,
const struct short_channel_id **scid)
const struct short_channel_id **scid,
bool store)
{
struct pending_cannouncement *pending;
struct bitcoin_blkid chain_hash;
@ -605,6 +610,7 @@ 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;
@ -727,7 +733,7 @@ ignored:
static void process_pending_channel_update(struct routing_state *rstate,
const struct short_channel_id *scid,
const u8 *cupdate)
const u8 *cupdate, bool store)
{
u8 *err;
@ -735,7 +741,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);
err = handle_channel_update(rstate, cupdate, store);
if (err) {
status_trace("Pending channel_update for %s: %s",
type_to_string(tmpctx, struct short_channel_id, scid),
@ -812,17 +818,18 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
"Announcement %s was replaced?",
tal_hex(tmpctx, pending->announce));
gossip_store_append(rstate->store, pending->announce);
if (pending->store)
gossip_store_append(rstate->store, pending->announce);
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]);
process_pending_channel_update(rstate, scid, pending->updates[1]);
process_pending_channel_update(rstate, scid, pending->updates[0], pending->store);
process_pending_channel_update(rstate, scid, pending->updates[1], pending->store);
process_pending_node_announcement(rstate, &pending->node_id_1);
process_pending_node_announcement(rstate, &pending->node_id_2);
process_pending_node_announcement(rstate, &pending->node_id_1, pending->store);
process_pending_node_announcement(rstate, &pending->node_id_2, pending->store);
tal_free(pending);
return local;
@ -883,7 +890,8 @@ void set_connection_values(struct chan *chan,
}
}
u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
u8 *handle_channel_update(struct routing_state *rstate, const u8 *update,
bool store)
{
u8 *serialized;
struct half_chan *c;
@ -983,7 +991,8 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
timestamp,
htlc_minimum_msat);
gossip_store_append(rstate->store, serialized);
if (store)
gossip_store_append(rstate->store, serialized);
replace_broadcast(chan, rstate->broadcasts,
&chan->half[direction].channel_update_msgidx,
take(serialized));
@ -1025,7 +1034,8 @@ static struct wireaddr *read_addresses(const tal_t *ctx, const u8 *ser)
return wireaddrs;
}
u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann,
bool store)
{
u8 *serialized;
struct sha256_double hash;
@ -1158,7 +1168,8 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
tal_free(node->alias);
node->alias = tal_dup_arr(node, u8, alias, 32, 0);
gossip_store_append(rstate->store, serialized);
if (store)
gossip_store_append(rstate->store, serialized);
replace_broadcast(node, rstate->broadcasts,
&node->node_announce_msgidx,
take(serialized));
@ -1318,7 +1329,7 @@ void routing_failure(struct routing_state *rstate,
(int) failcode);
return;
}
err = handle_channel_update(rstate, channel_update);
err = handle_channel_update(rstate, channel_update, true);
if (err) {
status_unusual("routing_failure: "
"bad channel_update %s",

9
gossipd/routing.h

@ -200,7 +200,8 @@ 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);
const struct short_channel_id **scid,
bool store);
/**
* handle_pending_cannouncement -- handle channel_announce once we've
@ -216,10 +217,12 @@ 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);
u8 *handle_channel_update(struct routing_state *rstate, const u8 *update,
bool store);
/* Returns NULL if all OK, otherwise an error for the peer which sent. */
u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node);
u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node,
bool store);
/* Set values on the struct node_connection */
void set_connection_values(struct chan *chan,

Loading…
Cancel
Save