Browse Source

gossipd: pass amount into gossip_store, rather than having it fetch.

We need to store the channel capacity for channel_announcement: hand it
in directly rather than having the gossip_store code do a lookup.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
htlc_accepted_hook
Rusty Russell 6 years ago
parent
commit
89291b930e
  1. 4
      gossipd/broadcast.c
  2. 6
      gossipd/broadcast.h
  3. 50
      gossipd/gossip_store.c
  4. 3
      gossipd/gossip_store.h
  5. 2
      gossipd/gossipd.c
  6. 12
      gossipd/routing.c

4
gossipd/broadcast.c

@ -63,6 +63,7 @@ void insert_broadcast_nostore(struct broadcast_state *bstate,
void insert_broadcast(struct broadcast_state **bstate, void insert_broadcast(struct broadcast_state **bstate,
const u8 *msg, const u8 *msg,
const struct amount_sat *channel_announce_sat,
struct broadcastable *bcast) struct broadcastable *bcast)
{ {
u32 offset; u32 offset;
@ -71,7 +72,8 @@ void insert_broadcast(struct broadcast_state **bstate,
if (!bcast->index) { if (!bcast->index) {
u64 idx; u64 idx;
bcast->index = idx = gossip_store_add((*bstate)->gs, msg); bcast->index = idx = gossip_store_add((*bstate)->gs, msg,
channel_announce_sat);
if (!idx) if (!idx)
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Could not add to gossip store: %s", "Could not add to gossip store: %s",

6
gossipd/broadcast.h

@ -37,9 +37,13 @@ struct broadcast_state *new_broadcast_state(struct routing_state *rstate,
struct list_head *peers); struct list_head *peers);
/* Append a queued message for broadcast. Must be explicitly deleted. /* Append a queued message for broadcast. Must be explicitly deleted.
* Also adds it to the gossip store. */ * Also adds it to the gossip store.
*
* If it's a channel_announcement, channel_announce_sat must be set.
*/
void insert_broadcast(struct broadcast_state **bstate, void insert_broadcast(struct broadcast_state **bstate,
const u8 *msg, const u8 *msg,
const struct amount_sat *channel_announce_sat,
struct broadcastable *bcast); struct broadcastable *bcast);
/* Add to broadcast, but not store: for gossip store compaction. */ /* Add to broadcast, but not store: for gossip store compaction. */

50
gossipd/gossip_store.c

@ -200,47 +200,18 @@ struct gossip_store *gossip_store_new(struct routing_state *rstate)
return gs; return gs;
} }
static u8 *make_store_channel_amount(const tal_t *ctx,
struct routing_state *rstate,
const u8 *gossip_msg)
{
secp256k1_ecdsa_signature node_signature_1, node_signature_2;
secp256k1_ecdsa_signature bitcoin_signature_1, bitcoin_signature_2;
u8 *features;
struct bitcoin_blkid chain_hash;
struct short_channel_id scid;
struct node_id node_id_1;
struct node_id node_id_2;
struct pubkey bitcoin_key_1;
struct pubkey bitcoin_key_2;
/* Which channel are we talking about here? */
if (!fromwire_channel_announcement(
tmpctx, gossip_msg, &node_signature_1, &node_signature_2,
&bitcoin_signature_1, &bitcoin_signature_2, &features,
&chain_hash, &scid, &node_id_1, &node_id_2, &bitcoin_key_1,
&bitcoin_key_2))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Error parsing channel_announcement");
struct chan *chan = get_channel(rstate, &scid);
assert(chan && amount_sat_greater(chan->sat, AMOUNT_SAT(0)));
return towire_gossip_store_channel_amount(ctx, chan->sat);
}
/** /**
* Wrap the raw gossip message and write it to fd * Wrap the raw gossip message and write it to fd
* *
* @param fd File descriptor to write the wrapped message into * @param fd File descriptor to write the wrapped message into
* @param rstate Routing state if we need to look up channel capacity
* @param gossip_msg The message to write * @param gossip_msg The message to write
* @param channel_announce_sat Amount iff gossip_msg is a channel_announcement
* @param lenp The length to increase by amount written. * @param lenp The length to increase by amount written.
* @return true if the message was written * @return true if the message was written
*/ */
static bool gossip_store_append(int fd, static bool gossip_store_append(int fd,
struct routing_state *rstate,
const u8 *gossip_msg, const u8 *gossip_msg,
const struct amount_sat *channel_announce_sat,
u64 *lenp) u64 *lenp)
{ {
if (!append_msg(fd, gossip_msg, lenp)) if (!append_msg(fd, gossip_msg, lenp))
@ -248,7 +219,8 @@ static bool gossip_store_append(int fd,
if (fromwire_peektype(gossip_msg) == WIRE_CHANNEL_ANNOUNCEMENT) { if (fromwire_peektype(gossip_msg) == WIRE_CHANNEL_ANNOUNCEMENT) {
/* This gives the channel amount. */ /* This gives the channel amount. */
u8 *msg = make_store_channel_amount(tmpctx, rstate, gossip_msg); u8 *msg = towire_gossip_store_channel_amount(tmpctx,
*channel_announce_sat);
if (!append_msg(fd, msg, lenp)) if (!append_msg(fd, msg, lenp))
return false; return false;
} }
@ -305,7 +277,6 @@ static size_t copy_message(int in_fd, int out_fd, unsigned offset)
* the broadcast map count. * the broadcast map count.
*/ */
static bool add_local_unnannounced(int in_fd, int out_fd, static bool add_local_unnannounced(int in_fd, int out_fd,
struct routing_state *rstate,
struct node *self, struct node *self,
u64 *len) u64 *len)
{ {
@ -322,7 +293,7 @@ static bool add_local_unnannounced(int in_fd, int out_fd,
msg = towire_gossipd_local_add_channel(tmpctx, &c->scid, msg = towire_gossipd_local_add_channel(tmpctx, &c->scid,
&peer->id, c->sat); &peer->id, c->sat);
if (!gossip_store_append(out_fd, rstate, msg, len)) if (!gossip_store_append(out_fd, msg, NULL, len))
return false; return false;
for (size_t i = 0; i < 2; i++) { for (size_t i = 0; i < 2; i++) {
@ -469,8 +440,7 @@ bool gossip_store_compact(struct gossip_store *gs,
/* Local unannounced channels are not in the store! */ /* Local unannounced channels are not in the store! */
self = get_node(gs->rstate, &gs->rstate->local_id); self = get_node(gs->rstate, &gs->rstate->local_id);
if (self && !add_local_unnannounced(gs->fd, fd, gs->rstate, self, if (self && !add_local_unnannounced(gs->fd, fd, self, &len)) {
&len)) {
status_broken("Failed writing unannounced to gossip store: %s", status_broken("Failed writing unannounced to gossip store: %s",
strerror(errno)); strerror(errno));
goto unlink_disable; goto unlink_disable;
@ -523,14 +493,16 @@ void gossip_store_maybe_compact(struct gossip_store *gs,
gossip_store_compact(gs, bs, offset); gossip_store_compact(gs, bs, offset);
} }
u64 gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg) u64 gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg,
const struct amount_sat *channel_announce_sat)
{ {
u64 off = gs->len; u64 off = gs->len;
/* Should never get here during loading! */ /* Should never get here during loading! */
assert(gs->writable); assert(gs->writable);
if (!gossip_store_append(gs->fd, gs->rstate, gossip_msg, &gs->len)) { if (!gossip_store_append(gs->fd, gossip_msg, channel_announce_sat,
&gs->len)) {
status_broken("Failed writing to gossip store: %s", status_broken("Failed writing to gossip store: %s",
strerror(errno)); strerror(errno));
return 0; return 0;
@ -548,7 +520,7 @@ void gossip_store_add_channel_delete(struct gossip_store *gs,
/* Should never get here during loading! */ /* Should never get here during loading! */
assert(gs->writable); assert(gs->writable);
if (!gossip_store_append(gs->fd, gs->rstate, msg, &gs->len)) if (!gossip_store_append(gs->fd, msg, NULL, &gs->len))
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Failed writing channel_delete to gossip store: %s", "Failed writing channel_delete to gossip store: %s",
strerror(errno)); strerror(errno));

3
gossipd/gossip_store.h

@ -30,7 +30,8 @@ void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs);
/** /**
* Add a gossip message to the gossip_store * Add a gossip message to the gossip_store
*/ */
u64 gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg); u64 gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg,
const struct amount_sat *channel_announce_sat);
/** /**
* Remember that we deleted a channel as a result of its outpoint being spent * Remember that we deleted a channel as a result of its outpoint being spent

2
gossipd/gossipd.c

@ -1661,7 +1661,7 @@ static struct io_plan *peer_msg_in(struct io_conn *conn,
ok = handle_local_add_channel(peer->daemon->rstate, msg); ok = handle_local_add_channel(peer->daemon->rstate, msg);
if (ok) if (ok)
gossip_store_add(peer->daemon->rstate->broadcasts->gs, gossip_store_add(peer->daemon->rstate->broadcasts->gs,
msg); msg, NULL);
goto handled_cmd; goto handled_cmd;
case WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE: case WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE:
ok = handle_local_channel_update(peer, msg); ok = handle_local_channel_update(peer, msg);

12
gossipd/routing.c

@ -340,7 +340,8 @@ static void remove_chan_from_node(struct routing_state *rstate,
* channel_announce, but we don't care that much about spurious * channel_announce, but we don't care that much about spurious
* retransmissions in this corner case */ * retransmissions in this corner case */
broadcast_del(rstate->broadcasts, &node->bcast); broadcast_del(rstate->broadcasts, &node->bcast);
insert_broadcast(&rstate->broadcasts, announce, &node->bcast); insert_broadcast(&rstate->broadcasts, announce, NULL,
&node->bcast);
} }
} }
@ -1336,7 +1337,8 @@ static void add_channel_announce_to_broadcast(struct routing_state *rstate,
chan->bcast.timestamp = timestamp; chan->bcast.timestamp = timestamp;
/* 0, unless we're loading from store */ /* 0, unless we're loading from store */
chan->bcast.index = index; chan->bcast.index = index;
insert_broadcast(&rstate->broadcasts, channel_announce, &chan->bcast); insert_broadcast(&rstate->broadcasts, channel_announce, &chan->sat,
&chan->bcast);
rstate->local_channel_announced |= is_local_channel(rstate, chan); rstate->local_channel_announced |= is_local_channel(rstate, chan);
} }
@ -1843,7 +1845,7 @@ bool routing_add_channel_update(struct routing_state *rstate,
assert(is_local_channel(rstate, chan)); assert(is_local_channel(rstate, chan));
if (!index) { if (!index) {
hc->bcast.index = gossip_store_add(rstate->broadcasts->gs, hc->bcast.index = gossip_store_add(rstate->broadcasts->gs,
update); update, NULL);
} else } else
hc->bcast.index = index; hc->bcast.index = index;
return true; return true;
@ -1853,7 +1855,7 @@ bool routing_add_channel_update(struct routing_state *rstate,
chan->half[direction].bcast.index = index; chan->half[direction].bcast.index = index;
insert_broadcast(&rstate->broadcasts, insert_broadcast(&rstate->broadcasts,
update, update, NULL,
&chan->half[direction].bcast); &chan->half[direction].bcast);
if (uc) { if (uc) {
@ -2061,7 +2063,7 @@ bool routing_add_node_announcement(struct routing_state *rstate,
node->bcast.timestamp = timestamp; node->bcast.timestamp = timestamp;
node->bcast.index = index; node->bcast.index = index;
insert_broadcast(&rstate->broadcasts, msg, &node->bcast); insert_broadcast(&rstate->broadcasts, msg, NULL, &node->bcast);
return true; return true;
} }

Loading…
Cancel
Save