From: Valentine Wallace Date: Fri, 16 Jun 2023 13:45:04 +0000 (-0400) Subject: Reverse (BlindedPath, BlindedPayInfo) tuple order in offers invoice. X-Git-Tag: v0.0.116-alpha1~7^2~7 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=3184393df2e22059d06cb87208942d67243136c6;p=rust-lightning Reverse (BlindedPath, BlindedPayInfo) tuple order in offers invoice. To make it uniform with PaymentParameters' Payee::Blinded::route_hints. --- diff --git a/fuzz/src/invoice_request_deser.rs b/fuzz/src/invoice_request_deser.rs index 394d57fce..f8fe34f2b 100644 --- a/fuzz/src/invoice_request_deser.rs +++ b/fuzz/src/invoice_request_deser.rs @@ -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() } diff --git a/fuzz/src/refund_deser.rs b/fuzz/src/refund_deser.rs index 359bbcc73..618b129f9 100644 --- a/fuzz/src/refund_deser.rs +++ b/fuzz/src/refund_deser.rs @@ -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() } diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 4d1398644..fb1f78fd6 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -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) -> Result<(), lightning::offers::parse::ParseError> { @@ -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 { let amount_msats = Self::check_amount_msats(invoice_request)?; @@ -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 { let amount_msats = refund.amount_msats(); @@ -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 { let amount_msats = Self::check_amount_msats(invoice_request)?; @@ -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 { let amount_msats = refund.amount_msats(); @@ -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 { @@ -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, payment_hash: PaymentHash, @@ -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[..] } @@ -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), @@ -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`]. @@ -878,15 +878,15 @@ impl TryFrom 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::>() + (Some(blindedpay), Some(paths)) => { + blindedpay.into_iter().zip(paths.into_iter()).collect::>() }, }; @@ -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), @@ -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), @@ -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"), @@ -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"), diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index ed884848f..f51d25267 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -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, SemanticError> { let created_at = std::time::SystemTime::now() .duration_since(std::time::SystemTime::UNIX_EPOCH) @@ -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, SemanticError> { if self.features().requires_unknown_bits() { @@ -530,7 +530,7 @@ impl InvoiceRequest { /// [`Invoice`]: crate::offers::invoice::Invoice #[cfg(feature = "std")] pub fn verify_and_respond_using_derived_keys( - &self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash, + &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash, expanded_key: &ExpandedKey, secp_ctx: &Secp256k1 ) -> Result, SemanticError> { let created_at = std::time::SystemTime::now() @@ -552,7 +552,7 @@ impl InvoiceRequest { /// /// [`Invoice`]: crate::offers::invoice::Invoice pub fn verify_and_respond_using_derived_keys_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, expanded_key: &ExpandedKey, secp_ctx: &Secp256k1 ) -> Result, SemanticError> { if self.features().requires_unknown_bits() { diff --git a/lightning/src/offers/refund.rs b/lightning/src/offers/refund.rs index 8fbc47d12..07e759917 100644 --- a/lightning/src/offers/refund.rs +++ b/lightning/src/offers/refund.rs @@ -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, SemanticError> { let created_at = std::time::SystemTime::now() @@ -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, SemanticError> { if self.features().requires_unknown_bits() { @@ -447,7 +447,7 @@ impl Refund { /// [`Invoice`]: crate::offers::invoice::Invoice #[cfg(feature = "std")] pub fn respond_using_derived_keys( - &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, SemanticError> where @@ -471,7 +471,7 @@ impl Refund { /// /// [`Invoice`]: crate::offers::invoice::Invoice pub fn respond_using_derived_keys_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, expanded_key: &ExpandedKey, entropy_source: ES ) -> Result, SemanticError> where diff --git a/lightning/src/offers/test_utils.rs b/lightning/src/offers/test_utils.rs index 26c0d0512..230c6aa16 100644 --- a/lightning/src/offers/test_utils.rs +++ b/lightning/src/offers/test_utils.rs @@ -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), @@ -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 {