lightningd/channel.h: rename channel_unsaved to the more explicit channel_state_uncommitted.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-10-02 09:29:50 +10:30
parent b228999e67
commit 3589cf6713
7 changed files with 38 additions and 21 deletions

View file

@ -968,7 +968,8 @@ void channel_internal_error(struct channel *channel, const char *fmt, ...)
channel_cleanup_commands(channel, why);
if (channel_unsaved(channel)) {
/* Nothing ventured, nothing lost! */
if (channel_state_uncommitted(channel)) {
channel_set_owner(channel, NULL);
delete_channel(channel);
tal_free(why);

View file

@ -551,16 +551,32 @@ static inline bool channel_state_closed(enum channel_state state)
abort();
}
static inline bool channel_unsaved(const struct channel *channel)
/* Not even int the database yet? */
static inline bool channel_state_uncommitted(const struct channel *channel)
{
return channel->state == DUALOPEND_OPEN_INIT
&& channel->dbid == 0;
switch (channel->state) {
case DUALOPEND_OPEN_INIT:
return channel->dbid == 0;
case CHANNELD_AWAITING_LOCKIN:
case DUALOPEND_AWAITING_LOCKIN:
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
case CLOSINGD_SIGEXCHANGE:
case CHANNELD_SHUTTING_DOWN:
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
return false;
}
abort();
}
/* Established enough, that we could reach out to peer to discuss */
static inline bool channel_wants_peercomms(const struct channel *channel)
{
if (channel_unsaved(channel))
if (channel_state_uncommitted(channel))
return false;
switch (channel->state) {
@ -585,7 +601,7 @@ static inline bool channel_wants_peercomms(const struct channel *channel)
/* Established enough, that we have to fail onto chain */
static inline bool channel_wants_onchain_fail(const struct channel *channel)
{
if (channel_unsaved(channel))
if (channel_state_uncommitted(channel))
return false;
switch (channel->state) {

View file

@ -1585,7 +1585,7 @@ void channel_notify_new_block(struct lightningd *ld,
peer;
peer = peer_node_id_map_next(ld->peers, &it)) {
list_for_each(&peer->channels, channel, list) {
if (channel_unsaved(channel))
if (channel_state_uncommitted(channel))
continue;
if (is_fundee_should_forget(ld, channel, block_height)) {
tal_arr_expand(&to_forget, channel);

View file

@ -620,7 +620,7 @@ static struct command_result *param_channel_or_peer(struct command *cmd,
if ((*sc)->uc)
return NULL;
(*sc)->unsaved_channel = peer_any_channel(peer, channel_unsaved, &more_than_one);
(*sc)->unsaved_channel = peer_any_channel(peer, channel_state_uncommitted, &more_than_one);
if ((*sc)->unsaved_channel) {
if (more_than_one)
goto more_than_one;

View file

@ -58,7 +58,7 @@ static void channel_disconnect(struct channel *channel,
void channel_unsaved_close_conn(struct channel *channel, const char *why)
{
/* Gotta be unsaved */
assert(channel_unsaved(channel));
assert(channel_state_uncommitted(channel));
log_info(channel->log, "Unsaved peer failed."
" Disconnecting and deleting channel. Reason: %s",
why);
@ -77,7 +77,7 @@ static void channel_saved_err_broken_reconn(struct channel *channel,
const char *errmsg;
/* We only reconnect to 'saved' channel peers */
assert(!channel_unsaved(channel));
assert(!channel_state_uncommitted(channel));
va_start(ap, fmt);
errmsg = tal_vfmt(tmpctx, fmt, ap);
@ -97,7 +97,7 @@ static void channel_err_broken(struct channel *channel,
errmsg = tal_vfmt(tmpctx, fmt, ap);
va_end(ap);
if (channel_unsaved(channel)) {
if (channel_state_uncommitted(channel)) {
log_broken(channel->log, "%s", errmsg);
channel_unsaved_close_conn(channel, errmsg);
} else
@ -1374,7 +1374,7 @@ static void handle_peer_wants_to_close(struct subd *dualopend,
OPT_ANCHORS_ZERO_FEE_HTLC_TX);
/* We shouldn't get this message while we're waiting to finish */
if (channel_unsaved(channel)) {
if (channel_state_uncommitted(channel)) {
log_broken(dualopend->ld->log, "Channel in wrong state for"
" shutdown, still has uncommitted"
" channel pending.");
@ -3604,7 +3604,7 @@ static void dualopen_errmsg(struct channel *channel,
/* Clean up any in-progress open attempts */
channel_cleanup_commands(channel, desc);
if (channel_unsaved(channel)) {
if (channel_state_uncommitted(channel)) {
log_info(channel->log, "%s", "Unsaved peer failed."
" Deleting channel.");
delete_channel(channel);
@ -3769,7 +3769,7 @@ bool peer_restart_dualopend(struct peer *peer,
u32 *local_shutdown_script_wallet_index;
u8 *msg;
if (channel_unsaved(channel))
if (channel_state_uncommitted(channel))
return peer_start_dualopend(peer, peer_fd, channel);
hsmfd = hsm_get_client_fd(peer->ld, &peer->id, channel->dbid,

View file

@ -179,7 +179,7 @@ static void peer_channels_cleanup(struct lightningd *ld,
if (channel_wants_peercomms(c)) {
channel_cleanup_commands(c, "Disconnected");
channel_fail_transient(c, true, "Disconnected");
} else if (channel_unsaved(c)) {
} else if (channel_state_uncommitted(c)) {
channel_unsaved_close_conn(c, "Disconnected");
}
}
@ -397,7 +397,7 @@ void channel_errmsg(struct channel *channel,
/* Clean up any in-progress open attempts */
channel_cleanup_commands(channel, desc);
if (channel_unsaved(channel)) {
if (channel_state_uncommitted(channel)) {
log_info(channel->log, "%s", "Unsaved peer failed."
" Deleting channel.");
delete_channel(channel);
@ -2162,7 +2162,7 @@ static void json_add_peer(struct lightningd *ld,
json_add_uncommitted_channel(response, p->uncommitted_channel, NULL);
list_for_each(&p->channels, channel, list) {
if (channel_unsaved(channel))
if (channel_state_uncommitted(channel))
json_add_unsaved_channel(response, channel, NULL);
else
json_add_channel(ld, response, NULL, channel, NULL);
@ -2281,7 +2281,7 @@ static void json_add_peerchannels(struct lightningd *ld,
json_add_uncommitted_channel(response, peer->uncommitted_channel, peer);
list_for_each(&peer->channels, channel, list) {
if (channel_unsaved(channel))
if (channel_state_uncommitted(channel))
json_add_unsaved_channel(response, channel, peer);
else
json_add_channel(ld, response, NULL, channel, peer);
@ -2379,7 +2379,7 @@ static void setup_peer(struct peer *peer, u32 delay)
bool connect = false;
list_for_each(&peer->channels, channel, list) {
if (channel_unsaved(channel))
if (channel_state_uncommitted(channel))
continue;
/* Watching lockin may be unnecessary, but it's harmless. */
channel_watch_funding(ld, channel);
@ -3300,7 +3300,7 @@ static struct command_result *json_dev_forget_channel(struct command *cmd,
"or `dev-fail` instead.");
}
if (!channel_unsaved(forget->channel))
if (!channel_state_uncommitted(forget->channel))
bitcoind_getutxout(cmd->ld->topology->bitcoind,
&forget->channel->funding,
process_dev_forget_channel, forget);

View file

@ -382,7 +382,7 @@ static struct command_result *json_listfunds(struct command *cmd,
struct channel *c;
list_for_each(&p->channels, c, list) {
/* We don't print out uncommitted channels */
if (channel_unsaved(c))
if (channel_state_uncommitted(c))
continue;
json_object_start(response, NULL);
json_add_node_id(response, "peer_id", &p->id);