mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
lightningd: stop all subds when we want to disconnect.
This prepares us for connectd disconnecting more gently: it can wait for these to all disconnect. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
64495cf166
commit
a32b3b68e2
@ -1023,11 +1023,9 @@ static void channel_err(struct channel *channel, bool disconnect, const char *wh
|
||||
channel_set_owner(channel, NULL);
|
||||
|
||||
/* Force a disconnect in case the issue is with TCP */
|
||||
if (disconnect && channel->peer->ld->connectd) {
|
||||
const struct peer *peer = channel->peer;
|
||||
subd_send_msg(peer->ld->connectd,
|
||||
take(towire_connectd_discard_peer(NULL, &peer->id,
|
||||
peer->connectd_counter)));
|
||||
if (disconnect) {
|
||||
force_peer_disconnect(channel->peer->ld, channel->peer,
|
||||
"One channel had an error");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <lightningd/channel_control.h>
|
||||
#include <lightningd/closing_control.h>
|
||||
#include <lightningd/coin_mvts.h>
|
||||
#include <lightningd/connect_control.h>
|
||||
#include <lightningd/dual_open_control.h>
|
||||
#include <lightningd/gossip_control.h>
|
||||
#include <lightningd/hsm_control.h>
|
||||
@ -1371,10 +1372,8 @@ bool peer_start_channeld(struct channel *channel,
|
||||
if (!channel->owner) {
|
||||
log_broken(channel->log, "Could not subdaemon channel: %s",
|
||||
strerror(errno));
|
||||
/* Disconnect it. */
|
||||
subd_send_msg(ld->connectd,
|
||||
take(towire_connectd_discard_peer(NULL, &channel->peer->id,
|
||||
channel->peer->connectd_counter)));
|
||||
force_peer_disconnect(ld, channel->peer,
|
||||
"Failed to create channeld");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <lightningd/chaintopology.h>
|
||||
#include <lightningd/channel.h>
|
||||
#include <lightningd/closing_control.h>
|
||||
#include <lightningd/connect_control.h>
|
||||
#include <lightningd/dual_open_control.h>
|
||||
#include <lightningd/hsm_control.h>
|
||||
#include <lightningd/jsonrpc.h>
|
||||
@ -397,9 +398,8 @@ void peer_start_closingd(struct channel *channel, struct peer_fd *peer_fd)
|
||||
log_broken(channel->log, "Could not subdaemon closing: %s",
|
||||
strerror(errno));
|
||||
/* Disconnect it. */
|
||||
subd_send_msg(ld->connectd,
|
||||
take(towire_connectd_discard_peer(NULL, &channel->peer->id,
|
||||
channel->peer->connectd_counter)));
|
||||
force_peer_disconnect(ld, channel->peer,
|
||||
"Failed to create closingd");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -614,6 +614,37 @@ static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fd
|
||||
return 0;
|
||||
}
|
||||
|
||||
void force_peer_disconnect(struct lightningd *ld,
|
||||
const struct peer *peer,
|
||||
const char *why)
|
||||
{
|
||||
struct channel *c, *next;
|
||||
|
||||
/* Don't bother on shutting down */
|
||||
if (!ld->connectd)
|
||||
return;
|
||||
|
||||
/* Disconnect subds */
|
||||
if (peer->uncommitted_channel)
|
||||
kill_uncommitted_channel(peer->uncommitted_channel, why);
|
||||
|
||||
list_for_each_safe(&peer->channels, c, next, list) {
|
||||
if (!c->owner)
|
||||
continue;
|
||||
|
||||
log_debug(c->log, "Forcing disconnect due to %s", why);
|
||||
/* This frees c! */
|
||||
if (channel_state_uncommitted(c->state))
|
||||
channel_unsaved_close_conn(c, why);
|
||||
else
|
||||
channel_set_owner(c, NULL);
|
||||
}
|
||||
|
||||
subd_send_msg(peer->ld->connectd,
|
||||
take(towire_connectd_discard_peer(NULL, &peer->id,
|
||||
peer->connectd_counter)));
|
||||
}
|
||||
|
||||
static void connect_init_done(struct subd *connectd,
|
||||
const u8 *reply,
|
||||
const int *fds UNUSED,
|
||||
|
@ -15,6 +15,11 @@ int connectd_init(struct lightningd *ld);
|
||||
void connectd_activate(struct lightningd *ld);
|
||||
void connectd_start_shutdown(struct subd *connectd);
|
||||
|
||||
/* Kill subds, tell connectd to disconnect once they're drained. */
|
||||
void force_peer_disconnect(struct lightningd *ld,
|
||||
const struct peer *peer,
|
||||
const char *why);
|
||||
|
||||
void try_reconnect(const tal_t *ctx,
|
||||
struct peer *peer,
|
||||
const struct wireaddr_internal *addrhint);
|
||||
|
@ -3873,9 +3873,8 @@ bool peer_restart_dualopend(struct peer *peer,
|
||||
log_broken(channel->log, "Could not subdaemon channel: %s",
|
||||
strerror(errno));
|
||||
/* Disconnect it. */
|
||||
subd_send_msg(peer->ld->connectd,
|
||||
take(towire_connectd_discard_peer(NULL, &channel->peer->id,
|
||||
channel->peer->connectd_counter)));
|
||||
force_peer_disconnect(peer->ld, peer,
|
||||
"Failed to create dualopend");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2431,9 +2431,7 @@ static struct command_result *json_disconnect(struct command *cmd,
|
||||
channel_state_name(channel));
|
||||
}
|
||||
|
||||
subd_send_msg(peer->ld->connectd,
|
||||
take(towire_connectd_discard_peer(NULL, &peer->id,
|
||||
peer->connectd_counter)));
|
||||
force_peer_disconnect(cmd->ld, peer, "disconnect command");
|
||||
|
||||
/* Connectd tells us when it's finally disconnected */
|
||||
dc = tal(cmd, struct disconnect_command);
|
||||
|
@ -255,6 +255,11 @@ struct plugin *find_plugin_for_command(struct lightningd *ld UNNEEDED,
|
||||
/* Generated stub for fixup_htlcs_out */
|
||||
void fixup_htlcs_out(struct lightningd *ld UNNEEDED)
|
||||
{ fprintf(stderr, "fixup_htlcs_out called!\n"); abort(); }
|
||||
/* Generated stub for force_peer_disconnect */
|
||||
void force_peer_disconnect(struct lightningd *ld UNNEEDED,
|
||||
const struct peer *peer UNNEEDED,
|
||||
const char *why UNNEEDED)
|
||||
{ fprintf(stderr, "force_peer_disconnect called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_bigsize */
|
||||
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
|
||||
@ -885,9 +890,6 @@ u8 *towire_channeld_dev_memleak(const tal_t *ctx UNNEEDED)
|
||||
/* Generated stub for towire_channeld_dev_reenable_commit */
|
||||
u8 *towire_channeld_dev_reenable_commit(const tal_t *ctx UNNEEDED)
|
||||
{ fprintf(stderr, "towire_channeld_dev_reenable_commit called!\n"); abort(); }
|
||||
/* Generated stub for towire_connectd_discard_peer */
|
||||
u8 *towire_connectd_discard_peer(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, u64 counter UNNEEDED)
|
||||
{ fprintf(stderr, "towire_connectd_discard_peer called!\n"); abort(); }
|
||||
/* Generated stub for towire_connectd_peer_connect_subd */
|
||||
u8 *towire_connectd_peer_connect_subd(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, u64 counter UNNEEDED, const struct channel_id *channel_id UNNEEDED)
|
||||
{ fprintf(stderr, "towire_connectd_peer_connect_subd called!\n"); abort(); }
|
||||
|
@ -165,6 +165,11 @@ void fatal(const char *fmt UNNEEDED, ...)
|
||||
/* Generated stub for fatal_vfmt */
|
||||
void fatal_vfmt(const char *fmt UNNEEDED, va_list ap UNNEEDED)
|
||||
{ fprintf(stderr, "fatal_vfmt called!\n"); abort(); }
|
||||
/* Generated stub for force_peer_disconnect */
|
||||
void force_peer_disconnect(struct lightningd *ld UNNEEDED,
|
||||
const struct peer *peer UNNEEDED,
|
||||
const char *why UNNEEDED)
|
||||
{ fprintf(stderr, "force_peer_disconnect called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_channeld_dev_memleak_reply */
|
||||
bool fromwire_channeld_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_channeld_dev_memleak_reply called!\n"); abort(); }
|
||||
@ -769,9 +774,6 @@ u8 *towire_channeld_offer_htlc(const tal_t *ctx UNNEEDED, struct amount_msat amo
|
||||
/* Generated stub for towire_channeld_sending_commitsig_reply */
|
||||
u8 *towire_channeld_sending_commitsig_reply(const tal_t *ctx UNNEEDED)
|
||||
{ fprintf(stderr, "towire_channeld_sending_commitsig_reply called!\n"); abort(); }
|
||||
/* Generated stub for towire_connectd_discard_peer */
|
||||
u8 *towire_connectd_discard_peer(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, u64 counter UNNEEDED)
|
||||
{ fprintf(stderr, "towire_connectd_discard_peer called!\n"); abort(); }
|
||||
/* Generated stub for towire_connectd_peer_connect_subd */
|
||||
u8 *towire_connectd_peer_connect_subd(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, u64 counter UNNEEDED, const struct channel_id *channel_id UNNEEDED)
|
||||
{ fprintf(stderr, "towire_connectd_peer_connect_subd called!\n"); abort(); }
|
||||
|
Loading…
Reference in New Issue
Block a user