- debug_assert!(
- self.onchain_tx_handler.channel_transaction_parameters.opt_anchors.is_none(),
- "This code needs updating for anchors");
- BitcoinOutPoint::new(txid, 0)
+ // Because HTLC transactions either only have 1 input and 1 output (pre-anchors) or
+ // are signed with SIGHASH_SINGLE|ANYONECANPAY under BIP-0143 (post-anchors), we can
+ // locate the correct output by ensuring its adjacent input spends the HTLC output
+ // in the commitment.
+ if let Some(ref tx) = htlc_spend_tx_opt {
+ let htlc_input_idx_opt = tx.input.iter().enumerate()
+ .find(|(_, input)| input.previous_output == htlc_commitment_outpoint)
+ .map(|(idx, _)| idx as u32);
+ debug_assert!(htlc_input_idx_opt.is_some());
+ BitcoinOutPoint::new(*txid, htlc_input_idx_opt.unwrap_or(0))
+ } else {
+ debug_assert!(!self.onchain_tx_handler.opt_anchors());
+ BitcoinOutPoint::new(*txid, 0)
+ }