Skip to content

Commit 9a981c1

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 d28a14a commit 9a981c1

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9580,7 +9580,12 @@ where
95809580
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
95819581
.filter(|(_, peer)| peer.is_connected)
95829582
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9583-
.map(|(node_id, _)| *node_id)
9583+
.map(|(node_id, _)| {
9584+
MessageForwardNode {
9585+
node_id: *node_id,
9586+
short_channel_id: None,
9587+
}
9588+
})
95849589
.collect::<Vec<_>>();
95859590

95869591
self.router

lightning/src/onion_message/messenger.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
175175
/// # })
176176
/// # }
177177
/// # fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
178-
/// # &self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
178+
/// # &self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<MessageForwardNode>, _secp_ctx: &Secp256k1<T>
179179
/// # ) -> Result<Vec<BlindedMessagePath>, ()> {
180180
/// # unreachable!()
181181
/// # }
@@ -452,7 +452,7 @@ pub trait MessageRouter {
452452
fn create_blinded_paths<
453453
T: secp256k1::Signing + secp256k1::Verification
454454
>(
455-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
455+
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
456456
) -> Result<Vec<BlindedMessagePath>, ()>;
457457

458458
/// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
@@ -476,7 +476,10 @@ pub trait MessageRouter {
476476
) -> Result<Vec<BlindedMessagePath>, ()> {
477477
let peers = peers
478478
.into_iter()
479-
.map(|MessageForwardNode { node_id, short_channel_id: _ }| node_id)
479+
.map(|mut node| {
480+
node.short_channel_id = None;
481+
node
482+
})
480483
.collect();
481484
self.create_blinded_paths(recipient, context, peers, secp_ctx)
482485
}
@@ -616,11 +619,14 @@ where
616619
T: secp256k1::Signing + secp256k1::Verification
617620
>(
618621
network_graph: &G, recipient: PublicKey, context: MessageContext,
619-
peers: Vec<PublicKey>, entropy_source: &ES, secp_ctx: &Secp256k1<T>,
622+
peers: Vec<MessageForwardNode>, entropy_source: &ES, secp_ctx: &Secp256k1<T>,
620623
) -> Result<Vec<BlindedMessagePath>, ()> {
621624
let peers = peers
622625
.into_iter()
623-
.map(|node_id| MessageForwardNode { node_id, short_channel_id: None });
626+
.map(|mut node| {
627+
node.short_channel_id = None;
628+
node
629+
});
624630
Self::create_blinded_paths_from_iter(network_graph, recipient, context, peers.into_iter(), entropy_source, secp_ctx, false)
625631
}
626632

@@ -648,7 +654,7 @@ where
648654
fn create_blinded_paths<
649655
T: secp256k1::Signing + secp256k1::Verification
650656
>(
651-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
657+
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
652658
) -> Result<Vec<BlindedMessagePath>, ()> {
653659
Self::create_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
654660
}
@@ -1255,7 +1261,12 @@ where
12551261
let peers = self.message_recipients.lock().unwrap()
12561262
.iter()
12571263
.filter(|(_, peer)| matches!(peer, OnionMessageRecipient::ConnectedPeer(_)))
1258-
.map(|(node_id, _ )| *node_id)
1264+
.map(|(node_id, _ )| {
1265+
MessageForwardNode {
1266+
node_id: *node_id,
1267+
short_channel_id: None,
1268+
}
1269+
})
12591270
.collect::<Vec<_>>();
12601271

12611272
self.message_router

lightning/src/routing/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl< G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Siz
199199
fn create_blinded_paths<
200200
T: secp256k1::Signing + secp256k1::Verification
201201
> (
202-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
202+
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
203203
) -> Result<Vec<BlindedMessagePath>, ()> {
204204
DefaultMessageRouter::create_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
205205
}

lightning/src/util/test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<'a> MessageRouter for TestRouter<'a> {
276276
T: secp256k1::Signing + secp256k1::Verification
277277
>(
278278
&self, recipient: PublicKey, context: MessageContext,
279-
peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
279+
peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
280280
) -> Result<Vec<BlindedMessagePath>, ()> {
281281
self.router.create_blinded_paths(recipient, context, peers, secp_ctx)
282282
}
@@ -319,7 +319,7 @@ impl<'a> MessageRouter for TestMessageRouter<'a> {
319319

320320
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
321321
&self, recipient: PublicKey, context: MessageContext,
322-
peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
322+
peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
323323
) -> Result<Vec<BlindedMessagePath>, ()> {
324324
self.inner.create_blinded_paths(recipient, context, peers, secp_ctx)
325325
}

0 commit comments

Comments
 (0)