Skip to content

Commit

Permalink
Merge pull request #32 from lightning-signer/add-ready-channel-wallet…
Browse files Browse the repository at this point in the history
…-index

Add ready channel wallet index
  • Loading branch information
ksedgwic authored Sep 3, 2021
2 parents 0aa4617 + f3b3ad2 commit a2dc5ba
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 21 deletions.
3 changes: 3 additions & 0 deletions contrib/remote_hsmd/hsmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
u16 funding_txout;
u16 local_to_self_delay;
u8 *local_shutdown_script;
u32 local_shutdown_wallet_index;
struct basepoints remote_basepoints;
struct pubkey remote_funding_pubkey;
u16 remote_to_self_delay;
Expand All @@ -1344,6 +1345,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
&channel_value, &push_value, &funding_txid,
&funding_txout, &local_to_self_delay,
&local_shutdown_script,
&local_shutdown_wallet_index,
&remote_basepoints,
&remote_funding_pubkey,
&remote_to_self_delay,
Expand All @@ -1361,6 +1363,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
funding_txout,
local_to_self_delay, // locally imposed on counterparty to_self outputs
local_shutdown_script,
local_shutdown_wallet_index,
&remote_basepoints,
&remote_funding_pubkey,
remote_to_self_delay, // counterparty imposed on our to_self outputs
Expand Down
8 changes: 7 additions & 1 deletion contrib/remote_hsmd/proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ proxy_stat proxy_handle_ready_channel(
u16 funding_txout,
u16 holder_to_self_delay,
u8 *holder_shutdown_script,
u32 holder_shutdown_wallet_index,
struct basepoints *counterparty_basepoints,
struct pubkey *counterparty_funding_pubkey,
u16 counterparty_to_self_delay,
Expand All @@ -582,7 +583,9 @@ proxy_stat proxy_handle_ready_channel(
"\"is_outbound\":%s, \"channel_value\":%" PRIu64 ", "
"\"push_value\":%" PRIu64 ", "
"\"funding_txid\":%s, \"funding_txout\":%d, "
"\"holder_to_self_delay\":%d, \"holder_shutdown_script\":%s, "
"\"holder_to_self_delay\":%d, "
"\"holder_shutdown_script\":%s, "
"\"holder_shutdown_wallet_index\":%d, "
"\"counterparty_basepoints\":%s, "
"\"counterparty_funding_pubkey\":%s, "
"\"counterparty_to_self_delay\":%d, "
Expand All @@ -601,6 +604,7 @@ proxy_stat proxy_handle_ready_channel(
holder_to_self_delay,
dump_hex(holder_shutdown_script,
tal_count(holder_shutdown_script)).c_str(),
holder_shutdown_wallet_index,
dump_basepoints(counterparty_basepoints).c_str(),
dump_pubkey(counterparty_funding_pubkey).c_str(),
counterparty_to_self_delay,
Expand All @@ -622,6 +626,8 @@ proxy_stat proxy_handle_ready_channel(
req.set_holder_selected_contest_delay(holder_to_self_delay);
marshal_script(holder_shutdown_script,
req.mutable_holder_shutdown_script());
if (holder_shutdown_wallet_index != UINT32_MAX)
req.add_holder_shutdown_key_path(holder_shutdown_wallet_index);
marshal_basepoints(counterparty_basepoints, counterparty_funding_pubkey,
req.mutable_counterparty_basepoints());
req.set_counterparty_selected_contest_delay(counterparty_to_self_delay);
Expand Down
1 change: 1 addition & 0 deletions contrib/remote_hsmd/proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ proxy_stat proxy_handle_ready_channel(
u16 funding_txout,
u16 local_to_self_delay,
u8 *local_shutdown_script,
u32 local_shutdown_wallet_index,
struct basepoints *remote_basepoints,
struct pubkey *remote_funding_pubkey,
u16 remote_to_self_delay,
Expand Down
1 change: 1 addition & 0 deletions hsmd/hsmd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ msgdata,hsmd_ready_channel,funding_txout,u16,
msgdata,hsmd_ready_channel,local_to_self_delay,u16,
msgdata,hsmd_ready_channel,local_shutdown_script_len,u16,
msgdata,hsmd_ready_channel,local_shutdown_script,u8,local_shutdown_script_len
msgdata,hsmd_ready_channel,local_shutdown_wallet_index,u32,
msgdata,hsmd_ready_channel,remote_basepoints,basepoints,
msgdata,hsmd_ready_channel,remote_funding_pubkey,pubkey,
msgdata,hsmd_ready_channel,remote_to_self_delay,u16,
Expand Down
8 changes: 5 additions & 3 deletions hsmd/hsmd_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions hsmd/hsmd_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions hsmd/libhsmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ static u8 *handle_ready_channel(struct hsmd_client *c, const u8 *msg_in)
u16 funding_txout;
u16 local_to_self_delay;
u8 *local_shutdown_script;
u32 local_shutdown_wallet_index;
struct basepoints remote_basepoints;
struct pubkey remote_funding_pubkey;
u16 remote_to_self_delay;
Expand All @@ -317,6 +318,7 @@ static u8 *handle_ready_channel(struct hsmd_client *c, const u8 *msg_in)
&channel_value, &push_value, &funding_txid,
&funding_txout, &local_to_self_delay,
&local_shutdown_script,
&local_shutdown_wallet_index,
&remote_basepoints,
&remote_funding_pubkey,
&remote_to_self_delay,
Expand Down
27 changes: 24 additions & 3 deletions lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,19 @@ openchannel_hook_final(struct openchannel_hook_payload *payload STEALS)
uc->got_offer = true;
}

// Determine the wallet index for our upfront_shutdown_script, UINT32_MAX if not found.
u32 upfront_shutdown_script_wallet_index = UINT32_MAX;
bool is_p2sh;
wallet_can_spend(
payload->openingd->ld->wallet,
our_upfront_shutdown_script,
&upfront_shutdown_script_wallet_index,
&is_p2sh);

subd_send_msg(openingd,
take(towire_openingd_got_offer_reply(NULL, errmsg,
our_upfront_shutdown_script)));
our_upfront_shutdown_script,
upfront_shutdown_script_wallet_index)));
}

