Skip to content

Commit 0b569e7

Browse files
rustyrussellendothermicdev
authored andcommitted
gossipd: tell lightningd about all our previous channel_updates at startup.
This will at least *help* the case where these were not populated, causing us to send errors without channel_updated appended. It's not perfect: we can still send such errors if the gossip store is corrupted, and we still send them for private channels, but it should help. (The much better fix is far more invasive, so slips to next release!) Signed-off-by: Rusty Russell <[email protected]>
1 parent e366c19 commit 0b569e7

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

gossipd/gossipd.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,42 @@ static void gossip_refresh_network(struct daemon *daemon)
747747
route_prune(daemon->rstate);
748748
}
749749

750+
static void tell_master_local_cupdates(struct daemon *daemon)
751+
{
752+
struct chan_map_iter i;
753+
struct chan *c;
754+
struct node *me;
755+
756+
me = get_node(daemon->rstate, &daemon->id);
757+
if (!me)
758+
return;
759+
760+
for (c = first_chan(me, &i); c; c = next_chan(me, &i)) {
761+
struct half_chan *hc;
762+
int direction;
763+
const u8 *cupdate;
764+
765+
/* We don't provide update_channel for unannounced channels */
766+
if (!is_chan_public(c))
767+
continue;
768+
769+
if (!local_direction(daemon->rstate, c, &direction))
770+
continue;
771+
772+
hc = &c->half[direction];
773+
if (!is_halfchan_defined(hc))
774+
continue;
775+
776+
cupdate = gossip_store_get(tmpctx,
777+
daemon->rstate->gs,
778+
hc->bcast.index);
779+
daemon_conn_send(daemon->master,
780+
take(towire_gossipd_init_cupdate(NULL,
781+
&c->scid,
782+
cupdate)));
783+
}
784+
}
785+
750786
/* Disables all channels connected to our node. */
751787
static void gossip_disable_local_channels(struct daemon *daemon)
752788
{
@@ -851,6 +887,10 @@ static void gossip_init(struct daemon *daemon, const u8 *msg)
851887
maybe_send_query_responses, daemon);
852888
tal_add_destructor(daemon->connectd, master_or_connectd_gone);
853889

890+
/* Tell it about all our local (public) channel_update messages,
891+
* so it doesn't unnecessarily regenerate them. */
892+
tell_master_local_cupdates(daemon);
893+
854894
/* OK, we are ready. */
855895
daemon_conn_send(daemon->master,
856896
take(towire_gossipd_init_reply(NULL)));
@@ -1143,6 +1183,7 @@ static struct io_plan *recv_req(struct io_conn *conn,
11431183
#endif /* !DEVELOPER */
11441184

11451185
/* We send these, we don't receive them */
1186+
case WIRE_GOSSIPD_INIT_CUPDATE:
11461187
case WIRE_GOSSIPD_INIT_REPLY:
11471188
case WIRE_GOSSIPD_GET_TXOUT:
11481189
case WIRE_GOSSIPD_DEV_MEMLEAK_REPLY:

gossipd/gossipd_wire.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ msgdata,gossipd_init,dev_fast_gossip,bool,
1818
msgdata,gossipd_init,dev_fast_gossip_prune,bool,
1919
msgdata,gossipd_init,ip_discovery,u32,
2020

21+
# Gossipd tells us all our public channel_updates before init_reply.
22+
msgtype,gossipd_init_cupdate,3101
23+
msgdata,gossipd_init_cupdate,scid,short_channel_id,
24+
msgdata,gossipd_init_cupdate,len,u16,
25+
msgdata,gossipd_init_cupdate,cupdate,u8,len
26+
2127
msgtype,gossipd_init_reply,3100
2228

2329
# In developer mode, we can mess with time.

lightningd/gossip_control.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,33 @@ static void get_txout(struct subd *gossip, const u8 *msg)
109109
}
110110
}
111111

112+
static void handle_init_cupdate(struct lightningd *ld, const u8 *msg)
113+
{
114+
struct short_channel_id scid;
115+
u8 *update;
116+
struct channel *channel;
117+
118+
if (!fromwire_gossipd_init_cupdate(msg, msg, &scid, &update)) {
119+
fatal("Gossip gave bad GOSSIPD_INIT_CUPDATE %s",
120+
tal_hex(msg, msg));
121+
}
122+
123+
/* In theory this could vanish before gossipd gets around to telling
124+
* us. */
125+
channel = any_channel_by_scid(ld, &scid, true);
126+
if (!channel) {
127+
log_unusual(ld->log, "init_cupdate for bad scid %s",
128+
type_to_string(tmpctx, struct short_channel_id,
129+
&scid));
130+
return;
131+
}
132+
133+
/* This should only happen on initialization, *but* gossipd also
134+
* disabled channels on startup, so that can set this first. */
135+
if (!channel->channel_update)
136+
channel->channel_update = tal_steal(channel, update);
137+
}
138+
112139
static void handle_local_channel_update(struct lightningd *ld, const u8 *msg)
113140
{
114141
struct short_channel_id scid;
@@ -177,6 +204,9 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
177204
case WIRE_GOSSIPD_DISCOVERED_IP:
178205
break;
179206

207+
case WIRE_GOSSIPD_INIT_CUPDATE:
208+
handle_init_cupdate(gossip->ld, msg);
209+
break;
180210
case WIRE_GOSSIPD_GET_TXOUT:
181211
get_txout(gossip, msg);
182212
break;

0 commit comments

Comments
 (0)