Skip to content

Commit a2dc5ba

Browse files
authored
Merge pull request #32 from lightning-signer/add-ready-channel-wallet-index
Add ready channel wallet index
2 parents 0aa4617 + f3b3ad2 commit a2dc5ba

14 files changed

+72
-21
lines changed

contrib/remote_hsmd/hsmd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
13331333
u16 funding_txout;
13341334
u16 local_to_self_delay;
13351335
u8 *local_shutdown_script;
1336+
u32 local_shutdown_wallet_index;
13361337
struct basepoints remote_basepoints;
13371338
struct pubkey remote_funding_pubkey;
13381339
u16 remote_to_self_delay;
@@ -1344,6 +1345,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
13441345
&channel_value, &push_value, &funding_txid,
13451346
&funding_txout, &local_to_self_delay,
13461347
&local_shutdown_script,
1348+
&local_shutdown_wallet_index,
13471349
&remote_basepoints,
13481350
&remote_funding_pubkey,
13491351
&remote_to_self_delay,
@@ -1361,6 +1363,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
13611363
funding_txout,
13621364
local_to_self_delay, // locally imposed on counterparty to_self outputs
13631365
local_shutdown_script,
1366+
local_shutdown_wallet_index,
13641367
&remote_basepoints,
13651368
&remote_funding_pubkey,
13661369
remote_to_self_delay, // counterparty imposed on our to_self outputs

