Skip to content

Commit 7f39e0c

Browse files
committed
f! move out of one tx input check
1 parent 1697b5b commit 7f39e0c

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,24 +2979,32 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29792979
commitment_tx_to_counterparty_output,
29802980
},
29812981
});
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) {
29842990
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
29862992
);
29872993
claimable_outpoints.append(&mut new_outpoints);
29882994
if let Some(new_outputs) = new_outputs_option {
29892995
watch_outputs.push(new_outputs);
29902996
}
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;
29913002
}
29923003
}
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);
29983005

2999-
self.is_paying_spendable_output(&tx, height, &block_hash, &logger);
3006+
self.is_paying_spendable_output(&tx, height, &block_hash, &logger);
3007+
}
30003008
}
30013009

30023010
if height > self.best_block.height() {

0 commit comments

Comments
 (0)