gossipd: finish startup before master prints that it's ready.

We're about to remove automatic retrying of connect, and that uncovered
that we actually print out our "Server started" message before we create
the listening socket.

Move the init higher (outside the db transaction) and make it a
request/response, the loop until it's done.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-04-23 19:38:01 +09:30
parent 8e976150ad
commit 5551c161ca
4 changed files with 24 additions and 4 deletions

View File

@ -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:

View File

@ -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

1 #include <common/cryptomsg.h>
19 gossipctl_init,,update_channel_interval,u32
20 # Master -> gossipd: Optional hint for where to find peer. # Gossipd->master, I am ready.
21 gossipctl_peer_addrhint,3014 gossipctl_init_reply,3100
22 # Master -> gossipd: Optional hint for where to find peer.
23 gossipctl_peer_addrhint,3014
24 gossipctl_peer_addrhint,,id,struct pubkey
25 gossipctl_peer_addrhint,,id,struct pubkey gossipctl_peer_addrhint,,addr,struct wireaddr
26 gossipctl_peer_addrhint,,addr,struct wireaddr # Master -> gossipd: connect to a peer. We may get a peer_connected or
27 # Master -> gossipd: connect to a peer. We may get a peer_connected or # peer_already_connected

View File

@ -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,

View File

@ -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");