From: Matt Corallo Date: Sat, 21 Sep 2024 04:23:09 +0000 (+0000) Subject: Avoid a `short_to_chan_info` read lock in `claim_funds_from_hop` X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=b423a33bc7e90234b5b9b45a960c59d1d0d2fdc7;p=rust-lightning Avoid a `short_to_chan_info` read lock in `claim_funds_from_hop` In 453ed11f80b40f28b6e95a74b1f7ed2cd7f012ad we started tracking the counterparty's `node_id` in `HTLCPreviousHopData`, however we were still trying to look it up using `prev_short_channel_id` in `claim_funds_from_hop`. Because we now usually have the counterparty's `node_id` directly accessible, we should skip the `prev_short_channel_id` lookup. This will also be more important in the next commit where we need to look up state for our counterparty to generate `ChannelMonitorUpdate`s whether we have a live channel or not. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 5315e6a4e..aab2ec031 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -6928,11 +6928,10 @@ where &self, prev_hop: HTLCPreviousHopData, payment_preimage: PaymentPreimage, payment_info: Option, completion_action: ComplFunc, ) { - let counterparty_node_id = - match self.short_to_chan_info.read().unwrap().get(&prev_hop.short_channel_id) { - Some((cp_id, _dup_chan_id)) => Some(cp_id.clone()), - None => None - }; + let counterparty_node_id = prev_hop.counterparty_node_id.or_else(|| { + let short_to_chan_info = self.short_to_chan_info.read().unwrap(); + short_to_chan_info.get(&prev_hop.short_channel_id).map(|(cp_id, _)| *cp_id) + }); let htlc_source = HTLCClaimSource { counterparty_node_id,