Skip to content

Commit

Permalink
gossipd: move gossip_store pointer from struct routing_state to daemon.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Feb 3, 2024
1 parent 6657488 commit af64d30
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 deletions.
11 changes: 6 additions & 5 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void queue_peer_msg(struct daemon *daemon,
void queue_peer_from_store(struct peer *peer,
const struct broadcastable *bcast)
{
struct gossip_store *gs = peer->daemon->rstate->gs;
struct gossip_store *gs = peer->daemon->gs;
queue_peer_msg(peer->daemon, &peer->id,
take(gossip_store_get(NULL, gs, bcast->index)));
}
Expand All @@ -128,7 +128,7 @@ static bool get_node_announcement(const tal_t *ctx,
if (!n->bcast.index)
return false;

msg = gossip_store_get(tmpctx, daemon->rstate->gs, n->bcast.index);
msg = gossip_store_get(tmpctx, daemon->gs, n->bcast.index);

/* Note: validity of node_id is already checked. */
if (!fromwire_node_announcement(ctx, msg,
Expand Down Expand Up @@ -599,7 +599,7 @@ static void tell_master_local_cupdates(struct daemon *daemon)
continue;

cupdate = gossip_store_get(tmpctx,
daemon->rstate->gs,
daemon->gs,
hc->bcast.index);
daemon_conn_send(daemon->master,
take(towire_gossipd_init_cupdate(NULL,
Expand All @@ -611,7 +611,7 @@ static void tell_master_local_cupdates(struct daemon *daemon)
if (me->bcast.index) {
const u8 *nannounce;
nannounce = gossip_store_get(tmpctx,
daemon->rstate->gs,
daemon->gs,
me->bcast.index);
daemon_conn_send(daemon->master,
take(towire_gossipd_init_nannounce(NULL,
Expand Down Expand Up @@ -696,11 +696,12 @@ static void gossip_init(struct daemon *daemon, const u8 *msg)
tal_free(dev_gossip_time);
}

daemon->gs = gossip_store_new(daemon);
daemon->rstate = new_routing_state(daemon, daemon);

/* Load stored gossip messages (FIXME: API sucks)*/
daemon->gossip_store_populated =
(gossip_store_load(daemon->rstate->gs) != 0);
(gossip_store_load(daemon->gs) != 0);

/* Start the twice- weekly refresh timer. */
notleak(new_reltimer(&daemon->timers, daemon,
Expand Down
3 changes: 3 additions & 0 deletions gossipd/gossipd.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ struct daemon {
/* Features lightningd told us to set. */
struct feature_set *our_features;

/* Gossip store */
struct gossip_store *gs;

/* Was there anything in the gossip store at startup? */
bool gossip_store_populated;

Expand Down
2 changes: 1 addition & 1 deletion gossipd/queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ static void get_checksum_and_timestamp(struct routing_state *rstate,
if (!is_halfchan_defined(hc)) {
*tstamp = *csum = 0;
} else {
const u8 *update = gossip_store_get(tmpctx, rstate->gs,
const u8 *update = gossip_store_get(tmpctx, rstate->daemon->gs,
hc->bcast.index);
*tstamp = hc->bcast.timestamp;
*csum = crc32_of_update(update);
Expand Down
81 changes: 40 additions & 41 deletions gossipd/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ struct routing_state *new_routing_state(const tal_t *ctx,
struct routing_state *rstate = tal(ctx, struct routing_state);
rstate->daemon = daemon;
rstate->nodes = new_node_map(rstate);
rstate->gs = gossip_store_new(daemon);
rstate->dying_channels = tal_arr(rstate, struct dying_channel, 0);

rstate->pending_cannouncements = tal(rstate, struct pending_cannouncement_map);
Expand Down Expand Up @@ -371,13 +370,13 @@ static void force_node_announce_rexmit(struct routing_state *rstate,
struct node *node)
{
const u8 *announce;
announce = gossip_store_get(tmpctx, rstate->gs, node->bcast.index);
announce = gossip_store_get(tmpctx, rstate->daemon->gs, node->bcast.index);

u32 initial_bcast_index = node->bcast.index;
gossip_store_delete(rstate->gs,
gossip_store_delete(rstate->daemon->gs,
&node->bcast,
WIRE_NODE_ANNOUNCEMENT);
node->bcast.index = gossip_store_add(rstate->gs,
node->bcast.index = gossip_store_add(rstate->daemon->gs,
announce,
node->bcast.timestamp,
false,
Expand All @@ -387,11 +386,11 @@ static void force_node_announce_rexmit(struct routing_state *rstate,
if (node->rgraph.index == initial_bcast_index){
node->rgraph.index = node->bcast.index;
} else {
announce = gossip_store_get(tmpctx, rstate->gs, node->rgraph.index);
gossip_store_delete(rstate->gs,
announce = gossip_store_get(tmpctx, rstate->daemon->gs, node->rgraph.index);
gossip_store_delete(rstate->daemon->gs,
&node->rgraph,
WIRE_NODE_ANNOUNCEMENT);
node->rgraph.index = gossip_store_add(rstate->gs,
node->rgraph.index = gossip_store_add(rstate->daemon->gs,
announce,
node->rgraph.timestamp,
false,
Expand Down Expand Up @@ -423,10 +422,10 @@ static void remove_chan_from_node(struct routing_state *rstate,
/* Last channel? Simply delete node (and associated announce) */
if (num_chans == 0) {
if (node->rgraph.index != node->bcast.index)
gossip_store_delete(rstate->gs,
gossip_store_delete(rstate->daemon->gs,
&node->rgraph,
WIRE_NODE_ANNOUNCEMENT);
gossip_store_delete(rstate->gs,
gossip_store_delete(rstate->daemon->gs,
&node->bcast,
WIRE_NODE_ANNOUNCEMENT);
tal_free(node);
Expand All @@ -440,10 +439,10 @@ static void remove_chan_from_node(struct routing_state *rstate,
/* Removed only public channel? Remove node announcement. */
if (!node_has_broadcastable_channels(node)) {
if (node->rgraph.index != node->bcast.index)
gossip_store_delete(rstate->gs,
gossip_store_delete(rstate->daemon->gs,
&node->rgraph,
WIRE_NODE_ANNOUNCEMENT);
gossip_store_delete(rstate->gs,
gossip_store_delete(rstate->daemon->gs,
&node->bcast,
WIRE_NODE_ANNOUNCEMENT);
node->rgraph.index = node->bcast.index = 0;
Expand Down Expand Up @@ -673,7 +672,7 @@ static void add_channel_announce_to_broadcast(struct routing_state *rstate,
if (index)
chan->bcast.index = index;
else
chan->bcast.index = gossip_store_add(rstate->gs,
chan->bcast.index = gossip_store_add(rstate->daemon->gs,
channel_announce,
chan->bcast.timestamp,
false,
Expand All @@ -686,17 +685,17 @@ static void delete_chan_messages_from_store(struct routing_state *rstate,
struct chan *chan)
{
/* If these aren't in the store, these are noops. */
gossip_store_delete(rstate->gs,
gossip_store_delete(rstate->daemon->gs,
&chan->bcast, WIRE_CHANNEL_ANNOUNCEMENT);
if (chan->half[0].rgraph.index != chan->half[0].bcast.index)
gossip_store_delete(rstate->gs,
gossip_store_delete(rstate->daemon->gs,
&chan->half[0].rgraph, WIRE_CHANNEL_UPDATE);
gossip_store_delete(rstate->gs,
gossip_store_delete(rstate->daemon->gs,
&chan->half[0].bcast, WIRE_CHANNEL_UPDATE);
if (chan->half[1].rgraph.index != chan->half[1].bcast.index)
gossip_store_delete(rstate->gs,
gossip_store_delete(rstate->daemon->gs,
&chan->half[1].rgraph, WIRE_CHANNEL_UPDATE);
gossip_store_delete(rstate->gs,
gossip_store_delete(rstate->daemon->gs,
&chan->half[1].bcast, WIRE_CHANNEL_UPDATE);
}

Expand All @@ -705,7 +704,7 @@ static void remove_channel_from_store(struct routing_state *rstate,
{
/* Put in tombstone marker. Zombie channels will have one already. */
if (!is_chan_zombie(chan))
gossip_store_mark_channel_deleted(rstate->gs, &chan->scid);
gossip_store_mark_channel_deleted(rstate->daemon->gs, &chan->scid);

/* Now delete old entries. */
delete_chan_messages_from_store(rstate, chan);
Expand Down Expand Up @@ -1076,7 +1075,7 @@ static void delete_spam_update(struct routing_state *rstate,
/* Spam updates will have a unique rgraph index */
if (hc->rgraph.index == hc->bcast.index)
return;
gossip_store_delete(rstate->gs, &hc->rgraph,
gossip_store_delete(rstate->daemon->gs, &hc->rgraph,
WIRE_CHANNEL_UPDATE);
hc->rgraph.index = hc->bcast.index;
hc->rgraph.timestamp = hc->bcast.timestamp;
Expand Down Expand Up @@ -1231,7 +1230,7 @@ bool routing_add_channel_update(struct routing_state *rstate,

/* Allow redundant updates once every 7 days */
if (timestamp < hc->bcast.timestamp + GOSSIP_PRUNE_INTERVAL(rstate->daemon->dev_fast_gossip_prune) / 2
&& !cupdate_different(rstate->gs, hc, update)) {
&& !cupdate_different(rstate->daemon->gs, hc, update)) {
SUPERVERBOSE("Ignoring redundant update for %s/%u"
" (last %u, now %u)",
type_to_string(tmpctx,
Expand Down Expand Up @@ -1267,7 +1266,7 @@ bool routing_add_channel_update(struct routing_state *rstate,
/* Delete any prior entries (noop if they don't exist) */
delete_spam_update(rstate, hc);
if (!spam)
gossip_store_delete(rstate->gs, &hc->bcast,
gossip_store_delete(rstate->daemon->gs, &hc->bcast,
WIRE_CHANNEL_UPDATE);

/* Update timestamp(s) */
Expand Down Expand Up @@ -1319,41 +1318,41 @@ bool routing_add_channel_update(struct routing_state *rstate,
/* Resurrection is a careful process. First delete the zombie-
* flagged channel_announcement which has already been
* tombstoned, and re-add to the store without zombie flag. */
zombie_announcement = gossip_store_get(tmpctx, rstate->gs,
zombie_announcement = gossip_store_get(tmpctx, rstate->daemon->gs,
chan->bcast.index);
u32 offset = tal_count(zombie_announcement) +
sizeof(struct gossip_hdr);
/* The channel_announcement addendum reminds us of its size. */
zombie_addendum = gossip_store_get(tmpctx, rstate->gs,
zombie_addendum = gossip_store_get(tmpctx, rstate->daemon->gs,
chan->bcast.index + offset);
gossip_store_delete(rstate->gs, &chan->bcast,
gossip_store_delete(rstate->daemon->gs, &chan->bcast,
WIRE_CHANNEL_ANNOUNCEMENT);
chan->bcast.index =
gossip_store_add(rstate->gs, zombie_announcement,
gossip_store_add(rstate->daemon->gs, zombie_announcement,
chan->bcast.timestamp,
false, false, false, zombie_addendum);
/* Deletion of the old addendum is optional. */
/* This opposing channel_update has been stashed away. Now that
* there are two valid updates, this one gets restored. */
/* FIXME: Handle spam case probably needs a helper f'n */
zombie_update[0] = gossip_store_get(tmpctx, rstate->gs,
zombie_update[0] = gossip_store_get(tmpctx, rstate->daemon->gs,
chan->half[!direction].bcast.index);
if (chan->half[!direction].bcast.index != chan->half[!direction].rgraph.index) {
/* Don't forget the spam channel_update */
zombie_update[1] = gossip_store_get(tmpctx, rstate->gs,
zombie_update[1] = gossip_store_get(tmpctx, rstate->daemon->gs,
chan->half[!direction].rgraph.index);
gossip_store_delete(rstate->gs, &chan->half[!direction].rgraph,
gossip_store_delete(rstate->daemon->gs, &chan->half[!direction].rgraph,
WIRE_CHANNEL_UPDATE);
}
gossip_store_delete(rstate->gs, &chan->half[!direction].bcast,
gossip_store_delete(rstate->daemon->gs, &chan->half[!direction].bcast,
WIRE_CHANNEL_UPDATE);
chan->half[!direction].bcast.index =
gossip_store_add(rstate->gs, zombie_update[0],
gossip_store_add(rstate->daemon->gs, zombie_update[0],
chan->half[!direction].bcast.timestamp,
false, false, false, NULL);
if (zombie_update[1])
chan->half[!direction].rgraph.index =
gossip_store_add(rstate->gs, zombie_update[1],
gossip_store_add(rstate->daemon->gs, zombie_update[1],
chan->half[!direction].rgraph.timestamp,
false, true, false, NULL);
else
Expand All @@ -1372,7 +1371,7 @@ bool routing_add_channel_update(struct routing_state *rstate,
hc->rgraph.index = index;
} else {
hc->rgraph.index
= gossip_store_add(rstate->gs, update, timestamp,
= gossip_store_add(rstate->daemon->gs, update, timestamp,
zombie, spam, dying, NULL);
if (!spam)
hc->bcast.index = hc->rgraph.index;
Expand Down Expand Up @@ -1733,7 +1732,7 @@ bool routing_add_node_announcement(struct routing_state *rstate,
/* Allow redundant updates once a day (faster in dev-fast-gossip-prune mode) */
redundant_time = GOSSIP_PRUNE_INTERVAL(rstate->daemon->dev_fast_gossip_prune) / 14;
if (timestamp < node->bcast.timestamp + redundant_time
&& !nannounce_different(rstate->gs, node, msg)) {
&& !nannounce_different(rstate->daemon->gs, node, msg)) {
SUPERVERBOSE(
"Ignoring redundant nannounce for %s"
" (last %u, now %u)",
Expand Down Expand Up @@ -1769,15 +1768,15 @@ bool routing_add_node_announcement(struct routing_state *rstate,
node->bcast.timestamp = timestamp;
/* remove prior spam update if one exists */
if (node->rgraph.index != node->bcast.index) {
gossip_store_delete(rstate->gs, &node->rgraph,
gossip_store_delete(rstate->daemon->gs, &node->rgraph,
WIRE_NODE_ANNOUNCEMENT);
}
/* Harmless if it was never added */
gossip_store_delete(rstate->gs, &node->bcast,
gossip_store_delete(rstate->daemon->gs, &node->bcast,
WIRE_NODE_ANNOUNCEMENT);
/* Remove prior spam update. */
} else if (node->rgraph.index != node->bcast.index) {
gossip_store_delete(rstate->gs, &node->rgraph,
gossip_store_delete(rstate->daemon->gs, &node->rgraph,
WIRE_NODE_ANNOUNCEMENT);
}

Expand All @@ -1788,7 +1787,7 @@ bool routing_add_node_announcement(struct routing_state *rstate,
node->bcast.index = index;
} else {
node->rgraph.index
= gossip_store_add(rstate->gs, msg, timestamp,
= gossip_store_add(rstate->daemon->gs, msg, timestamp,
false, spam, false, NULL);
if (!spam)
node->bcast.index = node->rgraph.index;
Expand Down Expand Up @@ -2020,7 +2019,7 @@ void routing_expire_channels(struct routing_state *rstate, u32 blockheight)
if (chan)
channel_spent(rstate, chan);
/* Delete dying marker itself */
gossip_store_delete(rstate->gs,
gossip_store_delete(rstate->daemon->gs,
&d->marker, WIRE_GOSSIP_STORE_CHAN_DYING);
tal_arr_remove(&rstate->dying_channels, i);
i--;
Expand Down Expand Up @@ -2062,14 +2061,14 @@ void routing_channel_spent(struct routing_state *rstate,

/* Save to gossip_store in case we restart */
msg = towire_gossip_store_chan_dying(tmpctx, &chan->scid, deadline);
index = gossip_store_add(rstate->gs, msg, 0, false, false, false, NULL);
index = gossip_store_add(rstate->daemon->gs, msg, 0, false, false, false, NULL);

/* Mark it dying, so we don't gossip it */
gossip_store_mark_dying(rstate->gs, &chan->bcast,
gossip_store_mark_dying(rstate->daemon->gs, &chan->bcast,
WIRE_CHANNEL_ANNOUNCEMENT);
for (int dir = 0; dir < ARRAY_SIZE(chan->half); dir++) {
if (is_halfchan_defined(&chan->half[dir])) {
gossip_store_mark_dying(rstate->gs,
gossip_store_mark_dying(rstate->daemon->gs,
&chan->half[dir].bcast,
WIRE_CHANNEL_UPDATE);
}
Expand Down
3 changes: 0 additions & 3 deletions gossipd/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ struct routing_state {
/* channel_announcement which are pending short_channel_id lookup */
struct pending_cannouncement_map *pending_cannouncements;

/* Gossip store */
struct gossip_store *gs;

/* A map of channels indexed by short_channel_ids */
UINTMAP(struct chan *) chanmap;

Expand Down

0 comments on commit af64d30

Please sign in to comment.