@@ -84,6 +84,7 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
8484
8585 case WIRE_HSMD_GET_PER_COMMITMENT_POINT :
8686 case WIRE_HSMD_CHECK_FUTURE_SECRET :
87+ case WIRE_HSMD_READY_CHANNEL :
8788 return (client -> capabilities & HSM_CAP_COMMITMENT_POINT ) != 0 ;
8889
8990 case WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX :
@@ -94,6 +95,7 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
9495 return (client -> capabilities & HSM_CAP_SIGN_CLOSING_TX ) != 0 ;
9596
9697 case WIRE_HSMD_INIT :
98+ case WIRE_HSMD_NEW_CHANNEL :
9799 case WIRE_HSMD_CLIENT_HSMFD :
98100 case WIRE_HSMD_SIGN_WITHDRAWAL :
99101 case WIRE_HSMD_SIGN_INVOICE :
@@ -112,6 +114,8 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
112114 case WIRE_HSMD_CANNOUNCEMENT_SIG_REPLY :
113115 case WIRE_HSMD_CUPDATE_SIG_REPLY :
114116 case WIRE_HSMD_CLIENT_HSMFD_REPLY :
117+ case WIRE_HSMD_NEW_CHANNEL_REPLY :
118+ case WIRE_HSMD_READY_CHANNEL_REPLY :
115119 case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY :
116120 case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY :
117121 case WIRE_HSMD_SIGN_INVOICE_REPLY :
@@ -266,6 +270,70 @@ static void get_channel_seed(const struct node_id *peer_id, u64 dbid,
266270 info , strlen (info ));
267271}
268272
273+ /*~ This is used to declare a new channel. */
274+ static u8 * handle_new_channel (struct hsmd_client * c , const u8 * msg_in )
275+ {
276+ struct node_id peer_id ;
277+ u64 dbid ;
278+
279+ if (!fromwire_hsmd_new_channel (msg_in , & peer_id , & dbid ))
280+ return hsmd_status_malformed_request (c , msg_in );
281+
282+ return towire_hsmd_new_channel_reply (NULL );
283+ }
284+
285+ static bool mem_is_zero (const void * mem , size_t len )
286+ {
287+ size_t i ;
288+ for (i = 0 ; i < len ; ++ i )
289+ if (((const unsigned char * )mem )[i ])
290+ return false;
291+ return true;
292+ }
293+
294+ /*~ This is used to provide all unchanging public channel parameters. */
295+ static u8 * handle_ready_channel (struct hsmd_client * c , const u8 * msg_in )
296+ {
297+ bool is_outbound ;
298+ struct amount_sat channel_value ;
299+ struct amount_msat push_value ;
300+ struct bitcoin_txid funding_txid ;
301+ u16 funding_txout ;
302+ u16 local_to_self_delay ;
303+ u8 * local_shutdown_script ;
304+ struct basepoints remote_basepoints ;
305+ struct pubkey remote_funding_pubkey ;
306+ u16 remote_to_self_delay ;
307+ u8 * remote_shutdown_script ;
308+ bool option_static_remotekey ;
309+ bool option_anchor_outputs ;
310+ struct amount_msat value_msat ;
311+
312+ if (!fromwire_hsmd_ready_channel (tmpctx , msg_in , & is_outbound ,
313+ & channel_value , & push_value , & funding_txid ,
314+ & funding_txout , & local_to_self_delay ,
315+ & local_shutdown_script ,
316+ & remote_basepoints ,
317+ & remote_funding_pubkey ,
318+ & remote_to_self_delay ,
319+ & remote_shutdown_script ,
320+ & option_static_remotekey ,
321+ & option_anchor_outputs ))
322+ return hsmd_status_malformed_request (c , msg_in );
323+
324+ /* Fail fast if any values are obviously uninitialized. */
325+ assert (amount_sat_greater (channel_value , AMOUNT_SAT (0 )));
326+ assert (amount_sat_to_msat (& value_msat , channel_value ));
327+ assert (amount_msat_less_eq (push_value , value_msat ));
328+ assert (!mem_is_zero (& funding_txid , sizeof (funding_txid )));
329+ assert (local_to_self_delay > 0 );
330+ assert (!mem_is_zero (& remote_basepoints , sizeof (remote_basepoints )));
331+ assert (!mem_is_zero (& remote_funding_pubkey , sizeof (remote_funding_pubkey )));
332+ assert (remote_to_self_delay > 0 );
333+
334+ return towire_hsmd_ready_channel_reply (NULL );
335+ }
336+
269337/*~ For almost every wallet tx we use the BIP32 seed, but not for onchain
270338 * unilateral closes from a peer: they (may) have an output to us using a
271339 * public key based on the channel basepoints. It's a bit spammy to spend
@@ -1080,12 +1148,15 @@ static u8 *handle_sign_remote_commitment_tx(struct hsmd_client *c, const u8 *msg
10801148 const u8 * funding_wscript ;
10811149 struct pubkey remote_per_commit ;
10821150 bool option_static_remotekey ;
1151+ struct sha256 * htlc_rhash ;
1152+ u64 commit_num ;
10831153
10841154 if (!fromwire_hsmd_sign_remote_commitment_tx (tmpctx , msg_in ,
10851155 & tx ,
10861156 & remote_funding_pubkey ,
10871157 & remote_per_commit ,
1088- & option_static_remotekey ))
1158+ & option_static_remotekey ,
1159+ & htlc_rhash , & commit_num ))
10891160 return hsmd_status_malformed_request (c , msg_in );
10901161 tx -> chainparams = c -> chainparams ;
10911162
@@ -1170,13 +1241,16 @@ static u8 *handle_sign_commitment_tx(struct hsmd_client *c, const u8 *msg_in)
11701241 struct secret channel_seed ;
11711242 struct bitcoin_tx * tx ;
11721243 struct bitcoin_signature sig ;
1244+ struct sha256 * rhashes ;
1245+ u64 commit_num ;
11731246 struct secrets secrets ;
11741247 const u8 * funding_wscript ;
11751248
11761249 if (!fromwire_hsmd_sign_commitment_tx (tmpctx , msg_in ,
11771250 & peer_id , & dbid ,
11781251 & tx ,
1179- & remote_funding_pubkey ))
1252+ & remote_funding_pubkey ,
1253+ & rhashes , & commit_num ))
11801254 return hsmd_status_malformed_request (c , msg_in );
11811255
11821256 tx -> chainparams = c -> chainparams ;
@@ -1344,6 +1418,10 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
13441418 "libhsmd" ,
13451419 hsmd_wire_name (t ));
13461420
1421+ case WIRE_HSMD_NEW_CHANNEL :
1422+ return handle_new_channel (client , msg );
1423+ case WIRE_HSMD_READY_CHANNEL :
1424+ return handle_ready_channel (client , msg );
13471425 case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY :
13481426 return handle_get_output_scriptpubkey (client , msg );
13491427 case WIRE_HSMD_CHECK_FUTURE_SECRET :
@@ -1390,6 +1468,8 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
13901468 case WIRE_HSMD_CANNOUNCEMENT_SIG_REPLY :
13911469 case WIRE_HSMD_CUPDATE_SIG_REPLY :
13921470 case WIRE_HSMD_CLIENT_HSMFD_REPLY :
1471+ case WIRE_HSMD_NEW_CHANNEL_REPLY :
1472+ case WIRE_HSMD_READY_CHANNEL_REPLY :
13931473 case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY :
13941474 case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY :
13951475 case WIRE_HSMD_SIGN_INVOICE_REPLY :
0 commit comments