]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Define the `PaymentMetadata` feature to be used in invoices
authorMatt Corallo <git@bluematt.me>
Tue, 21 Dec 2021 05:23:15 +0000 (05:23 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 26 Jan 2022 19:08:58 +0000 (19:08 +0000)
lightning-invoice/src/lib.rs
lightning/src/ln/features.rs
lightning/src/routing/router.rs

index c44db77575dec86ebe2e51ff9b432d20ce5f53ed..6987fdeb14309f543f830e3de98cabc339eaccf2 100644 (file)
@@ -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())
index 0ccce88e9f5d71743530a441504ac7c18b1da6a2..a5440650dd4a378ba08ed0df791efe210fd83cdc 100644 (file)
@@ -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());
        }
 
index cf2afbbbadb7e0baabba60d1f4f17e24799a8e03..a50e29cae05db7a815c3c72c7ec473d9f5e1e443 100644 (file)
@@ -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));
                }
        }