Skip to content

Commit

Permalink
Don't use compact blinded paths for reply paths
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jkczyz committed May 22, 2024
1 parent 3408c3f commit 2d2a087
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
26 changes: 23 additions & 3 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8572,7 +8572,8 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
let entropy = &*$self.entropy_source;
let secp_ctx = &$self.secp_ctx;

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let path = $self.create_compact_blinded_path()
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = OfferBuilder::deriving_signing_pubkey(
node_id, expanded_key, entropy, secp_ctx
)
Expand Down Expand Up @@ -8639,7 +8640,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
let entropy = &*$self.entropy_source;
let secp_ctx = &$self.secp_ctx;

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let path = $self.create_compact_blinded_path()
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = RefundBuilder::deriving_payer_id(
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
)?
Expand Down Expand Up @@ -8988,13 +8990,31 @@ where
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
}

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

let peers = self.per_peer_state.read().unwrap()
.iter()
.filter(|(_, peer)| peer.lock().unwrap().latest_features.supports_onion_messages())
.map(|(node_id, _)| *node_id)
.collect::<Vec<_>>();

self.router
.create_blinded_paths(recipient, peers, secp_ctx)
.and_then(|paths| paths.into_iter().next().ok_or(()))
}

/// Creates a blinded path by delegating to [`MessageRouter::create_compact_blinded_paths`].
///
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
fn create_compact_blinded_path(&self) -> Result<BlindedPath, ()> {
let recipient = self.get_our_node_id();
let secp_ctx = &self.secp_ctx;

let peers = self.per_peer_state.read().unwrap()
.iter()
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
Expand Down
8 changes: 2 additions & 6 deletions lightning/src/ln/offers_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,9 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
payer_note_truncated: None,
},
});
let introduction_node_id = resolve_introduction_node(alice, &reply_path);
assert_eq!(invoice_request.amount_msats(), None);
assert_ne!(invoice_request.payer_id(), david_id);
assert_eq!(introduction_node_id, charlie_id);
assert!(matches!(reply_path.introduction_node, IntroductionNode::DirectedShortChannelId(..)));
assert_eq!(reply_path.introduction_node, IntroductionNode::NodeId(charlie_id));

let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
Expand Down Expand Up @@ -582,11 +580,9 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
payer_note_truncated: None,
},
});
let introduction_node_id = resolve_introduction_node(alice, &reply_path);
assert_eq!(invoice_request.amount_msats(), None);
assert_ne!(invoice_request.payer_id(), bob_id);
assert_eq!(introduction_node_id, bob_id);
assert!(matches!(reply_path.introduction_node, IntroductionNode::DirectedShortChannelId(..)));
assert_eq!(reply_path.introduction_node, IntroductionNode::NodeId(bob_id));

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

0 comments on commit 2d2a087

Please sign in to comment.