Skip to content

Commit ca34313

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 c1d2cd0 commit ca34313

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
/// # }
@@ -484,7 +484,7 @@ pub trait MessageRouter {
484484
fn create_blinded_paths<
485485
T: secp256k1::Signing + secp256k1::Verification
486486
>(
487-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
487+
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
488488
) -> Result<Vec<BlindedMessagePath>, ()>;
489489

490490
/// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
@@ -508,7 +508,10 @@ pub trait MessageRouter {
508508
) -> Result<Vec<BlindedMessagePath>, ()> {
509509
let peers = peers
510510
.into_iter()
511-
.map(|MessageForwardNode { node_id, short_channel_id: _ }| node_id)
511+
.map(|mut node| {
512+
node.short_channel_id = None;
513+
node
514+
})
512515
.collect();
513516
self.create_blinded_paths(recipient, context, peers, secp_ctx)
514517
}
@@ -648,11 +651,14 @@ where
648651
T: secp256k1::Signing + secp256k1::Verification
649652
>(
650653
network_graph: &G, recipient: PublicKey, context: MessageContext,
651-
peers: Vec<PublicKey>, entropy_source: &ES, secp_ctx: &Secp256k1<T>,
654+
peers: Vec<MessageForwardNode>, entropy_source: &ES, secp_ctx: &Secp256k1<T>,
652655
) -> Result<Vec<BlindedMessagePath>, ()> {
653656
let peers = peers
654657
.into_iter()
655-
.map(|node_id| MessageForwardNode { node_id, short_channel_id: None });
658+
.map(|mut node| {
659+
node.short_channel_id = None;
660+
node
661+
});
656662
Self::create_blinded_paths_from_iter(network_graph, recipient, context, peers.into_iter(), entropy_source, secp_ctx, false)
657663
}
658664

@@ -680,7 +686,7 @@ where
680686
fn create_blinded_paths<
681687
T: secp256k1::Signing + secp256k1::Verification
682688
>(
683-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
689+
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
684690
) -> Result<Vec<BlindedMessagePath>, ()> {
685691
Self::create_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
686692
}
@@ -1293,7 +1299,12 @@ where
12931299
let peers = self.message_recipients.lock().unwrap()
12941300
.iter()
12951301
.filter(|(_, peer)| matches!(peer, OnionMessageRecipient::ConnectedPeer(_)))
1296-
.map(|(node_id, _ )| *node_id)
1302+
.map(|(node_id, _ )| {
1303+
MessageForwardNode {
1304+
node_id: *node_id,
1305+
short_channel_id: None,
1306+
}
1307+
})
12971308
.collect::<Vec<_>>();
12981309

12991310
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)