Browse Source

channel control: break out separate method for canceling

Break out a method for canceling a channel that will either
loop through contacting the peer to tell them of the error or
just directly cleans up if the peer is currently disconnected.
travis-debug
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
6ea1de4448
  1. 38
      lightningd/channel_control.c
  2. 3
      lightningd/channel_control.h

38
lightningd/channel_control.c

@ -235,18 +235,11 @@ static void peer_start_closingd_after_shutdown(struct channel *channel,
channel_set_state(channel, CHANNELD_SHUTTING_DOWN, CLOSINGD_SIGEXCHANGE); channel_set_state(channel, CHANNELD_SHUTTING_DOWN, CLOSINGD_SIGEXCHANGE);
} }
static void handle_error_channel(struct channel *channel, static void forget(struct channel *channel)
const u8 *msg)
{ {
struct command **forgets = tal_steal(tmpctx, channel->forgets); struct command **forgets = tal_steal(tmpctx, channel->forgets);
channel->forgets = tal_arr(channel, struct command *, 0); channel->forgets = tal_arr(channel, struct command *, 0);
if (!fromwire_channel_send_error_reply(msg)) {
channel_internal_error(channel, "bad send_error_reply: %s",
tal_hex(tmpctx, msg));
return;
}
/* Forget the channel. */ /* Forget the channel. */
delete_channel(channel); delete_channel(channel);
@ -262,6 +255,35 @@ static void handle_error_channel(struct channel *channel,
tal_free(forgets); tal_free(forgets);
} }
static void handle_error_channel(struct channel *channel,
const u8 *msg)
{
if (!fromwire_channel_send_error_reply(msg)) {
channel_internal_error(channel, "bad send_error_reply: %s",
tal_hex(tmpctx, msg));
return;
}
forget(channel);
}
void forget_channel(struct channel *channel, const char *why)
{
struct channel_id cid;
derive_channel_id(&cid, &channel->funding_txid,
channel->funding_outnum);
channel->error = towire_errorfmt(channel, &cid, "%s", why);
/* If the peer is connected, we let them know. Otherwise
* we just directly remove the channel */
if (channel->owner)
subd_send_msg(channel->owner,
take(towire_channel_send_error(NULL, why)));
else
forget(channel);
}
static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds) static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
{ {
enum channel_wire_type t = fromwire_peektype(msg); enum channel_wire_type t = fromwire_peektype(msg);

3
lightningd/channel_control.h

@ -30,4 +30,7 @@ struct command_result *cancel_channel_before_broadcast(struct command *cmd,
struct peer *peer, struct peer *peer,
const jsmntok_t *cidtok); const jsmntok_t *cidtok);
/* Forget a channel. Deletes the channel and handles all
* associated waiting commands, if present. Notifies peer if available */
void forget_channel(struct channel *channel, const char *err_msg);
#endif /* LIGHTNING_LIGHTNINGD_CHANNEL_CONTROL_H */ #endif /* LIGHTNING_LIGHTNINGD_CHANNEL_CONTROL_H */

Loading…
Cancel
Save