dualopen: check that peer is connected for json calls

Before we start trying to talk to the peer, check that they're
connected.
This commit is contained in:
niftynei 2021-01-22 11:25:21 -06:00 committed by neil saitug
parent d8221aae76
commit 02d99acca1

View File

@ -1719,6 +1719,10 @@ json_openchannel_bump(struct command *cmd,
type_to_string(tmpctx, struct channel_id, type_to_string(tmpctx, struct channel_id,
cid)); cid));
if (!channel->owner)
return command_fail(cmd, LIGHTNINGD,
"Peer not connected.");
if (channel->open_attempt) if (channel->open_attempt)
return command_fail(cmd, LIGHTNINGD, return command_fail(cmd, LIGHTNINGD,
"Commitments for this channel not " "Commitments for this channel not "
@ -1763,6 +1767,10 @@ json_openchannel_signed(struct command *cmd,
if (!channel) if (!channel)
return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL, return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL,
"Unknown channel"); "Unknown channel");
if (!channel->owner)
return command_fail(cmd, LIGHTNINGD,
"Peer not connected");
if (channel->open_attempt) if (channel->open_attempt)
return command_fail(cmd, LIGHTNINGD, return command_fail(cmd, LIGHTNINGD,
"Commitments for this channel not " "Commitments for this channel not "
@ -1870,6 +1878,10 @@ static struct command_result *json_openchannel_update(struct command *cmd,
"Unknown channel %s", "Unknown channel %s",
type_to_string(tmpctx, struct channel_id, type_to_string(tmpctx, struct channel_id,
cid)); cid));
if (!channel->owner)
return command_fail(cmd, LIGHTNINGD,
"Peer not connected");
if (!channel->open_attempt) if (!channel->open_attempt)
return command_fail(cmd, LIGHTNINGD, return command_fail(cmd, LIGHTNINGD,
"Channel open not in progress"); "Channel open not in progress");
@ -1979,10 +1991,9 @@ static struct command_result *json_openchannel_init(struct command *cmd,
} }
channel = peer_unsaved_channel(peer); channel = peer_unsaved_channel(peer);
if (!channel) if (!channel || !channel->owner)
return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED, return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED,
"Peer not connected"); "Peer not connected");
if (channel->open_attempt if (channel->open_attempt
|| !list_empty(&channel->inflights)) || !list_empty(&channel->inflights))
return command_fail(cmd, LIGHTNINGD, "Channel funding" return command_fail(cmd, LIGHTNINGD, "Channel funding"