Skip to content

Commit 5571499

Browse files
committed
f - resolve intro node with NodeIdLookUp
1 parent 44a78ba commit 5571499

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,
@@ -255,4 +255,17 @@ impl Direction {
255255
Direction::NodeTwo => core::cmp::max(node_a, node_b)
256256
}
257257
}
258+
259+
/// Returns the [`PublicKey`] from the inputs corresponding to the direction.
260+
pub fn select_pubkey<'a>(&self, node_a: &'a PublicKey, node_b: &'a PublicKey) -> &'a PublicKey {
261+
let (node_one, node_two) = if node_a < node_b {
262+
(node_a, node_b)
263+
} else {
264+
(node_b, node_a)
265+
};
266+
match self {
267+
Direction::NodeOne => node_one,
268+
Direction::NodeTwo => node_two,
269+
}
270+
}
258271
}

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)