Browse Source

lightningd: clean up close code now force is always true.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-experimental
Rusty Russell 4 years ago
parent
commit
0dec593aa8
  1. 37
      lightningd/peer_control.c

37
lightningd/peer_control.c

@ -70,8 +70,6 @@ struct close_command {
struct command *cmd; struct command *cmd;
/* Channel being closed. */ /* Channel being closed. */
struct channel *channel; struct channel *channel;
/* Should we force the close on timeout? */
bool force;
}; };
static void destroy_peer(struct peer *peer) static void destroy_peer(struct peer *peer)
@ -283,18 +281,11 @@ destroy_close_command(struct close_command *cc)
static void static void
close_command_timeout(struct close_command *cc) close_command_timeout(struct close_command *cc)
{ {
if (cc->force) /* This will trigger drop_to_chain, which will trigger
/* This will trigger drop_to_chain, which will trigger * resolution of the command and destruction of the
* resolution of the command and destruction of the * close_command. */
* close_command. */ channel_fail_permanent(cc->channel,
channel_fail_permanent(cc->channel, "Forcibly closed by 'close' command timeout");
"Forcibly closed by 'close' command timeout");
else
/* Fail the command directly, which will resolve the
* command and destroy the close_command. */
was_pending(command_fail(cc->cmd, LIGHTNINGD,
"Channel close negotiation not finished "
"before timeout"));
} }
/* Construct a close command structure and add to ld. */ /* Construct a close command structure and add to ld. */
@ -302,8 +293,7 @@ static void
register_close_command(struct lightningd *ld, register_close_command(struct lightningd *ld,
struct command *cmd, struct command *cmd,
struct channel *channel, struct channel *channel,
unsigned int *timeout, unsigned int timeout)
bool force)
{ {
struct close_command *cc; struct close_command *cc;
assert(channel); assert(channel);
@ -312,15 +302,13 @@ register_close_command(struct lightningd *ld,
list_add_tail(&ld->close_commands, &cc->list); list_add_tail(&ld->close_commands, &cc->list);
cc->cmd = cmd; cc->cmd = cmd;
cc->channel = channel; cc->channel = channel;
cc->force = force;
tal_add_destructor(cc, &destroy_close_command); tal_add_destructor(cc, &destroy_close_command);
tal_add_destructor2(channel, tal_add_destructor2(channel,
&destroy_close_command_on_channel_destroy, &destroy_close_command_on_channel_destroy,
cc); cc);
log_debug(ld->log, "close_command: force = %u, timeout = %i", log_debug(ld->log, "close_command: timeout = %u", timeout);
force, timeout ? *timeout : -1);
if (timeout) if (timeout)
new_reltimer(ld->timers, cc, time_from_sec(*timeout), new_reltimer(ld->timers, cc, time_from_sec(timeout),
&close_command_timeout, cc); &close_command_timeout, cc);
} }
@ -1393,9 +1381,7 @@ static struct command_result *json_close(struct command *cmd,
const jsmntok_t *idtok; const jsmntok_t *idtok;
struct peer *peer; struct peer *peer;
struct channel *channel COMPILER_WANTS_INIT("gcc 7.3.0 fails, 8.3 OK"); struct channel *channel COMPILER_WANTS_INIT("gcc 7.3.0 fails, 8.3 OK");
unsigned int *timeout = NULL; unsigned int *timeout;
bool force = true;
bool do_timeout;
const u8 *close_to_script = NULL; const u8 *close_to_script = NULL;
bool close_script_set; bool close_script_set;
const char *fee_negotiation_step_str; const char *fee_negotiation_step_str;
@ -1411,8 +1397,6 @@ static struct command_result *json_close(struct command *cmd,
NULL)) NULL))
return command_param_failed(); return command_param_failed();
do_timeout = (*timeout != 0);
peer = peer_from_json(cmd->ld, buffer, idtok); peer = peer_from_json(cmd->ld, buffer, idtok);
if (peer) if (peer)
channel = peer_active_channel(peer); channel = peer_active_channel(peer);
@ -1539,8 +1523,7 @@ static struct command_result *json_close(struct command *cmd,
} }
/* Register this command for later handling. */ /* Register this command for later handling. */
register_close_command(cmd->ld, cmd, channel, register_close_command(cmd->ld, cmd, channel, *timeout);
do_timeout ? timeout : NULL, force);
/* If we set `channel->shutdown_scriptpubkey[LOCAL]`, save it. */ /* If we set `channel->shutdown_scriptpubkey[LOCAL]`, save it. */
if (close_script_set) if (close_script_set)

Loading…
Cancel
Save