Skip to content

Commit 9463923

Browse files
committed
Define the PaymentMetadata feature to be used in invoices
1 parent 2a8a396 commit 9463923

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

lightning-invoice/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,8 @@ mod test {
19091909
);
19101910
assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&[21;32][..]).unwrap());
19111911
assert_eq!(invoice.payment_secret(), &PaymentSecret([42; 32]));
1912-
assert_eq!(invoice.features(), Some(&InvoiceFeatures::known()));
1912+
assert_eq!(invoice.features(), Some(&InvoiceFeatures::empty()
1913+
.set_payment_secret_required().set_variable_length_onion_required().set_basic_mpp_optional()));
19131914

19141915
let raw_invoice = builder.build_raw().unwrap();
19151916
assert_eq!(raw_invoice, *invoice.into_signed_raw().raw_invoice())

lightning/src/ln/features.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,33 @@ mod sealed {
192192
VariableLengthOnion | PaymentSecret,
193193
// Byte 2
194194
,
195+
// Byte 3
196+
,
197+
// Byte 4
198+
,
199+
// Byte 5
200+
,
201+
// Byte 6
202+
,
195203
],
204+
// Note that the optional feature bits set here are used to check if a bit is "known", but
205+
// the `InvoiceBuilder` in lightning-invoice starts with `empty()` and does not set these
206+
// bits unless the relevant data is included in the invoice.
196207
optional_features: [
197208
// Byte 0
198209
,
199210
// Byte 1
200211
,
201212
// Byte 2
202213
BasicMPP,
214+
// Byte 3
215+
,
216+
// Byte 4
217+
,
218+
// Byte 5
219+
,
220+
// Byte 6
221+
PaymentMetadata,
203222
],
204223
});
205224
// This isn't a "real" feature context, and is only used in the channel_type field in an
@@ -390,12 +409,15 @@ mod sealed {
390409
define_feature!(45, ChannelType, [InitContext, NodeContext],
391410
"Feature flags for `option_channel_type`.", set_channel_type_optional,
392411
set_channel_type_required, supports_channel_type, requires_channel_type);
412+
define_feature!(49, PaymentMetadata, [InvoiceContext],
413+
"Feature flags for payment metadata in invoices.", set_payment_metadata_optional,
414+
set_payment_metadata_required, supports_payment_metadata, requires_payment_metadata);
393415
define_feature!(55, Keysend, [NodeContext],
394416
"Feature flags for keysend payments.", set_keysend_optional, set_keysend_required,
395417
supports_keysend, requires_keysend);
396418

397419
#[cfg(test)]
398-
define_feature!(123456789, UnknownFeature, [NodeContext, ChannelContext, InvoiceContext],
420+
define_feature!(123456789, UnknownFeature, [NodeContext, ChannelContext, InitContext],
399421
"Feature flags for an unknown feature used in testing.", set_unknown_feature_optional,
400422
set_unknown_feature_required, supports_unknown_test_feature, requires_unknown_test_feature);
401423
}
@@ -885,10 +907,10 @@ mod tests {
885907
#[test]
886908
fn convert_to_context_with_unknown_flags() {
887909
// Ensure the `from` context has fewer known feature bytes than the `to` context.
888-
assert!(InvoiceFeatures::known().flags.len() < NodeFeatures::known().flags.len());
889-
let invoice_features = InvoiceFeatures::known().set_unknown_feature_optional();
890-
assert!(invoice_features.supports_unknown_bits());
891-
let node_features: NodeFeatures = invoice_features.to_context();
910+
assert!(InitFeatures::known().flags.len() < NodeFeatures::known().flags.len());
911+
let init_features = InitFeatures::known().set_unknown_feature_optional();
912+
assert!(init_features.supports_unknown_bits());
913+
let node_features: NodeFeatures = init_features.to_context();
892914
assert!(!node_features.supports_unknown_bits());
893915
}
894916

lightning/src/routing/router.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4569,7 +4569,6 @@ mod tests {
45694569
assert_eq!(route.paths[0][1].short_channel_id, 13);
45704570
assert_eq!(route.paths[0][1].fee_msat, 90_000);
45714571
assert_eq!(route.paths[0][1].cltv_expiry_delta, 42);
4572-
assert_eq!(route.paths[0][1].node_features.le_flags(), InvoiceFeatures::known().le_flags());
45734572
assert_eq!(route.paths[0][1].channel_features.le_flags(), &id_to_feature_flags(13));
45744573
}
45754574
}

0 commit comments

Comments
 (0)