diff --git a/gossipd/broadcast.c b/gossipd/broadcast.c index edf080168..92c75659c 100644 --- a/gossipd/broadcast.c +++ b/gossipd/broadcast.c @@ -40,8 +40,8 @@ void broadcast_del(struct broadcast_state *bstate, assert(b == bcast); bstate->count--; broadcast_state_check(bstate, "broadcast_del"); - bcast->index = 0; } + bcast->index = 0; } static void add_broadcast(struct broadcast_state *bstate, diff --git a/gossipd/gossip_store.c b/gossipd/gossip_store.c index d67f87108..6171d9a2d 100644 --- a/gossipd/gossip_store.c +++ b/gossipd/gossip_store.c @@ -637,7 +637,7 @@ void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs) stats[3]++; break; case WIRE_GOSSIPD_LOCAL_ADD_CHANNEL: - if (!handle_local_add_channel(rstate, msg)) { + if (!handle_local_add_channel(rstate, msg, gs->len)) { bad = "Bad local_add_channel"; goto truncate; } diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index be0a9dc7a..c17bcf9ab 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -1673,10 +1673,7 @@ static struct io_plan *peer_msg_in(struct io_conn *conn, ok = handle_get_update(peer, msg); goto handled_cmd; case WIRE_GOSSIPD_LOCAL_ADD_CHANNEL: - ok = handle_local_add_channel(peer->daemon->rstate, msg); - if (ok) - gossip_store_add(peer->daemon->rstate->broadcasts->gs, - msg, NULL); + ok = handle_local_add_channel(peer->daemon->rstate, msg, 0); goto handled_cmd; case WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE: ok = handle_local_channel_update(peer, msg); diff --git a/gossipd/routing.c b/gossipd/routing.c index f0425cb8d..269d2825b 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -427,6 +427,8 @@ struct chan *new_chan(struct routing_state *rstate, chan->nodes[n1idx] = n1; chan->nodes[!n1idx] = n2; broadcastable_init(&chan->bcast); + /* This is how we indicate it's not public yet. */ + chan->bcast.timestamp = 0; chan->sat = satoshis; add_chan(n2, chan); @@ -2450,11 +2452,13 @@ void memleak_remove_routing_tables(struct htable *memtable, } #endif /* DEVELOPER */ -bool handle_local_add_channel(struct routing_state *rstate, const u8 *msg) +bool handle_local_add_channel(struct routing_state *rstate, + const u8 *msg, u64 index) { struct short_channel_id scid; struct node_id remote_node_id; struct amount_sat sat; + struct chan *chan; if (!fromwire_gossipd_local_add_channel(msg, &scid, &remote_node_id, &sat)) { @@ -2473,7 +2477,10 @@ bool handle_local_add_channel(struct routing_state *rstate, const u8 *msg) type_to_string(tmpctx, struct short_channel_id, &scid)); /* Create new (unannounced) channel */ - new_chan(rstate, &scid, &rstate->local_id, &remote_node_id, sat); + chan = new_chan(rstate, &scid, &rstate->local_id, &remote_node_id, sat); + if (!index) + index = gossip_store_add(rstate->broadcasts->gs, msg, NULL); + chan->bcast.index = index; return true; } diff --git a/gossipd/routing.h b/gossipd/routing.h index 802c55ae3..ba8926bd1 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -57,11 +57,11 @@ struct chan { /* Use this instead of tal_free(chan)! */ void free_chan(struct routing_state *rstate, struct chan *chan); -/* A local channel can exist which isn't announced; normal channels are only - * created once we have both an announcement *and* an update. */ +/* A local channel can exist which isn't announced: we abuse timestamp + * to indicate this. */ static inline bool is_chan_public(const struct chan *chan) { - return chan->bcast.index != 0; + return chan->bcast.timestamp != 0; } static inline bool is_halfchan_defined(const struct half_chan *hc) @@ -386,7 +386,8 @@ bool routing_add_node_announcement(struct routing_state *rstate, * is the case for private channels or channels that have not yet reached * `announce_depth`. */ -bool handle_local_add_channel(struct routing_state *rstate, const u8 *msg); +bool handle_local_add_channel(struct routing_state *rstate, const u8 *msg, + u64 index); #if DEVELOPER void memleak_remove_routing_tables(struct htable *memtable,