@@ -1429,75 +1429,51 @@ static void start_commit_timer(struct peer *peer)
1429
1429
send_commit_if_not_stfu , peer );
1430
1430
}
1431
1431
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 )
1435
1433
{
1436
- struct secret * s ;
1434
+ struct secret * unused ;
1437
1435
const u8 * msg ;
1438
1436
1439
1437
msg = hsm_req (tmpctx ,
1440
1438
take (towire_hsmd_get_per_commitment_point (NULL , index )));
1441
1439
1442
1440
if (!fromwire_hsmd_get_per_commitment_point_reply (tmpctx , msg ,
1443
1441
point ,
1444
- & s ))
1442
+ & unused ))
1445
1443
status_failed (STATUS_FAIL_HSM_IO ,
1446
1444
"Bad per_commitment_point reply %s" ,
1447
1445
tal_hex (tmpctx , msg ));
1446
+ }
1448
1447
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 ));
1457
1456
}
1458
1457
1459
1458
/* revoke_index == current index - 1 (usually; not for retransmission) */
1460
1459
static u8 * make_revocation_msg (const struct peer * peer , u64 revoke_index ,
1461
1460
struct pubkey * point )
1462
1461
{
1463
- const u8 * msg ;
1464
1462
struct secret old_commit_secret ;
1465
1463
1466
1464
/* 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 );
1485
1472
1486
1473
return towire_revoke_and_ack (peer , & peer -> channel_id , & old_commit_secret ,
1487
1474
point );
1488
1475
}
1489
1476
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
-
1501
1477
/* Convert changed htlcs into parts which lightningd expects. */
1502
1478
static void marshall_htlc_info (const tal_t * ctx ,
1503
1479
const struct htlc * * changed_htlcs ,
@@ -1564,8 +1540,6 @@ static void send_revocation(struct peer *peer,
1564
1540
struct added_htlc * added ;
1565
1541
const u8 * msg ;
1566
1542
const u8 * msg_for_master ;
1567
- struct secret old_secret2 ;
1568
- struct pubkey next_point2 ;
1569
1543
1570
1544
/* Marshall it now before channel_sending_revoke_and_ack changes htlcs */
1571
1545
/* FIXME: Make infrastructure handle state post-revoke_and_ack! */
@@ -1608,24 +1582,10 @@ static void send_revocation(struct peer *peer,
1608
1582
1609
1583
/* Now that the master has persisted the new commitment advance the HSMD
1610
1584
* 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
- }
1624
1585
1625
1586
/* 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 );
1629
1589
1630
1590
/* Now we can finally send revoke_and_ack to peer */
1631
1591
peer_write (peer -> pps , take (msg ));
@@ -2061,7 +2021,7 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
2061
2021
"error" );
2062
2022
}
2063
2023
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) */
2065
2025
htlcs = collect_htlcs (NULL , htlc_map );
2066
2026
msg2 = towire_hsmd_validate_commitment_tx (NULL ,
2067
2027
txs [0 ],
@@ -2123,10 +2083,8 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
2123
2083
tal_steal (commitsigs , result );
2124
2084
}
2125
2085
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 );
2130
2088
2131
2089
send_revocation (peer , & commit_sig , htlc_sigs , changed_htlcs , txs [0 ],
2132
2090
old_secret , & next_point , commitsigs );
@@ -2778,7 +2736,7 @@ static struct commitsig *interactive_send_commitments(struct peer *peer,
2778
2736
/* Funding counts as 0th commit so we do inflight_index + 1 */
2779
2737
if (fromwire_peektype (msg ) == WIRE_COMMITMENT_SIGNED ) {
2780
2738
get_per_commitment_point (next_index_local - 1 ,
2781
- & my_current_per_commitment_point , NULL );
2739
+ & my_current_per_commitment_point );
2782
2740
2783
2741
result = handle_peer_commit_sig (peer , msg ,
2784
2742
inflight_index + 1 ,
@@ -4672,10 +4630,7 @@ static void check_current_dataloss_fields(struct peer *peer,
4672
4630
memset (& old_commit_secret , 0 , sizeof (old_commit_secret ));
4673
4631
else {
4674
4632
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 );
4679
4634
}
4680
4635
4681
4636
if (!secret_eq_consttime (& old_commit_secret ,
@@ -4810,7 +4765,7 @@ static void peer_reconnect(struct peer *peer,
4810
4765
/* Our current per-commitment point is the commitment point in the last
4811
4766
* received signed commitment */
4812
4767
get_per_commitment_point (peer -> next_index [LOCAL ] - 1 ,
4813
- & my_current_per_commitment_point , NULL );
4768
+ & my_current_per_commitment_point );
4814
4769
4815
4770
send_tlvs = NULL ;
4816
4771
@@ -5419,7 +5374,7 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
5419
5374
/* Need to retrieve the first point again, even if we
5420
5375
* moved on, as channel_ready explicitly includes the
5421
5376
* first one. */
5422
- get_per_commitment_point (1 , & point , NULL );
5377
+ get_per_commitment_point (1 , & point );
5423
5378
5424
5379
msg = towire_channel_ready (NULL , & peer -> channel_id ,
5425
5380
& point , tlvs );
@@ -6006,7 +5961,7 @@ static void init_channel(struct peer *peer)
6006
5961
assert (peer -> next_index [REMOTE ] > 0 );
6007
5962
6008
5963
get_per_commitment_point (peer -> next_index [LOCAL ],
6009
- & peer -> next_local_per_commit , NULL );
5964
+ & peer -> next_local_per_commit );
6010
5965
6011
5966
peer -> channel = new_full_channel (peer , & peer -> channel_id ,
6012
5967
& funding ,
0 commit comments