@@ -669,18 +669,28 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L> = ChannelManage
669
669
/// you're using lightning-net-tokio.
670
670
//
671
671
// Lock order:
672
- // These `ChannelManager` locks should be aquired in the following lock order, if any of these
673
- // locks are held at the same time:
674
- // 1. `channel_state`
675
- // 2. `per_peer_state`
676
- // 3. `pending_inbound_payments`
677
- // 4. `pending_outbound_payments`
678
- // 5. `pending_events`
679
- // 6. `pending_background_events`
672
+ // The tree structure below illustrates the lock order requirements for the different locks of the
673
+ // `ChannelManager`. If two or more locks on the same branch is held at the same time, locks should
674
+ // be taken in the order of the lowest to highest level in the tree.
680
675
//
681
- // These locks should be aquired after the `channel_state` lock, in case the `channel_state` lock
682
- // is taken at the same time:
683
- // * `id_to_peer`
676
+ // Lock order tree:
677
+ // │
678
+ // │──`channel_state`
679
+ // │ │
680
+ // │ │──`id_to_peer`
681
+ // │ │
682
+ // │ │──`per_peer_state`
683
+ // │ │
684
+ // │ │──`best_block`
685
+ // │ │
686
+ // │ │──`pending_inbound_payments`
687
+ // │ │
688
+ // │ │──`pending_outbound_payments`
689
+ // │ │
690
+ // │ │──`pending_events`
691
+ // │ │
692
+ // │ │──`pending_background_events`
693
+ // │
684
694
pub struct ChannelManager < Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref >
685
695
where M :: Target : chain:: Watch < Signer > ,
686
696
T :: Target : BroadcasterInterface ,
@@ -694,12 +704,14 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
694
704
chain_monitor : M ,
695
705
tx_broadcaster : T ,
696
706
707
+ /// See `ChannelManager` struct-level documentation for lock order requirements.
697
708
#[ cfg( test) ]
698
709
pub ( super ) best_block : RwLock < BestBlock > ,
699
710
#[ cfg( not( test) ) ]
700
711
best_block : RwLock < BestBlock > ,
701
712
secp_ctx : Secp256k1 < secp256k1:: All > ,
702
713
714
+ /// See `ChannelManager` struct-level documentation for lock order requirements.
703
715
#[ cfg( any( test, feature = "_test_utils" ) ) ]
704
716
pub ( super ) channel_state : Mutex < ChannelHolder < Signer > > ,
705
717
#[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
@@ -709,6 +721,8 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
709
721
/// expose them to users via a PaymentReceived event. HTLCs which do not meet the requirements
710
722
/// here are failed when we process them as pending-forwardable-HTLCs, and entries are removed
711
723
/// after we generate a PaymentReceived upon receipt of all MPP parts or when they time out.
724
+ ///
725
+ /// See `ChannelManager` struct-level documentation for lock order requirements.
712
726
pending_inbound_payments : Mutex < HashMap < PaymentHash , PendingInboundPayment > > ,
713
727
714
728
/// The session_priv bytes and retry metadata of outbound payments which are pending resolution.
0 commit comments