Skip to content

Commit f88da8f

Browse files
committed
Disallow offer_metadata in Refund
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.
1 parent dd38454 commit f88da8f

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

lightning/src/offers/parse.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ pub enum SemanticError {
157157
InvalidQuantity,
158158
/// A quantity or quantity bounds was provided but was not expected.
159159
UnexpectedQuantity,
160+
/// Metadata was provided but was not expected.
161+
UnexpectedMetadata,
160162
/// Payer metadata was expected but was missing.
161163
MissingPayerMetadata,
162164
/// A payer id was expected but was missing.

lightning/src/offers/refund.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ impl RefundBuilder {
118118
}
119119

120120
let refund = RefundContents {
121-
payer: PayerContents(metadata), metadata: None, description, absolute_expiry: None,
122-
issuer: None, paths: None, chain: None, amount_msats,
123-
features: InvoiceRequestFeatures::empty(), quantity: None, payer_id, payer_note: None,
121+
payer: PayerContents(metadata), description, absolute_expiry: None, issuer: None,
122+
paths: None, chain: None, amount_msats, features: InvoiceRequestFeatures::empty(),
123+
quantity: None, payer_id, payer_note: None,
124124
};
125125

126126
Ok(RefundBuilder { refund })
@@ -229,7 +229,6 @@ pub struct Refund {
229229
pub(super) struct RefundContents {
230230
payer: PayerContents,
231231
// offer fields
232-
metadata: Option<Vec<u8>>,
233232
description: String,
234233
absolute_expiry: Option<Duration>,
235234
issuer: Option<String>,
@@ -395,7 +394,7 @@ impl RefundContents {
395394

396395
let offer = OfferTlvStreamRef {
397396
chains: None,
398-
metadata: self.metadata.as_ref(),
397+
metadata: None,
399398
currency: None,
400399
amount: None,
401400
description: Some(&self.description),
@@ -497,6 +496,10 @@ impl TryFrom<RefundTlvStream> for RefundContents {
497496
Some(metadata) => PayerContents(metadata),
498497
};
499498

499+
if metadata.is_some() {
500+
return Err(SemanticError::UnexpectedMetadata);
501+
}
502+
500503
if chains.is_some() {
501504
return Err(SemanticError::UnexpectedChain);
502505
}
@@ -541,8 +544,8 @@ impl TryFrom<RefundTlvStream> for RefundContents {
541544

542545
// TODO: Should metadata be included?
543546
Ok(RefundContents {
544-
payer, metadata, description, absolute_expiry, issuer, paths, chain, amount_msats,
545-
features, quantity, payer_id, payer_note,
547+
payer, description, absolute_expiry, issuer, paths, chain, amount_msats, features,
548+
quantity, payer_id, payer_note,
546549
})
547550
}
548551
}
@@ -949,6 +952,17 @@ mod tests {
949952
panic!("error parsing refund: {:?}", e);
950953
}
951954

955+
let metadata = vec![42; 32];
956+
let mut tlv_stream = refund.as_tlv_stream();
957+
tlv_stream.1.metadata = Some(&metadata);
958+
959+
match Refund::try_from(tlv_stream.to_bytes()) {
960+
Ok(_) => panic!("expected error"),
961+
Err(e) => {
962+
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedMetadata));
963+
},
964+
}
965+
952966
let chains = vec![ChainHash::using_genesis_block(Network::Testnet)];
953967
let mut tlv_stream = refund.as_tlv_stream();
954968
tlv_stream.1.chains = Some(&chains);

0 commit comments

Comments
 (0)