Browse Source

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>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
5551c161ca
  1. 4
      gossipd/gossip.c
  2. 3
      gossipd/gossip_wire.csv
  3. 15
      lightningd/gossip_control.c
  4. 6
      lightningd/lightningd.c

4
gossipd/gossip.c

@ -1508,6 +1508,9 @@ static struct io_plan *gossip_init(struct daemon_conn *master,
/* Load stored gossip messages */ /* Load stored gossip messages */
gossip_store_load(daemon->rstate, daemon->rstate->store); 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); 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); return handle_outpoint_spent(conn, daemon, master->msg_in);
/* We send these, we don't receive them */ /* We send these, we don't receive them */
case WIRE_GOSSIPCTL_INIT_REPLY:
case WIRE_GOSSIPCTL_RELEASE_PEER_REPLY: case WIRE_GOSSIPCTL_RELEASE_PEER_REPLY:
case WIRE_GOSSIPCTL_RELEASE_PEER_REPLYFAIL: case WIRE_GOSSIPCTL_RELEASE_PEER_REPLYFAIL:
case WIRE_GOSSIP_GETNODES_REPLY: case WIRE_GOSSIP_GETNODES_REPLY:

3
gossipd/gossip_wire.csv

@ -19,6 +19,9 @@ gossipctl_init,,rgb,3*u8
gossipctl_init,,alias,32*u8 gossipctl_init,,alias,32*u8
gossipctl_init,,update_channel_interval,u32 gossipctl_init,,update_channel_interval,u32
# Gossipd->master, I am ready.
gossipctl_init_reply,3100
# Master -> gossipd: Optional hint for where to find peer. # Master -> gossipd: Optional hint for where to find peer.
gossipctl_peer_addrhint,3014 gossipctl_peer_addrhint,3014
gossipctl_peer_addrhint,,id,struct pubkey gossipctl_peer_addrhint,,id,struct pubkey

Can't render this file because it has a wrong number of fields in line 6.

15
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_GOSSIP_MARK_CHANNEL_UNROUTABLE:
case WIRE_GOSSIPCTL_PEER_DISCONNECT: case WIRE_GOSSIPCTL_PEER_DISCONNECT:
/* This is a reply, so never gets through to here. */ /* This is a reply, so never gets through to here. */
case WIRE_GOSSIPCTL_INIT_REPLY:
case WIRE_GOSSIP_GET_UPDATE_REPLY: case WIRE_GOSSIP_GET_UPDATE_REPLY:
case WIRE_GOSSIP_GETNODES_REPLY: case WIRE_GOSSIP_GETNODES_REPLY:
case WIRE_GOSSIP_GETROUTE_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; 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 /* Create the `gossipd` subdaemon and send the initialization
* message */ * message */
void gossip_init(struct lightningd *ld) void gossip_init(struct lightningd *ld)
@ -208,7 +218,10 @@ void gossip_init(struct lightningd *ld)
get_offered_global_features(tmpctx), get_offered_global_features(tmpctx),
get_offered_local_features(tmpctx), ld->wireaddrs, ld->rgb, get_offered_local_features(tmpctx), ld->wireaddrs, ld->rgb,
ld->alias, ld->config.channel_update_interval); 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, void gossipd_notify_spend(struct lightningd *ld,

6
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. */ /* Now we know our ID, we can set our color/alias if not already. */
setup_color_and_alias(ld); setup_color_and_alias(ld);
/* Set up gossip daemon. */
gossip_init(ld);
/* Everything is within a transaction. */ /* Everything is within a transaction. */
db_begin_transaction(ld->wallet->db); db_begin_transaction(ld->wallet->db);
@ -328,9 +331,6 @@ int main(int argc, char *argv[])
ld->ini_autocleaninvoice_cycle, ld->ini_autocleaninvoice_cycle,
ld->ini_autocleaninvoice_expiredby); ld->ini_autocleaninvoice_expiredby);
/* Set up gossip daemon. */
gossip_init(ld);
/* Load peers from database */ /* Load peers from database */
if (!wallet_channels_load_active(ld, ld->wallet)) if (!wallet_channels_load_active(ld, ld->wallet))
fatal("Could not load channels from the database"); fatal("Could not load channels from the database");

Loading…
Cancel
Save