@@ -2979,24 +2979,32 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2979
2979
commitment_tx_to_counterparty_output,
2980
2980
} ,
2981
2981
} ) ;
2982
- } else {
2983
- if let Some ( & commitment_number) = self . counterparty_commitment_txn_on_chain . get ( & prevout. txid ) {
2982
+ }
2983
+ } else if tx. input . len ( ) > 1 {
2984
+ // While all commitment transactions have one input, HTLC transactions may have more
2985
+ // if the HTLC was present in an anchor channel. HTLCs can also be resolved in a few
2986
+ // other ways which can have more than one output.
2987
+ for tx_input in & tx. input {
2988
+ let commitment_txid = tx_input. previous_output . txid ;
2989
+ if let Some ( & commitment_number) = self . counterparty_commitment_txn_on_chain . get ( & commitment_txid) {
2984
2990
let ( mut new_outpoints, new_outputs_option) = self . check_spend_counterparty_htlc (
2985
- & tx, commitment_number, & prevout . txid , height, & logger
2991
+ & tx, commitment_number, & commitment_txid , height, & logger
2986
2992
) ;
2987
2993
claimable_outpoints. append ( & mut new_outpoints) ;
2988
2994
if let Some ( new_outputs) = new_outputs_option {
2989
2995
watch_outputs. push ( new_outputs) ;
2990
2996
}
2997
+ // Since there may be multiple HTLCs (all from the same commitment) being
2998
+ // claimed by the counterparty within the same transaction, and
2999
+ // `check_spend_counterparty_htlc` already checks for all of them, we can
3000
+ // safely break from our loop.
3001
+ break ;
2991
3002
}
2992
3003
}
2993
- }
2994
- // While all commitment/HTLC-Success/HTLC-Timeout transactions have one input, HTLCs
2995
- // can also be resolved in a few other ways which can have more than one output. Thus,
2996
- // we call is_resolving_htlc_output here outside of the tx.input.len() == 1 check.
2997
- self . is_resolving_htlc_output ( & tx, height, & block_hash, & logger) ;
3004
+ self . is_resolving_htlc_output ( & tx, height, & block_hash, & logger) ;
2998
3005
2999
- self . is_paying_spendable_output ( & tx, height, & block_hash, & logger) ;
3006
+ self . is_paying_spendable_output ( & tx, height, & block_hash, & logger) ;
3007
+ }
3000
3008
}
3001
3009
3002
3010
if height > self . best_block . height ( ) {
0 commit comments