Skip to content

Commit 0ceb5be

Browse files
f - Add debug_assertions of channel_state in fail_htlc_backwards_internal
1 parent 45e0a63 commit 0ceb5be

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,6 +3881,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
38813881
/// Note that while this function pushes events as well as FailHTLC's to fail htlcs for
38823882
/// designated channels, no assumptions are made that the channels are still available.
38833883
fn fail_htlc_backwards_internal(&self, source: HTLCSource, payment_hash: &PaymentHash, onion_error: HTLCFailReason,destination: HTLCDestination) {
3884+
#[cfg(debug_assertions)]
3885+
{
3886+
// Ensure that the `channel_state` lock is not held when calling this function.
3887+
// This ensures that future code doesn't introduce a lock_order requirement for
3888+
// `forward_htlcs` to be locked after the `channel_state` lock, which calling this
3889+
// function with the `channel_state` locked would.
3890+
assert!(self.channel_state.try_lock().is_ok());
3891+
}
3892+
38843893
//TODO: There is a timing attack here where if a node fails an HTLC back to us they can
38853894
//identify whether we sent it or not based on the (I presume) very different runtime
38863895
//between the branches here. We should make this async and move it into the forward HTLCs

0 commit comments

Comments
 (0)