@@ -3454,48 +3454,45 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3454
3454
/// Process pending events from the `chain::Watch`, returning whether any events were processed.
3455
3455
fn process_pending_monitor_events ( & self ) -> bool {
3456
3456
let mut failed_channels = Vec :: new ( ) ;
3457
- let has_pending_monitor_events = {
3458
- let pending_monitor_events = self . chain_monitor . release_pending_monitor_events ( ) ;
3459
- let has_pending_monitor_events = !pending_monitor_events. is_empty ( ) ;
3460
- for monitor_event in pending_monitor_events {
3461
- match monitor_event {
3462
- MonitorEvent :: HTLCEvent ( htlc_update) => {
3463
- if let Some ( preimage) = htlc_update. payment_preimage {
3464
- log_trace ! ( self . logger, "Claiming HTLC with preimage {} from our monitor" , log_bytes!( preimage. 0 ) ) ;
3465
- self . claim_funds_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_update. source , preimage) ;
3466
- } else {
3467
- log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
3468
- 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 ( ) } ) ;
3457
+ let pending_monitor_events = self . chain_monitor . release_pending_monitor_events ( ) ;
3458
+ let has_pending_monitor_events = !pending_monitor_events. is_empty ( ) ;
3459
+ for monitor_event in pending_monitor_events {
3460
+ match monitor_event {
3461
+ MonitorEvent :: HTLCEvent ( htlc_update) => {
3462
+ if let Some ( preimage) = htlc_update. payment_preimage {
3463
+ log_trace ! ( self . logger, "Claiming HTLC with preimage {} from our monitor" , log_bytes!( preimage. 0 ) ) ;
3464
+ self . claim_funds_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_update. source , preimage) ;
3465
+ } else {
3466
+ log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
3467
+ 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 ( ) } ) ;
3468
+ }
3469
+ } ,
3470
+ MonitorEvent :: CommitmentTxBroadcasted ( funding_outpoint) => {
3471
+ let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3472
+ let channel_state = & mut * channel_lock;
3473
+ let by_id = & mut channel_state. by_id ;
3474
+ let short_to_id = & mut channel_state. short_to_id ;
3475
+ let pending_msg_events = & mut channel_state. pending_msg_events ;
3476
+ if let Some ( mut chan) = by_id. remove ( & funding_outpoint. to_channel_id ( ) ) {
3477
+ if let Some ( short_id) = chan. get_short_channel_id ( ) {
3478
+ short_to_id. remove ( & short_id) ;
3469
3479
}
3470
- } ,
3471
- MonitorEvent :: CommitmentTxBroadcasted ( funding_outpoint) => {
3472
- let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3473
- let channel_state = & mut * channel_lock;
3474
- let by_id = & mut channel_state. by_id ;
3475
- let short_to_id = & mut channel_state. short_to_id ;
3476
- let pending_msg_events = & mut channel_state. pending_msg_events ;
3477
- if let Some ( mut chan) = by_id. remove ( & funding_outpoint. to_channel_id ( ) ) {
3478
- if let Some ( short_id) = chan. get_short_channel_id ( ) {
3479
- short_to_id. remove ( & short_id) ;
3480
- }
3481
- failed_channels. push ( chan. force_shutdown ( false ) ) ;
3482
- if let Ok ( update) = self . get_channel_update ( & chan) {
3483
- pending_msg_events. push ( events:: MessageSendEvent :: BroadcastChannelUpdate {
3484
- msg : update
3485
- } ) ;
3486
- }
3487
- pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
3488
- node_id : chan. get_counterparty_node_id ( ) ,
3489
- action : msgs:: ErrorAction :: SendErrorMessage {
3490
- msg : msgs:: ErrorMessage { channel_id : chan. channel_id ( ) , data : "Channel force-closed" . to_owned ( ) }
3491
- } ,
3480
+ failed_channels. push ( chan. force_shutdown ( false ) ) ;
3481
+ if let Ok ( update) = self . get_channel_update ( & chan) {
3482
+ pending_msg_events. push ( events:: MessageSendEvent :: BroadcastChannelUpdate {
3483
+ msg : update
3492
3484
} ) ;
3493
3485
}
3494
- } ,
3495
- }
3486
+ pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
3487
+ node_id : chan. get_counterparty_node_id ( ) ,
3488
+ action : msgs:: ErrorAction :: SendErrorMessage {
3489
+ msg : msgs:: ErrorMessage { channel_id : chan. channel_id ( ) , data : "Channel force-closed" . to_owned ( ) }
3490
+ } ,
3491
+ } ) ;
3492
+ }
3493
+ } ,
3496
3494
}
3497
- has_pending_monitor_events
3498
- } ;
3495
+ }
3499
3496
3500
3497
for failure in failed_channels. drain ( ..) {
3501
3498
self . finish_force_close_channel ( failure) ;
0 commit comments