Browse Source

fundchannel: add txout field to RPC/API

We'll need the outpoint for the funding output.
pull/2938/head
lisa neigut 6 years ago
committed by Rusty Russell
parent
commit
7ea21c36b1
  1. 5
      contrib/pylightning/lightning/lightning.py
  2. 14
      lightningd/opening_control.c
  3. 4
      openingd/opening_wire.csv
  4. 5
      openingd/openingd.c
  5. 5
      tests/test_connection.py

5
contrib/pylightning/lightning/lightning.py

@ -499,13 +499,14 @@ class LightningRpc(UnixDomainSocketRpc):
} }
return self.call("fundchannel_start", payload) 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 = { payload = {
"id": node_id, "id": node_id,
"txid": funding_txid, "txid": funding_txid,
"txout": funding_txout,
} }
return self.call("fundchannel_continue", payload) return self.call("fundchannel_continue", payload)

14
lightningd/opening_control.c

@ -364,6 +364,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
&fc->uc->minimum_depth, &fc->uc->minimum_depth,
&channel_info.remote_fundingkey, &channel_info.remote_fundingkey,
&expected_txid, &expected_txid,
&funding_outnum,
&feerate, &feerate,
&fc->uc->our_config.channel_reserve, &fc->uc->our_config.channel_reserve,
&remote_upfront_shutdown_script)) { &remote_upfront_shutdown_script)) {
@ -1056,13 +1057,22 @@ static struct command_result *json_fund_channel_continue(struct command *cmd,
struct bitcoin_txid *funding_txid; struct bitcoin_txid *funding_txid;
struct peer *peer; struct peer *peer;
struct channel *channel; struct channel *channel;
u32 *funding_txout_num;
u16 funding_txout;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_node_id, &id), p_req("id", param_node_id, &id),
p_req("txid", param_txid, &funding_txid), p_req("txid", param_txid, &funding_txid),
p_req("txout", param_number, &funding_txout_num),
NULL)) NULL))
return command_param_failed(); 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); peer = peer_by_id(cmd->ld, id);
if (!peer) { if (!peer) {
return command_fail(cmd, LIGHTNINGD, "Unknown peer"); return command_fail(cmd, LIGHTNINGD, "Unknown peer");
@ -1079,7 +1089,9 @@ static struct command_result *json_fund_channel_continue(struct command *cmd,
if (!peer->uncommitted_channel->fc) if (!peer->uncommitted_channel->fc)
return command_fail(cmd, LIGHTNINGD, "No channel funding in progress."); 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)); subd_send_msg(peer->uncommitted_channel->openingd, take(msg));
return command_still_pending(cmd); return command_still_pending(cmd);
} }

4
openingd/opening_wire.csv

@ -72,6 +72,7 @@ opening_funder_reply,,their_per_commit_point,struct pubkey
opening_funder_reply,,minimum_depth,u32 opening_funder_reply,,minimum_depth,u32
opening_funder_reply,,remote_fundingkey,struct pubkey opening_funder_reply,,remote_fundingkey,struct pubkey
opening_funder_reply,,funding_txid,struct bitcoin_txid opening_funder_reply,,funding_txid,struct bitcoin_txid
opening_funder_reply,,funding_txout,u16
opening_funder_reply,,feerate_per_kw,u32 opening_funder_reply,,feerate_per_kw,u32
opening_funder_reply,,our_channel_reserve_satoshis,struct amount_sat opening_funder_reply,,our_channel_reserve_satoshis,struct amount_sat
opening_funder_reply,,shutdown_len,u16 opening_funder_reply,,shutdown_len,u16
@ -90,11 +91,12 @@ opening_funder_start_reply,6102
opening_funder_start_reply,,script_len,u8 opening_funder_start_reply,,script_len,u8
opening_funder_start_reply,,scriptpubkey,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 # tx that will be paid for by an external wallet
# response to this is a normal `opening_funder_reply` ?? # response to this is a normal `opening_funder_reply` ??
opening_funder_continue,6012 opening_funder_continue,6012
opening_funder_continue,,funding_txid,struct bitcoin_txid opening_funder_continue,,funding_txid,struct bitcoin_txid
opening_funder_continue,,funding_txout,u16
# Openingd->master: we failed to negotiation channel # Openingd->master: we failed to negotiation channel
opening_funder_failed,6004 opening_funder_failed,6004

Can't render this file because it has a wrong number of fields in line 6.

5
openingd/openingd.c

@ -1038,6 +1038,7 @@ static u8 *funder_channel(struct state *state,
minimum_depth, minimum_depth,
&their_funding_pubkey, &their_funding_pubkey,
&state->funding_txid, &state->funding_txid,
state->funding_txout,
state->feerate_per_kw, state->feerate_per_kw,
state->localconf.channel_reserve, state->localconf.channel_reserve,
state->remote_upfront_shutdown_script); state->remote_upfront_shutdown_script);
@ -1573,6 +1574,7 @@ static u8 *handle_master_in(struct state *state)
u32 change_keyindex; u32 change_keyindex;
u8 channel_flags; u8 channel_flags;
struct bitcoin_txid funding_txid; struct bitcoin_txid funding_txid;
u16 funding_txout;
struct utxo **utxos; struct utxo **utxos;
struct ext_key bip32_base; struct ext_key bip32_base;
@ -1606,7 +1608,8 @@ static u8 *handle_master_in(struct state *state)
return NULL; return NULL;
case WIRE_OPENING_FUNDER_CONTINUE: case WIRE_OPENING_FUNDER_CONTINUE:
if (!fromwire_opening_funder_continue(msg, if (!fromwire_opening_funder_continue(msg,
&funding_txid)) &funding_txid,
&funding_txout))
master_badmsg(WIRE_OPENING_FUNDER_CONTINUE, msg); master_badmsg(WIRE_OPENING_FUNDER_CONTINUE, msg);
return funder_channel_continue(state, &funding_txid); return funder_channel_continue(state, &funding_txid);
case WIRE_OPENING_DEV_MEMLEAK: case WIRE_OPENING_DEV_MEMLEAK:

5
tests/test_connection.py

@ -831,17 +831,18 @@ def test_funding_external_wallet_corners(node_factory, bitcoind):
amount = amount - 1 amount = amount - 1
fake_txid = '929764844a8f9938b669a60a1d51a11c9e2613c7eb4776e4126f1f20c0a685c3' fake_txid = '929764844a8f9938b669a60a1d51a11c9e2613c7eb4776e4126f1f20c0a685c3'
fake_txout = 0
with pytest.raises(RpcError, match=r'Unknown peer'): with pytest.raises(RpcError, match=r'Unknown peer'):
l1.rpc.fundchannel_start(l2.info['id'], amount) l1.rpc.fundchannel_start(l2.info['id'], amount)
with pytest.raises(RpcError, match=r'Unknown peer'): 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. # Should not be able to continue without being in progress.
l1.rpc.connect(l2.info['id'], 'localhost', l2.port) l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
with pytest.raises(RpcError, match=r'No channel funding in progress.'): 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): def test_funding_external_wallet(node_factory, bitcoind):

Loading…
Cancel
Save