@@ -275,6 +275,70 @@ static void get_channel_seed(const struct node_id *peer_id, u64 dbid,
275275 info , strlen (info ));
276276}
277277
278+ /*~ This is used to declare a new channel. */
279+ static u8 * handle_new_channel (struct hsmd_client * c , const u8 * msg_in )
280+ {
281+ struct node_id peer_id ;
282+ u64 dbid ;
283+
284+ if (!fromwire_hsmd_new_channel (msg_in , & peer_id , & dbid ))
285+ return hsmd_status_malformed_request (c , msg_in );
286+
287+ return towire_hsmd_new_channel_reply (NULL );
288+ }
289+
290+ static bool mem_is_zero (const void * mem , size_t len )
291+ {
292+ size_t i ;
293+ for (i = 0 ; i < len ; ++ i )
294+ if (((const unsigned char * )mem )[i ])
295+ return false;
296+ return true;
297+ }
298+
299+ /*~ This is used to provide all unchanging public channel parameters. */
300+ static u8 * handle_ready_channel (struct hsmd_client * c , const u8 * msg_in )
301+ {
302+ bool is_outbound ;
303+ struct amount_sat channel_value ;
304+ struct amount_msat push_value ;
305+ struct bitcoin_txid funding_txid ;
306+ u16 funding_txout ;
307+ u16 local_to_self_delay ;
308+ u8 * local_shutdown_script ;
309+ struct basepoints remote_basepoints ;
310+ struct pubkey remote_funding_pubkey ;
311+ u16 remote_to_self_delay ;
312+ u8 * remote_shutdown_script ;
313+ bool option_static_remotekey ;
314+ bool option_anchor_outputs ;
315+ struct amount_msat value_msat ;
316+
317+ if (!fromwire_hsmd_ready_channel (tmpctx , msg_in , & is_outbound ,
318+ & channel_value , & push_value , & funding_txid ,
319+ & funding_txout , & local_to_self_delay ,
320+ & local_shutdown_script ,
321+ & remote_basepoints ,
322+ & remote_funding_pubkey ,
323+ & remote_to_self_delay ,
324+ & remote_shutdown_script ,
325+ & option_static_remotekey ,
326+ & option_anchor_outputs ))
327+ return hsmd_status_malformed_request (c , msg_in );
328+
329+ /* Fail fast if any values are obviously uninitialized. */
330+ assert (amount_sat_greater (channel_value , AMOUNT_SAT (0 )));
331+ assert (amount_sat_to_msat (& value_msat , channel_value ));
332+ assert (amount_msat_less_eq (push_value , value_msat ));
333+ assert (!mem_is_zero (& funding_txid , sizeof (funding_txid )));
334+ assert (local_to_self_delay > 0 );
335+ assert (!mem_is_zero (& remote_basepoints , sizeof (remote_basepoints )));
336+ assert (!mem_is_zero (& remote_funding_pubkey , sizeof (remote_funding_pubkey )));
337+ assert (remote_to_self_delay > 0 );
338+
339+ return towire_hsmd_ready_channel_reply (NULL );
340+ }
341+
278342/*~ For almost every wallet tx we use the BIP32 seed, but not for onchain
279343 * unilateral closes from a peer: they (may) have an output to us using a
280344 * public key based on the channel basepoints. It's a bit spammy to spend
@@ -1222,13 +1286,16 @@ static u8 *handle_sign_commitment_tx(struct hsmd_client *c, const u8 *msg_in)
12221286 struct secret channel_seed ;
12231287 struct bitcoin_tx * tx ;
12241288 struct bitcoin_signature sig ;
1289+ struct sha256 * rhashes ;
1290+ u64 commit_num ;
12251291 struct secrets secrets ;
12261292 const u8 * funding_wscript ;
12271293
12281294 if (!fromwire_hsmd_sign_commitment_tx (tmpctx , msg_in ,
12291295 & peer_id , & dbid ,
12301296 & tx ,
1231- & remote_funding_pubkey ))
1297+ & remote_funding_pubkey ,
1298+ & rhashes , & commit_num ))
12321299 return hsmd_status_malformed_request (c , msg_in );
12331300
12341301 tx -> chainparams = c -> chainparams ;
@@ -1396,6 +1463,10 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
13961463 "libhsmd" ,
13971464 hsmd_wire_name (t ));
13981465
1466+ case WIRE_HSMD_NEW_CHANNEL :
1467+ return handle_new_channel (client , msg );
1468+ case WIRE_HSMD_READY_CHANNEL :
1469+ return handle_ready_channel (client , msg );
13991470 case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY :
14001471 return handle_get_output_scriptpubkey (client , msg );
14011472 case WIRE_HSMD_CHECK_FUTURE_SECRET :
@@ -1444,6 +1515,8 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
14441515 case WIRE_HSMD_CANNOUNCEMENT_SIG_REPLY :
14451516 case WIRE_HSMD_CUPDATE_SIG_REPLY :
14461517 case WIRE_HSMD_CLIENT_HSMFD_REPLY :
1518+ case WIRE_HSMD_NEW_CHANNEL_REPLY :
1519+ case WIRE_HSMD_READY_CHANNEL_REPLY :
14471520 case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY :
14481521 case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY :
14491522 case WIRE_HSMD_SIGN_INVOICE_REPLY :
0 commit comments