lightningd: reintroduce "slow connect" logic.

Just keep a flag on the peer, and delay connection longer if that is set.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-07-18 21:42:28 +09:30 committed by neil saitug
parent 02e169fd27
commit a08728497b
4 changed files with 22 additions and 10 deletions

View File

@ -931,7 +931,7 @@ void channel_set_billboard(struct channel *channel, bool perm, const char *str)
static void channel_err(struct channel *channel,
const char *why,
u32 seconds_before_reconnect /* FIXME: use this! */)
bool delay_reconnect)
{
log_info(channel->log, "Peer transient failure in %s: %s",
channel_state_name(channel), why);
@ -944,6 +944,7 @@ static void channel_err(struct channel *channel,
return;
}
#endif
channel->peer->delay_reconnect = delay_reconnect;
channel_set_owner(channel, NULL);
}
@ -953,7 +954,7 @@ void channel_fail_transient_delayreconnect(struct channel *channel, const char *
va_list ap;
va_start(ap, fmt);
channel_err(channel, tal_vfmt(tmpctx, fmt, ap), 60);
channel_err(channel, tal_vfmt(tmpctx, fmt, ap), true);
va_end(ap);
}
@ -962,7 +963,7 @@ void channel_fail_transient(struct channel *channel, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
channel_err(channel, tal_vfmt(tmpctx, fmt, ap), 1);
channel_err(channel, tal_vfmt(tmpctx, fmt, ap), false);
va_end(ap);
}

View File

@ -346,7 +346,7 @@ static void connect_failed(struct lightningd *ld,
const struct node_id *id,
errcode_t errcode,
const char *errmsg,
u32 seconds_to_delay,
const u32 *seconds_to_delay,
const struct wireaddr_internal *addrhint)
{
struct peer *peer;
@ -360,10 +360,16 @@ static void connect_failed(struct lightningd *ld,
/* If we have an active channel, then reconnect. */
peer = peer_by_id(ld, id);
if (peer) {
if (peer_any_active_channel(peer, NULL))
try_reconnect(peer, peer, seconds_to_delay, addrhint);
}
if (peer && peer_any_active_channel(peer, NULL)) {
u32 delay;
if (seconds_to_delay)
delay = *seconds_to_delay;
else
delay = peer->delay_reconnect ? 60 : 1;
log_peer_debug(ld->log, id, "Reconnecting in %u seconds", delay);
try_reconnect(peer, peer, delay, addrhint);
} else
log_peer_debug(ld->log, id, "Not reconnecting: %s", peer ? "no active channel" : "no channels");
}
void connect_failed_disconnect(struct lightningd *ld,
@ -371,7 +377,7 @@ void connect_failed_disconnect(struct lightningd *ld,
const struct wireaddr_internal *addrhint)
{
connect_failed(ld, id, CONNECT_DISCONNECTED_DURING,
"disconnected during connection", 1, addrhint);
"disconnected during connection", NULL, addrhint);
}
static void handle_connect_failed(struct lightningd *ld, const u8 *msg)
@ -387,7 +393,7 @@ static void handle_connect_failed(struct lightningd *ld, const u8 *msg)
fatal("Connect gave bad CONNECTD_CONNECT_FAILED message %s",
tal_hex(msg, msg));
connect_failed(ld, &id, errcode, errmsg, seconds_to_delay, addrhint);
connect_failed(ld, &id, errcode, errmsg, &seconds_to_delay, addrhint);
}
void connect_succeeded(struct lightningd *ld, const struct peer *peer,

View File

@ -100,6 +100,7 @@ struct peer *new_peer(struct lightningd *ld, u64 dbid,
list_head_init(&peer->channels);
peer->direction = node_id_idx(&peer->ld->id, &peer->id);
peer->connected = PEER_DISCONNECTED;
peer->delay_reconnect = false;
#if DEVELOPER
peer->ignore_htlcs = false;
#endif
@ -1329,6 +1330,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg)
/* We mark peer in "connecting" state until hooks have passed. */
assert(peer->connected == PEER_DISCONNECTED);
peer->connected = PEER_CONNECTING;
peer->delay_reconnect = false;
/* Update peer address and direction */
peer->addr = hook_payload->addr;

View File

@ -30,6 +30,9 @@ struct peer {
/* Connection counter from connectd. */
u64 connectd_counter;
/* Did we fail badly last time? Don't reconnect too fast. */
bool delay_reconnect;
/* Our channels */
struct list_head channels;