Skip to content

Commit

Permalink
connectd: channel_gossip when we've tried to connect to all peers.
Browse files Browse the repository at this point in the history
It then waits 10 more seconds (for plugins to call setlease, especially)
before it will update a node_announcement.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jan 31, 2024
1 parent e4b21b4 commit 06d5983
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lightningd/channel_gossip.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ struct channel_gossip {
const struct peer_update *peer_update;
};

/* FIXME: this is a hack! We should wait 1 minute after connectd has
* tried to connect to all peers. */
static bool starting_up = true, gossipd_init_done = false;

/* We send non-forwardable channel updates if we can. */
Expand Down Expand Up @@ -794,6 +792,14 @@ static void set_not_starting_up(struct lightningd *ld)
log_debug(ld->log, "channel_gossip: no longer in startup mode");
}

/* We also wait ten seconds *after* connection, for lease registration */
void channel_gossip_startup_done(struct lightningd *ld)
{
notleak(new_reltimer(ld->timers, ld,
time_from_sec(10),
set_not_starting_up, ld));
}

/* Gossipd init is done: if you expected a channel_update, be
* disappointed. */
void channel_gossip_init_done(struct lightningd *ld)
Expand Down Expand Up @@ -823,10 +829,6 @@ void channel_gossip_init_done(struct lightningd *ld)
send_channel_announcement(channel);
}
}

notleak(new_reltimer(ld->timers, ld,
time_from_sec(60),
set_not_starting_up, ld));
}

/* Peer has connected. */
Expand Down
3 changes: 3 additions & 0 deletions lightningd/channel_gossip.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ struct peer_update;
void channel_gossip_init(struct channel *channel,
const struct peer_update *remote_update TAKES);

/* We've attempted reconnect to all peers. */
void channel_gossip_startup_done(struct lightningd *ld);

/* Something about channel/blockchain changed: update if required */
void channel_gossip_update(struct channel *channel);

Expand Down
12 changes: 12 additions & 0 deletions lightningd/connect_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <gossipd/gossipd_wiregen.h>
#include <hsmd/permissions.h>
#include <lightningd/channel.h>
#include <lightningd/channel_gossip.h>
#include <lightningd/connect_control.h>
#include <lightningd/dual_open_control.h>
#include <lightningd/hsm_control.h>
Expand Down Expand Up @@ -565,6 +566,15 @@ void connectd_start_shutdown(struct subd *connectd)
while (io_loop(NULL, NULL) != connectd);
}

static void startup_connect_one_done(struct lightningd *ld)
{
if (!ld->num_startup_connects)
return;

if (--ld->num_startup_connects == 0)
channel_gossip_startup_done(ld);
}

static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fds)
{
enum connectd_wire t = fromwire_peektype(msg);
Expand Down Expand Up @@ -594,6 +604,7 @@ static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fd
break;

case WIRE_CONNECTD_PEER_CONNECTED:
startup_connect_one_done(connectd->ld);
peer_connected(connectd->ld, msg);
break;

Expand All @@ -606,6 +617,7 @@ static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fd
break;

case WIRE_CONNECTD_CONNECT_FAILED:
startup_connect_one_done(connectd->ld);
handle_connect_failed(connectd->ld, msg);
break;

Expand Down
1 change: 1 addition & 0 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->try_reexec = false;
ld->recover_secret = NULL;
ld->db_upgrade_ok = NULL;
ld->num_startup_connects = 0;

/* --experimental-upgrade-protocol */
ld->experimental_upgrade_protocol = false;
Expand Down
3 changes: 3 additions & 0 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ struct lightningd {
/* Do we want to reconnect to other peers? */
bool reconnect;

/* How many outstanding startup connection attempts? */
size_t num_startup_connects;

/* Do we want to listen for other peers? */
bool listen;

Expand Down
6 changes: 6 additions & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -2488,6 +2488,8 @@ static void setup_peer(struct peer *peer, u32 delay)

/* Make sure connectd knows to try reconnecting. */
if (connect) {
ld->num_startup_connects++;

/* To delay, make it seem like we just connected. */
if (delay > 0) {
peer->reconnect_delay = delay;
Expand All @@ -2510,6 +2512,10 @@ void setup_peers(struct lightningd *ld)
setup_peer(p, delay > 0 ? delay : 0);
delay++;
}

/* In case there are no peers at all to connect to */
if (ld->num_startup_connects == 0)
channel_gossip_startup_done(ld);
}

/* Pull peers, channels and HTLCs from db, and wire them up. */
Expand Down
3 changes: 3 additions & 0 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const struct peer_update *channel_gossip_get_remote_update(const struct channel
/* Generated stub for channel_gossip_peer_connected */
void channel_gossip_peer_connected(struct peer *peer UNNEEDED)
{ fprintf(stderr, "channel_gossip_peer_connected called!\n"); abort(); }
/* Generated stub for channel_gossip_startup_done */
void channel_gossip_startup_done(struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "channel_gossip_startup_done called!\n"); abort(); }
/* Generated stub for channel_has_htlc_in */
struct htlc_in *channel_has_htlc_in(struct channel *channel UNNEEDED)
{ fprintf(stderr, "channel_has_htlc_in called!\n"); abort(); }
Expand Down
3 changes: 3 additions & 0 deletions wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ struct peer_fd *new_peer_fd(const tal_t *ctx UNNEEDED, int peer_fd UNNEEDED)
/* Generated stub for new_uncommitted_channel */
struct uncommitted_channel *new_uncommitted_channel(struct peer *peer UNNEEDED)
{ fprintf(stderr, "new_uncommitted_channel called!\n"); abort(); }
/* Generated stub for node_announcement_same */
bool node_announcement_same(const u8 *nann1 UNNEEDED, const u8 *nann2 UNNEEDED)
{ fprintf(stderr, "node_announcement_same called!\n"); abort(); }
/* Generated stub for notify_chain_mvt */
void notify_chain_mvt(struct lightningd *ld UNNEEDED, const struct chain_coin_mvt *mvt UNNEEDED)
{ fprintf(stderr, "notify_chain_mvt called!\n"); abort(); }
Expand Down

0 comments on commit 06d5983

Please sign in to comment.