Skip to content

Commit 2b0d07f

Browse files
f - Move short_to_chan_info into standalone lock 2
1 parent eb6b63d commit 2b0d07f

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
@@ -4111,10 +4111,20 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
41114111
let mut expected_amt_msat = None;
41124112
let mut valid_mpp = true;
41134113
for htlc in sources.iter() {
4114-
if let None = self.short_to_chan_info.read().unwrap().get(&htlc.prev_hop.short_channel_id) {
4114+
let chan_id = match self.short_to_chan_info.read().unwrap().get(&htlc.prev_hop.short_channel_id) {
4115+
Some((_cp_id, chan_id)) => chan_id.clone(),
4116+
None => {
4117+
valid_mpp = false;
4118+
break;
4119+
}
4120+
};
4121+
4122+
let chan_opt = channel_state.as_ref().unwrap().by_id.get(&chan_id);
4123+
if chan_opt.map(|chan| !chan.is_usable()).unwrap_or(true) {
41154124
valid_mpp = false;
41164125
break;
41174126
}
4127+
41184128
if expected_amt_msat.is_some() && expected_amt_msat != Some(htlc.total_msat) {
41194129
log_error!(self.logger, "Somehow ended up with an MPP payment with different total amounts - this should not be reachable!");
41204130
debug_assert!(false);
@@ -5596,7 +5606,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
55965606
let scid_candidate = fake_scid::Namespace::Phantom.get_fake_scid(best_block.height(), &self.genesis_hash, &self.fake_scid_rand_bytes, &self.keys_manager);
55975607
// Ensure the generated scid doesn't conflict with a real channel.
55985608
match short_to_chan_info.get(&scid_candidate) {
5599-
Some((_cp_id, _chan_id)) => continue,
5609+
Some(_) => continue,
56005610
None => return scid_candidate
56015611
}
56025612
}
@@ -5830,7 +5840,7 @@ where
58305840

58315841
fn get_relevant_txids(&self) -> Vec<Txid> {
58325842
let channel_state = self.channel_state.lock().unwrap();
5833-
let mut res = Vec::with_capacity(self.short_to_chan_info.read().unwrap().len());
5843+
let mut res = Vec::with_capacity(channel_state.by_id.len());
58345844
for chan in channel_state.by_id.values() {
58355845
if let Some(funding_txo) = chan.get_funding_txo() {
58365846
res.push(funding_txo.txid);

0 commit comments

Comments
 (0)