Skip to content

Commit 1f01103

Browse files
f - Move short_to_chan_info into standalone lock 2
1 parent edbff4c commit 1f01103

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4129,10 +4129,20 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
41294129
let mut expected_amt_msat = None;
41304130
let mut valid_mpp = true;
41314131
for htlc in sources.iter() {
4132-
if let None = self.short_to_chan_info.read().unwrap().get(&htlc.prev_hop.short_channel_id) {
4132+
let chan_id = match self.short_to_chan_info.read().unwrap().get(&htlc.prev_hop.short_channel_id) {
4133+
Some((_cp_id, chan_id)) => chan_id.clone(),
4134+
None => {
4135+
valid_mpp = false;
4136+
break;
4137+
}
4138+
};
4139+
4140+
let chan_opt = channel_state.as_ref().unwrap().by_id.get(&chan_id);
4141+
if chan_opt.map(|chan| !chan.is_usable()).unwrap_or(true) {
41334142
valid_mpp = false;
41344143
break;
41354144
}
4145+
41364146
if expected_amt_msat.is_some() && expected_amt_msat != Some(htlc.total_msat) {
41374147
log_error!(self.logger, "Somehow ended up with an MPP payment with different total amounts - this should not be reachable!");
41384148
debug_assert!(false);
@@ -5614,7 +5624,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
56145624
let scid_candidate = fake_scid::Namespace::Phantom.get_fake_scid(best_block.height(), &self.genesis_hash, &self.fake_scid_rand_bytes, &self.keys_manager);
56155625
// Ensure the generated scid doesn't conflict with a real channel.
56165626
match short_to_chan_info.get(&scid_candidate) {
5617-
Some((_cp_id, _chan_id)) => continue,
5627+
Some(_) => continue,
56185628
None => return scid_candidate
56195629
}
56205630
}
@@ -5848,7 +5858,7 @@ where
58485858

58495859
fn get_relevant_txids(&self) -> Vec<Txid> {
58505860
let channel_state = self.channel_state.lock().unwrap();
5851-
let mut res = Vec::with_capacity(self.short_to_chan_info.read().unwrap().len());
5861+
let mut res = Vec::with_capacity(channel_state.by_id.len());
58525862
for chan in channel_state.by_id.values() {
58535863
if let Some(funding_txo) = chan.get_funding_txo() {
58545864
res.push(funding_txo.txid);

0 commit comments

Comments
 (0)