diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 9151276de..4708578cb 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -2842,24 +2842,6 @@ static struct command_result *json_openchannel_init(struct command *cmd, return command_fail(cmd, FUNDING_UNKNOWN_PEER, "Unknown peer"); } - channel = peer_any_unsaved_channel(peer, NULL); - if (!channel) { - channel = new_unsaved_channel(peer, - peer->ld->config.fee_base, - peer->ld->config.fee_per_satoshi); - - /* We derive initial channel_id *now*, so we can tell it to - * connectd. */ - derive_tmp_channel_id(&channel->cid, - &channel->local_basepoints.revocation); - } - - if (channel->open_attempt - || !list_empty(&channel->inflights)) - return command_fail(cmd, FUNDING_STATE_INVALID, - "Channel funding in-progress. %s", - channel_state_name(channel)); - if (!feature_negotiated(cmd->ld->our_features, peer->their_features, OPT_DUAL_FUND)) { @@ -2898,6 +2880,20 @@ static struct command_result *json_openchannel_init(struct command *cmd, type_to_string(tmpctx, struct wally_psbt, psbt)); + if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) { + return command_fail(cmd, FUND_MAX_EXCEEDED, + "Failed to create socketpair: %s", + strerror(errno)); + } + + /* Now we can't fail, create channel */ + channel = new_unsaved_channel(peer, + peer->ld->config.fee_base, + peer->ld->config.fee_per_satoshi); + /* We derive initial channel_id *now*, so we can tell it to connectd. */ + derive_tmp_channel_id(&channel->cid, + &channel->local_basepoints.revocation); + /* Get a new open_attempt going */ channel->opener = LOCAL; channel->open_attempt = oa = new_channel_open_attempt(channel); @@ -2943,12 +2939,6 @@ static struct command_result *json_openchannel_init(struct command *cmd, false, rates); - if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) { - return command_fail(cmd, FUND_MAX_EXCEEDED, - "Failed to create socketpair: %s", - strerror(errno)); - } - /* Start dualopend! */ if (!peer_start_dualopend(peer, new_peer_fd(cmd, fds[0]), channel)) { close(fds[1]); @@ -3424,24 +3414,14 @@ static struct command_result *json_queryrates(struct command *cmd, peer->connected == PEER_DISCONNECTED ? "not connected" : "still connecting"); - /* 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, - peer->ld->config.fee_per_satoshi); + channel = new_unsaved_channel(peer, + peer->ld->config.fee_base, + peer->ld->config.fee_per_satoshi); - /* We derive initial channel_id *now*, so we can tell it to - * connectd. */ - derive_tmp_channel_id(&channel->cid, - &channel->local_basepoints.revocation); - } - - if (channel->open_attempt - || !list_empty(&channel->inflights)) - return command_fail(cmd, FUNDING_STATE_INVALID, - "Channel funding in-progress. %s", - channel_state_name(channel)); + /* We derive initial channel_id *now*, so we can tell it to + * connectd. */ + derive_tmp_channel_id(&channel->cid, + &channel->local_basepoints.revocation); if (!feature_negotiated(cmd->ld->our_features, peer->their_features, diff --git a/tests/test_connection.py b/tests/test_connection.py index d2aa4167c..d39e6c815 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1460,9 +1460,6 @@ def test_funding_v2_corners(node_factory, bitcoind): l1.rpc.openchannel_init(l2.info['id'], amount + 1, psbt) start = l1.rpc.openchannel_init(l2.info['id'], amount, psbt) - with pytest.raises(RpcError, match=r'Channel funding in-progress. DUALOPEND_OPEN_INIT'): - l1.rpc.fundchannel(l2.info['id'], amount) - # We can abort a channel l1.rpc.openchannel_abort(start['channel_id'])