Skip to content

Commit 411b9b4

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 5326171 commit 411b9b4

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
@@ -8270,7 +8270,8 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
82708270
let entropy = &*$self.entropy_source;
82718271
let secp_ctx = &$self.secp_ctx;
82728272

8273-
let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8273+
let path = $self.create_compact_blinded_path()
8274+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
82748275
let builder = OfferBuilder::deriving_signing_pubkey(
82758276
node_id, expanded_key, entropy, secp_ctx
82768277
)
@@ -8337,7 +8338,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
83378338
let entropy = &*$self.entropy_source;
83388339
let secp_ctx = &$self.secp_ctx;
83398340

8340-
let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8341+
let path = $self.create_compact_blinded_path()
8342+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
83418343
let builder = RefundBuilder::deriving_payer_id(
83428344
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
83438345
)?
@@ -8686,13 +8688,31 @@ where
86868688
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
86878689
}
86888690

8689-
/// Creates a blinded path by delegating to [`MessageRouter::create_compact_blinded_paths`].
8691+
/// Creates a blinded path by delegating to [`MessageRouter::create_blinded_paths`].
86908692
///
86918693
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
86928694
fn create_blinded_path(&self) -> Result<BlindedPath, ()> {
86938695
let recipient = self.get_our_node_id();
86948696
let secp_ctx = &self.secp_ctx;
86958697

8698+
let peers = self.per_peer_state.read().unwrap()
8699+
.iter()
8700+
.filter(|(_, peer)| peer.lock().unwrap().latest_features.supports_onion_messages())
8701+
.map(|(node_id, _)| *node_id)
8702+
.collect::<Vec<_>>();
8703+
8704+
self.router
8705+
.create_blinded_paths(recipient, peers, secp_ctx)
8706+
.and_then(|paths| paths.into_iter().next().ok_or(()))
8707+
}
8708+
8709+
/// Creates a blinded path by delegating to [`MessageRouter::create_compact_blinded_paths`].
8710+
///
8711+
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
8712+
fn create_compact_blinded_path(&self) -> Result<BlindedPath, ()> {
8713+
let recipient = self.get_our_node_id();
8714+
let secp_ctx = &self.secp_ctx;
8715+
86968716
let peers = self.per_peer_state.read().unwrap()
86978717
.iter()
86988718
.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)