@@ -667,6 +667,20 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L> = ChannelManage
667
667
/// essentially you should default to using a SimpleRefChannelManager, and use a
668
668
/// SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
669
669
/// you're using lightning-net-tokio.
670
+ //
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`
680
+ //
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`
670
684
pub struct ChannelManager < Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref >
671
685
where M :: Target : chain:: Watch < Signer > ,
672
686
T :: Target : BroadcasterInterface ,
@@ -695,12 +709,6 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
695
709
/// expose them to users via a PaymentReceived event. HTLCs which do not meet the requirements
696
710
/// here are failed when we process them as pending-forwardable-HTLCs, and entries are removed
697
711
/// after we generate a PaymentReceived upon receipt of all MPP parts or when they time out.
698
- ///
699
- /// If any of these locks are held at the same time, they must be acquired prior and in the
700
- /// following order:
701
- /// * `channel_state`
702
- /// * `forward_htlcs`
703
- /// * `per_peer_state`
704
712
pending_inbound_payments : Mutex < HashMap < PaymentHash , PendingInboundPayment > > ,
705
713
706
714
/// The session_priv bytes and retry metadata of outbound payments which are pending resolution.
@@ -713,13 +721,6 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
713
721
/// after reloading from disk while replaying blocks against ChannelMonitors.
714
722
///
715
723
/// See `PendingOutboundPayment` documentation for more info.
716
- ///
717
- /// If any of these locks are held at the same time as, they must be acquired prior and in the
718
- /// following order:
719
- /// * `channel_state`
720
- /// * `forward_htlcs`
721
- /// * `per_peer_state`
722
- /// * `pending_inbound_payments`
723
724
pending_outbound_payments : Mutex < HashMap < PaymentId , PendingOutboundPayment > > ,
724
725
725
726
/// SCID/SCID Alias -> forward infos. Key of 0 means payments received.
@@ -730,8 +731,6 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
730
731
///
731
732
/// Note that no consistency guarantees are made about the existence of a channel with the
732
733
/// `short_channel_id` here, nor the `short_channel_id` in the `PendingHTLCInfo`!
733
- ///
734
- /// Locked *after* `channel_state`.
735
734
#[ cfg( test) ]
736
735
pub ( super ) forward_htlcs : Mutex < HashMap < u64 , Vec < HTLCForwardInfo > > > ,
737
736
#[ cfg( not( test) ) ]
@@ -760,8 +759,6 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
760
759
/// We should add `counterparty_node_id`s to `MonitorEvent`s, and eventually rely on it in the
761
760
/// future. That would make this map redundant, as only the `ChannelManager::per_peer_state` is
762
761
/// required to access the channel with the `counterparty_node_id`.
763
- ///
764
- /// Locked *after* `channel_state`.
765
762
id_to_peer : Mutex < HashMap < [ u8 ; 32 ] , PublicKey > > ,
766
763
767
764
our_network_key : SecretKey ,
@@ -792,29 +789,10 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
792
789
/// Because adding or removing an entry is rare, we usually take an outer read lock and then
793
790
/// operate on the inner value freely. Sadly, this prevents parallel operation when opening a
794
791
/// new channel.
795
- ///
796
- /// If any of these locks are held at the same time, they must be acquired prior and in the
797
- /// following order:
798
- /// * `channel_state`
799
- /// * `forward_htlcs`
800
792
per_peer_state : RwLock < HashMap < PublicKey , Mutex < PeerState > > > ,
801
793
802
- /// If any of these locks are held at the same time, they must be acquired prior and in the
803
- /// following order:
804
- /// * `channel_state`
805
- /// * `forward_htlcs`
806
- /// * `per_peer_state`
807
- /// * `pending_inbound_payments`
808
- /// * `pending_outbound_payments`
809
794
pending_events : Mutex < Vec < events:: Event > > ,
810
- /// If any of these locks are held at the same time, they must be acquired prior and in the
811
- /// following order:
812
- /// * `channel_state`
813
- /// * `forward_htlcs`
814
- /// * `per_peer_state`
815
- /// * `pending_inbound_payments`
816
- /// * `pending_outbound_payments`
817
- /// * `pending_events`
795
+
818
796
pending_background_events : Mutex < Vec < BackgroundEvent > > ,
819
797
/// Used when we have to take a BIG lock to make sure everything is self-consistent.
820
798
/// Essentially just when we're serializing ourselves out.
0 commit comments