@@ -674,6 +674,8 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L> = ChannelManage
674
674
// |
675
675
// |__`forward_htlcs`
676
676
// |
677
+ // |__`pending_background_events`
678
+ // |
677
679
// |__`pending_inbound_payments`
678
680
// | |
679
681
// | |__`claimable_htlcs`
@@ -685,8 +687,6 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L> = ChannelManage
685
687
// | |__`id_to_peer`
686
688
// | |
687
689
// | |__`pending_events`
688
- // | | |
689
- // | | |__`pending_background_events`
690
690
// | |
691
691
// | |__`per_peer_state`
692
692
// | |
@@ -5360,6 +5360,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
5360
5360
/// pushing the channel monitor update (if any) to the background events queue and removing the
5361
5361
/// Channel object.
5362
5362
fn handle_init_event_channel_failures ( & self , mut failed_channels : Vec < ShutdownResult > ) {
5363
+ #[ cfg( debug_assertions) ]
5364
+ {
5365
+ // Ensure that the different lock branches are not held when calling this function.
5366
+ // This ensures that future code doesn't introduce a lock_order requirement for
5367
+ // `pending_background_events`.
5368
+ assert ! ( self . channel_state. try_lock( ) . is_ok( ) ) ;
5369
+ assert ! ( self . per_peer_state. read( ) . is_ok( ) ) ;
5370
+ assert ! ( self . pending_inbound_payments. try_lock( ) . is_ok( ) ) ;
5371
+ assert ! ( self . pending_events. try_lock( ) . is_ok( ) ) ;
5372
+ }
5363
5373
for mut failure in failed_channels. drain ( ..) {
5364
5374
// Either a commitment transactions has been confirmed on-chain or
5365
5375
// Channel::block_disconnected detected that the funding transaction has been
@@ -6668,24 +6678,25 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
6668
6678
}
6669
6679
}
6670
6680
6671
-
6672
- let pending_inbound_payments = self . pending_inbound_payments . lock ( ) . unwrap ( ) ;
6673
- let pending_outbound_payments = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
6674
- let events = self . pending_events . lock ( ) . unwrap ( ) ;
6675
- ( events. len ( ) as u64 ) . write ( writer) ?;
6676
- for event in events. iter ( ) {
6677
- event. write ( writer) ?;
6681
+ {
6682
+ let events = self . pending_events . lock ( ) . unwrap ( ) ;
6683
+ ( events. len ( ) as u64 ) . write ( writer) ?;
6684
+ for event in events. iter ( ) {
6685
+ event. write ( writer) ?;
6686
+ }
6678
6687
}
6679
6688
6680
- let background_events = self . pending_background_events . lock ( ) . unwrap ( ) ;
6681
- ( background_events. len ( ) as u64 ) . write ( writer) ?;
6682
- for event in background_events. iter ( ) {
6683
- match event {
6684
- BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, monitor_update) ) => {
6685
- 0u8 . write ( writer) ?;
6686
- funding_txo. write ( writer) ?;
6687
- monitor_update. write ( writer) ?;
6688
- } ,
6689
+ {
6690
+ let background_events = self . pending_background_events . lock ( ) . unwrap ( ) ;
6691
+ ( background_events. len ( ) as u64 ) . write ( writer) ?;
6692
+ for event in background_events. iter ( ) {
6693
+ match event {
6694
+ BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, monitor_update) ) => {
6695
+ 0u8 . write ( writer) ?;
6696
+ funding_txo. write ( writer) ?;
6697
+ monitor_update. write ( writer) ?;
6698
+ } ,
6699
+ }
6689
6700
}
6690
6701
}
6691
6702
@@ -6695,12 +6706,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
6695
6706
( self . highest_seen_timestamp . load ( Ordering :: Acquire ) as u32 ) . write ( writer) ?;
6696
6707
( self . highest_seen_timestamp . load ( Ordering :: Acquire ) as u32 ) . write ( writer) ?;
6697
6708
6709
+ let pending_inbound_payments = self . pending_inbound_payments . lock ( ) . unwrap ( ) ;
6698
6710
( pending_inbound_payments. len ( ) as u64 ) . write ( writer) ?;
6699
6711
for ( hash, pending_payment) in pending_inbound_payments. iter ( ) {
6700
6712
hash. write ( writer) ?;
6701
6713
pending_payment. write ( writer) ?;
6702
6714
}
6703
6715
6716
+ let pending_outbound_payments = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
6704
6717
// For backwards compat, write the session privs and their total length.
6705
6718
let mut num_pending_outbounds_compat: u64 = 0 ;
6706
6719
for ( _, outbound) in pending_outbound_payments. iter ( ) {
0 commit comments