Skip to content

Commit b423a33

Browse files
committed
Avoid a short_to_chan_info read lock in claim_funds_from_hop
In 453ed11 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.
1 parent 9f9d448 commit b423a33

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6928,11 +6928,10 @@ where
69286928
&self, prev_hop: HTLCPreviousHopData, payment_preimage: PaymentPreimage,
69296929
payment_info: Option<PaymentClaimDetails>, completion_action: ComplFunc,
69306930
) {
6931-
let counterparty_node_id =
6932-
match self.short_to_chan_info.read().unwrap().get(&prev_hop.short_channel_id) {
6933-
Some((cp_id, _dup_chan_id)) => Some(cp_id.clone()),
6934-
None => None
6935-
};
6931+
let counterparty_node_id = prev_hop.counterparty_node_id.or_else(|| {
6932+
let short_to_chan_info = self.short_to_chan_info.read().unwrap();
6933+
short_to_chan_info.get(&prev_hop.short_channel_id).map(|(cp_id, _)| *cp_id)
6934+
});
69366935

69376936
let htlc_source = HTLCClaimSource {
69386937
counterparty_node_id,

0 commit comments

Comments
 (0)