Browse Source

gossip_store: avoid gratuitous copy on load.

Doesn't make measurable difference, but an obvious optimization.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
pr-2587
Rusty Russell 6 years ago
committed by neil saitug
parent
commit
62918fcb3b
  1. 8
      gossipd/gossip_store.c
  2. 12
      gossipd/routing.c

8
gossipd/gossip_store.c

@ -327,7 +327,7 @@ void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs)
&gossip_msg,
&satoshis)) {
if (!routing_add_channel_announcement(rstate,
gossip_msg,
take(gossip_msg),
satoshis)) {
bad = "Bad channel_announcement";
goto truncate;
@ -335,14 +335,16 @@ void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs)
stats[0]++;
} else if (fromwire_gossip_store_channel_update(msg, msg,
&gossip_msg)) {
if (!routing_add_channel_update(rstate, gossip_msg)) {
if (!routing_add_channel_update(rstate,
take(gossip_msg))) {
bad = "Bad channel_update";
goto truncate;
}
stats[1]++;
} else if (fromwire_gossip_store_node_announcement(msg, msg,
&gossip_msg)) {
if (!routing_add_node_announcement(rstate, gossip_msg)) {
if (!routing_add_node_announcement(rstate,
take(gossip_msg))) {
bad = "Bad node_announcement";
goto truncate;
}

12
gossipd/routing.c

@ -889,6 +889,10 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
struct pubkey bitcoin_key_1;
struct pubkey bitcoin_key_2;
/* Make sure we own msg, even if we don't save it. */
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,
@ -1228,6 +1232,10 @@ bool routing_add_channel_update(struct routing_state *rstate,
struct chan *chan;
u8 direction;
/* Make sure we own msg, even if we don't save it. */
if (taken(update))
tal_steal(tmpctx, update);
if (!fromwire_channel_update(update, &signature, &chain_hash,
&short_channel_id, &timestamp,
&message_flags, &channel_flags,
@ -1499,6 +1507,10 @@ bool routing_add_node_announcement(struct routing_state *rstate, const u8 *msg T
u8 *features, *addresses;
struct wireaddr *wireaddrs;
/* Make sure we own msg, even if we don't save it. */
if (taken(msg))
tal_steal(tmpctx, msg);
/* Note: validity of node_id is already checked. */
if (!fromwire_node_announcement(tmpctx, msg,
&signature, &features, &timestamp,

Loading…
Cancel
Save