@@ -3302,8 +3302,17 @@ where
3302
3302
self . update_best_block ( & block. header , height) ;
3303
3303
}
3304
3304
3305
- fn block_disconnected ( & self , header : & BlockHeader , _height : u32 ) {
3306
- ChannelManager :: block_disconnected ( self , header) ;
3305
+ fn block_disconnected ( & self , header : & BlockHeader , height : u32 ) {
3306
+ assert_eq ! ( * self . last_block_hash. read( ) . unwrap( ) , header. block_hash( ) ,
3307
+ "Blocks must be disconnected in chain-order - the disconnected header must be the last connected header" ) ;
3308
+
3309
+ let _persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
3310
+ let new_height = self . latest_block_height . fetch_sub ( 1 , Ordering :: AcqRel ) as u32 - 1 ;
3311
+ assert_eq ! ( new_height, height - 1 ,
3312
+ "Blocks must be disconnected in chain-order - the disconnected block must have the correct height" ) ;
3313
+ * self . last_block_hash . write ( ) . unwrap ( ) = header. prev_blockhash ;
3314
+
3315
+ self . do_chain_event ( new_height, |channel| channel. update_best_block ( new_height, header. time ) ) ;
3307
3316
}
3308
3317
}
3309
3318
@@ -3472,52 +3481,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3472
3481
}
3473
3482
}
3474
3483
3475
- /// Updates channel state based on a disconnected block.
3476
- ///
3477
- /// If necessary, the channel may be force-closed without letting the counterparty participate
3478
- /// in the shutdown.
3479
- pub fn block_disconnected ( & self , header : & BlockHeader ) {
3480
- // Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
3481
- // during initialization prior to the chain_monitor being fully configured in some cases.
3482
- // See the docs for `ChannelManagerReadArgs` for more.
3483
- let _persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
3484
-
3485
- assert_eq ! ( * self . last_block_hash. read( ) . unwrap( ) , header. block_hash( ) ,
3486
- "Blocks must be disconnected in chain-order - the disconnected header must be the last connected header" ) ;
3487
- let new_height = self . latest_block_height . fetch_sub ( 1 , Ordering :: AcqRel ) as u32 - 1 ;
3488
- * self . last_block_hash . write ( ) . unwrap ( ) = header. prev_blockhash ;
3489
-
3490
- let mut failed_channels = Vec :: new ( ) ;
3491
- {
3492
- let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3493
- let channel_state = & mut * channel_lock;
3494
- let short_to_id = & mut channel_state. short_to_id ;
3495
- let pending_msg_events = & mut channel_state. pending_msg_events ;
3496
- channel_state. by_id . retain ( |_, v| {
3497
- if let Err ( err_msg) = v. update_best_block ( new_height, header. time ) {
3498
- if let Some ( short_id) = v. get_short_channel_id ( ) {
3499
- short_to_id. remove ( & short_id) ;
3500
- }
3501
- failed_channels. push ( v. force_shutdown ( true ) ) ;
3502
- if let Ok ( update) = self . get_channel_update ( & v) {
3503
- pending_msg_events. push ( events:: MessageSendEvent :: BroadcastChannelUpdate {
3504
- msg : update
3505
- } ) ;
3506
- }
3507
- pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
3508
- node_id : v. get_counterparty_node_id ( ) ,
3509
- action : msgs:: ErrorAction :: SendErrorMessage { msg : err_msg } ,
3510
- } ) ;
3511
- false
3512
- } else {
3513
- true
3514
- }
3515
- } ) ;
3516
- }
3517
-
3518
- self . handle_init_event_channel_failures ( failed_channels) ;
3519
- }
3520
-
3521
3484
/// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
3522
3485
/// indicating whether persistence is necessary. Only one listener on
3523
3486
/// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
0 commit comments