From: Viktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com> Date: Wed, 12 Oct 2022 19:26:28 +0000 (+0200) Subject: Lock pending inbound and outbound payments to before `channel_state` X-Git-Tag: v0.0.113~32^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=6b12117782a06f759152741b9bf54802b50c7e58;p=rust-lightning 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. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index f1c894368..7a11bd816 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -663,21 +663,21 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L> = ChannelManage // | // |__`forward_htlcs` // | -// |__`channel_state` +// |__`pending_inbound_payments` // | | -// | |__`id_to_peer` +// | |__`claimable_htlcs` // | | -// | |__`short_to_chan_info` -// | | -// | |__`per_peer_state` -// | | -// | |__`outbound_scid_aliases` +// | |__`pending_outbound_payments` // | | -// | |__`pending_inbound_payments` +// | |__`channel_state` +// | | +// | |__`id_to_peer` // | | -// | |__`claimable_htlcs` +// | |__`short_to_chan_info` // | | -// | |__`pending_outbound_payments` +// | |__`per_peer_state` +// | | +// | |__`outbound_scid_aliases` // | | // | |__`best_block` // | | @@ -6777,18 +6777,19 @@ impl Writeable for ChannelMana } } - let mut htlc_purposes: Vec = Vec::new(); - { - let claimable_htlcs = self.claimable_htlcs.lock().unwrap(); - (claimable_htlcs.len() as u64).write(writer)?; - for (payment_hash, (purpose, previous_hops)) in claimable_htlcs.iter() { - payment_hash.write(writer)?; - (previous_hops.len() as u64).write(writer)?; - for htlc in previous_hops.iter() { - htlc.write(writer)?; - } - htlc_purposes.push(purpose.clone()); + let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap(); + let claimable_htlcs = self.claimable_htlcs.lock().unwrap(); + let pending_outbound_payments = self.pending_outbound_payments.lock().unwrap(); + + let mut htlc_purposes: Vec<&events::PaymentPurpose> = Vec::new(); + (claimable_htlcs.len() as u64).write(writer)?; + for (payment_hash, (purpose, previous_hops)) in claimable_htlcs.iter() { + payment_hash.write(writer)?; + (previous_hops.len() as u64).write(writer)?; + for htlc in previous_hops.iter() { + htlc.write(writer)?; } + htlc_purposes.push(purpose); } let per_peer_state = self.per_peer_state.write().unwrap(); @@ -6799,8 +6800,6 @@ impl Writeable for ChannelMana peer_state.latest_features.write(writer)?; } - let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap(); - let pending_outbound_payments = self.pending_outbound_payments.lock().unwrap(); let events = self.pending_events.lock().unwrap(); (events.len() as u64).write(writer)?; for event in events.iter() {