Skip to content

Commit 398bd57

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 de16f74 commit 398bd57

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
@@ -9400,7 +9400,12 @@ where
94009400
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
94019401
.filter(|(_, peer)| peer.is_connected)
94029402
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9403-
.map(|(node_id, _)| *node_id)
9403+
.map(|(node_id, _)| {
9404+
MessageForwardNode {
9405+
node_id: *node_id,
9406+
short_channel_id: None,
9407+
}
9408+
})
94049409
.collect::<Vec<_>>();
94059410

94069411
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
}
@@ -1251,7 +1257,12 @@ where
12511257
let peers = self.message_recipients.lock().unwrap()
12521258
.iter()
12531259
.filter(|(_, peer)| matches!(peer, OnionMessageRecipient::ConnectedPeer(_)))
1254-
.map(|(node_id, _ )| *node_id)
1260+
.map(|(node_id, _ )| {
1261+
MessageForwardNode {
1262+
node_id: *node_id,
1263+
short_channel_id: None,
1264+
}
1265+
})
12551266
.collect::<Vec<_>>();
12561267

12571268
self.message_router

lightning/src/routing/router.rs

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

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)