@@ -3399,26 +3399,35 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
33993399
34003400 // Prune HTLCs from the previous counterparty commitment tx so we don't generate failure/fulfill
34013401 // 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+ }
34123419 }
3420+ removed_fulfilled_htlcs = true ;
34133421 }
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" ) ;
34143427 }
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" ) ;
34203428 }
3421- }
3429+ } ;
3430+ core:: iter:: once ( & mut self . funding ) . chain ( & mut self . pending_funding ) . for_each ( prune_htlc_sources) ;
34223431
34233432 if !self . payment_preimages . is_empty ( ) {
34243433 let min_idx = self . get_min_seen_secret ( ) ;
@@ -4049,6 +4058,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
40494058
40504059 mem:: swap ( & mut self . funding , & mut new_funding) ;
40514060 self . onchain_tx_handler . update_after_renegotiated_funding_locked (
4061+ self . funding . channel_parameters . clone ( ) ,
40524062 self . funding . current_holder_commitment_tx . clone ( ) ,
40534063 self . funding . prev_holder_commitment_tx . clone ( ) ,
40544064 ) ;
@@ -5164,6 +5174,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
51645174 let txid = tx. compute_txid ( ) ;
51655175 log_trace ! ( logger, "Transaction {} confirmed in block {}" , txid , block_hash) ;
51665176 // 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+ }
51675181 if Some ( txid) == self . funding_spend_confirmed {
51685182 log_debug ! ( logger, "Skipping redundant processing of funding-spend tx {} as it was previously confirmed" , txid) ;
51695183 continue ' tx_iter;
0 commit comments