Skip to content

Commit ccd292e

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 885d4c9 commit ccd292e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lightning/src/ln/channelmanager.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -6839,10 +6839,12 @@ where
68396839
{
68406840
let per_peer_state = self.per_peer_state.read().unwrap();
68416841
let chan_id = prev_hop.channel_id;
6842-
let counterparty_node_id_opt = match self.short_to_chan_info.read().unwrap().get(&prev_hop.short_channel_id) {
6843-
Some((cp_id, _dup_chan_id)) => Some(cp_id.clone()),
6844-
None => None
6845-
};
6842+
let counterparty_node_id_opt = prev_hop.counterparty_node_id.or_else(|| {
6843+
match self.short_to_chan_info.read().unwrap().get(&prev_hop.short_channel_id) {
6844+
Some((cp_id, _dup_chan_id)) => Some(cp_id.clone()),
6845+
None => None
6846+
}
6847+
});
68466848

68476849
let peer_state_opt = counterparty_node_id_opt.as_ref().map(
68486850
|counterparty_node_id| per_peer_state.get(counterparty_node_id)

0 commit comments

Comments
 (0)