mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-11 01:27:58 +01:00
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:
parent
b228999e67
commit
3589cf6713
7 changed files with 38 additions and 21 deletions
|
@ -968,7 +968,8 @@ void channel_internal_error(struct channel *channel, const char *fmt, ...)
|
||||||
|
|
||||||
channel_cleanup_commands(channel, why);
|
channel_cleanup_commands(channel, why);
|
||||||
|
|
||||||
if (channel_unsaved(channel)) {
|
/* Nothing ventured, nothing lost! */
|
||||||
|
if (channel_state_uncommitted(channel)) {
|
||||||
channel_set_owner(channel, NULL);
|
channel_set_owner(channel, NULL);
|
||||||
delete_channel(channel);
|
delete_channel(channel);
|
||||||
tal_free(why);
|
tal_free(why);
|
||||||
|
|
|
@ -551,16 +551,32 @@ static inline bool channel_state_closed(enum channel_state state)
|
||||||
abort();
|
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
|
switch (channel->state) {
|
||||||
&& channel->dbid == 0;
|
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 */
|
/* Established enough, that we could reach out to peer to discuss */
|
||||||
static inline bool channel_wants_peercomms(const struct channel *channel)
|
static inline bool channel_wants_peercomms(const struct channel *channel)
|
||||||
{
|
{
|
||||||
if (channel_unsaved(channel))
|
if (channel_state_uncommitted(channel))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (channel->state) {
|
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 */
|
/* Established enough, that we have to fail onto chain */
|
||||||
static inline bool channel_wants_onchain_fail(const struct channel *channel)
|
static inline bool channel_wants_onchain_fail(const struct channel *channel)
|
||||||
{
|
{
|
||||||
if (channel_unsaved(channel))
|
if (channel_state_uncommitted(channel))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (channel->state) {
|
switch (channel->state) {
|
||||||
|
|
|
@ -1585,7 +1585,7 @@ void channel_notify_new_block(struct lightningd *ld,
|
||||||
peer;
|
peer;
|
||||||
peer = peer_node_id_map_next(ld->peers, &it)) {
|
peer = peer_node_id_map_next(ld->peers, &it)) {
|
||||||
list_for_each(&peer->channels, channel, list) {
|
list_for_each(&peer->channels, channel, list) {
|
||||||
if (channel_unsaved(channel))
|
if (channel_state_uncommitted(channel))
|
||||||
continue;
|
continue;
|
||||||
if (is_fundee_should_forget(ld, channel, block_height)) {
|
if (is_fundee_should_forget(ld, channel, block_height)) {
|
||||||
tal_arr_expand(&to_forget, channel);
|
tal_arr_expand(&to_forget, channel);
|
||||||
|
|
|
@ -620,7 +620,7 @@ static struct command_result *param_channel_or_peer(struct command *cmd,
|
||||||
if ((*sc)->uc)
|
if ((*sc)->uc)
|
||||||
return NULL;
|
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 ((*sc)->unsaved_channel) {
|
||||||
if (more_than_one)
|
if (more_than_one)
|
||||||
goto more_than_one;
|
goto more_than_one;
|
||||||
|
|
|
@ -58,7 +58,7 @@ static void channel_disconnect(struct channel *channel,
|
||||||
void channel_unsaved_close_conn(struct channel *channel, const char *why)
|
void channel_unsaved_close_conn(struct channel *channel, const char *why)
|
||||||
{
|
{
|
||||||
/* Gotta be unsaved */
|
/* Gotta be unsaved */
|
||||||
assert(channel_unsaved(channel));
|
assert(channel_state_uncommitted(channel));
|
||||||
log_info(channel->log, "Unsaved peer failed."
|
log_info(channel->log, "Unsaved peer failed."
|
||||||
" Disconnecting and deleting channel. Reason: %s",
|
" Disconnecting and deleting channel. Reason: %s",
|
||||||
why);
|
why);
|
||||||
|
@ -77,7 +77,7 @@ static void channel_saved_err_broken_reconn(struct channel *channel,
|
||||||
const char *errmsg;
|
const char *errmsg;
|
||||||
|
|
||||||
/* We only reconnect to 'saved' channel peers */
|
/* We only reconnect to 'saved' channel peers */
|
||||||
assert(!channel_unsaved(channel));
|
assert(!channel_state_uncommitted(channel));
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
errmsg = tal_vfmt(tmpctx, fmt, ap);
|
errmsg = tal_vfmt(tmpctx, fmt, ap);
|
||||||
|
@ -97,7 +97,7 @@ static void channel_err_broken(struct channel *channel,
|
||||||
errmsg = tal_vfmt(tmpctx, fmt, ap);
|
errmsg = tal_vfmt(tmpctx, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (channel_unsaved(channel)) {
|
if (channel_state_uncommitted(channel)) {
|
||||||
log_broken(channel->log, "%s", errmsg);
|
log_broken(channel->log, "%s", errmsg);
|
||||||
channel_unsaved_close_conn(channel, errmsg);
|
channel_unsaved_close_conn(channel, errmsg);
|
||||||
} else
|
} else
|
||||||
|
@ -1374,7 +1374,7 @@ static void handle_peer_wants_to_close(struct subd *dualopend,
|
||||||
OPT_ANCHORS_ZERO_FEE_HTLC_TX);
|
OPT_ANCHORS_ZERO_FEE_HTLC_TX);
|
||||||
|
|
||||||
/* We shouldn't get this message while we're waiting to finish */
|
/* 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"
|
log_broken(dualopend->ld->log, "Channel in wrong state for"
|
||||||
" shutdown, still has uncommitted"
|
" shutdown, still has uncommitted"
|
||||||
" channel pending.");
|
" channel pending.");
|
||||||
|
@ -3604,7 +3604,7 @@ static void dualopen_errmsg(struct channel *channel,
|
||||||
/* Clean up any in-progress open attempts */
|
/* Clean up any in-progress open attempts */
|
||||||
channel_cleanup_commands(channel, desc);
|
channel_cleanup_commands(channel, desc);
|
||||||
|
|
||||||
if (channel_unsaved(channel)) {
|
if (channel_state_uncommitted(channel)) {
|
||||||
log_info(channel->log, "%s", "Unsaved peer failed."
|
log_info(channel->log, "%s", "Unsaved peer failed."
|
||||||
" Deleting channel.");
|
" Deleting channel.");
|
||||||
delete_channel(channel);
|
delete_channel(channel);
|
||||||
|
@ -3769,7 +3769,7 @@ bool peer_restart_dualopend(struct peer *peer,
|
||||||
u32 *local_shutdown_script_wallet_index;
|
u32 *local_shutdown_script_wallet_index;
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
|
|
||||||
if (channel_unsaved(channel))
|
if (channel_state_uncommitted(channel))
|
||||||
return peer_start_dualopend(peer, peer_fd, channel);
|
return peer_start_dualopend(peer, peer_fd, channel);
|
||||||
|
|
||||||
hsmfd = hsm_get_client_fd(peer->ld, &peer->id, channel->dbid,
|
hsmfd = hsm_get_client_fd(peer->ld, &peer->id, channel->dbid,
|
||||||
|
|
|
@ -179,7 +179,7 @@ static void peer_channels_cleanup(struct lightningd *ld,
|
||||||
if (channel_wants_peercomms(c)) {
|
if (channel_wants_peercomms(c)) {
|
||||||
channel_cleanup_commands(c, "Disconnected");
|
channel_cleanup_commands(c, "Disconnected");
|
||||||
channel_fail_transient(c, true, "Disconnected");
|
channel_fail_transient(c, true, "Disconnected");
|
||||||
} else if (channel_unsaved(c)) {
|
} else if (channel_state_uncommitted(c)) {
|
||||||
channel_unsaved_close_conn(c, "Disconnected");
|
channel_unsaved_close_conn(c, "Disconnected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,7 @@ void channel_errmsg(struct channel *channel,
|
||||||
/* Clean up any in-progress open attempts */
|
/* Clean up any in-progress open attempts */
|
||||||
channel_cleanup_commands(channel, desc);
|
channel_cleanup_commands(channel, desc);
|
||||||
|
|
||||||
if (channel_unsaved(channel)) {
|
if (channel_state_uncommitted(channel)) {
|
||||||
log_info(channel->log, "%s", "Unsaved peer failed."
|
log_info(channel->log, "%s", "Unsaved peer failed."
|
||||||
" Deleting channel.");
|
" Deleting channel.");
|
||||||
delete_channel(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);
|
json_add_uncommitted_channel(response, p->uncommitted_channel, NULL);
|
||||||
|
|
||||||
list_for_each(&p->channels, channel, list) {
|
list_for_each(&p->channels, channel, list) {
|
||||||
if (channel_unsaved(channel))
|
if (channel_state_uncommitted(channel))
|
||||||
json_add_unsaved_channel(response, channel, NULL);
|
json_add_unsaved_channel(response, channel, NULL);
|
||||||
else
|
else
|
||||||
json_add_channel(ld, response, NULL, channel, NULL);
|
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);
|
json_add_uncommitted_channel(response, peer->uncommitted_channel, peer);
|
||||||
list_for_each(&peer->channels, channel, list) {
|
list_for_each(&peer->channels, channel, list) {
|
||||||
if (channel_unsaved(channel))
|
if (channel_state_uncommitted(channel))
|
||||||
json_add_unsaved_channel(response, channel, peer);
|
json_add_unsaved_channel(response, channel, peer);
|
||||||
else
|
else
|
||||||
json_add_channel(ld, response, NULL, channel, peer);
|
json_add_channel(ld, response, NULL, channel, peer);
|
||||||
|
@ -2379,7 +2379,7 @@ static void setup_peer(struct peer *peer, u32 delay)
|
||||||
bool connect = false;
|
bool connect = false;
|
||||||
|
|
||||||
list_for_each(&peer->channels, channel, list) {
|
list_for_each(&peer->channels, channel, list) {
|
||||||
if (channel_unsaved(channel))
|
if (channel_state_uncommitted(channel))
|
||||||
continue;
|
continue;
|
||||||
/* Watching lockin may be unnecessary, but it's harmless. */
|
/* Watching lockin may be unnecessary, but it's harmless. */
|
||||||
channel_watch_funding(ld, channel);
|
channel_watch_funding(ld, channel);
|
||||||
|
@ -3300,7 +3300,7 @@ static struct command_result *json_dev_forget_channel(struct command *cmd,
|
||||||
"or `dev-fail` instead.");
|
"or `dev-fail` instead.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!channel_unsaved(forget->channel))
|
if (!channel_state_uncommitted(forget->channel))
|
||||||
bitcoind_getutxout(cmd->ld->topology->bitcoind,
|
bitcoind_getutxout(cmd->ld->topology->bitcoind,
|
||||||
&forget->channel->funding,
|
&forget->channel->funding,
|
||||||
process_dev_forget_channel, forget);
|
process_dev_forget_channel, forget);
|
||||||
|
|
|
@ -382,7 +382,7 @@ static struct command_result *json_listfunds(struct command *cmd,
|
||||||
struct channel *c;
|
struct channel *c;
|
||||||
list_for_each(&p->channels, c, list) {
|
list_for_each(&p->channels, c, list) {
|
||||||
/* We don't print out uncommitted channels */
|
/* We don't print out uncommitted channels */
|
||||||
if (channel_unsaved(c))
|
if (channel_state_uncommitted(c))
|
||||||
continue;
|
continue;
|
||||||
json_object_start(response, NULL);
|
json_object_start(response, NULL);
|
||||||
json_add_node_id(response, "peer_id", &p->id);
|
json_add_node_id(response, "peer_id", &p->id);
|
||||||
|
|
Loading…
Add table
Reference in a new issue