static bool
Expand Down Expand Up @@ -769,8 +779,9 @@ static void opening_got_offer(struct subd *openingd,
/* Tell them they can't open, if we already have open channel. */
if (peer_active_channel(uc->peer)) {
subd_send_msg(openingd,
take(towire_openingd_got_offer_reply(NULL,
"Already have active channel", NULL)));
take(towire_openingd_got_offer_reply(
NULL, "Already have active channel",
NULL, UINT32_MAX)));
return;
}

Expand Down Expand Up @@ -1262,10 +1273,20 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
fc->our_upfront_shutdown_script
= tal_steal(fc, fc->our_upfront_shutdown_script);

// Determine the wallet index for our upfront_shutdown_script, UINT32_MAX if not found.
u32 upfront_shutdown_script_wallet_index = UINT32_MAX;
bool is_p2sh;
wallet_can_spend(
fc->cmd->ld->wallet,
fc->our_upfront_shutdown_script,
&upfront_shutdown_script_wallet_index,
&is_p2sh);

msg = towire_openingd_funder_start(NULL,
*amount,
fc->push,
fc->our_upfront_shutdown_script,
upfront_shutdown_script_wallet_index,
*feerate_per_kw,
fc->channel_flags);

Expand Down
9 changes: 8 additions & 1 deletion openingd/openingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ struct state {
/* If non-NULL, this is the scriptpubkey we/they *must* close with */
u8 *upfront_shutdown_script[NUM_SIDES];

/* If not UINT32_MAX, the wallet index for the LOCAL script */
u32 local_upfront_shutdown_wallet_index;

/* This is a cluster of fields in open_channel and accept_channel which
* indicate the restrictions each side places on the channel. */
struct channel_config localconf, remoteconf;
Expand Down Expand Up @@ -531,6 +534,7 @@ static bool funder_finalize_channel_setup(struct state *state,
state->funding_txout,
state->localconf.to_self_delay,
state->upfront_shutdown_script[LOCAL],
state->local_upfront_shutdown_wallet_index,
&state->their_points,
&state->their_funding_pubkey,
state->remoteconf.to_self_delay,
Expand Down Expand Up @@ -980,7 +984,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
/* We don't allocate off tmpctx, because that's freed inside
* opening_negotiate_msg */
if (!fromwire_openingd_got_offer_reply(state, msg, &err_reason,
&state->upfront_shutdown_script[LOCAL]))
&state->upfront_shutdown_script[LOCAL],
&state->local_upfront_shutdown_wallet_index))
master_badmsg(WIRE_OPENINGD_GOT_OFFER_REPLY, msg);

/* If they give us a reason to reject, do so. */
Expand Down Expand Up @@ -1060,6 +1065,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
state->funding_txout,
state->localconf.to_self_delay,
state->upfront_shutdown_script[LOCAL],
state->local_upfront_shutdown_wallet_index,
&theirs,
&their_funding_pubkey,
state->remoteconf.to_self_delay,
Expand Down Expand Up @@ -1343,6 +1349,7 @@ static u8 *handle_master_in(struct state *state)
if (!fromwire_openingd_funder_start(state, msg, &state->funding,
&state->push_msat,
&state->upfront_shutdown_script[LOCAL],
&state->local_upfront_shutdown_wallet_index,
&state->feerate_per_kw,
&channel_flags))
master_badmsg(WIRE_OPENINGD_FUNDER_START, msg);
Expand Down
2 changes: 2 additions & 0 deletions openingd/openingd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ msgtype,openingd_got_offer_reply,6105
msgdata,openingd_got_offer_reply,rejection,?wirestring,
msgdata,openingd_got_offer_reply,shutdown_len,u16,
msgdata,openingd_got_offer_reply,our_shutdown_scriptpubkey,?u8,shutdown_len
msgdata,openingd_got_offer_reply,our_shutdown_wallet_index,u32,

#include <common/penalty_base.h>
# Openingd->master: we've successfully offered channel.
Expand Down Expand Up @@ -85,6 +86,7 @@ msgdata,openingd_funder_start,funding_satoshis,amount_sat,
msgdata,openingd_funder_start,push_msat,amount_msat,
msgdata,openingd_funder_start,len_upfront,u16,
msgdata,openingd_funder_start,upfront_shutdown_script,u8,len_upfront
msgdata,openingd_funder_start,upfront_shutdown_wallet_index,u32,
msgdata,openingd_funder_start,feerate_per_kw,u32,
msgdata,openingd_funder_start,channel_flags,u8,

Expand Down
14 changes: 9 additions & 5 deletions openingd/openingd_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a2dc5ba

Please sign in to comment.