mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-26 10:24:29 +01:00
gossipd: track gossip_store locations of local channels.
We currently don't care, but the next patch means we have to find them again. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user