contrib/remote_hsmd/proxy.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ proxy_stat proxy_handle_ready_channel(
569569
u16 funding_txout,
570570
u16 holder_to_self_delay,
571571
u8 *holder_shutdown_script,
572+
u32 holder_shutdown_wallet_index,
572573
struct basepoints *counterparty_basepoints,
573574
struct pubkey *counterparty_funding_pubkey,
574575
u16 counterparty_to_self_delay,
@@ -582,7 +583,9 @@ proxy_stat proxy_handle_ready_channel(
582583
"\"is_outbound\":%s, \"channel_value\":%" PRIu64 ", "
583584
"\"push_value\":%" PRIu64 ", "
584585
"\"funding_txid\":%s, \"funding_txout\":%d, "
585-
"\"holder_to_self_delay\":%d, \"holder_shutdown_script\":%s, "
586+
"\"holder_to_self_delay\":%d, "
587+
"\"holder_shutdown_script\":%s, "
588+
"\"holder_shutdown_wallet_index\":%d, "
586589
"\"counterparty_basepoints\":%s, "
587590
"\"counterparty_funding_pubkey\":%s, "
588591
"\"counterparty_to_self_delay\":%d, "
@@ -601,6 +604,7 @@ proxy_stat proxy_handle_ready_channel(
601604
holder_to_self_delay,
602605
dump_hex(holder_shutdown_script,
603606
tal_count(holder_shutdown_script)).c_str(),
607+
holder_shutdown_wallet_index,
604608
dump_basepoints(counterparty_basepoints).c_str(),
605609
dump_pubkey(counterparty_funding_pubkey).c_str(),
606610
counterparty_to_self_delay,
@@ -622,6 +626,8 @@ proxy_stat proxy_handle_ready_channel(
622626
req.set_holder_selected_contest_delay(holder_to_self_delay);
623627
marshal_script(holder_shutdown_script,
624628
req.mutable_holder_shutdown_script());
629+
if (holder_shutdown_wallet_index != UINT32_MAX)
630+
req.add_holder_shutdown_key_path(holder_shutdown_wallet_index);
625631
marshal_basepoints(counterparty_basepoints, counterparty_funding_pubkey,
626632
req.mutable_counterparty_basepoints());
627633
req.set_counterparty_selected_contest_delay(counterparty_to_self_delay);

contrib/remote_hsmd/proxy.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ proxy_stat proxy_handle_ready_channel(
7171
u16 funding_txout,
7272
u16 local_to_self_delay,
7373
u8 *local_shutdown_script,
74+
u32 local_shutdown_wallet_index,
7475
struct basepoints *remote_basepoints,
7576
struct pubkey *remote_funding_pubkey,
7677
u16 remote_to_self_delay,

hsmd/hsmd_wire.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ msgdata,hsmd_ready_channel,funding_txout,u16,
6363
msgdata,hsmd_ready_channel,local_to_self_delay,u16,
6464
msgdata,hsmd_ready_channel,local_shutdown_script_len,u16,
6565
msgdata,hsmd_ready_channel,local_shutdown_script,u8,local_shutdown_script_len
66+
msgdata,hsmd_ready_channel,local_shutdown_wallet_index,u32,
6667
msgdata,hsmd_ready_channel,remote_basepoints,basepoints,
6768
msgdata,hsmd_ready_channel,remote_funding_pubkey,pubkey,
6869
msgdata,hsmd_ready_channel,remote_to_self_delay,u16,

hsmd/hsmd_wiregen.c

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hsmd/hsmd_wiregen.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hsmd/libhsmd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ static u8 *handle_ready_channel(struct hsmd_client *c, const u8 *msg_in)
305305
u16 funding_txout;
306306
u16 local_to_self_delay;
307307
u8 *local_shutdown_script;
308+
u32 local_shutdown_wallet_index;
308309
struct basepoints remote_basepoints;
309310
struct pubkey remote_funding_pubkey;
310311
u16 remote_to_self_delay;
@@ -317,6 +318,7 @@ static u8 *handle_ready_channel(struct hsmd_client *c, const u8 *msg_in)
317318
&channel_value, &push_value, &funding_txid,
318319
&funding_txout, &local_to_self_delay,
319320
&local_shutdown_script,
321+
&local_shutdown_wallet_index,
320322
&remote_basepoints,
321323
&remote_funding_pubkey,
322324
&remote_to_self_delay,

lightningd/opening_control.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,19 @@ openchannel_hook_final(struct openchannel_hook_payload *payload STEALS)
678678
uc->got_offer = true;
679679
}
680680

681+
// Determine the wallet index for our upfront_shutdown_script, UINT32_MAX if not found.
682+
u32 upfront_shutdown_script_wallet_index = UINT32_MAX;
683+
bool is_p2sh;
684+
wallet_can_spend(
685+
payload->openingd->ld->wallet,
686+
our_upfront_shutdown_script,
687+
&upfront_shutdown_script_wallet_index,
688+
&is_p2sh);
689+
681690
subd_send_msg(openingd,
682691
take(towire_openingd_got_offer_reply(NULL, errmsg,
683-
our_upfront_shutdown_script)));
692+
our_upfront_shutdown_script,
693+
upfront_shutdown_script_wallet_index)));
684694
}
685695

686696
static bool
@@ -769,8 +779,9 @@ static void opening_got_offer(struct subd *openingd,
769779
/* Tell them they can't open, if we already have open channel. */
770780
if (peer_active_channel(uc->peer)) {
771781
subd_send_msg(openingd,
772-
take(towire_openingd_got_offer_reply(NULL,
773-
"Already have active channel", NULL)));
782+
take(towire_openingd_got_offer_reply(
783+
NULL, "Already have active channel",
784+
NULL, UINT32_MAX)));
774785
return;
775786
}
776787

@@ -1262,10 +1273,20 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
12621273
fc->our_upfront_shutdown_script
12631274
= tal_steal(fc, fc->our_upfront_shutdown_script);
12641275

1276+
// Determine the wallet index for our upfront_shutdown_script, UINT32_MAX if not found.
1277+
u32 upfront_shutdown_script_wallet_index = UINT32_MAX;
1278+
bool is_p2sh;
1279+
wallet_can_spend(
1280+
fc->cmd->ld->wallet,
1281+
fc->our_upfront_shutdown_script,
1282+
&upfront_shutdown_script_wallet_index,
1283+
&is_p2sh);
1284+
12651285
msg = towire_openingd_funder_start(NULL,
12661286
*amount,
12671287
fc->push,
12681288
fc->our_upfront_shutdown_script,
1289+
upfront_shutdown_script_wallet_index,
12691290
*feerate_per_kw,
12701291
fc->channel_flags);
12711292

