mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
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.
This commit is contained in:
parent
278b69dfbe
commit
6ea1de4448
@ -235,18 +235,11 @@ static void peer_start_closingd_after_shutdown(struct channel *channel,
|
||||
channel_set_state(channel, CHANNELD_SHUTTING_DOWN, CLOSINGD_SIGEXCHANGE);
|
||||
}
|
||||
|
||||
static void handle_error_channel(struct channel *channel,
|
||||
const u8 *msg)
|
||||
static void forget(struct channel *channel)
|
||||
{
|
||||
struct command **forgets = tal_steal(tmpctx, channel->forgets);
|
||||
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. */
|
||||
delete_channel(channel);
|
||||
|
||||
@ -262,6 +255,35 @@ static void handle_error_channel(struct channel *channel,
|
||||
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)
|
||||
{
|
||||
enum channel_wire_type t = fromwire_peektype(msg);
|
||||
|
@ -30,4 +30,7 @@ struct command_result *cancel_channel_before_broadcast(struct command *cmd,
|
||||
struct peer *peer,
|
||||
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 */
|
||||
|
Loading…
Reference in New Issue
Block a user