Skip to content

Commit 3d54ae8

Browse files
committed
There can only be one input in matched txn in ChannelMonitor
This lets us simplify a few tidbits of loop.
1 parent 41eeb00 commit 3d54ae8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ln/channelmonitor.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1352,9 +1352,14 @@ impl ChannelMonitor {
13521352
fn block_connected(&self, txn_matched: &[&Transaction], height: u32, broadcaster: &BroadcasterInterface)-> Vec<(Sha256dHash, Vec<TxOut>)> {
13531353
let mut watch_outputs = Vec::new();
13541354
for tx in txn_matched {
1355-
let mut txn: Vec<Transaction> = Vec::new();
1356-
for txin in tx.input.iter() {
1357-
if self.funding_txo.is_none() || (txin.previous_output.txid == self.funding_txo.as_ref().unwrap().0.txid && txin.previous_output.vout == self.funding_txo.as_ref().unwrap().0.index as u32) {
1355+
if tx.input.len() == 1 {
1356+
// Assuming our keys were not leaked (in which case we're screwed no matter what),
1357+
// commitment transactions and HTLC transactions will all only ever have one input,
1358+
// which is an easy way to filter out any potential non-matching txn for lazy
1359+
// filters.
1360+
let prevout = &tx.input[0].previous_output;
1361+
let mut txn: Vec<Transaction> = Vec::new();
1362+
if self.funding_txo.is_none() || (prevout.txid == self.funding_txo.as_ref().unwrap().0.txid && prevout.vout == self.funding_txo.as_ref().unwrap().0.index as u32) {
13581363
let (remote_txn, new_outputs) = self.check_spend_remote_transaction(tx, height);
13591364
txn = remote_txn;
13601365
if !new_outputs.1.is_empty() {

0 commit comments

Comments
 (0)