Skip to content

Commit 8318961

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 700902d commit 8318961

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -674,19 +674,19 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L> = ChannelManage
674674
// |
675675
// |__`forward_htlcs`
676676
// |
677-
// |__`channel_state`
677+
// |__`pending_inbound_payments`
678678
// | |
679-
// | |__`id_to_peer`
679+
// | |__`claimable_htlcs`
680680
// | |
681-
// | |__`per_peer_state`
681+
// | |__`pending_outbound_payments`
682682
// | |
683-
// | |__`outbound_scid_aliases`
684-
// | |
685-
// | |__`pending_inbound_payments`
683+
// | |__`channel_state`
686684
// | |
687-
// | |__`claimable_htlcs`
685+
// | |__`id_to_peer`
688686
// | |
689-
// | |__`pending_outbound_payments`
687+
// | |__`per_peer_state`
688+
// | |
689+
// | |__`outbound_scid_aliases`
690690
// | |
691691
// | |__`best_block`
692692
// | |
@@ -2474,9 +2474,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
24742474
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
24752475

24762476
let err: Result<(), _> = loop {
2477+
let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap();
24772478
let mut channel_lock = self.channel_state.lock().unwrap();
24782479

2479-
let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap();
24802480
let payment_entry = pending_outbounds.entry(payment_id);
24812481
if let hash_map::Entry::Occupied(payment) = &payment_entry {
24822482
if !payment.get().is_retryable() {
@@ -6666,18 +6666,19 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelMana
66666666
}
66676667
}
66686668

6669-
let mut htlc_purposes: Vec<events::PaymentPurpose> = Vec::new();
6670-
{
6671-
let claimable_htlcs = self.claimable_htlcs.lock().unwrap();
6672-
(claimable_htlcs.len() as u64).write(writer)?;
6673-
for (payment_hash, (purpose, previous_hops)) in claimable_htlcs.iter() {
6674-
payment_hash.write(writer)?;
6675-
(previous_hops.len() as u64).write(writer)?;
6676-
for htlc in previous_hops.iter() {
6677-
htlc.write(writer)?;
6678-
}
6679-
htlc_purposes.push(purpose.clone());
6669+
let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap();
6670+
let claimable_htlcs = self.claimable_htlcs.lock().unwrap();
6671+
let pending_outbound_payments = self.pending_outbound_payments.lock().unwrap();
6672+
6673+
let mut htlc_purposes: Vec<&events::PaymentPurpose> = Vec::new();
6674+
(claimable_htlcs.len() as u64).write(writer)?;
6675+
for (payment_hash, (purpose, previous_hops)) in claimable_htlcs.iter() {
6676+
payment_hash.write(writer)?;
6677+
(previous_hops.len() as u64).write(writer)?;
6678+
for htlc in previous_hops.iter() {
6679+
htlc.write(writer)?;
66806680
}
6681+
htlc_purposes.push(purpose);
66816682
}
66826683

66836684
let per_peer_state = self.per_peer_state.write().unwrap();
@@ -6688,8 +6689,6 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelMana
66886689
peer_state.latest_features.write(writer)?;
66896690
}
66906691

6691-
let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap();
6692-
let pending_outbound_payments = self.pending_outbound_payments.lock().unwrap();
66936692
let events = self.pending_events.lock().unwrap();
66946693
(events.len() as u64).write(writer)?;
66956694
for event in events.iter() {

0 commit comments

Comments
 (0)