openingd/openingd.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ struct state {
105105
/* If non-NULL, this is the scriptpubkey we/they *must* close with */
106106
u8 *upfront_shutdown_script[NUM_SIDES];
107107

108+
/* If not UINT32_MAX, the wallet index for the LOCAL script */
109+
u32 local_upfront_shutdown_wallet_index;
110+
108111
/* This is a cluster of fields in open_channel and accept_channel which
109112
* indicate the restrictions each side places on the channel. */
110113
struct channel_config localconf, remoteconf;
@@ -531,6 +534,7 @@ static bool funder_finalize_channel_setup(struct state *state,
531534
state->funding_txout,
532535
state->localconf.to_self_delay,
533536
state->upfront_shutdown_script[LOCAL],
537+
state->local_upfront_shutdown_wallet_index,
534538
&state->their_points,
535539
&state->their_funding_pubkey,
536540
state->remoteconf.to_self_delay,
@@ -980,7 +984,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
980984
/* We don't allocate off tmpctx, because that's freed inside
981985
* opening_negotiate_msg */
982986
if (!fromwire_openingd_got_offer_reply(state, msg, &err_reason,
983-
&state->upfront_shutdown_script[LOCAL]))
987+
&state->upfront_shutdown_script[LOCAL],
988+
&state->local_upfront_shutdown_wallet_index))
984989
master_badmsg(WIRE_OPENINGD_GOT_OFFER_REPLY, msg);
985990

986991
/* If they give us a reason to reject, do so. */
@@ -1060,6 +1065,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
10601065
state->funding_txout,
10611066
state->localconf.to_self_delay,
10621067
state->upfront_shutdown_script[LOCAL],
1068+
state->local_upfront_shutdown_wallet_index,
10631069
&theirs,
10641070
&their_funding_pubkey,
10651071
state->remoteconf.to_self_delay,
@@ -1343,6 +1349,7 @@ static u8 *handle_master_in(struct state *state)
13431349
if (!fromwire_openingd_funder_start(state, msg, &state->funding,
13441350
&state->push_msat,
13451351
&state->upfront_shutdown_script[LOCAL],
1352+
&state->local_upfront_shutdown_wallet_index,
13461353
&state->feerate_per_kw,
13471354
&channel_flags))
13481355
master_badmsg(WIRE_OPENINGD_FUNDER_START, msg);

openingd/openingd_wire.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ msgtype,openingd_got_offer_reply,6105
5555
msgdata,openingd_got_offer_reply,rejection,?wirestring,
5656
msgdata,openingd_got_offer_reply,shutdown_len,u16,
5757
msgdata,openingd_got_offer_reply,our_shutdown_scriptpubkey,?u8,shutdown_len
58+
msgdata,openingd_got_offer_reply,our_shutdown_wallet_index,u32,
5859

5960
#include <common/penalty_base.h>
6061
# Openingd->master: we've successfully offered channel.
@@ -85,6 +86,7 @@ msgdata,openingd_funder_start,funding_satoshis,amount_sat,
8586
msgdata,openingd_funder_start,push_msat,amount_msat,
8687
msgdata,openingd_funder_start,len_upfront,u16,
8788
msgdata,openingd_funder_start,upfront_shutdown_script,u8,len_upfront
89+
msgdata,openingd_funder_start,upfront_shutdown_wallet_index,u32,
8890
msgdata,openingd_funder_start,feerate_per_kw,u32,
8991
msgdata,openingd_funder_start,channel_flags,u8,
9092

openingd/openingd_wiregen.c

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)