Skip to content

Commit 4e2269d

Browse files
Add lock order docs to ChannelManager fields
1 parent d6e2b98 commit 4e2269d

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,12 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
697697
/// expose them to users via a PaymentReceived event. HTLCs which do not meet the requirements
698698
/// here are failed when we process them as pending-forwardable-HTLCs, and entries are removed
699699
/// after we generate a PaymentReceived upon receipt of all MPP parts or when they time out.
700-
/// Locked *after* channel_state.
700+
///
701+
/// If any of these locks are held at the same time as `pending_inbound_payments`, the lock
702+
/// order requires that these locks are taken prior to `pending_inbound_payments`:
703+
/// * `channel_state`
704+
/// * `forward_htlcs`
705+
/// * `per_peer_state`
701706
pending_inbound_payments: Mutex<HashMap<PaymentHash, PendingInboundPayment>>,
702707

703708
/// The session_priv bytes and retry metadata of outbound payments which are pending resolution.
@@ -711,7 +716,12 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
711716
///
712717
/// See `PendingOutboundPayment` documentation for more info.
713718
///
714-
/// Locked *after* channel_state.
719+
/// If any of these locks are held at the same time as `pending_outbound_payments`, the lock
720+
/// order requires that these locks are taken prior to `pending_outbound_payments`:
721+
/// * `channel_state`
722+
/// * `forward_htlcs`
723+
/// * `per_peer_state`
724+
/// * `pending_inbound_payments`
715725
pending_outbound_payments: Mutex<HashMap<PaymentId, PendingOutboundPayment>>,
716726

717727
/// SCID/SCID Alias -> forward infos. Key of 0 means payments received.
@@ -722,6 +732,8 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
722732
///
723733
/// Note that no consistency guarantees are made about the existence of a channel with the
724734
/// `short_channel_id` here, nor the `short_channel_id` in the `PendingHTLCInfo`!
735+
///
736+
/// If also holding `channel_state` lock, must lock `channel_state` prior to `forward_htlcs`.
725737
#[cfg(any(test, feature = "_test_utils"))]
726738
pub(super) forward_htlcs: Mutex<HashMap<u64, Vec<HTLCForwardInfo>>>,
727739
#[cfg(not(any(test, feature = "_test_utils")))]
@@ -785,10 +797,28 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
785797
/// operate on the inner value freely. Sadly, this prevents parallel operation when opening a
786798
/// new channel.
787799
///
788-
/// If also holding `channel_state` lock, must lock `channel_state` prior to `per_peer_state`.
800+
/// If any of these locks are held at the same time as `per_peer_state`, the lock order
801+
/// requires that these locks are taken prior to `per_peer_state`:
802+
/// * `channel_state`
803+
/// * `forward_htlcs`
789804
per_peer_state: RwLock<HashMap<PublicKey, Mutex<PeerState>>>,
790805

806+
/// If any of these locks are held at the same time as `pending_events`, the lock order
807+
/// requires that these locks are taken prior to `pending_events`:
808+
/// * `channel_state`
809+
/// * `forward_htlcs`
810+
/// * `per_peer_state`
811+
/// * `pending_inbound_payments`
812+
/// * `pending_outbound_payments`
791813
pending_events: Mutex<Vec<events::Event>>,
814+
/// If any of these locks are held at the same time as `pending_background_events`, the lock
815+
/// order requires that these locks are taken prior to `pending_background_events`:
816+
/// * `channel_state`
817+
/// * `forward_htlcs`
818+
/// * `per_peer_state`
819+
/// * `pending_inbound_payments`
820+
/// * `pending_outbound_payments`
821+
/// * `pending_events`
792822
pending_background_events: Mutex<Vec<BackgroundEvent>>,
793823
/// Used when we have to take a BIG lock to make sure everything is self-consistent.
794824
/// Essentially just when we're serializing ourselves out.

0 commit comments

Comments
 (0)