Skip to content

Commit a73e36c

Browse files
committed
Use MessageForwardNode Instead of PublicKey for create_blinded_paths
This sets the foundation for the upcoming commit, where the Blinded Path creation process is simplified to have a single function flow for creating both types of Blinded Paths.
1 parent 25c81fa commit a73e36c

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9664,7 +9664,12 @@ where
96649664
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
96659665
.filter(|(_, peer)| peer.is_connected)
96669666
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9667-
.map(|(node_id, _)| *node_id)
9667+
.map(|(node_id, _)| {
9668+
MessageForwardNode {
9669+
node_id: *node_id,
9670+
short_channel_id: None,
9671+
}
9672+
})
96689673
.collect::<Vec<_>>();
96699674

96709675
self.message_router

lightning/src/onion_message/messenger.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, DRH, CMH> where
183183
/// # })
184184
/// # }
185185
/// # fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
186-
/// # &self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
186+
/// # &self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<MessageForwardNode>, _secp_ctx: &Secp256k1<T>
187187
/// # ) -> Result<Vec<BlindedMessagePath>, ()> {
188188
/// # unreachable!()
189189
/// # }
@@ -464,7 +464,7 @@ pub trait MessageRouter {
464464
fn create_blinded_paths<
465465
T: secp256k1::Signing + secp256k1::Verification
466466
>(
467-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
467+
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
468468
) -> Result<Vec<BlindedMessagePath>, ()>;
469469

470470
/// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
@@ -488,7 +488,10 @@ pub trait MessageRouter {
488488
) -> Result<Vec<BlindedMessagePath>, ()> {
489489
let peers = peers
490490
.into_iter()
491-
.map(|MessageForwardNode { node_id, short_channel_id: _ }| node_id)
491+
.map(|mut node| {
492+
node.short_channel_id = None;
493+
node
494+
})
492495
.collect();
493496
self.create_blinded_paths(recipient, context, peers, secp_ctx)
494497
}
@@ -628,11 +631,14 @@ where
628631
T: secp256k1::Signing + secp256k1::Verification
629632
>(
630633
network_graph: &G, recipient: PublicKey, context: MessageContext,
631-
peers: Vec<PublicKey>, entropy_source: &ES, secp_ctx: &Secp256k1<T>,
634+
peers: Vec<MessageForwardNode>, entropy_source: &ES, secp_ctx: &Secp256k1<T>,
632635
) -> Result<Vec<BlindedMessagePath>, ()> {
633636
let peers = peers
634637
.into_iter()
635-
.map(|node_id| MessageForwardNode { node_id, short_channel_id: None });
638+
.map(|mut node| {
639+
node.short_channel_id = None;
640+
node
641+
});
636642
Self::create_blinded_paths_from_iter(network_graph, recipient, context, peers.into_iter(), entropy_source, secp_ctx, false)
637643
}
638644

@@ -660,7 +666,7 @@ where
660666
fn create_blinded_paths<
661667
T: secp256k1::Signing + secp256k1::Verification
662668
>(
663-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
669+
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
664670
) -> Result<Vec<BlindedMessagePath>, ()> {
665671
Self::create_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
666672
}
@@ -1273,7 +1279,12 @@ where
12731279
let peers = self.message_recipients.lock().unwrap()
12741280
.iter()
12751281
.filter(|(_, peer)| matches!(peer, OnionMessageRecipient::ConnectedPeer(_)))
1276-
.map(|(node_id, _ )| *node_id)
1282+
.map(|(node_id, _ )| {
1283+
MessageForwardNode {
1284+
node_id: *node_id,
1285+
short_channel_id: None,
1286+
}
1287+
})
12771288
.collect::<Vec<_>>();
12781289

12791290
self.message_router

lightning/src/util/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<'a> MessageRouter for TestMessageRouter<'a> {
293293

294294
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
295295
&self, recipient: PublicKey, context: MessageContext,
296-
peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
296+
peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
297297
) -> Result<Vec<BlindedMessagePath>, ()> {
298298
self.inner.create_blinded_paths(recipient, context, peers, secp_ctx)
299299
}

0 commit comments

Comments
 (0)