Skip to content

Commit 10b6d87

Browse files
committed
f - resolve intro node with NodeIdLookUp
1 parent 123aa8b commit 10b6d87

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,
@@ -260,4 +260,17 @@ impl Direction {
260260
Direction::NodeTwo => node_two,
261261
}
262262
}
263+
264+
/// Returns the [`PublicKey`] from the inputs corresponding to the direction.
265+
pub fn select_pubkey<'a>(&self, node_a: &'a PublicKey, node_b: &'a PublicKey) -> &'a PublicKey {
266+
let (node_one, node_two) = if node_a < node_b {
267+
(node_a, node_b)
268+
} else {
269+
(node_b, node_a)
270+
};
271+
match self {
272+
Direction::NodeOne => node_one,
273+
Direction::NodeTwo => node_two,
274+
}
275+
}
263276
}

lightning/src/onion_message/messenger.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,14 +610,17 @@ where
610610
// advance the blinded path by 1 hop so the second hop is the new introduction node.
611611
if intermediate_nodes.len() == 0 {
612612
if let Destination::BlindedPath(ref mut blinded_path) = destination {
613+
let our_node_id = node_signer.get_node_id(Recipient::Node)
614+
.map_err(|()| SendError::GetNodeIdFailed)?;
613615
let introduction_node_id = match blinded_path.introduction_node {
614616
IntroductionNode::NodeId(pubkey) => pubkey,
615-
IntroductionNode::DirectedShortChannelId(..) => {
616-
return Err(SendError::UnresolvedIntroductionNode);
617+
IntroductionNode::DirectedShortChannelId(direction, scid) => {
618+
match node_id_lookup.next_node_id(scid) {
619+
Some(next_node_id) => *direction.select_pubkey(&our_node_id, &next_node_id),
620+
None => return Err(SendError::UnresolvedIntroductionNode),
621+
}
617622
},
618623
};
619-
let our_node_id = node_signer.get_node_id(Recipient::Node)
620-
.map_err(|()| SendError::GetNodeIdFailed)?;
621624
if introduction_node_id == our_node_id {
622625
advance_path_by_one(blinded_path, node_signer, node_id_lookup, &secp_ctx)
623626
.map_err(|()| SendError::BlindedPathAdvanceFailed)?;

0 commit comments

Comments
 (0)