Include Refund context in blinded payment paths
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 26 Mar 2024 23:57:57 +0000 (18:57 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Thu, 18 Apr 2024 14:15:21 +0000 (09:15 -0500)
When requesting a payment for a refund, include a context in the
Bolt12Invoice's blinded payment paths indicated it is for such. When the
eventual payment is received, the user can use the payment hash to
correlate it with the corresponding Refund.

lightning/src/blinded_path/payment.rs
lightning/src/ln/channelmanager.rs

index 99979ecf4a37140ef5f7375fdc2c0cc67e0eaa7b..ad7b229b53fa1c830d042d24a892360666bf5b65 100644 (file)
@@ -114,6 +114,11 @@ pub enum PaymentContext {
        ///
        /// [`Offer`]: crate::offers::offer::Offer
        Bolt12Offer(Bolt12OfferContext),
+
+       /// The payment was made for an invoice sent for a BOLT 12 [`Refund`].
+       ///
+       /// [`Refund`]: crate::offers::refund::Refund
+       Bolt12Refund(Bolt12RefundContext),
 }
 
 /// An unknown payment context.
@@ -131,6 +136,12 @@ pub struct Bolt12OfferContext {
        pub offer_id: OfferId,
 }
 
+/// The context of a payment made for an invoice sent for a BOLT 12 [`Refund`].
+///
+/// [`Refund`]: crate::offers::refund::Refund
+#[derive(Clone, Debug, Eq, PartialEq)]
+pub struct Bolt12RefundContext {}
+
 impl PaymentContext {
        pub(crate) fn unknown() -> Self {
                PaymentContext::Unknown(UnknownPaymentContext(()))
@@ -358,6 +369,7 @@ impl_writeable_tlv_based_enum!(PaymentContext,
        ;
        (0, Unknown),
        (1, Bolt12Offer),
+       (2, Bolt12Refund),
 );
 
 impl Writeable for UnknownPaymentContext {
@@ -376,6 +388,8 @@ impl_writeable_tlv_based!(Bolt12OfferContext, {
        (0, offer_id, required),
 });
 
+impl_writeable_tlv_based!(Bolt12RefundContext, {});
+
 #[cfg(test)]
 mod tests {
        use bitcoin::secp256k1::PublicKey;
index 5487ae8ab84ce4c3bcdaee9226c43a821169c4bc..54640ca7d05e86eb2f7f048cbf36731afdd0f750 100644 (file)
@@ -32,7 +32,7 @@ use bitcoin::secp256k1::Secp256k1;
 use bitcoin::{secp256k1, Sequence};
 
 use crate::blinded_path::{BlindedPath, NodeIdLookUp};
-use crate::blinded_path::payment::{Bolt12OfferContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
+use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
 use crate::chain;
 use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
 use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
@@ -8826,7 +8826,7 @@ where
 
                match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
                        Ok((payment_hash, payment_secret)) => {
-                               let payment_context = PaymentContext::unknown();
+                               let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
                                let payment_paths = self.create_blinded_payment_paths(
                                        amount_msats, payment_secret, payment_context
                                )