Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing to blinded payment paths #2120

Merged
2 changes: 1 addition & 1 deletion fuzz/src/invoice_request_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>(
},
];

let payment_paths = paths.into_iter().zip(payinfo.into_iter()).collect();
let payment_paths = payinfo.into_iter().zip(paths.into_iter()).collect();
let payment_hash = PaymentHash([42; 32]);
invoice_request.respond_with(payment_paths, payment_hash)?.build()
}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/refund_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>(
},
];

let payment_paths = paths.into_iter().zip(payinfo.into_iter()).collect();
let payment_paths = payinfo.into_iter().zip(paths.into_iter()).collect();
let payment_hash = PaymentHash([42; 32]);
refund.respond_with(payment_paths, payment_hash, signing_pubkey)?.build()
}
Expand Down
54 changes: 27 additions & 27 deletions lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//! # use lightning::offers::invoice::BlindedPayInfo;
//! # use lightning::blinded_path::BlindedPath;
//! #
//! # fn create_payment_paths() -> Vec<(BlindedPath, BlindedPayInfo)> { unimplemented!() }
//! # fn create_payment_paths() -> Vec<(BlindedPayInfo, BlindedPath)> { unimplemented!() }
//! # fn create_payment_hash() -> PaymentHash { unimplemented!() }
//! #
//! # fn parse_invoice_request(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::ParseError> {
Expand Down Expand Up @@ -166,7 +166,7 @@ impl SigningPubkeyStrategy for DerivedSigningPubkey {}

impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
pub(super) fn for_offer(
invoice_request: &'a InvoiceRequest, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>,
invoice_request: &'a InvoiceRequest, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>,
created_at: Duration, payment_hash: PaymentHash
) -> Result<Self, SemanticError> {
let amount_msats = Self::check_amount_msats(invoice_request)?;
Expand All @@ -182,7 +182,7 @@ impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
}

