Skip to content

Commit 8926c25

Browse files
committed
Also avoid pruning preimages for previous local tx in ChannelMonitor
1 parent f5225a1 commit 8926c25

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/ln/channelmonitor.rs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -294,26 +294,37 @@ impl ChannelMonitor {
294294
}
295295
}
296296

297-
let local_signed_commitment_tx = &self.current_local_signed_commitment_tx;
298-
let min_idx = self.get_min_seen_secret();
299-
let remote_hash_commitment_number = &mut self.remote_hash_commitment_number;
300-
self.payment_preimages.retain(|&k, _| {
301-
for &(ref htlc, _s1, _s2) in &local_signed_commitment_tx.as_ref().expect("Channel needs at least an initial commitment tx !").htlc_outputs {
302-
if k == htlc.payment_hash {
303-
return true
297+
if !self.payment_preimages.is_empty() {
298+
let local_signed_commitment_tx = self.current_local_signed_commitment_tx.as_ref().expect("Channel needs at least an initial commitment tx !");
299+
let prev_local_signed_commitment_tx = self.prev_local_signed_commitment_tx.as_ref();
300+
let min_idx = self.get_min_seen_secret();
301+
let remote_hash_commitment_number = &mut self.remote_hash_commitment_number;
302+
303+
self.payment_preimages.retain(|&k, _| {
304+
for &(ref htlc, _, _) in &local_signed_commitment_tx.htlc_outputs {
305+
if k == htlc.payment_hash {
306+
return true
307+
}
304308
}
305-
}
306-
let contains = if let Some(cn) = remote_hash_commitment_number.get(&k) {
307-
if *cn < min_idx {
308-
return true
309+
if let Some(prev_local_commitment_tx) = prev_local_signed_commitment_tx {
310+
for &(ref htlc, _, _) in prev_local_commitment_tx.htlc_outputs.iter() {
311+
if k == htlc.payment_hash {
312+
return true
313+
}
314+
}
309315
}
310-
true
311-
} else { false };
312-
if contains {
313-
remote_hash_commitment_number.remove(&k);
314-
}
315-
false
316-
});
316+
let contains = if let Some(cn) = remote_hash_commitment_number.get(&k) {
317+
if *cn < min_idx {
318+
return true
319+
}
320+
true
321+
} else { false };
322+
if contains {
323+
remote_hash_commitment_number.remove(&k);
324+
}
325+
false
326+
});
327+
}
317328

318329
Ok(())
319330
}

0 commit comments

Comments
 (0)