Skip to content

Commit 01abb87

Browse files
committed
Include a one-hop blinded path in Offer and Refund
While this doesn't add much privacy over not including any blinded paths, it allows us to exercise code for receiving on blinded paths.
1 parent df207cd commit 01abb87

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct BlindedHop {
5757

5858
impl BlindedPath {
5959
/// Create a one-hop blinded path for a message.
60-
pub fn one_hop_for_message<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>(
60+
pub fn one_hop_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
6161
recipient_node_id: PublicKey, entropy_source: &ES, secp_ctx: &Secp256k1<T>
6262
) -> Result<Self, ()> {
6363
Self::new_for_message(&[recipient_node_id], entropy_source, secp_ctx)
@@ -68,7 +68,7 @@ impl BlindedPath {
6868
///
6969
/// Errors if no hops are provided or if `node_pk`(s) are invalid.
7070
// TODO: make all payloads the same size with padding + add dummy hops
71-
pub fn new_for_message<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>(
71+
pub fn new_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
7272
node_pks: &[PublicKey], entropy_source: &ES, secp_ctx: &Secp256k1<T>
7373
) -> Result<Self, ()> {
7474
if node_pks.is_empty() { return Err(()) }

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use bitcoin::secp256k1::{SecretKey,PublicKey};
3030
use bitcoin::secp256k1::Secp256k1;
3131
use bitcoin::{LockTime, secp256k1, Sequence};
3232

33+
use crate::blinded_path::BlindedPath;
3334
use crate::chain;
3435
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
3536
use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
@@ -7073,6 +7074,9 @@ where
70737074
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
70747075
/// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer.
70757076
///
7077+
/// Uses a one-hop [`BlindedPath`] for the offer with [`ChannelManager::get_our_node_id`] as the
7078+
/// introduction node and a derived signing pubkey for recipient privacy.
7079+
///
70767080
/// [`Offer`]: crate::offers::offer::Offer
70777081
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
70787082
pub fn create_offer_builder(
@@ -7082,17 +7086,21 @@ where
70827086
let expanded_key = &self.inbound_payment_key;
70837087
let entropy = &*self.entropy_source;
70847088
let secp_ctx = &self.secp_ctx;
7089+
let path = self.create_one_hop_blinded_path();
70857090

7086-
// TODO: Set blinded paths
70877091
OfferBuilder::deriving_signing_pubkey(description, node_id, expanded_key, entropy, secp_ctx)
70887092
.chain_hash(self.chain_hash)
7093+
.path(path)
70897094
}
70907095

70917096
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
70927097
/// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
70937098
///
70947099
/// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
70957100
///
7101+
/// Uses a one-hop [`BlindedPath`] for the refund with [`ChannelManager::get_our_node_id`] as
7102+
/// the introduction node and a derived payer id for sender privacy.
7103+
///
70967104
/// [`Refund`]: crate::offers::refund::Refund
70977105
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
70987106
pub fn create_refund_builder(
@@ -7103,11 +7111,14 @@ where
71037111
let expanded_key = &self.inbound_payment_key;
71047112
let entropy = &*self.entropy_source;
71057113
let secp_ctx = &self.secp_ctx;
7114+
let path = self.create_one_hop_blinded_path();
71067115

7107-
// TODO: Set blinded paths
71087116
let builder = RefundBuilder::deriving_payer_id(
71097117
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
7110-
)?.chain_hash(self.chain_hash);
7118+
)?
7119+
.chain_hash(self.chain_hash)
7120+
.path(path);
7121+
71117122
self.pending_outbound_payments
71127123
.add_new_awaiting_invoice(payment_id, retry_strategy, max_total_routing_fee_msat)
71137124
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
@@ -7215,6 +7226,15 @@ where
72157226
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
72167227
}
72177228

7229+
/// Creates a one-hop blinded path with [`ChannelManager::get_our_node_id`] as the introduction
7230+
/// node.
7231+
fn create_one_hop_blinded_path(&self) -> BlindedPath {
7232+
let entropy_source = self.entropy_source.deref();
7233+
let secp_ctx = &self.secp_ctx;
7234+
BlindedPath::one_hop_for_message(self.get_our_node_id(), entropy_source, secp_ctx).unwrap()
7235+
7236+
}
7237+
72187238
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
72197239
/// are used when constructing the phantom invoice's route hints.
72207240
///

lightning/src/routing/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub trait Router {
9090
&self, payer: &PublicKey, route_params: &RouteParameters,
9191
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs
9292
) -> Result<Route, LightningError>;
93+
9394
/// Finds a [`Route`] for a payment between the given `payer` and a payee.
9495
///
9596
/// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]

0 commit comments

Comments
 (0)