]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Disallow offer_metadata in Refund
authorJeffrey Czyz <jkczyz@gmail.com>
Thu, 19 Jan 2023 00:58:20 +0000 (18:58 -0600)
committerJeffrey Czyz <jkczyz@gmail.com>
Mon, 30 Jan 2023 21:44:39 +0000 (15:44 -0600)
The offer_metadata was optional but is redundant with invreq_metadata
(i.e., payer_metadata) for refunds. It is now disallowed in the spec and
was already unsupported by RefundBuilder.

lightning/src/offers/parse.rs
lightning/src/offers/refund.rs

index a7d13e57050379d7982c819501186708d79cf34c..35c1425acc13b86316858065afb1ed15a7a6402e 100644 (file)
@@ -157,6 +157,8 @@ pub enum SemanticError {
        InvalidQuantity,
        /// A quantity or quantity bounds was provided but was not expected.
        UnexpectedQuantity,
+       /// Metadata was provided but was not expected.
+       UnexpectedMetadata,
        /// Payer metadata was expected but was missing.
        MissingPayerMetadata,
        /// A payer id was expected but was missing.
index f800274c973341d0ed33fd9c89dffc8fcb475b19..e022f12755d83e6e92739e86c9f8257ee56ad9e8 100644 (file)
@@ -118,9 +118,9 @@ impl RefundBuilder {
                }
 
                let refund = RefundContents {
-                       payer: PayerContents(metadata), metadata: None, description, absolute_expiry: None,
-                       issuer: None, paths: None, chain: None, amount_msats,
-                       features: InvoiceRequestFeatures::empty(), quantity: None, payer_id, payer_note: None,
+                       payer: PayerContents(metadata), description, absolute_expiry: None, issuer: None,
+                       paths: None, chain: None, amount_msats, features: InvoiceRequestFeatures::empty(),
+                       quantity: None, payer_id, payer_note: None,
                };
 
                Ok(RefundBuilder { refund })
@@ -229,7 +229,6 @@ pub struct Refund {
 pub(super) struct RefundContents {
        payer: PayerContents,
        // offer fields
-       metadata: Option<Vec<u8>>,
        description: String,
        absolute_expiry: Option<Duration>,
        issuer: Option<String>,
@@ -395,7 +394,7 @@ impl RefundContents {
 
                let offer = OfferTlvStreamRef {
                        chains: None,
-                       metadata: self.metadata.as_ref(),
+                       metadata: None,
                        currency: None,
                        amount: None,
                        description: Some(&self.description),
@@ -497,6 +496,10 @@ impl TryFrom<RefundTlvStream> for RefundContents {
                        Some(metadata) => PayerContents(metadata),
                };
 
+               if metadata.is_some() {
+                       return Err(SemanticError::UnexpectedMetadata);
+               }
+
                if chains.is_some() {
                        return Err(SemanticError::UnexpectedChain);
                }
@@ -539,10 +542,9 @@ impl TryFrom<RefundTlvStream> for RefundContents {
                        Some(payer_id) => payer_id,
                };
 
-               // TODO: Should metadata be included?
                Ok(RefundContents {
-                       payer, metadata, description, absolute_expiry, issuer, paths, chain, amount_msats,
-                       features, quantity, payer_id, payer_note,
+                       payer, description, absolute_expiry, issuer, paths, chain, amount_msats, features,
+                       quantity, payer_id, payer_note,
                })
        }
 }
@@ -949,6 +951,17 @@ mod tests {
                        panic!("error parsing refund: {:?}", e);
                }
 
+               let metadata = vec![42; 32];
+               let mut tlv_stream = refund.as_tlv_stream();
+               tlv_stream.1.metadata = Some(&metadata);
+
+               match Refund::try_from(tlv_stream.to_bytes()) {
+                       Ok(_) => panic!("expected error"),
+                       Err(e) => {
+                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedMetadata));
+                       },
+               }
+
                let chains = vec![ChainHash::using_genesis_block(Network::Testnet)];
                let mut tlv_stream = refund.as_tlv_stream();
                tlv_stream.1.chains = Some(&chains);