mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-12 10:30:29 +01:00
connectd: channel_gossip when we've tried to connect to all peers.
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>
This commit is contained in:
parent
e4b21b467a
commit
06d59839ec
8 changed files with 39 additions and 6 deletions
|
@ -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. */
|
||||
|
@ -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)
|
||||
|
@ -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. */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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. */
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue