@@ -8294,49 +8294,51 @@ where
8294
8294
// Whether the downstream channel was closed or not, try to re-apply any payment
8295
8295
// preimages from it which may be needed in upstream channels for forwarded
8296
8296
// payments.
8297
- for ( htlc_source, ( htlc, preimage_opt) ) in monitor. get_all_current_outbound_htlcs ( ) {
8298
- match htlc_source {
8299
- HTLCSource :: PreviousHopData ( prev_hop_data) => {
8297
+ let outbound_claimed_htlcs_iter = monitor. get_all_current_outbound_htlcs ( )
8298
+ . into_iter ( )
8299
+ . filter_map ( |( htlc_source, ( htlc, preimage_opt) ) | {
8300
+ if let HTLCSource :: PreviousHopData ( prev_hop_data) = htlc_source {
8300
8301
if let Some ( payment_preimage) = preimage_opt {
8301
- let mut is_chan_open = false ;
8302
- if let Some ( ( node_id, chan_id) ) = short_to_chan_info. get ( & prev_hop_data. short_channel_id ) {
8303
- if let Some ( mut peer) = per_peer_state. get_mut ( node_id) . map ( |node| node. lock ( ) . unwrap ( ) ) {
8304
- if let Some ( chan) = peer. channel_by_id . get_mut ( chan_id) {
8305
- is_chan_open = true ;
8306
- match chan. get_update_fulfill_htlc_and_commit ( prev_hop_data. htlc_id , payment_preimage, & args. logger ) {
8307
- UpdateFulfillCommitFetch :: DuplicateClaim { } => { } ,
8308
- UpdateFulfillCommitFetch :: NewClaim { monitor_update, .. } => {
8309
- // The ChannelMonitor that gave us this
8310
- // preimage is for a now-closed channel -
8311
- // no further updates to that channel can
8312
- // happen which would result in the
8313
- // preimage being removed, thus we're
8314
- // guaranteed to regenerate this claim on
8315
- // restart as long as the source monitor
8316
- // sticks around.
8317
- pending_background_events. push (
8318
- BackgroundEvent :: MonitorUpdateRegeneratedOnStartup {
8319
- counterparty_node_id : * node_id,
8320
- funding_txo : prev_hop_data. outpoint ,
8321
- update : monitor_update. clone ( )
8322
- } ) ;
8323
- } ,
8324
- }
8325
- }
8326
- }
8327
- }
8328
- if !is_chan_open {
8329
- let monitor_update = ChannelMonitorUpdate {
8330
- update_id : CLOSED_CHANNEL_UPDATE_ID ,
8331
- updates : vec ! [ ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } ] ,
8332
- } ;
8333
- pending_background_events. push ( BackgroundEvent ::
8334
- ClosingMonitorUpdateRegeneratedOnStartup (
8335
- ( prev_hop_data. outpoint , monitor_update) ) ) ;
8302
+ Some ( ( prev_hop_data, htlc, payment_preimage) )
8303
+ } else { None }
8304
+ } else { None }
8305
+ } ) ;
8306
+ for ( prev_hop_data, htlc, payment_preimage) in outbound_claimed_htlcs_iter {
8307
+ let mut is_chan_open = false ;
8308
+ if let Some ( ( node_id, chan_id) ) = short_to_chan_info. get ( & prev_hop_data. short_channel_id ) {
8309
+ if let Some ( mut peer) = per_peer_state. get_mut ( node_id) . map ( |node| node. lock ( ) . unwrap ( ) ) {
8310
+ if let Some ( chan) = peer. channel_by_id . get_mut ( chan_id) {
8311
+ is_chan_open = true ;
8312
+ match chan. get_update_fulfill_htlc_and_commit ( prev_hop_data. htlc_id , payment_preimage, & args. logger ) {
8313
+ UpdateFulfillCommitFetch :: DuplicateClaim { } => { } ,
8314
+ UpdateFulfillCommitFetch :: NewClaim { monitor_update, .. } => {
8315
+ // The ChannelMonitor that gave us this
8316
+ // preimage is for a now-closed channel -
8317
+ // no further updates to that channel can
8318
+ // happen which would result in the
8319
+ // preimage being removed, thus we're
8320
+ // guaranteed to regenerate this claim on
8321
+ // restart as long as the source monitor
8322
+ // sticks around.
8323
+ pending_background_events. push (
8324
+ BackgroundEvent :: MonitorUpdateRegeneratedOnStartup {
8325
+ counterparty_node_id : * node_id,
8326
+ funding_txo : prev_hop_data. outpoint ,
8327
+ update : monitor_update. clone ( )
8328
+ } ) ;
8329
+ } ,
8336
8330
}
8337
8331
}
8338
- } ,
8339
- _ => { } ,
8332
+ }
8333
+ }
8334
+ if !is_chan_open {
8335
+ let monitor_update = ChannelMonitorUpdate {
8336
+ update_id : CLOSED_CHANNEL_UPDATE_ID ,
8337
+ updates : vec ! [ ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } ] ,
8338
+ } ;
8339
+ pending_background_events. push (
8340
+ BackgroundEvent :: ClosingMonitorUpdateRegeneratedOnStartup (
8341
+ ( prev_hop_data. outpoint , monitor_update) ) ) ;
8340
8342
}
8341
8343
}
8342
8344
}
0 commit comments