From: Matt Corallo Date: Tue, 21 Dec 2021 05:23:15 +0000 (+0000) Subject: Define the `PaymentMetadata` feature to be used in invoices X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=1c1fc456bc20994c3d51b89fd7a16c90945b9a68;p=rust-lightning Define the `PaymentMetadata` feature to be used in invoices --- diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index c44db7757..6987fdeb1 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -1875,7 +1875,8 @@ mod test { ); assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&[21;32][..]).unwrap()); assert_eq!(invoice.payment_secret(), &PaymentSecret([42; 32])); - assert_eq!(invoice.features(), Some(&InvoiceFeatures::known())); + assert_eq!(invoice.features(), Some(&InvoiceFeatures::empty() + .set_payment_secret_required().set_variable_length_onion_required().set_basic_mpp_optional())); let raw_invoice = builder.build_raw().unwrap(); assert_eq!(raw_invoice, *invoice.into_signed_raw().raw_invoice()) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 0ccce88e9..a5440650d 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -192,7 +192,18 @@ mod sealed { VariableLengthOnion | PaymentSecret, // Byte 2 , + // Byte 3 + , + // Byte 4 + , + // Byte 5 + , + // Byte 6 + , ], + // Note that the optional feature bits set here are used to check if a bit is "known", but + // the `InvoiceBuilder` in lightning-invoice starts with `empty()` and does not set these + // bits unless the relevant data is included in the invoice. optional_features: [ // Byte 0 , @@ -200,6 +211,14 @@ mod sealed { , // Byte 2 BasicMPP, + // Byte 3 + , + // Byte 4 + , + // Byte 5 + , + // Byte 6 + PaymentMetadata, ], }); // This isn't a "real" feature context, and is only used in the channel_type field in an @@ -390,12 +409,15 @@ mod sealed { define_feature!(45, ChannelType, [InitContext, NodeContext], "Feature flags for `option_channel_type`.", set_channel_type_optional, set_channel_type_required, supports_channel_type, requires_channel_type); + define_feature!(49, PaymentMetadata, [InvoiceContext], + "Feature flags for payment metadata in invoices.", set_payment_metadata_optional, + set_payment_metadata_required, supports_payment_metadata, requires_payment_metadata); define_feature!(55, Keysend, [NodeContext], "Feature flags for keysend payments.", set_keysend_optional, set_keysend_required, supports_keysend, requires_keysend); #[cfg(test)] - define_feature!(123456789, UnknownFeature, [NodeContext, ChannelContext, InvoiceContext], + define_feature!(123456789, UnknownFeature, [NodeContext, ChannelContext, InitContext], "Feature flags for an unknown feature used in testing.", set_unknown_feature_optional, set_unknown_feature_required, supports_unknown_test_feature, requires_unknown_test_feature); } @@ -885,10 +907,10 @@ mod tests { #[test] fn convert_to_context_with_unknown_flags() { // Ensure the `from` context has fewer known feature bytes than the `to` context. - assert!(InvoiceFeatures::known().flags.len() < NodeFeatures::known().flags.len()); - let invoice_features = InvoiceFeatures::known().set_unknown_feature_optional(); - assert!(invoice_features.supports_unknown_bits()); - let node_features: NodeFeatures = invoice_features.to_context(); + assert!(InitFeatures::known().flags.len() < NodeFeatures::known().flags.len()); + let init_features = InitFeatures::known().set_unknown_feature_optional(); + assert!(init_features.supports_unknown_bits()); + let node_features: NodeFeatures = init_features.to_context(); assert!(!node_features.supports_unknown_bits()); } diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index cf2afbbba..a50e29cae 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -4599,7 +4599,6 @@ mod tests { assert_eq!(route.paths[0][1].short_channel_id, 13); assert_eq!(route.paths[0][1].fee_msat, 90_000); assert_eq!(route.paths[0][1].cltv_expiry_delta, 42); - assert_eq!(route.paths[0][1].node_features.le_flags(), InvoiceFeatures::known().le_flags()); assert_eq!(route.paths[0][1].channel_features.le_flags(), &id_to_feature_flags(13)); } }