lightningd: remove (most) functions to search channels by status.

This is generally verboten now, since there can be multiple.  There are a
few exceptions:

1. We sometimes want to know if there are *any* active channels.
2. Some dev commands still take peer id when they mean channel_id.
3. We still allow peer id when it's fully determined.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON-RPC: `close` by peer id will fail if there is more than one live channel (use `channel_id` or `short_channel_id` as id arg).
This commit is contained in:
Rusty Russell
2022-03-23 09:29:20 +10:30
parent f85425d106
commit 21e1d68e3b
11 changed files with 181 additions and 150 deletions

View File

@@ -1782,7 +1782,7 @@ static void accepter_got_offer(struct subd *dualopend,
{
struct openchannel2_payload *payload;
if (peer_active_channel(channel->peer)) {
if (peer_any_active_channel(channel->peer, NULL)) {
subd_send_msg(dualopend,
take(towire_dualopend_fail(NULL,
"Already have active channel")));
@@ -2584,13 +2584,13 @@ static struct command_result *json_openchannel_init(struct command *cmd,
return command_fail(cmd, FUNDING_UNKNOWN_PEER, "Unknown peer");
}
channel = peer_active_channel(peer);
channel = peer_any_active_channel(peer, NULL);
if (channel) {
return command_fail(cmd, LIGHTNINGD, "Peer already %s",
channel_state_name(channel));
}
channel = peer_unsaved_channel(peer);
channel = peer_any_unsaved_channel(peer, NULL);
if (!channel) {
channel = new_unsaved_channel(peer,
peer->ld->config.fee_base,
@@ -2839,18 +2839,6 @@ static void handle_commit_received(struct subd *dualopend,
total_funding);
if (channel->state == DUALOPEND_OPEN_INIT) {
if (peer_active_channel(channel->peer)) {
channel_saved_err_broken_reconn(channel,
"Already have active"
" channel with %s",
type_to_string(tmpctx,
struct node_id,
&channel->peer->id));
channel->open_attempt
= tal_free(channel->open_attempt);
return;
}
if (!(inflight = wallet_commit_channel(ld, channel,
remote_commit,
&remote_commit_sig,
@@ -3091,15 +3079,8 @@ static struct command_result *json_queryrates(struct command *cmd,
return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED,
"Peer not connected");
/* We can't query rates for a peer we have a channel with */
channel = peer_active_channel(peer);
if (channel)
return command_fail(cmd, LIGHTNINGD, "Peer in state %s,"
" can't query peer's rates if already"
" have a channel",
channel_state_name(channel));
channel = peer_unsaved_channel(peer);
/* FIXME: This is wrong: we should always create a new channel? */
channel = peer_any_unsaved_channel(peer, NULL);
if (!channel) {
channel = new_unsaved_channel(peer,
peer->ld->config.fee_base,