Skip to content

Commit

Permalink
fundchannel: add txout field to RPC/API
Browse files Browse the repository at this point in the history
We'll need the outpoint for the funding output.
  • Loading branch information
niftynei authored and rustyrussell committed Jun 12, 2019
1 parent b0b813a commit 7ea21c3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
5 changes: 3 additions & 2 deletions contrib/pylightning/lightning/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,14 @@ def fundchannel_start(self, node_id, satoshi, feerate=None, announce=True):
}
return self.call("fundchannel_start", payload)

def fundchannel_continue(self, node_id, funding_txid):
def fundchannel_continue(self, node_id, funding_txid, funding_txout):
"""
Complete channel establishment with {id}, using {funding_txid}
Complete channel establishment with {id}, using {funding_txid} at {funding_txout}
"""
payload = {
"id": node_id,
"txid": funding_txid,
"txout": funding_txout,
}
return self.call("fundchannel_continue", payload)

Expand Down
14 changes: 13 additions & 1 deletion lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
&fc->uc->minimum_depth,
&channel_info.remote_fundingkey,
&expected_txid,
&funding_outnum,
&feerate,
&fc->uc->our_config.channel_reserve,
&remote_upfront_shutdown_script)) {
Expand Down Expand Up @@ -1056,13 +1057,22 @@ static struct command_result *json_fund_channel_continue(struct command *cmd,
struct bitcoin_txid *funding_txid;
struct peer *peer;
struct channel *channel;
u32 *funding_txout_num;
u16 funding_txout;

if (!param(cmd, buffer, params,
p_req("id", param_node_id, &id),
p_req("txid", param_txid, &funding_txid),
p_req("txout", param_number, &funding_txout_num),
NULL))
return command_param_failed();

if (*funding_txout_num > UINT16_MAX)
return command_fail(cmd, LIGHTNINGD,
"Invalid parameter: funding tx vout too large %u",
*funding_txout_num);

funding_txout = *funding_txout_num;
peer = peer_by_id(cmd->ld, id);
if (!peer) {
return command_fail(cmd, LIGHTNINGD, "Unknown peer");
Expand All @@ -1079,7 +1089,9 @@ static struct command_result *json_fund_channel_continue(struct command *cmd,
if (!peer->uncommitted_channel->fc)
return command_fail(cmd, LIGHTNINGD, "No channel funding in progress.");

msg = towire_opening_funder_continue(NULL, funding_txid);
msg = towire_opening_funder_continue(NULL,
funding_txid,
funding_txout);
subd_send_msg(peer->uncommitted_channel->openingd, take(msg));
return command_still_pending(cmd);
}
Expand Down
4 changes: 3 additions & 1 deletion openingd/opening_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ opening_funder_reply,,their_per_commit_point,struct pubkey
opening_funder_reply,,minimum_depth,u32
opening_funder_reply,,remote_fundingkey,struct pubkey
opening_funder_reply,,funding_txid,struct bitcoin_txid
opening_funder_reply,,funding_txout,u16
opening_funder_reply,,feerate_per_kw,u32
opening_funder_reply,,our_channel_reserve_satoshis,struct amount_sat
opening_funder_reply,,shutdown_len,u16
Expand All @@ -90,11 +91,12 @@ opening_funder_start_reply,6102
opening_funder_start_reply,,script_len,u8
opening_funder_start_reply,,scriptpubkey,script_len*u8

# master->openingd: continue channel establsihment for a funding
# master->openingd: continue channel establishment for a funding
# tx that will be paid for by an external wallet
# response to this is a normal `opening_funder_reply` ??
opening_funder_continue,6012
opening_funder_continue,,funding_txid,struct bitcoin_txid
opening_funder_continue,,funding_txout,u16

# Openingd->master: we failed to negotiation channel
opening_funder_failed,6004
Expand Down
5 changes: 4 additions & 1 deletion openingd/openingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ static u8 *funder_channel(struct state *state,
minimum_depth,
&their_funding_pubkey,
&state->funding_txid,
state->funding_txout,
state->feerate_per_kw,
state->localconf.channel_reserve,
state->remote_upfront_shutdown_script);
Expand Down Expand Up @@ -1573,6 +1574,7 @@ static u8 *handle_master_in(struct state *state)
u32 change_keyindex;
u8 channel_flags;
struct bitcoin_txid funding_txid;
u16 funding_txout;
struct utxo **utxos;
struct ext_key bip32_base;

Expand Down Expand Up @@ -1606,7 +1608,8 @@ static u8 *handle_master_in(struct state *state)
return NULL;
case WIRE_OPENING_FUNDER_CONTINUE:
if (!fromwire_opening_funder_continue(msg,
&funding_txid))
&funding_txid,
&funding_txout))
master_badmsg(WIRE_OPENING_FUNDER_CONTINUE, msg);
return funder_channel_continue(state, &funding_txid);
case WIRE_OPENING_DEV_MEMLEAK:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,17 +831,18 @@ def test_funding_external_wallet_corners(node_factory, bitcoind):

amount = amount - 1
fake_txid = '929764844a8f9938b669a60a1d51a11c9e2613c7eb4776e4126f1f20c0a685c3'
fake_txout = 0

with pytest.raises(RpcError, match=r'Unknown peer'):
l1.rpc.fundchannel_start(l2.info['id'], amount)

with pytest.raises(RpcError, match=r'Unknown peer'):
l1.rpc.fundchannel_continue(l2.info['id'], fake_txid)
l1.rpc.fundchannel_continue(l2.info['id'], fake_txid, fake_txout)

# Should not be able to continue without being in progress.
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
with pytest.raises(RpcError, match=r'No channel funding in progress.'):
l1.rpc.fundchannel_continue(l2.info['id'], fake_txid)
l1.rpc.fundchannel_continue(l2.info['id'], fake_txid, fake_txout)


def test_funding_external_wallet(node_factory, bitcoind):
Expand Down

0 comments on commit 7ea21c3

Please sign in to comment.