pub(super) fn for_refund(
refund: &'a Refund, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, created_at: Duration,
refund: &'a Refund, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, created_at: Duration,
payment_hash: PaymentHash, signing_pubkey: PublicKey
) -> Result<Self, SemanticError> {
let amount_msats = refund.amount_msats();
Expand All @@ -199,7 +199,7 @@ impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {

impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
pub(super) fn for_offer_using_keys(
invoice_request: &'a InvoiceRequest, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>,
invoice_request: &'a InvoiceRequest, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>,
created_at: Duration, payment_hash: PaymentHash, keys: KeyPair
) -> Result<Self, SemanticError> {
let amount_msats = Self::check_amount_msats(invoice_request)?;
Expand All @@ -215,7 +215,7 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
}

pub(super) fn for_refund_using_keys(
refund: &'a Refund, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, created_at: Duration,
refund: &'a Refund, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, created_at: Duration,
payment_hash: PaymentHash, keys: KeyPair,
) -> Result<Self, SemanticError> {
let amount_msats = refund.amount_msats();
Expand Down Expand Up @@ -247,7 +247,7 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
}

fn fields(
payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, created_at: Duration,
payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, created_at: Duration,
payment_hash: PaymentHash, amount_msats: u64, signing_pubkey: PublicKey
) -> InvoiceFields {
InvoiceFields {
Expand Down Expand Up @@ -454,7 +454,7 @@ enum InvoiceContents {
/// Invoice-specific fields for an `invoice` message.
#[derive(Clone, Debug, PartialEq)]
struct InvoiceFields {
payment_paths: Vec<(BlindedPath, BlindedPayInfo)>,
payment_paths: Vec<(BlindedPayInfo, BlindedPath)>,
created_at: Duration,
relative_expiry: Option<Duration>,
payment_hash: PaymentHash,
Expand All @@ -476,7 +476,7 @@ impl Invoice {
///
/// Blinded paths provide recipient privacy by obfuscating its node id. Note, however, that this
/// privacy is lost if a public node id is used for [`Invoice::signing_pubkey`].
pub fn payment_paths(&self) -> &[(BlindedPath, BlindedPayInfo)] {
pub fn payment_paths(&self) -> &[(BlindedPayInfo, BlindedPath)] {
&self.contents.fields().payment_paths[..]
}

Expand Down Expand Up @@ -703,8 +703,8 @@ impl InvoiceFields {
};

InvoiceTlvStreamRef {
paths: Some(Iterable(self.payment_paths.iter().map(|(path, _)| path))),
blindedpay: Some(Iterable(self.payment_paths.iter().map(|(_, payinfo)| payinfo))),
paths: Some(Iterable(self.payment_paths.iter().map(|(_, path)| path))),
blindedpay: Some(Iterable(self.payment_paths.iter().map(|(payinfo, _)| payinfo))),
created_at: Some(self.created_at.as_secs()),
relative_expiry: self.relative_expiry.map(|duration| duration.as_secs() as u32),
payment_hash: Some(&self.payment_hash),
Expand Down Expand Up @@ -750,13 +750,13 @@ tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef, 160..240, {
});

type BlindedPathIter<'a> = core::iter::Map<
core::slice::Iter<'a, (BlindedPath, BlindedPayInfo)>,
for<'r> fn(&'r (BlindedPath, BlindedPayInfo)) -> &'r BlindedPath,
core::slice::Iter<'a, (BlindedPayInfo, BlindedPath)>,
for<'r> fn(&'r (BlindedPayInfo, BlindedPath)) -> &'r BlindedPath,
>;

type BlindedPayInfoIter<'a> = core::iter::Map<
core::slice::Iter<'a, (BlindedPath, BlindedPayInfo)>,
for<'r> fn(&'r (BlindedPath, BlindedPayInfo)) -> &'r BlindedPayInfo,
core::slice::Iter<'a, (BlindedPayInfo, BlindedPath)>,
for<'r> fn(&'r (BlindedPayInfo, BlindedPath)) -> &'r BlindedPayInfo,
>;

/// Information needed to route a payment across a [`BlindedPath`].
Expand Down Expand Up @@ -878,15 +878,15 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
},
) = tlv_stream;

let payment_paths = match (paths, blindedpay) {
(None, _) => return Err(SemanticError::MissingPaths),
(_, None) => return Err(SemanticError::InvalidPayInfo),
(Some(paths), _) if paths.is_empty() => return Err(SemanticError::MissingPaths),
(Some(paths), Some(blindedpay)) if paths.len() != blindedpay.len() => {
let payment_paths = match (blindedpay, paths) {
(_, None) => return Err(SemanticError::MissingPaths),
(None, _) => return Err(SemanticError::InvalidPayInfo),
(_, Some(paths)) if paths.is_empty() => return Err(SemanticError::MissingPaths),
(Some(blindedpay), Some(paths)) if paths.len() != blindedpay.len() => {
return Err(SemanticError::InvalidPayInfo);
},
(Some(paths), Some(blindedpay)) => {
paths.into_iter().zip(blindedpay.into_iter()).collect::<Vec<_>>()
(Some(blindedpay), Some(paths)) => {
blindedpay.into_iter().zip(paths.into_iter()).collect::<Vec<_>>()
},
};

Expand Down Expand Up @@ -1052,8 +1052,8 @@ mod tests {
payer_note: None,
},
InvoiceTlvStreamRef {
paths: Some(Iterable(payment_paths.iter().map(|(path, _)| path))),
blindedpay: Some(Iterable(payment_paths.iter().map(|(_, payinfo)| payinfo))),
paths: Some(Iterable(payment_paths.iter().map(|(_, path)| path))),
blindedpay: Some(Iterable(payment_paths.iter().map(|(payinfo, _)| payinfo))),
created_at: Some(now.as_secs()),
relative_expiry: None,
payment_hash: Some(&payment_hash),
Expand Down Expand Up @@ -1130,8 +1130,8 @@ mod tests {
payer_note: None,
},
InvoiceTlvStreamRef {
paths: Some(Iterable(payment_paths.iter().map(|(path, _)| path))),
blindedpay: Some(Iterable(payment_paths.iter().map(|(_, payinfo)| payinfo))),
paths: Some(Iterable(payment_paths.iter().map(|(_, path)| path))),
blindedpay: Some(Iterable(payment_paths.iter().map(|(payinfo, _)| payinfo))),
created_at: Some(now.as_secs()),
relative_expiry: None,
payment_hash: Some(&payment_hash),
Expand Down Expand Up @@ -1516,7 +1516,7 @@ mod tests {

let empty_payment_paths = vec![];
let mut tlv_stream = invoice.as_tlv_stream();
tlv_stream.3.paths = Some(Iterable(empty_payment_paths.iter().map(|(path, _)| path)));
tlv_stream.3.paths = Some(Iterable(empty_payment_paths.iter().map(|(_, path)| path)));

match Invoice::try_from(tlv_stream.to_bytes()) {
Ok(_) => panic!("expected error"),
Expand All @@ -1526,7 +1526,7 @@ mod tests {
let mut payment_paths = payment_paths();
payment_paths.pop();
let mut tlv_stream = invoice.as_tlv_stream();
tlv_stream.3.blindedpay = Some(Iterable(payment_paths.iter().map(|(_, payinfo)| payinfo)));
tlv_stream.3.blindedpay = Some(Iterable(payment_paths.iter().map(|(payinfo, _)| payinfo)));

match Invoice::try_from(tlv_stream.to_bytes()) {
Ok(_) => panic!("expected error"),
Expand Down
8 changes: 4 additions & 4 deletions lightning/src/offers/invoice_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl InvoiceRequest {
/// [`Duration`]: core::time::Duration
#[cfg(feature = "std")]
pub fn respond_with(
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash
&self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash
) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
let created_at = std::time::SystemTime::now()
.duration_since(std::time::SystemTime::UNIX_EPOCH)
Expand Down Expand Up @@ -509,7 +509,7 @@ impl InvoiceRequest {
///
/// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at
pub fn respond_with_no_std(
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
&self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
created_at: core::time::Duration
) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
if self.features().requires_unknown_bits() {
Expand All @@ -530,7 +530,7 @@ impl InvoiceRequest {
/// [`Invoice`]: crate::offers::invoice::Invoice
#[cfg(feature = "std")]
pub fn verify_and_respond_using_derived_keys<T: secp256k1::Signing>(
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
&self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
expanded_key: &ExpandedKey, secp_ctx: &Secp256k1<T>
) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError> {
let created_at = std::time::SystemTime::now()
Expand All @@ -552,7 +552,7 @@ impl InvoiceRequest {
///
/// [`Invoice`]: crate::offers::invoice::Invoice
pub fn verify_and_respond_using_derived_keys_no_std<T: secp256k1::Signing>(
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
&self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
created_at: core::time::Duration, expanded_key: &ExpandedKey, secp_ctx: &Secp256k1<T>
) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError> {
if self.features().requires_unknown_bits() {
Expand Down
8 changes: 4 additions & 4 deletions lightning/src/offers/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl Refund {
/// [`Duration`]: core::time::Duration
#[cfg(feature = "std")]
pub fn respond_with(
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
&self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
signing_pubkey: PublicKey,
) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
let created_at = std::time::SystemTime::now()
Expand Down Expand Up @@ -427,7 +427,7 @@ impl Refund {
///
/// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at
pub fn respond_with_no_std(
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
&self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
signing_pubkey: PublicKey, created_at: Duration
) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
if self.features().requires_unknown_bits() {
Expand All @@ -447,7 +447,7 @@ impl Refund {
/// [`Invoice`]: crate::offers::invoice::Invoice
#[cfg(feature = "std")]
pub fn respond_using_derived_keys<ES: Deref>(
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
&self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
expanded_key: &ExpandedKey, entropy_source: ES
) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError>
where
Expand All @@ -471,7 +471,7 @@ impl Refund {
///
/// [`Invoice`]: crate::offers::invoice::Invoice
pub fn respond_using_derived_keys_no_std<ES: Deref>(
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
&self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
created_at: core::time::Duration, expanded_key: &ExpandedKey, entropy_source: ES
) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError>
where
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/offers/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(super) fn privkey(byte: u8) -> SecretKey {
SecretKey::from_slice(&[byte; 32]).unwrap()
}

pub(super) fn payment_paths() -> Vec<(BlindedPath, BlindedPayInfo)> {
pub(super) fn payment_paths() -> Vec<(BlindedPayInfo, BlindedPath)> {
let paths = vec![
BlindedPath {
introduction_node_id: pubkey(40),
Expand Down Expand Up @@ -97,7 +97,7 @@ pub(super) fn payment_paths() -> Vec<(BlindedPath, BlindedPayInfo)> {
},
];

paths.into_iter().zip(payinfo.into_iter()).collect()
payinfo.into_iter().zip(paths.into_iter()).collect()
}

pub(super) fn payment_hash() -> PaymentHash {
Expand Down
Loading