Fix computing in-flight HTLCs in between retries + test
[rust-lightning] / lightning / src / offers / refund.rs
index f800274c973341d0ed33fd9c89dffc8fcb475b19..fff33873954a6f92ab55ad2de8d326447dafd0ac 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>,
@@ -332,7 +331,9 @@ impl Refund {
        /// offer, which does have a `signing_pubkey`.
        ///
        /// The `payment_paths` parameter is useful for maintaining the payment recipient's privacy. It
-       /// must contain one or more elements.
+       /// must contain one or more elements ordered from most-preferred to least-preferred, if there's
+       /// a preference. Note, however, that any privacy is lost if a public node id is used for
+       /// `signing_pubkey`.
        ///
        /// Errors if the request contains unknown required features.
        ///
@@ -395,7 +396,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 +498,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 +544,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 +953,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);