Skip to content

Commit fb2a0b0

Browse files
TheBlueMattandozw
authored andcommitted
Define the PaymentMetadata feature to be used in invoices
1 parent 6592081 commit fb2a0b0

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

lightning-invoice/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,11 @@ mod test {
19221922
);
19231923
assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&[21;32][..]).unwrap());
19241924
assert_eq!(invoice.payment_secret(), &PaymentSecret([42; 32]));
1925-
assert_eq!(invoice.features(), Some(&InvoiceFeatures::known()));
1925+
let mut features = InvoiceFeatures::empty();
1926+
features.set_payment_secret_required();
1927+
features.set_variable_length_onion_required();
1928+
features.set_basic_mpp_optional();
1929+
assert_eq!(invoice.features(), Some(&features));
19261930

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

lightning/src/ln/features.rs

Lines changed: 28 additions & 7 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
@@ -402,13 +421,15 @@ mod sealed {
402421
define_feature!(47, SCIDPrivacy, [InitContext, NodeContext, ChannelTypeContext],
403422
"Feature flags for only forwarding with SCID aliasing. Called `option_scid_alias` in the BOLTs",
404423
set_scid_privacy_optional, set_scid_privacy_required, supports_scid_privacy, requires_scid_privacy);
405-
424+
define_feature!(49, PaymentMetadata, [InvoiceContext],
425+
"Feature flags for payment metadata in invoices.", set_payment_metadata_optional,
426+
set_payment_metadata_required, supports_payment_metadata, requires_payment_metadata);
406427
define_feature!(55, Keysend, [NodeContext],
407428
"Feature flags for keysend payments.", set_keysend_optional, set_keysend_required,
408429
supports_keysend, requires_keysend);
409430

410431
#[cfg(test)]
411-
define_feature!(123456789, UnknownFeature, [NodeContext, ChannelContext, InvoiceContext],
432+
define_feature!(123456789, UnknownFeature, [NodeContext, ChannelContext, InitContext],
412433
"Feature flags for an unknown feature used in testing.", set_unknown_feature_optional,
413434
set_unknown_feature_required, supports_unknown_test_feature, requires_unknown_test_feature);
414435
}
@@ -921,11 +942,11 @@ mod tests {
921942
#[test]
922943
fn convert_to_context_with_unknown_flags() {
923944
// Ensure the `from` context has fewer known feature bytes than the `to` context.
924-
assert!(InvoiceFeatures::known().flags.len() < NodeFeatures::known().flags.len());
925-
let mut invoice_features = InvoiceFeatures::known();
926-
invoice_features.set_unknown_feature_optional();
927-
assert!(invoice_features.supports_unknown_bits());
928-
let node_features: NodeFeatures = invoice_features.to_context();
945+
assert!(InitFeatures::known().flags.len() < NodeFeatures::known().flags.len());
946+
let mut init_features = InitFeatures::known();
947+
init_features.set_unknown_feature_optional();
948+
assert!(init_features.supports_unknown_bits());
949+
let node_features: NodeFeatures = init_features.to_context();
929950
assert!(!node_features.supports_unknown_bits());
930951
}
931952

lightning/src/routing/router.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4917,7 +4917,6 @@ mod tests {
49174917
assert_eq!(route.paths[0][1].short_channel_id, 13);
49184918
assert_eq!(route.paths[0][1].fee_msat, 90_000);
49194919
assert_eq!(route.paths[0][1].cltv_expiry_delta, 42);
4920-
assert_eq!(route.paths[0][1].node_features.le_flags(), InvoiceFeatures::known().le_flags());
49214920
assert_eq!(route.paths[0][1].channel_features.le_flags(), &id_to_feature_flags(13));
49224921
}
49234922
}

0 commit comments

Comments
 (0)