@@ -3399,26 +3399,35 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3399
3399
3400
3400
// Prune HTLCs from the previous counterparty commitment tx so we don't generate failure/fulfill
3401
3401
// events for now-revoked/fulfilled HTLCs.
3402
- if let Some ( txid) = self . funding . prev_counterparty_commitment_txid . take ( ) {
3403
- if self . funding . current_counterparty_commitment_txid . unwrap ( ) != txid {
3404
- let cur_claimables = self . funding . counterparty_claimable_outpoints . get (
3405
- & self . funding . current_counterparty_commitment_txid . unwrap ( ) ) . unwrap ( ) ;
3406
- for ( _, ref source_opt) in self . funding . counterparty_claimable_outpoints . get ( & txid) . unwrap ( ) {
3407
- if let Some ( source) = source_opt {
3408
- if !cur_claimables. iter ( )
3409
- . any ( |( _, cur_source_opt) | cur_source_opt == source_opt)
3410
- {
3411
- self . counterparty_fulfilled_htlcs . remove ( & SentHTLCId :: from_source ( source) ) ;
3402
+ let mut removed_fulfilled_htlcs = false ;
3403
+ let prune_htlc_sources = |funding : & mut FundingScope | {
3404
+ if let Some ( txid) = funding. prev_counterparty_commitment_txid . take ( ) {
3405
+ if funding. current_counterparty_commitment_txid . unwrap ( ) != txid {
3406
+ let cur_claimables = funding. counterparty_claimable_outpoints . get (
3407
+ & funding. current_counterparty_commitment_txid . unwrap ( ) ) . unwrap ( ) ;
3408
+ // We only need to remove fulfilled HTLCs once for the first `FundingScope` we
3409
+ // come across since all `FundingScope`s share the same set of HTLC sources.
3410
+ if !removed_fulfilled_htlcs {
3411
+ for ( _, ref source_opt) in funding. counterparty_claimable_outpoints . get ( & txid) . unwrap ( ) {
3412
+ if let Some ( source) = source_opt {
3413
+ if !cur_claimables. iter ( )
3414
+ . any ( |( _, cur_source_opt) | cur_source_opt == source_opt)
3415
+ {
3416
+ self . counterparty_fulfilled_htlcs . remove ( & SentHTLCId :: from_source ( source) ) ;
3417
+ }
3418
+ }
3412
3419
}
3420
+ removed_fulfilled_htlcs = true ;
3413
3421
}
3422
+ for & mut ( _, ref mut source_opt) in funding. counterparty_claimable_outpoints . get_mut ( & txid) . unwrap ( ) {
3423
+ * source_opt = None ;
3424
+ }
3425
+ } else {
3426
+ assert ! ( cfg!( fuzzing) , "Commitment txids are unique outside of fuzzing, where hashes can collide" ) ;
3414
3427
}
3415
- for & mut ( _, ref mut source_opt) in self . funding . counterparty_claimable_outpoints . get_mut ( & txid) . unwrap ( ) {
3416
- * source_opt = None ;
3417
- }
3418
- } else {
3419
- assert ! ( cfg!( fuzzing) , "Commitment txids are unique outside of fuzzing, where hashes can collide" ) ;
3420
3428
}
3421
- }
3429
+ } ;
3430
+ core:: iter:: once ( & mut self . funding ) . chain ( & mut self . pending_funding ) . for_each ( prune_htlc_sources) ;
3422
3431
3423
3432
if !self . payment_preimages . is_empty ( ) {
3424
3433
let min_idx = self . get_min_seen_secret ( ) ;
@@ -4049,6 +4058,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4049
4058
4050
4059
mem:: swap ( & mut self . funding , & mut new_funding) ;
4051
4060
self . onchain_tx_handler . update_after_renegotiated_funding_locked (
4061
+ self . funding . channel_parameters . clone ( ) ,
4052
4062
self . funding . current_holder_commitment_tx . clone ( ) ,
4053
4063
self . funding . prev_holder_commitment_tx . clone ( ) ,
4054
4064
) ;
@@ -5164,6 +5174,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5164
5174
let txid = tx. compute_txid ( ) ;
5165
5175
log_trace ! ( logger, "Transaction {} confirmed in block {}" , txid , block_hash) ;
5166
5176
// If a transaction has already been confirmed, ensure we don't bother processing it duplicatively.
5177
+ if self . alternative_funding_confirmed . map ( |( alternative_funding_txid, _) | alternative_funding_txid == txid) . unwrap_or ( false ) {
5178
+ log_debug ! ( logger, "Skipping redundant processing of funding-spend tx {} as it was previously confirmed" , txid) ;
5179
+ continue ' tx_iter;
5180
+ }
5167
5181
if Some ( txid) == self . funding_spend_confirmed {
5168
5182
log_debug ! ( logger, "Skipping redundant processing of funding-spend tx {} as it was previously confirmed" , txid) ;
5169
5183
continue ' tx_iter;
0 commit comments