Skip to content

Commit 30a77b7

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 35dca53 commit 30a77b7

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 22 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
// | |
@@ -2455,7 +2455,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
24552455
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
24562456

24572457
let err: Result<(), _> = loop {
2458-
let mut channel_lock = self.channel_state.lock().unwrap();
24592458

24602459
let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap();
24612460
let payment_entry = pending_outbounds.entry(payment_id);
@@ -2467,6 +2466,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
24672466
}
24682467
}
24692468

2469+
let mut channel_lock = self.channel_state.lock().unwrap();
2470+
24702471
let id = match channel_lock.short_to_chan_info.get(&path.first().unwrap().short_channel_id) {
24712472
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!".to_owned()}),
24722473
Some((_cp_id, chan_id)) => chan_id.clone(),
@@ -6641,18 +6642,19 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
66416642
}
66426643
}
66436644

6644-
let mut htlc_purposes: Vec<events::PaymentPurpose> = Vec::new();
6645-
{
6646-
let claimable_htlcs = self.claimable_htlcs.lock().unwrap();
6647-
(claimable_htlcs.len() as u64).write(writer)?;
6648-
for (payment_hash, (purpose, previous_hops)) in claimable_htlcs.iter() {
6649-
payment_hash.write(writer)?;
6650-
(previous_hops.len() as u64).write(writer)?;
6651-
for htlc in previous_hops.iter() {
6652-
htlc.write(writer)?;
6653-
}
6654-
htlc_purposes.push(purpose.clone());
6645+
let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap();
6646+
let claimable_htlcs = self.claimable_htlcs.lock().unwrap();
6647+
let pending_outbound_payments = self.pending_outbound_payments.lock().unwrap();
6648+
6649+
let mut htlc_purposes: Vec<&events::PaymentPurpose> = Vec::new();
6650+
(claimable_htlcs.len() as u64).write(writer)?;
6651+
for (payment_hash, (purpose, previous_hops)) in claimable_htlcs.iter() {
6652+
payment_hash.write(writer)?;
6653+
(previous_hops.len() as u64).write(writer)?;
6654+
for htlc in previous_hops.iter() {
6655+
htlc.write(writer)?;
66556656
}
6657+
htlc_purposes.push(purpose);
66566658
}
66576659

66586660
let per_peer_state = self.per_peer_state.write().unwrap();
@@ -6663,8 +6665,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
66636665
peer_state.latest_features.write(writer)?;
66646666
}
66656667

6666-
let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap();
6667-
let pending_outbound_payments = self.pending_outbound_payments.lock().unwrap();
66686668
let events = self.pending_events.lock().unwrap();
66696669
(events.len() as u64).write(writer)?;
66706670
for event in events.iter() {

0 commit comments

Comments
 (0)