@@ -3141,6 +3141,29 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3141
3141
self . finish_force_close_channel ( failure) ;
3142
3142
}
3143
3143
}
3144
+
3145
+ /// Handle a list of channel failures during a block_connected or block_disconnected call,
3146
+ /// pushing the channel monitor update (if any) to the background events queue and removing the
3147
+ /// Channel object.
3148
+ fn handle_init_event_channel_failures ( & self , mut failed_channels : Vec < ShutdownResult > ) {
3149
+ for mut failure in failed_channels. drain ( ..) {
3150
+ // Either a commitment transactions has been confirmed on-chain or
3151
+ // Channel::block_disconnected detected that the funding transaction has been
3152
+ // reorganized out of the main chain.
3153
+ // We cannot broadcast our latest local state via monitor update (as
3154
+ // Channel::force_shutdown tries to make us do) as we may still be in initialization,
3155
+ // so we track the update internally and handle it when the user next calls
3156
+ // timer_chan_freshness_every_min, guaranteeing we're running normally.
3157
+ if let Some ( ( funding_txo, update) ) = failure. 0 . take ( ) {
3158
+ assert_eq ! ( update. updates. len( ) , 1 ) ;
3159
+ if let ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } = update. updates [ 0 ] {
3160
+ assert ! ( should_broadcast) ;
3161
+ } else { unreachable ! ( ) ; }
3162
+ self . pending_background_events . lock ( ) . unwrap ( ) . push ( BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) ) ;
3163
+ }
3164
+ self . finish_force_close_channel ( failure) ;
3165
+ }
3166
+ }
3144
3167
}
3145
3168
3146
3169
impl < Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > MessageSendEventsProvider for ChannelManager < Signer , M , T , K , F , L >
@@ -3296,20 +3319,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3296
3319
!htlcs. is_empty ( ) // Only retain this entry if htlcs has at least one entry.
3297
3320
} ) ;
3298
3321
}
3299
- for mut failure in failed_channels. drain ( ..) {
3300
- // It looks like our counterparty went on-chain. We cannot broadcast our latest local
3301
- // state via monitor update (as Channel::force_shutdown tries to make us do) as we may
3302
- // still be in initialization, so we track the update internally and handle it when the
3303
- // user next calls timer_chan_freshness_every_min, guaranteeing we're running normally.
3304
- if let Some ( ( funding_txo, update) ) = failure. 0 . take ( ) {
3305
- assert_eq ! ( update. updates. len( ) , 1 ) ;
3306
- if let ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } = update. updates [ 0 ] {
3307
- assert ! ( should_broadcast) ;
3308
- } else { unreachable ! ( ) ; }
3309
- self . pending_background_events . lock ( ) . unwrap ( ) . push ( BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) ) ;
3310
- }
3311
- self . finish_force_close_channel ( failure) ;
3312
- }
3322
+
3323
+ self . handle_init_event_channel_failures ( failed_channels) ;
3313
3324
3314
3325
for ( source, payment_hash, reason) in timed_out_htlcs. drain ( ..) {
3315
3326
self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , source, & payment_hash, reason) ;
@@ -3362,21 +3373,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3362
3373
}
3363
3374
} ) ;
3364
3375
}
3365
- for mut failure in failed_channels. drain ( ..) {
3366
- // Channel::block_disconnected tells us to close if the funding transaction was
3367
- // un-confirmed due to a reorg. We cannot broadcast our latest local state via monitor
3368
- // update (as Channel::force_shutdown tries to make us do) as we may still be in
3369
- // initialization, so we track the update internally and handle it when the user next
3370
- // calls timer_chan_freshness_every_min, guaranteeing we're running normally.
3371
- if let Some ( ( funding_txo, update) ) = failure. 0 . take ( ) {
3372
- assert_eq ! ( update. updates. len( ) , 1 ) ;
3373
- if let ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } = update. updates [ 0 ] {
3374
- assert ! ( should_broadcast) ;
3375
- } else { unreachable ! ( ) ; }
3376
- self . pending_background_events . lock ( ) . unwrap ( ) . push ( BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) ) ;
3377
- }
3378
- self . finish_force_close_channel ( failure) ;
3379
- }
3376
+ self . handle_init_event_channel_failures ( failed_channels) ;
3380
3377
self . latest_block_height . fetch_sub ( 1 , Ordering :: AcqRel ) ;
3381
3378
* self . last_block_hash . try_lock ( ) . expect ( "block_(dis)connected must not be called in parallel" ) = header. block_hash ( ) ;
3382
3379
}
0 commit comments