Skip to content

Commit 0245a7c

Browse files
author
Antoine Riard
committed
[TBS] del trailing whitespaces + retain instead of drain
1 parent 6903094 commit 0245a7c

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/ln/channelmonitor.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,26 +287,28 @@ impl ChannelMonitor {
287287
}
288288
}
289289

290-
let mut pruned_payment_preimages = HashMap::with_capacity(self.payment_preimages.capacity());
291-
for (k, v) in self.payment_preimages.drain() {
292-
for (htlc, _s1, _s2) in &self.current_local_signed_commitment_tx.as_ref().expect("Channel need at least an initial commitment tx !").htlc_outputs {
293-
if k == htlc.payment_hash {
294-
pruned_payment_preimages.insert(k, v);
295-
}
296-
}
297-
for (_tx, htlcs) in &self.remote_claimable_outpoints {
298-
for htlc in htlcs {
290+
let local_signed_commitment_tx = &self.current_local_signed_commitment_tx;
291+
let remote_claimable_outpoints = &self.remote_claimable_outpoints;
292+
self.payment_preimages.retain( | &k, _|
293+
{
294+
for (htlc, _s1, _s2) in &local_signed_commitment_tx.as_ref().expect("Channel needs at least an initial commitment tx !").htlc_outputs {
299295
if k == htlc.payment_hash {
300-
pruned_payment_preimages.insert(k, v);
296+
return true
301297
}
302298
}
303-
}
304-
}
305-
self.payment_preimages = pruned_payment_preimages;
299+
for (_tx, htlcs) in remote_claimable_outpoints {
300+
for htlc in htlcs {
301+
if k == htlc.payment_hash {
302+
return true
303+
}
304+
}
305+
}
306+
false
307+
});
306308

307309
Ok(())
308310
}
309-
311+
310312
/// Informs this monitor of the latest remote (ie non-broadcastable) commitment transaction.
311313
/// The monitor watches for it to be broadcasted and then uses the HTLC information (and
312314
/// possibly future revocation/preimage information) to claim outputs where possible.

0 commit comments

Comments
 (0)