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