@@ -1429,75 +1429,51 @@ static void start_commit_timer(struct peer *peer)
14291429 send_commit_if_not_stfu , peer );
14301430}
14311431
1432- /* If old_secret is NULL, we don't care, otherwise it is filled in. */
1433- static void get_per_commitment_point (u64 index , struct pubkey * point ,
1434- struct secret * old_secret )
1432+ static void get_per_commitment_point (u64 index , struct pubkey * point )
14351433{
1436- struct secret * s ;
1434+ struct secret * unused ;
14371435 const u8 * msg ;
14381436
14391437 msg = hsm_req (tmpctx ,
14401438 take (towire_hsmd_get_per_commitment_point (NULL , index )));
14411439
14421440 if (!fromwire_hsmd_get_per_commitment_point_reply (tmpctx , msg ,
14431441 point ,
1444- & s ))
1442+ & unused ))
14451443 status_failed (STATUS_FAIL_HSM_IO ,
14461444 "Bad per_commitment_point reply %s" ,
14471445 tal_hex (tmpctx , msg ));
1446+ }
14481447
1449- if ( old_secret ) {
1450- if (! s )
1451- status_failed ( STATUS_FAIL_HSM_IO ,
1452- "No secret in per_commitment_point_reply %"
1453- PRIu64 ,
1454- index );
1455- * old_secret = * s ;
1456- }
1448+ static void revoke_commitment ( u64 index , struct pubkey * point , struct secret * old_secret )
1449+ {
1450+ const u8 * msg ;
1451+ msg = hsm_req ( tmpctx , take ( towire_hsmd_revoke_commitment_tx ( tmpctx , index )));
1452+ if (! fromwire_hsmd_revoke_commitment_tx_reply ( msg , old_secret , point ))
1453+ status_failed ( STATUS_FAIL_HSM_IO ,
1454+ "Reading revoke_commitment_tx reply: %s" ,
1455+ tal_hex ( tmpctx , msg ));
14571456}
14581457
14591458/* revoke_index == current index - 1 (usually; not for retransmission) */
14601459static u8 * make_revocation_msg (const struct peer * peer , u64 revoke_index ,
14611460 struct pubkey * point )
14621461{
1463- const u8 * msg ;
14641462 struct secret old_commit_secret ;
14651463
14661464 /* Now that the master has persisted the new commitment advance the HSMD
1467- * and fetch the revocation secret for the old one. */
1468- if (!hsm_is_capable (peer -> hsm_capabilities , WIRE_HSMD_REVOKE_COMMITMENT_TX )) {
1469- /* Prior to HSM_VERSION 5 we call get_per_commitment_point to
1470- * get the old_secret and next point.
1471- */
1472- get_per_commitment_point (revoke_index + 2 , point , & old_commit_secret );
1473- } else {
1474- /* After HSM_VERSION 5 we explicitly revoke the commitment in case
1475- * the original revoke didn't complete. The hsmd_revoke_commitment_tx
1476- * call is idempotent ...
1477- */
1478- msg = towire_hsmd_revoke_commitment_tx (tmpctx , revoke_index );
1479- msg = hsm_req (tmpctx , take (msg ));
1480- if (!fromwire_hsmd_revoke_commitment_tx_reply (msg , & old_commit_secret , point ))
1481- status_failed (STATUS_FAIL_HSM_IO ,
1482- "Reading revoke_commitment_tx reply: %s" ,
1483- tal_hex (tmpctx , msg ));
1484- }
1465+ * and fetch the revocation secret for the old one.
1466+ *
1467+ * After HSM_VERSION 5 we explicitly revoke the commitment in case
1468+ * the original revoke didn't complete. The hsmd_revoke_commitment_tx
1469+ * call is idempotent ...
1470+ */
1471+ revoke_commitment (revoke_index , point , & old_commit_secret );
14851472
14861473 return towire_revoke_and_ack (peer , & peer -> channel_id , & old_commit_secret ,
14871474 point );
14881475}
14891476
1490- static u8 * make_revocation_msg_from_secret (const struct peer * peer ,
1491- u64 revoke_index ,
1492- struct pubkey * point ,
1493- const struct secret * old_commit_secret ,
1494- const struct pubkey * next_point )
1495- {
1496- * point = * next_point ;
1497- return towire_revoke_and_ack (peer , & peer -> channel_id ,
1498- old_commit_secret , next_point );
1499- }
1500-
15011477/* Convert changed htlcs into parts which lightningd expects. */
15021478static void marshall_htlc_info (const tal_t * ctx ,
15031479 const struct htlc * * changed_htlcs ,
@@ -1564,8 +1540,6 @@ static void send_revocation(struct peer *peer,
15641540 struct added_htlc * added ;
15651541 const u8 * msg ;
15661542 const u8 * msg_for_master ;
1567- struct secret old_secret2 ;
1568- struct pubkey next_point2 ;
15691543
15701544 /* Marshall it now before channel_sending_revoke_and_ack changes htlcs */
15711545 /* FIXME: Make infrastructure handle state post-revoke_and_ack! */
@@ -1608,24 +1582,10 @@ static void send_revocation(struct peer *peer,
16081582
16091583 /* Now that the master has persisted the new commitment advance the HSMD
16101584 * and fetch the revocation secret for the old one. */
1611- if (!hsm_is_capable (peer -> hsm_capabilities , WIRE_HSMD_REVOKE_COMMITMENT_TX )) {
1612- /* Prior to HSM_VERSION 5 we use the old_secret
1613- * received earlier from validate_commitment_tx. */
1614- old_secret2 = * old_secret ;
1615- next_point2 = * next_point ;
1616- } else {
1617- msg = towire_hsmd_revoke_commitment_tx (tmpctx , peer -> next_index [LOCAL ] - 2 );
1618- msg = hsm_req (tmpctx , take (msg ));
1619- if (!fromwire_hsmd_revoke_commitment_tx_reply (msg , & old_secret2 , & next_point2 ))
1620- status_failed (STATUS_FAIL_HSM_IO ,
1621- "Reading revoke_commitment_tx reply: %s" ,
1622- tal_hex (tmpctx , msg ));
1623- }
16241585
16251586 /* Revoke previous commit, get new point. */
1626- msg = make_revocation_msg_from_secret (peer , peer -> next_index [LOCAL ]- 2 ,
1627- & peer -> next_local_per_commit ,
1628- & old_secret2 , & next_point2 );
1587+ msg = make_revocation_msg (peer , peer -> next_index [LOCAL ]- 2 ,
1588+ & peer -> next_local_per_commit );
16291589
16301590 /* Now we can finally send revoke_and_ack to peer */
16311591 peer_write (peer -> pps , take (msg ));
@@ -2061,7 +2021,7 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
20612021 "error" );
20622022 }
20632023
2064- /* Validate the counterparty's signatures, returns prior per_commitment_secret. */
2024+ /* As of HSM_VERSION 5 returned old_secret is always NULL (revoke returns it instead) */
20652025 htlcs = collect_htlcs (NULL , htlc_map );
20662026 msg2 = towire_hsmd_validate_commitment_tx (NULL ,
20672027 txs [0 ],
@@ -2123,10 +2083,8 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
21232083 tal_steal (commitsigs , result );
21242084 }
21252085
2126- // If the HSM doesn't support WIRE_HSMD_REVOKE_COMMITMENT_TX we'd better
2127- // have the old_secret at this point.
2128- if (!hsm_is_capable (peer -> hsm_capabilities , WIRE_HSMD_REVOKE_COMMITMENT_TX ))
2129- assert (old_secret );
2086+ /* After HSM_VERSION 5 old_secret is always NULL */
2087+ assert (!old_secret );
21302088
21312089 send_revocation (peer , & commit_sig , htlc_sigs , changed_htlcs , txs [0 ],
21322090 old_secret , & next_point , commitsigs );
@@ -2778,7 +2736,7 @@ static struct commitsig *interactive_send_commitments(struct peer *peer,
27782736 /* Funding counts as 0th commit so we do inflight_index + 1 */
27792737 if (fromwire_peektype (msg ) == WIRE_COMMITMENT_SIGNED ) {
27802738 get_per_commitment_point (next_index_local - 1 ,
2781- & my_current_per_commitment_point , NULL );
2739+ & my_current_per_commitment_point );
27822740
27832741 result = handle_peer_commit_sig (peer , msg ,
27842742 inflight_index + 1 ,
@@ -4672,10 +4630,7 @@ static void check_current_dataloss_fields(struct peer *peer,
46724630 memset (& old_commit_secret , 0 , sizeof (old_commit_secret ));
46734631 else {
46744632 struct pubkey unused ;
4675- /* This gets previous revocation number, since asking for
4676- * commitment point N gives secret for N-2 */
4677- get_per_commitment_point (next_revocation_number + 1 ,
4678- & unused , & old_commit_secret );
4633+ revoke_commitment (next_revocation_number - 1 , & unused , & old_commit_secret );
46794634 }
46804635
46814636 if (!secret_eq_consttime (& old_commit_secret ,
@@ -4810,7 +4765,7 @@ static void peer_reconnect(struct peer *peer,
48104765 /* Our current per-commitment point is the commitment point in the last
48114766 * received signed commitment */
48124767 get_per_commitment_point (peer -> next_index [LOCAL ] - 1 ,
4813- & my_current_per_commitment_point , NULL );
4768+ & my_current_per_commitment_point );
48144769
48154770 send_tlvs = NULL ;
48164771
@@ -5419,7 +5374,7 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
54195374 /* Need to retrieve the first point again, even if we
54205375 * moved on, as channel_ready explicitly includes the
54215376 * first one. */
5422- get_per_commitment_point (1 , & point , NULL );
5377+ get_per_commitment_point (1 , & point );
54235378
54245379 msg = towire_channel_ready (NULL , & peer -> channel_id ,
54255380 & point , tlvs );
@@ -6006,7 +5961,7 @@ static void init_channel(struct peer *peer)
60065961 assert (peer -> next_index [REMOTE ] > 0 );
60075962
60085963 get_per_commitment_point (peer -> next_index [LOCAL ],
6009- & peer -> next_local_per_commit , NULL );
5964+ & peer -> next_local_per_commit );
60105965
60115966 peer -> channel = new_full_channel (peer , & peer -> channel_id ,
60125967 & funding ,
0 commit comments