mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-23 06:54:30 +01:00
lightningd: don't explicitly tell connectd to disconnect, have it do it on sending error/warning.
Connectd already does this when we *receive* an error or warning, but now do it on send. This causes some slight behavior change: we don't disconnect when we close a channel, for example (our behaviour here has been inconsistent across versions, depending on the code). When connectd is told to disconnect, it now does so immediately, and doesn't wait for subds to drain etc. That simplifies the manual disconnect case, which now cleans up as it would from any other disconnection when connectd says it's disconnected. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
neil saitug
parent
2962b93199
commit
a3c4908f4a
@@ -22,14 +22,10 @@
|
||||
void channel_set_owner(struct channel *channel, struct subd *owner)
|
||||
{
|
||||
struct subd *old_owner = channel->owner;
|
||||
bool was_connected = channel_is_connected(channel);
|
||||
channel->owner = owner;
|
||||
|
||||
if (old_owner) {
|
||||
if (old_owner)
|
||||
subd_release_channel(old_owner, channel);
|
||||
if (was_connected && !channel_is_connected(channel))
|
||||
maybe_disconnect_peer(channel->peer->ld, channel->peer);
|
||||
}
|
||||
}
|
||||
|
||||
struct htlc_out *channel_has_htlc_out(struct channel *channel)
|
||||
|
||||
@@ -641,33 +641,6 @@ void connectd_activate(struct lightningd *ld)
|
||||
assert(ret == ld->connectd);
|
||||
}
|
||||
|
||||
void maybe_disconnect_peer(struct lightningd *ld, struct peer *peer)
|
||||
{
|
||||
struct channel *channel;
|
||||
|
||||
/* Any channels left which want to talk? */
|
||||
if (peer->uncommitted_channel)
|
||||
return;
|
||||
|
||||
list_for_each(&peer->channels, channel, list)
|
||||
if (channel_is_connected(channel))
|
||||
return;
|
||||
|
||||
/* If shutting down, connectd no longer exists.
|
||||
* FIXME: Call peer_disconnect_done(), but nobody cares. */
|
||||
if (!ld->connectd) {
|
||||
peer->connected = PEER_DISCONNECTED;
|
||||
return;
|
||||
}
|
||||
|
||||
/* If connectd was the one who told us to cleanup peer, don't
|
||||
* tell it to discard again: it might have reconnected! */
|
||||
if (peer->connected == PEER_CONNECTED)
|
||||
subd_send_msg(ld->connectd,
|
||||
take(towire_connectd_discard_peer(NULL, &peer->id,
|
||||
peer->connectd_counter)));
|
||||
}
|
||||
|
||||
static struct command_result *json_sendcustommsg(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
|
||||
@@ -24,7 +24,4 @@ void connect_failed_disconnect(struct lightningd *ld,
|
||||
const struct node_id *id,
|
||||
const struct wireaddr_internal *addr);
|
||||
|
||||
/* Disconnect a peer (if no subds want to talk any more) */
|
||||
void maybe_disconnect_peer(struct lightningd *ld, struct peer *peer);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_CONNECT_CONTROL_H */
|
||||
|
||||
@@ -31,7 +31,6 @@ static void destroy_uncommitted_channel(struct uncommitted_channel *uc)
|
||||
|
||||
uc->peer->uncommitted_channel = NULL;
|
||||
|
||||
maybe_disconnect_peer(uc->peer->ld, uc->peer);
|
||||
maybe_delete_peer(uc->peer);
|
||||
}
|
||||
|
||||
|
||||
@@ -1539,11 +1539,6 @@ void peer_disconnect_done(struct lightningd *ld, const u8 *msg)
|
||||
assert(p->connectd_counter == connectd_counter);
|
||||
log_peer_debug(ld->log, &id, "peer_disconnect_done");
|
||||
p->connected = PEER_DISCONNECTED;
|
||||
|
||||
/* If there are literally no channels, might as well
|
||||
* free immediately. */
|
||||
if (!p->uncommitted_channel && list_empty(&p->channels))
|
||||
p = tal_free(p);
|
||||
}
|
||||
|
||||
/* If you were trying to connect, it failed. */
|
||||
@@ -1561,6 +1556,10 @@ void peer_disconnect_done(struct lightningd *ld, const u8 *msg)
|
||||
was_pending(command_success(i->cmd,
|
||||
json_stream_success(i->cmd)));
|
||||
}
|
||||
|
||||
/* If connection was only thing keeping it, this will delete it. */
|
||||
if (p)
|
||||
maybe_delete_peer(p);
|
||||
}
|
||||
|
||||
static bool check_funding_details(const struct bitcoin_tx *tx,
|
||||
@@ -2084,9 +2083,8 @@ static struct command_result *json_disconnect(struct command *cmd,
|
||||
struct node_id *id;
|
||||
struct disconnect_command *dc;
|
||||
struct peer *peer;
|
||||
struct channel *channel, **channels;
|
||||
struct channel *channel;
|
||||
bool *force;
|
||||
bool disconnected = false;
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("id", param_node_id, &id),
|
||||
@@ -2109,58 +2107,11 @@ static struct command_result *json_disconnect(struct command *cmd,
|
||||
channel_state_name(channel));
|
||||
}
|
||||
|
||||
/* Careful here! Disconnecting can free peer! */
|
||||
channels = tal_arr(cmd, struct channel *, 0);
|
||||
list_for_each(&peer->channels, channel, list) {
|
||||
if (!channel->owner)
|
||||
continue;
|
||||
if (!channel->owner->talks_to_peer)
|
||||
continue;
|
||||
|
||||
switch (channel->state) {
|
||||
case DUALOPEND_OPEN_INIT:
|
||||
case CHANNELD_AWAITING_LOCKIN:
|
||||
case CHANNELD_NORMAL:
|
||||
case CHANNELD_SHUTTING_DOWN:
|
||||
case DUALOPEND_AWAITING_LOCKIN:
|
||||
case CLOSINGD_SIGEXCHANGE:
|
||||
tal_arr_expand(&channels, channel);
|
||||
continue;
|
||||
case CLOSINGD_COMPLETE:
|
||||
case AWAITING_UNILATERAL:
|
||||
case FUNDING_SPEND_SEEN:
|
||||
case ONCHAIN:
|
||||
case CLOSED:
|
||||
/* We don't expect these to have owners who connect! */
|
||||
log_broken(channel->log,
|
||||
"Don't expect owner %s in state %s",
|
||||
channel->owner->name,
|
||||
channel_state_name(channel));
|
||||
continue;
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
/* This can free peer too! */
|
||||
if (peer->uncommitted_channel) {
|
||||
kill_uncommitted_channel(peer->uncommitted_channel,
|
||||
"disconnect command");
|
||||
disconnected = true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < tal_count(channels); i++) {
|
||||
if (channel_unsaved(channels[i]))
|
||||
channel_unsaved_close_conn(channels[i],
|
||||
"disconnect command");
|
||||
else
|
||||
channel_fail_reconnect(channels[i],
|
||||
"disconnect command");
|
||||
disconnected = true;
|
||||
}
|
||||
|
||||
/* It's just sitting in connectd? */
|
||||
if (!disconnected)
|
||||
maybe_disconnect_peer(cmd->ld, peer);
|
||||
/* If it's not already disconnecting, tell connectd to disconnect */
|
||||
if (peer->connected == PEER_CONNECTED)
|
||||
subd_send_msg(peer->ld->connectd,
|
||||
take(towire_connectd_discard_peer(NULL, &peer->id,
|
||||
peer->connectd_counter)));
|
||||
|
||||
/* Connectd tells us when it's finally disconnected */
|
||||
dc = tal(cmd, struct disconnect_command);
|
||||
|
||||
@@ -387,7 +387,9 @@ void json_add_short_channel_id(struct json_stream *response UNNEEDED,
|
||||
const struct short_channel_id *id UNNEEDED)
|
||||
{ fprintf(stderr, "json_add_short_channel_id called!\n"); abort(); }
|
||||
/* Generated stub for json_add_string */
|
||||
void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const char *value TAKES UNNEEDED)
|
||||
void json_add_string(struct json_stream *js UNNEEDED,
|
||||
const char *fieldname UNNEEDED,
|
||||
const char *str TAKES UNNEEDED)
|
||||
{ fprintf(stderr, "json_add_string called!\n"); abort(); }
|
||||
/* Generated stub for json_add_stringn */
|
||||
void json_add_stringn(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
|
||||
@@ -509,9 +511,6 @@ void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "log_ called!\n"); abort(); }
|
||||
/* Generated stub for maybe_disconnect_peer */
|
||||
void maybe_disconnect_peer(struct lightningd *ld UNNEEDED, struct peer *peer UNNEEDED)
|
||||
{ fprintf(stderr, "maybe_disconnect_peer called!\n"); abort(); }
|
||||
/* Generated stub for merkle_tlv */
|
||||
void merkle_tlv(const struct tlv_field *fields UNNEEDED, struct sha256 *merkle UNNEEDED)
|
||||
{ fprintf(stderr, "merkle_tlv called!\n"); abort(); }
|
||||
@@ -716,6 +715,9 @@ 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(); }
|
||||
|
||||
@@ -47,7 +47,9 @@ void json_add_str_fmt(struct json_stream *js UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
{ fprintf(stderr, "json_add_str_fmt called!\n"); abort(); }
|
||||
/* Generated stub for json_add_string */
|
||||
void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const char *value TAKES UNNEEDED)
|
||||
void json_add_string(struct json_stream *js UNNEEDED,
|
||||
const char *fieldname UNNEEDED,
|
||||
const char *str TAKES UNNEEDED)
|
||||
{ fprintf(stderr, "json_add_string called!\n"); abort(); }
|
||||
/* Generated stub for json_add_time */
|
||||
void json_add_time(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
|
||||
|
||||
Reference in New Issue
Block a user