From 50b8655cbe0c09fd827fdca015a137f134893910 Mon Sep 17 00:00:00 2001 From: niftynei Date: Tue, 19 Jan 2021 18:55:59 -0600 Subject: [PATCH] channel: remove 'uncommitted_channel' from channel lookup We're going to be removing "uncommitted_channel" from v2 open stat --- lightningd/channel.c | 14 ++++--------- lightningd/channel.h | 5 ++--- lightningd/dual_open_control.c | 36 +++++++--------------------------- 3 files changed, 13 insertions(+), 42 deletions(-) diff --git a/lightningd/channel.c b/lightningd/channel.c index 0b08aeebd..19e1e89d1 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -441,30 +441,24 @@ struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid) } struct channel *channel_by_cid(struct lightningd *ld, - const struct channel_id *cid, - struct uncommitted_channel **uc) + const struct channel_id *cid) { struct peer *p; struct channel *channel; list_for_each(&ld->peers, p, list) { if (p->uncommitted_channel) { - if (channel_id_eq(&p->uncommitted_channel->cid, cid)) { - if (uc) - *uc = p->uncommitted_channel; + /* We can't use this method for old, uncommitted + * channels; there's no "channel" struct here! */ + if (channel_id_eq(&p->uncommitted_channel->cid, cid)) return NULL; - } } list_for_each(&p->channels, channel, list) { if (channel_id_eq(&channel->cid, cid)) { - if (uc) - *uc = p->uncommitted_channel; return channel; } } } - if (uc) - *uc = NULL; return NULL; } diff --git a/lightningd/channel.h b/lightningd/channel.h index a60f29c17..f1dd947c4 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -311,10 +311,9 @@ struct channel *active_channel_by_scid(struct lightningd *ld, struct channel *any_channel_by_scid(struct lightningd *ld, const struct short_channel_id *scid); -/* Get channel by channel_id, optionally returning uncommitted_channel. */ +/* Get channel by channel_id */ struct channel *channel_by_cid(struct lightningd *ld, - const struct channel_id *cid, - struct uncommitted_channel **uc); + const struct channel_id *cid); void channel_set_last_tx(struct channel *channel, struct bitcoin_tx *tx, diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 48269f4f9..fc8b01e55 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -1702,7 +1702,6 @@ json_openchannel_signed(struct command *cmd, const jsmntok_t *params) { struct wally_psbt *psbt; - struct uncommitted_channel *uc; struct channel_id *cid; struct channel *channel; struct bitcoin_txid txid; @@ -1713,11 +1712,7 @@ json_openchannel_signed(struct command *cmd, NULL)) return command_param_failed(); - channel = channel_by_cid(cmd->ld, cid, &uc); - if (uc) - return command_fail(cmd, LIGHTNINGD, - "Commitments for this channel not " - "yet secured, see `openchannel_update`"); + channel = channel_by_cid(cmd->ld, cid); if (!channel) return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL, "Unknown channel"); @@ -1729,8 +1724,7 @@ json_openchannel_signed(struct command *cmd, "this channel"); if (channel->openchannel_signed_cmd) return command_fail(cmd, LIGHTNINGD, - "Already sent sigs, waiting for" - " peer's"); + "Already sent sigs, waiting for peer's"); /* Verify that the psbt's txid matches that of the * funding txid for this channel */ @@ -1786,7 +1780,6 @@ static struct command_result *json_openchannel_update(struct command *cmd, struct wally_psbt *psbt; struct channel_id *cid; struct channel *channel; - struct uncommitted_channel *uc; u8 *msg; if (!param(cmd, buffer, params, @@ -1795,27 +1788,13 @@ static struct command_result *json_openchannel_update(struct command *cmd, NULL)) return command_param_failed(); - /* We expect this to return NULL, as the channel hasn't been - * created yet. Instead, the uncommitted channel is populated */ - channel = channel_by_cid(cmd->ld, cid, &uc); - if (channel) - return command_fail(cmd, LIGHTNINGD, "Channel already %s", - channel_state_name(channel)); - - if (!uc) - return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL, + channel = channel_by_cid(cmd->ld, cid); + if (!channel) + return command_fail(cmd, LIGHTNINGD, "Unknown channel %s", type_to_string(tmpctx, struct channel_id, cid)); - if (!uc->fc || !uc->fc->inflight) - return command_fail(cmd, LIGHTNINGD, - "No channel funding in progress"); - - if (uc->fc->cmd) - return command_fail(cmd, LIGHTNINGD, - "Channel funding in progress"); - /* Add serials to PSBT */ psbt_add_serials(psbt, TX_INITIATOR); if (!psbt_has_required_fields(psbt)) @@ -1824,10 +1803,9 @@ static struct command_result *json_openchannel_update(struct command *cmd, type_to_string(tmpctx, struct wally_psbt, psbt)); - uc->fc->cmd = cmd; - msg = towire_dualopend_psbt_updated(NULL, psbt); - subd_send_msg(uc->open_daemon, take(msg)); + /* FIXME: daemon? */ + subd_send_msg(NULL, take(msg)); return command_still_pending(cmd); }