diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 47aa96e12..be4fa587d 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -1508,6 +1508,9 @@ static struct io_plan *gossip_init(struct daemon_conn *master, /* Load stored gossip messages */ gossip_store_load(daemon->rstate, daemon->rstate->store); + /* OK, we're ready! */ + daemon_conn_send(&daemon->master, + take(towire_gossipctl_init_reply(NULL))); return daemon_conn_read_next(master->conn, master); } @@ -2025,6 +2028,7 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master return handle_outpoint_spent(conn, daemon, master->msg_in); /* We send these, we don't receive them */ + case WIRE_GOSSIPCTL_INIT_REPLY: case WIRE_GOSSIPCTL_RELEASE_PEER_REPLY: case WIRE_GOSSIPCTL_RELEASE_PEER_REPLYFAIL: case WIRE_GOSSIP_GETNODES_REPLY: diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index 503e444c9..412e6ce16 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -19,6 +19,9 @@ gossipctl_init,,rgb,3*u8 gossipctl_init,,alias,32*u8 gossipctl_init,,update_channel_interval,u32 +# Gossipd->master, I am ready. +gossipctl_init_reply,3100 + # Master -> gossipd: Optional hint for where to find peer. gossipctl_peer_addrhint,3014 gossipctl_peer_addrhint,,id,struct pubkey diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 809346b44..48036ff90 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -138,6 +138,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) case WIRE_GOSSIP_MARK_CHANNEL_UNROUTABLE: case WIRE_GOSSIPCTL_PEER_DISCONNECT: /* This is a reply, so never gets through to here. */ + case WIRE_GOSSIPCTL_INIT_REPLY: case WIRE_GOSSIP_GET_UPDATE_REPLY: case WIRE_GOSSIP_GETNODES_REPLY: case WIRE_GOSSIP_GETROUTE_REPLY: @@ -176,6 +177,15 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) return 0; } +static void gossip_init_done(struct subd *gossip UNUSED, + const u8 *reply UNUSED, + const int *fds UNUSED, + void *unused UNUSED) +{ + /* Break out of loop, so we can begin */ + io_break(gossip); +} + /* Create the `gossipd` subdaemon and send the initialization * message */ void gossip_init(struct lightningd *ld) @@ -208,7 +218,10 @@ void gossip_init(struct lightningd *ld) get_offered_global_features(tmpctx), get_offered_local_features(tmpctx), ld->wireaddrs, ld->rgb, ld->alias, ld->config.channel_update_interval); - subd_send_msg(ld->gossip, msg); + subd_req(ld->gossip, ld->gossip, msg, -1, 0, gossip_init_done, NULL); + + /* Wait for init done */ + io_loop(NULL, NULL); } void gossipd_notify_spend(struct lightningd *ld, diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index be935b804..b28d7837a 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -309,6 +309,9 @@ int main(int argc, char *argv[]) /* Now we know our ID, we can set our color/alias if not already. */ setup_color_and_alias(ld); + /* Set up gossip daemon. */ + gossip_init(ld); + /* Everything is within a transaction. */ db_begin_transaction(ld->wallet->db); @@ -328,9 +331,6 @@ int main(int argc, char *argv[]) ld->ini_autocleaninvoice_cycle, ld->ini_autocleaninvoice_expiredby); - /* Set up gossip daemon. */ - gossip_init(ld); - /* Load peers from database */ if (!wallet_channels_load_active(ld, ld->wallet)) fatal("Could not load channels from the database");