@@ -1321,6 +1321,7 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
1321
1321
struct bitcoin_tx * * txs ,
1322
1322
const u8 * funding_wscript ,
1323
1323
const struct htlc * * htlc_map ,
1324
+ const struct pubkey * remote_per_commit ,
1324
1325
u64 commit_index ,
1325
1326
struct bitcoin_signature * commit_sig )
1326
1327
{
@@ -1333,7 +1334,7 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
1333
1334
htlcs = collect_htlcs (tmpctx , htlc_map );
1334
1335
msg = towire_hsmd_sign_remote_commitment_tx (NULL , txs [0 ],
1335
1336
& peer -> channel -> funding_pubkey [REMOTE ],
1336
- & peer -> remote_per_commit ,
1337
+ remote_per_commit ,
1337
1338
channel_has (peer -> channel ,
1338
1339
OPT_STATIC_REMOTEKEY ),
1339
1340
commit_index ,
@@ -1357,7 +1358,7 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
1357
1358
dump_htlcs (peer -> channel , "Sending commit_sig" );
1358
1359
1359
1360
if (!derive_simple_key (& peer -> channel -> basepoints [LOCAL ].htlc ,
1360
- & peer -> remote_per_commit ,
1361
+ remote_per_commit ,
1361
1362
& local_htlckey ))
1362
1363
status_failed (STATUS_FAIL_INTERNAL_ERROR ,
1363
1364
"Deriving local_htlckey" );
@@ -1377,7 +1378,7 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
1377
1378
wscript = bitcoin_tx_output_get_witscript (tmpctx , txs [0 ],
1378
1379
txs [i + 1 ]-> wtx -> inputs [0 ].index );
1379
1380
msg = towire_hsmd_sign_remote_htlc_tx (NULL , txs [i + 1 ], wscript ,
1380
- & peer -> remote_per_commit ,
1381
+ remote_per_commit ,
1381
1382
channel_has_anchors (peer -> channel ));
1382
1383
1383
1384
msg = hsm_req (tmpctx , take (msg ));
@@ -1530,6 +1531,32 @@ static u8 *send_commit_part(const tal_t *ctx,
1530
1531
int local_anchor_outnum ;
1531
1532
struct tlv_commitment_signed_tlvs * cs_tlv
1532
1533
= tlv_commitment_signed_tlvs_new (tmpctx );
1534
+ const struct pubkey * remote_per_commit = NULL ;
1535
+
1536
+ status_debug ("send_commit_part: "
1537
+ "remote_index=%" PRIu64 " "
1538
+ "remote_next_index=%" PRIu64 " "
1539
+ "old_remote_per_commit=%s "
1540
+ "remote_per_commit=%s" ,
1541
+ remote_index ,
1542
+ peer -> next_index [REMOTE ],
1543
+ type_to_string (tmpctx , struct pubkey , & peer -> old_remote_per_commit ),
1544
+ type_to_string (tmpctx , struct pubkey , & peer -> remote_per_commit ));
1545
+
1546
+ /* We need to be able to sign at the current commitment number for retries
1547
+ * and splice candidates or the next commitment number for state advances
1548
+ */
1549
+ if (remote_index == peer -> next_index [REMOTE ] - 1 )
1550
+ remote_per_commit = & peer -> old_remote_per_commit ;
1551
+ else if (remote_index == peer -> next_index [REMOTE ])
1552
+ remote_per_commit = & peer -> remote_per_commit ;
1553
+ else {
1554
+ status_broken ("send_commit_part called with remote_index=%" PRIu64 " "
1555
+ "when peer->next_index[REMOTE]=%" PRIu64 "" ,
1556
+ remote_index ,
1557
+ peer -> next_index [REMOTE ]);
1558
+ abort ();
1559
+ }
1533
1560
1534
1561
/* In theory, peer will ignore TLV 1 as unknown, but while
1535
1562
* spec is in flux this is dangerous, as it may change: so don't
@@ -1546,12 +1573,12 @@ static u8 *send_commit_part(const tal_t *ctx,
1546
1573
1547
1574
txs = channel_txs (tmpctx , funding , funding_sats , & htlc_map ,
1548
1575
direct_outputs , & funding_wscript ,
1549
- peer -> channel , & peer -> remote_per_commit ,
1576
+ peer -> channel , remote_per_commit ,
1550
1577
remote_index , REMOTE ,
1551
1578
splice_amnt , remote_splice_amnt , & local_anchor_outnum );
1552
1579
htlc_sigs =
1553
1580
calc_commitsigs (tmpctx , peer , txs , funding_wscript , htlc_map ,
1554
- remote_index , & commit_sig );
1581
+ remote_per_commit , remote_index , & commit_sig );
1555
1582
1556
1583
if (direct_outputs [LOCAL ] != NULL ) {
1557
1584
pbase = penalty_base_new (tmpctx , remote_index ,
0 commit comments