@@ -1491,6 +1491,74 @@ static struct io_plan *pass_client_hsmfd(struct io_conn *conn,
1491
1491
send_pending_client_fd , c );
1492
1492
}
1493
1493
1494
+ /*~ This is used to declare a new channel. */
1495
+ static struct io_plan * handle_new_channel (struct io_conn * conn ,
1496
+ struct client * c ,
1497
+ const u8 * msg_in )
1498
+ {
1499
+ struct node_id peer_id ;
1500
+ u64 dbid ;
1501
+
1502
+ if (!fromwire_hsm_new_channel (msg_in , & peer_id , & dbid ))
1503
+ return bad_req (conn , c , msg_in );
1504
+
1505
+ return req_reply (conn , c ,
1506
+ take (towire_hsm_new_channel_reply (NULL )));
1507
+ }
1508
+
1509
+ static bool mem_is_zero (const void * mem , size_t len )
1510
+ {
1511
+ size_t i ;
1512
+ for (i = 0 ; i < len ; ++ i )
1513
+ if (((const unsigned char * )mem )[i ])
1514
+ return false;
1515
+ return true;
1516
+ }
1517
+
1518
+ /*~ This is used to provide all unchanging public channel parameters. */
1519
+ static struct io_plan * handle_ready_channel (struct io_conn * conn ,
1520
+ struct client * c ,
1521
+ const u8 * msg_in )
1522
+ {
1523
+ bool is_outbound ;
1524
+ struct amount_sat channel_value ;
1525
+ struct amount_msat push_value ;
1526
+ struct bitcoin_txid funding_txid ;
1527
+ u16 funding_txout ;
1528
+ u16 local_to_self_delay ;
1529
+ u8 * local_shutdown_script ;
1530
+ struct basepoints remote_basepoints ;
1531
+ struct pubkey remote_funding_pubkey ;
1532
+ u16 remote_to_self_delay ;
1533
+ u8 * remote_shutdown_script ;
1534
+ bool option_static_remotekey ;
1535
+ struct amount_msat value_msat ;
1536
+
1537
+ if (!fromwire_hsm_ready_channel (tmpctx , msg_in , & is_outbound ,
1538
+ & channel_value , & push_value , & funding_txid ,
1539
+ & funding_txout , & local_to_self_delay ,
1540
+ & local_shutdown_script ,
1541
+ & remote_basepoints ,
1542
+ & remote_funding_pubkey ,
1543
+ & remote_to_self_delay ,
1544
+ & remote_shutdown_script ,
1545
+ & option_static_remotekey ))
1546
+ return bad_req (conn , c , msg_in );
1547
+
1548
+ /* Fail fast if any values are obviously uninitialized. */
1549
+ assert (amount_sat_greater (channel_value , AMOUNT_SAT (0 )));
1550
+ assert (amount_sat_to_msat (& value_msat , channel_value ));
1551
+ assert (amount_msat_less_eq (push_value , value_msat ));
1552
+ assert (!mem_is_zero (& funding_txid , sizeof (funding_txid )));
1553
+ assert (local_to_self_delay > 0 );
1554
+ assert (!mem_is_zero (& remote_basepoints , sizeof (remote_basepoints )));
1555
+ assert (!mem_is_zero (& remote_funding_pubkey , sizeof (remote_funding_pubkey )));
1556
+ assert (remote_to_self_delay > 0 );
1557
+
1558
+ return req_reply (conn , c ,
1559
+ take (towire_hsm_ready_channel_reply (NULL )));
1560
+ }
1561
+
1494
1562
/*~ For almost every wallet tx we use the BIP32 seed, but not for onchain
1495
1563
* unilateral closes from a peer: they (may) have an output to us using a
1496
1564
* public key based on the channel basepoints. It's a bit spammy to spend
@@ -1891,6 +1959,7 @@ static bool check_client_capabilities(struct client *client,
1891
1959
1892
1960
case WIRE_HSM_GET_PER_COMMITMENT_POINT :
1893
1961
case WIRE_HSM_CHECK_FUTURE_SECRET :
1962
+ case WIRE_HSM_READY_CHANNEL :
1894
1963
return (client -> capabilities & HSM_CAP_COMMITMENT_POINT ) != 0 ;
1895
1964
1896
1965
case WIRE_HSM_SIGN_REMOTE_COMMITMENT_TX :
@@ -1901,6 +1970,7 @@ static bool check_client_capabilities(struct client *client,
1901
1970
return (client -> capabilities & HSM_CAP_SIGN_CLOSING_TX ) != 0 ;
1902
1971
1903
1972
case WIRE_HSM_INIT :
1973
+ case WIRE_HSM_NEW_CHANNEL :
1904
1974
case WIRE_HSM_CLIENT_HSMFD :
1905
1975
case WIRE_HSM_SIGN_FUNDING :
1906
1976
case WIRE_HSM_SIGN_WITHDRAWAL :
@@ -1918,6 +1988,8 @@ static bool check_client_capabilities(struct client *client,
1918
1988
case WIRE_HSM_CANNOUNCEMENT_SIG_REPLY :
1919
1989
case WIRE_HSM_CUPDATE_SIG_REPLY :
1920
1990
case WIRE_HSM_CLIENT_HSMFD_REPLY :
1991
+ case WIRE_HSM_NEW_CHANNEL_REPLY :
1992
+ case WIRE_HSM_READY_CHANNEL_REPLY :
1921
1993
case WIRE_HSM_SIGN_FUNDING_REPLY :
1922
1994
case WIRE_HSM_NODE_ANNOUNCEMENT_SIG_REPLY :
1923
1995
case WIRE_HSM_SIGN_WITHDRAWAL_REPLY :
@@ -1957,6 +2029,12 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
1957
2029
case WIRE_HSM_CLIENT_HSMFD :
1958
2030
return pass_client_hsmfd (conn , c , c -> msg_in );
1959
2031
2032
+ case WIRE_HSM_NEW_CHANNEL :
2033
+ return handle_new_channel (conn , c , c -> msg_in );
2034
+
2035
+ case WIRE_HSM_READY_CHANNEL :
2036
+ return handle_ready_channel (conn , c , c -> msg_in );
2037
+
1960
2038
case WIRE_HSM_GET_CHANNEL_BASEPOINTS :
1961
2039
return handle_get_channel_basepoints (conn , c , c -> msg_in );
1962
2040
@@ -2023,6 +2101,8 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
2023
2101
case WIRE_HSM_CANNOUNCEMENT_SIG_REPLY :
2024
2102
case WIRE_HSM_CUPDATE_SIG_REPLY :
2025
2103
case WIRE_HSM_CLIENT_HSMFD_REPLY :
2104
+ case WIRE_HSM_NEW_CHANNEL_REPLY :
2105
+ case WIRE_HSM_READY_CHANNEL_REPLY :
2026
2106
case WIRE_HSM_SIGN_FUNDING_REPLY :
2027
2107
case WIRE_HSM_NODE_ANNOUNCEMENT_SIG_REPLY :
2028
2108
case WIRE_HSM_SIGN_WITHDRAWAL_REPLY :
0 commit comments