Skip to content

Commit 6c94add

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 6c94add

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
// | |
@@ -2455,9 +2455,9 @@ 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 pending_outbounds = self.pending_outbound_payments.lock().unwrap();
24582459
let mut channel_lock = self.channel_state.lock().unwrap();
24592460

2460-
let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap();
24612461
let payment_entry = pending_outbounds.entry(payment_id);
24622462
if let hash_map::Entry::Occupied(payment) = &payment_entry {
24632463
if !payment.get().is_retryable() {
@@ -6641,18 +6641,19 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
66416641
}
66426642
}
66436643

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());
6644+
let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap();
6645+
let claimable_htlcs = self.claimable_htlcs.lock().unwrap();
6646+
let pending_outbound_payments = self.pending_outbound_payments.lock().unwrap();
6647+
6648+
let mut htlc_purposes: Vec<&events::PaymentPurpose> = Vec::new();
6649+
(claimable_htlcs.len() as u64).write(writer)?;
6650+
for (payment_hash, (purpose, previous_hops)) in claimable_htlcs.iter() {
6651+
payment_hash.write(writer)?;
6652+
(previous_hops.len() as u64).write(writer)?;
6653+
for htlc in previous_hops.iter() {
6654+
htlc.write(writer)?;
66556655
}
6656+
htlc_purposes.push(purpose);
66566657
}
66576658

66586659
let per_peer_state = self.per_peer_state.write().unwrap();
@@ -6663,8 +6664,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
66636664
peer_state.latest_features.write(writer)?;
66646665
}
66656666

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

0 commit comments

Comments
 (0)