@@ -294,26 +294,37 @@ impl ChannelMonitor {
294
294
}
295
295
}
296
296
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
+ }
304
308
}
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
+ }
309
315
}
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
+ }
317
328
318
329
Ok ( ( ) )
319
330
}
0 commit comments