Skip to content

Commit 9cd6f48

Browse files
committed
f - resolve intro node with NodeIdLookUp
1 parent fcbb9a3 commit 9cd6f48

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub enum IntroductionNode {
5858
///
5959
/// [BOLT 7]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_announcement-message
6060
/// [`ChannelAnnouncement`]: crate::ln::msgs::ChannelAnnouncement
61-
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
61+
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
6262
pub enum Direction {
6363
/// The lesser node id when compared lexicographically in ascending order.
6464
NodeOne,
@@ -256,4 +256,17 @@ impl Direction {
256256
Direction::NodeTwo => core::cmp::max(node_a, node_b)
257257
}
258258
}
259+
260+
/// Returns the [`PublicKey`] from the inputs corresponding to the direction.
261+
pub fn select_pubkey<'a>(&self, node_a: &'a PublicKey, node_b: &'a PublicKey) -> &'a PublicKey {
262+
let (node_one, node_two) = if node_a < node_b {
263+
(node_a, node_b)
264+
} else {
265+
(node_b, node_a)
266+
};
267+
match self {
268+
Direction::NodeOne => node_one,
269+
Direction::NodeTwo => node_two,
270+
}
271+
}
259272
}

lightning/src/onion_message/messenger.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,14 +605,17 @@ where
605605
// advance the blinded path by 1 hop so the second hop is the new introduction node.
606606
if intermediate_nodes.len() == 0 {
607607
if let Destination::BlindedPath(ref mut blinded_path) = destination {
608+
let our_node_id = node_signer.get_node_id(Recipient::Node)
609+
.map_err(|()| SendError::GetNodeIdFailed)?;
608610
let introduction_node_id = match blinded_path.introduction_node {
609611
IntroductionNode::NodeId(pubkey) => pubkey,
610-
IntroductionNode::DirectedShortChannelId(..) => {
611-
return Err(SendError::UnresolvedIntroductionNode);
612+
IntroductionNode::DirectedShortChannelId(direction, scid) => {
613+
match node_id_lookup.next_node_id(scid) {
614+
Some(next_node_id) => *direction.select_pubkey(&our_node_id, &next_node_id),
615+
None => return Err(SendError::UnresolvedIntroductionNode),
616+
}
612617
},
613618
};
614-
let our_node_id = node_signer.get_node_id(Recipient::Node)
615-
.map_err(|()| SendError::GetNodeIdFailed)?;
616619
if introduction_node_id == our_node_id {
617620
advance_path_by_one(blinded_path, node_signer, node_id_lookup, &secp_ctx)
618621
.map_err(|()| SendError::BlindedPathAdvanceFailed)?;

0 commit comments

Comments
 (0)