Skip to content

Commit 6b12117

Browse files
Lock pending inbound and outbound payments to before channel_state
As the `channel_state` lock will be removed, we prepare for that by flipping the lock order for `pending_inbound_payments` and `pending_outbound_payments` locks to before the `channel_state` lock.
1 parent f0c6dfb commit 6b12117

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -663,21 +663,21 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L> = ChannelManage
663663
// |
664664
// |__`forward_htlcs`
665665
// |
666-
// |__`channel_state`
666+
// |__`pending_inbound_payments`
667667
// | |
668-
// | |__`id_to_peer`
668+
// | |__`claimable_htlcs`
669669
// | |
670-
// | |__`short_to_chan_info`
671-
// | |
672-
// | |__`per_peer_state`
673-
// | |
674-
// | |__`outbound_scid_aliases`
670+
// | |__`pending_outbound_payments`
675671
// | |
676-
// | |__`pending_inbound_payments`
672+
// | |__`channel_state`
673+
// | |
674+
// | |__`id_to_peer`
677675
// | |
678-
// | |__`claimable_htlcs`
676+
// | |__`short_to_chan_info`
679677
// | |
680-
// | |__`pending_outbound_payments`
678+
// | |__`per_peer_state`
679+
// | |
680+
// | |__`outbound_scid_aliases`
681681
// | |
682682
// | |__`best_block`
683683
// | |
@@ -6777,18 +6777,19 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelMana
67776777
}
67786778
}
67796779

6780-
let mut htlc_purposes: Vec<events::PaymentPurpose> = Vec::new();
6781-
{
6782-
let claimable_htlcs = self.claimable_htlcs.lock().unwrap();
6783-
(claimable_htlcs.len() as u64).write(writer)?;
6784-
for (payment_hash, (purpose, previous_hops)) in claimable_htlcs.iter() {
6785-
payment_hash.write(writer)?;
6786-
(previous_hops.len() as u64).write(writer)?;
6787-
for htlc in previous_hops.iter() {
6788-
htlc.write(writer)?;
6789-
}
6790-
htlc_purposes.push(purpose.clone());
6780+
let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap();
6781+
let claimable_htlcs = self.claimable_htlcs.lock().unwrap();
6782+
let pending_outbound_payments = self.pending_outbound_payments.lock().unwrap();
6783+
6784+
let mut htlc_purposes: Vec<&events::PaymentPurpose> = Vec::new();
6785+
(claimable_htlcs.len() as u64).write(writer)?;
6786+
for (payment_hash, (purpose, previous_hops)) in claimable_htlcs.iter() {
6787+
payment_hash.write(writer)?;
6788+
(previous_hops.len() as u64).write(writer)?;
6789+
for htlc in previous_hops.iter() {
6790+
htlc.write(writer)?;
67916791
}
6792+
htlc_purposes.push(purpose);
67926793
}
67936794

67946795
let per_peer_state = self.per_peer_state.write().unwrap();
@@ -6799,8 +6800,6 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelMana
67996800
peer_state.latest_features.write(writer)?;
68006801
}
68016802

6802-
let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap();
6803-
let pending_outbound_payments = self.pending_outbound_payments.lock().unwrap();
68046803
let events = self.pending_events.lock().unwrap();
68056804
(events.len() as u64).write(writer)?;
68066805
for event in events.iter() {

0 commit comments

Comments
 (0)