Skip to content

Commit

Permalink
gossipd: don't keep channel_announcement messages in memory.
Browse files Browse the repository at this point in the history
MCP results from 5 runs, min-max(mean +/- stddev):
	store_load_msec:35107-37944(36686+/-1e+03)
	vsz_kb:1218036
	store_rewrite_sec:14.060000-17.970000(15.966+/-1.6)
	listnodes_sec:1.270000-1.350000(1.314+/-0.034)
	listchannels_sec:28.510000-30.270000(29.6+/-0.6)
	routing_sec:30.230000-31.510000(30.83+/-0.44)
	peer_write_all_sec:67.390000-70.710000(68.568+/-1.2)

MCP notable changes from previous patch (>1 stddev):
	-vsz_kb:1780516
	+vsz_kb:1218036

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and niftynei committed Apr 12, 2019
1 parent 2fd4a01 commit 3280466
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gossipd/gossip_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static bool add_local_unnannounced(int fd,
const u8 *msg;

/* Ignore already announced. */
if (c->channel_announce)
if (is_chan_public(c))
continue;

msg = towire_gossipd_local_add_channel(tmpctx, &c->scid,
Expand Down
2 changes: 1 addition & 1 deletion gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ static void maybe_create_next_scid_reply(struct peer *peer)
if (!chan || !is_chan_public(chan))
continue;

queue_peer_msg(peer, chan->channel_announce);
queue_peer_from_store(peer, &chan->bcast);
if (chan->half[0].channel_update)
queue_peer_msg(peer, chan->half[0].channel_update);
if (chan->half[1].channel_update)
Expand Down
18 changes: 11 additions & 7 deletions gossipd/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ struct chan *new_chan(struct routing_state *rstate,
chan->nodes[n1idx] = n1;
chan->nodes[!n1idx] = n2;
chan->txout_script = NULL;
chan->channel_announce = NULL;
broadcastable_init(&chan->bcast);
chan->sat = satoshis;
chan->local_disabled = false;
Expand Down Expand Up @@ -917,14 +916,14 @@ static bool is_local_channel(const struct routing_state *rstate,

static void add_channel_announce_to_broadcast(struct routing_state *rstate,
struct chan *chan,
const u8 *channel_announce,
u32 timestamp,
u32 index)
{
chan->bcast.timestamp = timestamp;
/* 0, unless we're loading from store */
chan->bcast.index = index;
insert_broadcast(&rstate->broadcasts, chan->channel_announce,
&chan->bcast);
insert_broadcast(&rstate->broadcasts, channel_announce, &chan->bcast);
rstate->local_channel_announced |= is_local_channel(rstate, chan);
}

Expand All @@ -950,6 +949,9 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
if (taken(msg))
tal_steal(tmpctx, msg);

if (taken(msg))
tal_steal(tmpctx, msg);

if (!fromwire_channel_announcement(
tmpctx, msg, &node_signature_1, &node_signature_2,
&bitcoin_signature_1, &bitcoin_signature_2, &features, &chain_hash,
Expand Down Expand Up @@ -1427,15 +1429,17 @@ bool routing_add_channel_update(struct routing_state *rstate,
* receiving the first corresponding `channel_update`.
*/
if (uc) {
chan->channel_announce = tal_steal(chan, uc->channel_announce);
add_channel_announce_to_broadcast(rstate, chan, timestamp,
add_channel_announce_to_broadcast(rstate, chan,
uc->channel_announce,
timestamp,
uc->index);
} else if (!chan->channel_announce) {
} else if (!is_chan_public(chan)) {
/* For private channels, we get updates without an announce: don't
* broadcast them! But save local ones to store anyway. */
struct half_chan *hc = &chan->half[direction];
/* Don't save if we're loading from store */
if (is_local_channel(rstate, chan) && !index) {
assert(is_local_channel(rstate, chan));
if (!index) {
hc->bcast.index = gossip_store_add(rstate->broadcasts->gs,
hc->channel_update);
} else
Expand Down
3 changes: 0 additions & 3 deletions gossipd/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ struct chan {
/* node[0].id < node[1].id */
struct node *nodes[2];

/* NULL if not announced yet (ie. not public). */
const u8 *channel_announce;

/* Timestamp and index into store file */
struct broadcastable bcast;

Expand Down

0 comments on commit 3280466

Please sign in to comment.