]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Avoid a `short_to_chan_info` read lock in `claim_funds_from_hop`
authorMatt Corallo <git@bluematt.me>
Sat, 21 Sep 2024 04:23:09 +0000 (04:23 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 5 Nov 2024 20:13:48 +0000 (20:13 +0000)
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.

lightning/src/ln/channelmanager.rs

index 5315e6a4ef618918158963bb9c2d7b7f7380888c..aab2ec03164b759c3ef31aee4b3a035ac4a7043c 100644 (file)
@@ -6928,11 +6928,10 @@ where
                &self, prev_hop: HTLCPreviousHopData, payment_preimage: PaymentPreimage,
                payment_info: Option<PaymentClaimDetails>, 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,