@@ -3415,48 +3415,45 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3415
3415
/// Process pending events from the `chain::Watch`, returning whether any events were processed.
3416
3416
fn process_pending_monitor_events ( & self ) -> bool {
3417
3417
let mut failed_channels = Vec :: new ( ) ;
3418
- let has_pending_monitor_events = {
3419
- let pending_monitor_events = self . chain_monitor . release_pending_monitor_events ( ) ;
3420
- let has_pending_monitor_events = !pending_monitor_events. is_empty ( ) ;
3421
- for monitor_event in pending_monitor_events {
3422
- match monitor_event {
3423
- MonitorEvent :: HTLCEvent ( htlc_update) => {
3424
- if let Some ( preimage) = htlc_update. payment_preimage {
3425
- log_trace ! ( self . logger, "Claiming HTLC with preimage {} from our monitor" , log_bytes!( preimage. 0 ) ) ;
3426
- self . claim_funds_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_update. source , preimage) ;
3427
- } else {
3428
- log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
3429
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } ) ;
3418
+ let pending_monitor_events = self . chain_monitor . release_pending_monitor_events ( ) ;
3419
+ let has_pending_monitor_events = !pending_monitor_events. is_empty ( ) ;
3420
+ for monitor_event in pending_monitor_events {
3421
+ match monitor_event {
3422
+ MonitorEvent :: HTLCEvent ( htlc_update) => {
3423
+ if let Some ( preimage) = htlc_update. payment_preimage {
3424
+ log_trace ! ( self . logger, "Claiming HTLC with preimage {} from our monitor" , log_bytes!( preimage. 0 ) ) ;
3425
+ self . claim_funds_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_update. source , preimage) ;
3426
+ } else {
3427
+ log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
3428
+ self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } ) ;
3429
+ }
3430
+ } ,
3431
+ MonitorEvent :: CommitmentTxBroadcasted ( funding_outpoint) => {
3432
+ let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3433
+ let channel_state = & mut * channel_lock;
3434
+ let by_id = & mut channel_state. by_id ;
3435
+ let short_to_id = & mut channel_state. short_to_id ;
3436
+ let pending_msg_events = & mut channel_state. pending_msg_events ;
3437
+ if let Some ( mut chan) = by_id. remove ( & funding_outpoint. to_channel_id ( ) ) {
3438
+ if let Some ( short_id) = chan. get_short_channel_id ( ) {
3439
+ short_to_id. remove ( & short_id) ;
3430
3440
}
3431
- } ,
3432
- MonitorEvent :: CommitmentTxBroadcasted ( funding_outpoint) => {
3433
- let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3434
- let channel_state = & mut * channel_lock;
3435
- let by_id = & mut channel_state. by_id ;
3436
- let short_to_id = & mut channel_state. short_to_id ;
3437
- let pending_msg_events = & mut channel_state. pending_msg_events ;
3438
- if let Some ( mut chan) = by_id. remove ( & funding_outpoint. to_channel_id ( ) ) {
3439
- if let Some ( short_id) = chan. get_short_channel_id ( ) {
3440
- short_to_id. remove ( & short_id) ;
3441
- }
3442
- failed_channels. push ( chan. force_shutdown ( false ) ) ;
3443
- if let Ok ( update) = self . get_channel_update ( & chan) {
3444
- pending_msg_events. push ( events:: MessageSendEvent :: BroadcastChannelUpdate {
3445
- msg : update
3446
- } ) ;
3447
- }
3448
- pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
3449
- node_id : chan. get_counterparty_node_id ( ) ,
3450
- action : msgs:: ErrorAction :: SendErrorMessage {
3451
- msg : msgs:: ErrorMessage { channel_id : chan. channel_id ( ) , data : "Channel force-closed" . to_owned ( ) }
3452
- } ,
3441
+ failed_channels. push ( chan. force_shutdown ( false ) ) ;
3442
+ if let Ok ( update) = self . get_channel_update ( & chan) {
3443
+ pending_msg_events. push ( events:: MessageSendEvent :: BroadcastChannelUpdate {
3444
+ msg : update
3453
3445
} ) ;
3454
3446
}
3455
- } ,
3456
- }
3447
+ pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
3448
+ node_id : chan. get_counterparty_node_id ( ) ,
3449
+ action : msgs:: ErrorAction :: SendErrorMessage {
3450
+ msg : msgs:: ErrorMessage { channel_id : chan. channel_id ( ) , data : "Channel force-closed" . to_owned ( ) }
3451
+ } ,
3452
+ } ) ;
3453
+ }
3454
+ } ,
3457
3455
}
3458
- has_pending_monitor_events
3459
- } ;
3456
+ }
3460
3457
3461
3458
for failure in failed_channels. drain ( ..) {
3462
3459
self . finish_force_close_channel ( failure) ;
0 commit comments