]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Use BlindedPath::new_for_payment in fuzz tests
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 23 Jul 2024 20:40:32 +0000 (15:40 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 30 Jul 2024 21:06:24 +0000 (16:06 -0500)
When creating a Bolt12Invoice in fuzz tests, use
BlindedPath::new_for_payment instead of BlindedPath::new_for_message.
This way PaymentContext is used instead of MessageContext, as is more
realistic though should not affect the test. This allows us to remove
OffersContext::Unknown.

fuzz/src/invoice_request_deser.rs
fuzz/src/refund_deser.rs

index 54b842febc9c7a2d464788ecd4c488de51a149a5..d418cbe51d8e87bffff9c61f998aed05b80fa5e2 100644 (file)
 use crate::utils::test_logger;
 use bitcoin::secp256k1::{self, Keypair, Parity, PublicKey, Secp256k1, SecretKey};
 use core::convert::TryFrom;
-use lightning::blinded_path::message::{ForwardNode, MessageContext, OffersContext};
+use lightning::blinded_path::payment::{
+       Bolt12OfferContext, ForwardNode, ForwardTlvs, PaymentConstraints, PaymentContext, PaymentRelay,
+       ReceiveTlvs,
+};
 use lightning::blinded_path::BlindedPath;
+use lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA;
 use lightning::ln::features::BlindedHopFeatures;
+use lightning::ln::types::PaymentSecret;
 use lightning::ln::PaymentHash;
-use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
-use lightning::offers::invoice_request::InvoiceRequest;
+use lightning::offers::invoice::UnsignedBolt12Invoice;
+use lightning::offers::invoice_request::{InvoiceRequest, InvoiceRequestFields};
+use lightning::offers::offer::OfferId;
 use lightning::offers::parse::Bolt12SemanticError;
 use lightning::sign::EntropySource;
 use lightning::util::ser::Writeable;
+use lightning::util::string::UntrustedString;
 
 #[inline]
 pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
@@ -76,57 +83,54 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
        invoice_request: &InvoiceRequest, secp_ctx: &Secp256k1<T>,
 ) -> Result<UnsignedBolt12Invoice, Bolt12SemanticError> {
        let entropy_source = Randomness {};
-       let intermediate_nodes = [
-               [
-                       ForwardNode { node_id: pubkey(43), short_channel_id: None },
-                       ForwardNode { node_id: pubkey(44), short_channel_id: None },
-               ],
-               [
-                       ForwardNode { node_id: pubkey(45), short_channel_id: None },
-                       ForwardNode { node_id: pubkey(46), short_channel_id: None },
-               ],
-       ];
-       let paths = vec![
-               BlindedPath::new_for_message(
-                       &intermediate_nodes[0],
-                       pubkey(42),
-                       MessageContext::Offers(OffersContext::Unknown {}),
-                       &entropy_source,
-                       secp_ctx,
-               )
-               .unwrap(),
-               BlindedPath::new_for_message(
-                       &intermediate_nodes[1],
-                       pubkey(42),
-                       MessageContext::Offers(OffersContext::Unknown {}),
-                       &entropy_source,
-                       secp_ctx,
-               )
-               .unwrap(),
-       ];
-
-       let payinfo = vec![
-               BlindedPayInfo {
-                       fee_base_msat: 1,
-                       fee_proportional_millionths: 1_000,
-                       cltv_expiry_delta: 42,
-                       htlc_minimum_msat: 100,
-                       htlc_maximum_msat: 1_000_000_000_000,
-                       features: BlindedHopFeatures::empty(),
+       let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
+               offer_id: OfferId([42; 32]),
+               invoice_request: InvoiceRequestFields {
+                       payer_id: invoice_request.payer_id(),
+                       quantity: invoice_request.quantity(),
+                       payer_note_truncated: invoice_request
+                               .payer_note()
+                               .map(|s| UntrustedString(s.to_string())),
+               },
+       });
+       let payee_tlvs = ReceiveTlvs {
+               payment_secret: PaymentSecret([42; 32]),
+               payment_constraints: PaymentConstraints {
+                       max_cltv_expiry: 1_000_000,
+                       htlc_minimum_msat: 1,
                },
-               BlindedPayInfo {
-                       fee_base_msat: 1,
-                       fee_proportional_millionths: 1_000,
-                       cltv_expiry_delta: 42,
-                       htlc_minimum_msat: 100,
-                       htlc_maximum_msat: 1_000_000_000_000,
+               payment_context,
+       };
+       let intermediate_nodes = [ForwardNode {
+               tlvs: ForwardTlvs {
+                       short_channel_id: 43,
+                       payment_relay: PaymentRelay {
+                               cltv_expiry_delta: 40,
+                               fee_proportional_millionths: 1_000,
+                               fee_base_msat: 1,
+                       },
+                       payment_constraints: PaymentConstraints {
+                               max_cltv_expiry: payee_tlvs.payment_constraints.max_cltv_expiry + 40,
+                               htlc_minimum_msat: 100,
+                       },
                        features: BlindedHopFeatures::empty(),
                },
-       ];
+               node_id: pubkey(43),
+               htlc_maximum_msat: 1_000_000_000_000,
+       }];
+       let payment_path = BlindedPath::new_for_payment(
+               &intermediate_nodes,
+               pubkey(42),
+               payee_tlvs,
+               u64::MAX,
+               MIN_FINAL_CLTV_EXPIRY_DELTA,
+               &entropy_source,
+               secp_ctx,
+       )
+       .unwrap();
 
-       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()
+       invoice_request.respond_with(vec![payment_path], payment_hash)?.build()
 }
 
 pub fn invoice_request_deser_test<Out: test_logger::Output>(data: &[u8], out: Out) {
index 8e9e6442f4716dfb9c368bfdab178af049765333..5a692280683ca3ad39eed2689c82ed55b839bf59 100644 (file)
 use crate::utils::test_logger;
 use bitcoin::secp256k1::{self, Keypair, PublicKey, Secp256k1, SecretKey};
 use core::convert::TryFrom;
-use lightning::blinded_path::message::{ForwardNode, MessageContext, OffersContext};
+use lightning::blinded_path::payment::{
+       Bolt12RefundContext, ForwardNode, ForwardTlvs, PaymentConstraints, PaymentContext,
+       PaymentRelay, ReceiveTlvs,
+};
 use lightning::blinded_path::BlindedPath;
+use lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA;
 use lightning::ln::features::BlindedHopFeatures;
+use lightning::ln::types::PaymentSecret;
 use lightning::ln::PaymentHash;
-use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
+use lightning::offers::invoice::UnsignedBolt12Invoice;
 use lightning::offers::parse::Bolt12SemanticError;
 use lightning::offers::refund::Refund;
 use lightning::sign::EntropySource;
@@ -65,57 +70,45 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
        refund: &Refund, signing_pubkey: PublicKey, secp_ctx: &Secp256k1<T>,
 ) -> Result<UnsignedBolt12Invoice, Bolt12SemanticError> {
        let entropy_source = Randomness {};
-       let intermediate_nodes = [
-               [
-                       ForwardNode { node_id: pubkey(43), short_channel_id: None },
-                       ForwardNode { node_id: pubkey(44), short_channel_id: None },
-               ],
-               [
-                       ForwardNode { node_id: pubkey(45), short_channel_id: None },
-                       ForwardNode { node_id: pubkey(46), short_channel_id: None },
-               ],
-       ];
-       let paths = vec![
-               BlindedPath::new_for_message(
-                       &intermediate_nodes[0],
-                       pubkey(42),
-                       MessageContext::Offers(OffersContext::Unknown {}),
-                       &entropy_source,
-                       secp_ctx,
-               )
-               .unwrap(),
-               BlindedPath::new_for_message(
-                       &intermediate_nodes[1],
-                       pubkey(42),
-                       MessageContext::Offers(OffersContext::Unknown {}),
-                       &entropy_source,
-                       secp_ctx,
-               )
-               .unwrap(),
-       ];
-
-       let payinfo = vec![
-               BlindedPayInfo {
-                       fee_base_msat: 1,
-                       fee_proportional_millionths: 1_000,
-                       cltv_expiry_delta: 42,
-                       htlc_minimum_msat: 100,
-                       htlc_maximum_msat: 1_000_000_000_000,
-                       features: BlindedHopFeatures::empty(),
+       let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
+       let payee_tlvs = ReceiveTlvs {
+               payment_secret: PaymentSecret([42; 32]),
+               payment_constraints: PaymentConstraints {
+                       max_cltv_expiry: 1_000_000,
+                       htlc_minimum_msat: 1,
                },
-               BlindedPayInfo {
-                       fee_base_msat: 1,
-                       fee_proportional_millionths: 1_000,
-                       cltv_expiry_delta: 42,
-                       htlc_minimum_msat: 100,
-                       htlc_maximum_msat: 1_000_000_000_000,
+               payment_context,
+       };
+       let intermediate_nodes = [ForwardNode {
+               tlvs: ForwardTlvs {
+                       short_channel_id: 43,
+                       payment_relay: PaymentRelay {
+                               cltv_expiry_delta: 40,
+                               fee_proportional_millionths: 1_000,
+                               fee_base_msat: 1,
+                       },
+                       payment_constraints: PaymentConstraints {
+                               max_cltv_expiry: payee_tlvs.payment_constraints.max_cltv_expiry + 40,
+                               htlc_minimum_msat: 100,
+                       },
                        features: BlindedHopFeatures::empty(),
                },
-       ];
+               node_id: pubkey(43),
+               htlc_maximum_msat: 1_000_000_000_000,
+       }];
+       let payment_path = BlindedPath::new_for_payment(
+               &intermediate_nodes,
+               pubkey(42),
+               payee_tlvs,
+               u64::MAX,
+               MIN_FINAL_CLTV_EXPIRY_DELTA,
+               &entropy_source,
+               secp_ctx,
+       )
+       .unwrap();
 
-       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()
+       refund.respond_with(vec![payment_path], payment_hash, signing_pubkey)?.build()
 }
 
 pub fn refund_deser_test<Out: test_logger::Output>(data: &[u8], out: Out) {