Skip to content

Commit 2d2a087

Browse files
committed
Don't use compact blinded paths for reply paths
There's no need to save space when creating reply paths since they are part of onion messages rather than in QR codes. Use normal blinded paths for these instead as they are less likely to become invalid in case of channel closure.
1 parent 3408c3f commit 2d2a087

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8572,7 +8572,8 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
85728572
let entropy = &*$self.entropy_source;
85738573
let secp_ctx = &$self.secp_ctx;
85748574

8575-
let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8575+
let path = $self.create_compact_blinded_path()
8576+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
85768577
let builder = OfferBuilder::deriving_signing_pubkey(
85778578
node_id, expanded_key, entropy, secp_ctx
85788579
)
@@ -8639,7 +8640,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
86398640
let entropy = &*$self.entropy_source;
86408641
let secp_ctx = &$self.secp_ctx;
86418642

8642-
let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8643+
let path = $self.create_compact_blinded_path()
8644+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
86438645
let builder = RefundBuilder::deriving_payer_id(
86448646
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
86458647
)?
@@ -8988,13 +8990,31 @@ where
89888990
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
89898991
}
89908992

8991-
/// Creates a blinded path by delegating to [`MessageRouter::create_compact_blinded_paths`].
8993+
/// Creates a blinded path by delegating to [`MessageRouter::create_blinded_paths`].
89928994
///
89938995
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
89948996
fn create_blinded_path(&self) -> Result<BlindedPath, ()> {
89958997
let recipient = self.get_our_node_id();
89968998
let secp_ctx = &self.secp_ctx;
89978999

9000+
let peers = self.per_peer_state.read().unwrap()
9001+
.iter()
9002+
.filter(|(_, peer)| peer.lock().unwrap().latest_features.supports_onion_messages())
9003+
.map(|(node_id, _)| *node_id)
9004+
.collect::<Vec<_>>();
9005+
9006+
self.router
9007+
.create_blinded_paths(recipient, peers, secp_ctx)
9008+
.and_then(|paths| paths.into_iter().next().ok_or(()))
9009+
}
9010+
9011+
/// Creates a blinded path by delegating to [`MessageRouter::create_compact_blinded_paths`].
9012+
///
9013+
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
9014+
fn create_compact_blinded_path(&self) -> Result<BlindedPath, ()> {
9015+
let recipient = self.get_our_node_id();
9016+
let secp_ctx = &self.secp_ctx;
9017+
89989018
let peers = self.per_peer_state.read().unwrap()
89999019
.iter()
90009020
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))

lightning/src/ln/offers_tests.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,9 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
427427
payer_note_truncated: None,
428428
},
429429
});
430-
let introduction_node_id = resolve_introduction_node(alice, &reply_path);
431430
assert_eq!(invoice_request.amount_msats(), None);
432431
assert_ne!(invoice_request.payer_id(), david_id);
433-
assert_eq!(introduction_node_id, charlie_id);
434-
assert!(matches!(reply_path.introduction_node, IntroductionNode::DirectedShortChannelId(..)));
432+
assert_eq!(reply_path.introduction_node, IntroductionNode::NodeId(charlie_id));
435433

436434
let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
437435
charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
@@ -582,11 +580,9 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
582580
payer_note_truncated: None,
583581
},
584582
});
585-
let introduction_node_id = resolve_introduction_node(alice, &reply_path);
586583
assert_eq!(invoice_request.amount_msats(), None);
587584
assert_ne!(invoice_request.payer_id(), bob_id);
588-
assert_eq!(introduction_node_id, bob_id);
589-
assert!(matches!(reply_path.introduction_node, IntroductionNode::DirectedShortChannelId(..)));
585+
assert_eq!(reply_path.introduction_node, IntroductionNode::NodeId(bob_id));
590586

591587
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
592588
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);

0 commit comments

Comments
 (0)