@@ -2503,6 +2503,18 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2503
2503
{
2504
2504
self . payment_preimages . insert ( payment_hash. clone ( ) , payment_preimage. clone ( ) ) ;
2505
2505
2506
+ let confirmed_spend_txid = self . funding_spend_confirmed . or_else ( || {
2507
+ self . onchain_events_awaiting_threshold_conf . iter ( ) . find_map ( |event| match event. event {
2508
+ OnchainEvent :: FundingSpendConfirmation { .. } => Some ( event. txid ) ,
2509
+ _ => None ,
2510
+ } )
2511
+ } ) ;
2512
+ let confirmed_spend_txid = if let Some ( txid) = confirmed_spend_txid {
2513
+ txid
2514
+ } else {
2515
+ return ;
2516
+ } ;
2517
+
2506
2518
// If the channel is force closed, try to claim the output from this preimage.
2507
2519
// First check if a counterparty commitment transaction has been broadcasted:
2508
2520
macro_rules! claim_htlcs {
@@ -2512,14 +2524,24 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2512
2524
}
2513
2525
}
2514
2526
if let Some ( txid) = self . current_counterparty_commitment_txid {
2515
- if let Some ( commitment_number) = self . counterparty_commitment_txn_on_chain . get ( & txid) {
2516
- claim_htlcs ! ( * commitment_number, txid) ;
2527
+ if txid == confirmed_spend_txid {
2528
+ if let Some ( commitment_number) = self . counterparty_commitment_txn_on_chain . get ( & txid) {
2529
+ claim_htlcs ! ( * commitment_number, txid) ;
2530
+ } else {
2531
+ debug_assert ! ( false ) ;
2532
+ log_error ! ( self . logger, "Detected counterparty commitment tx on-chain without tracking commitment number" ) ;
2533
+ }
2517
2534
return ;
2518
2535
}
2519
2536
}
2520
2537
if let Some ( txid) = self . prev_counterparty_commitment_txid {
2521
- if let Some ( commitment_number) = self . counterparty_commitment_txn_on_chain . get ( & txid) {
2522
- claim_htlcs ! ( * commitment_number, txid) ;
2538
+ if txid == confirmed_spend_txid {
2539
+ if let Some ( commitment_number) = self . counterparty_commitment_txn_on_chain . get ( & txid) {
2540
+ claim_htlcs ! ( * commitment_number, txid) ;
2541
+ } else {
2542
+ debug_assert ! ( false ) ;
2543
+ log_error ! ( self . logger, "Detected counterparty commitment tx on-chain without tracking commitment number" ) ;
2544
+ }
2523
2545
return ;
2524
2546
}
2525
2547
}
@@ -2530,13 +2552,22 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2530
2552
// *we* sign a holder commitment transaction, not when e.g. a watchtower broadcasts one of our
2531
2553
// holder commitment transactions.
2532
2554
if self . broadcasted_holder_revokable_script . is_some ( ) {
2533
- // Assume that the broadcasted commitment transaction confirmed in the current best
2534
- // block. Even if not, its a reasonable metric for the bump criteria on the HTLC
2535
- // transactions.
2536
- let ( claim_reqs, _) = self . get_broadcasted_holder_claims ( & self . current_holder_commitment_tx , self . best_block . height ( ) ) ;
2537
- self . onchain_tx_handler . update_claims_view_from_requests ( claim_reqs, self . best_block . height ( ) , self . best_block . height ( ) , broadcaster, fee_estimator, logger) ;
2538
- if let Some ( ref tx) = self . prev_holder_signed_commitment_tx {
2539
- let ( claim_reqs, _) = self . get_broadcasted_holder_claims ( & tx, self . best_block . height ( ) ) ;
2555
+ let holder_commitment_tx = if self . current_holder_commitment_tx . txid == confirmed_spend_txid {
2556
+ Some ( & self . current_holder_commitment_tx )
2557
+ } else if let Some ( prev_holder_commitment_tx) = & self . prev_holder_signed_commitment_tx {
2558
+ if prev_holder_commitment_tx. txid == confirmed_spend_txid {
2559
+ Some ( prev_holder_commitment_tx)
2560
+ } else {
2561
+ None
2562
+ }
2563
+ } else {
2564
+ None
2565
+ } ;
2566
+ if let Some ( holder_commitment_tx) = holder_commitment_tx {
2567
+ // Assume that the broadcasted commitment transaction confirmed in the current best
2568
+ // block. Even if not, its a reasonable metric for the bump criteria on the HTLC
2569
+ // transactions.
2570
+ let ( claim_reqs, _) = self . get_broadcasted_holder_claims ( & holder_commitment_tx, self . best_block . height ( ) ) ;
2540
2571
self . onchain_tx_handler . update_claims_view_from_requests ( claim_reqs, self . best_block . height ( ) , self . best_block . height ( ) , broadcaster, fee_estimator, logger) ;
2541
2572
}
2542
2573
}
0 commit comments