]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add detection of feature_static_remotekey support and print
authorMatt Corallo <git@bluematt.me>
Tue, 3 Mar 2020 20:27:45 +0000 (15:27 -0500)
committerMatt Corallo <git@bluematt.me>
Wed, 29 Apr 2020 18:50:09 +0000 (14:50 -0400)
This adds the ability to check for static_remotekey in appropriate
feature contexts and prints it at connect time. It is still
considered unknown for the purposes of requires_unknown_bits() as
we don't yet implement it.

lightning/src/ln/features.rs
lightning/src/ln/peer_handler.rs

index b65b9b1b245e0a8922a4b69a8dbebfe2f76a500e..4f263d47592c9f94a7abb5bcceff2f705c297790 100644 (file)
@@ -97,7 +97,7 @@ mod sealed {
                        // Byte 0
                        DataLossProtect | InitialRoutingSync | UpfrontShutdownScript,
                        // Byte 1
-                       VariableLengthOnion | PaymentSecret,
+                       VariableLengthOnion | StaticRemoteKey | PaymentSecret,
                        // Byte 2
                        BasicMPP,
                ],
@@ -115,7 +115,7 @@ mod sealed {
                        // Byte 0
                        DataLossProtect | UpfrontShutdownScript,
                        // Byte 1
-                       VariableLengthOnion | PaymentSecret,
+                       VariableLengthOnion | StaticRemoteKey | PaymentSecret,
                        // Byte 2
                        BasicMPP,
                ],
@@ -236,6 +236,8 @@ mod sealed {
                "Feature flags for `option_upfront_shutdown_script`.");
        define_feature!(9, VariableLengthOnion, [InitContext, NodeContext],
                "Feature flags for `var_onion_optin`.");
+       define_feature!(13, StaticRemoteKey, [InitContext, NodeContext],
+               "Feature flags for `option_static_remotekey`.");
        define_feature!(15, PaymentSecret, [InitContext, NodeContext],
                "Feature flags for `payment_secret`.");
        define_feature!(17, BasicMPP, [InitContext, NodeContext],
@@ -470,6 +472,12 @@ impl<T: sealed::VariableLengthOnion> Features<T> {
        }
 }
 
+impl<T: sealed::StaticRemoteKey> Features<T> {
+       pub(crate) fn supports_static_remote_key(&self) -> bool {
+               <T as sealed::StaticRemoteKey>::supports_feature(&self.flags)
+       }
+}
+
 impl<T: sealed::InitialRoutingSync> Features<T> {
        pub(crate) fn initial_routing_sync(&self) -> bool {
                <T as sealed::InitialRoutingSync>::supports_feature(&self.flags)
@@ -600,11 +608,11 @@ mod tests {
                {
                        // Check that the flags are as expected:
                        // - option_data_loss_protect
-                       // - var_onion_optin | payment_secret
+                       // - var_onion_optin | static_remote_key | payment_secret
                        // - basic_mpp
                        assert_eq!(node_features.flags.len(), 3);
                        assert_eq!(node_features.flags[0], 0b00000010);
-                       assert_eq!(node_features.flags[1], 0b10000010);
+                       assert_eq!(node_features.flags[1], 0b10100010);
                        assert_eq!(node_features.flags[2], 0b00000010);
                }
 
index 51a546de60b24c6926c36be422679a6826c32122..02bb2625b1519269aad4a8333ddd466ff75e2948 100644 (file)
@@ -629,10 +629,11 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
                                                                                                        return Err(PeerHandleError{ no_connection_possible: false });
                                                                                                }
 
-                                                                                               log_info!(self, "Received peer Init message: data_loss_protect: {}, initial_routing_sync: {}, upfront_shutdown_script: {}, unkown local flags: {}, unknown global flags: {}",
+                                                                                               log_info!(self, "Received peer Init message: data_loss_protect: {}, initial_routing_sync: {}, upfront_shutdown_script: {}, static_remote_key: {}, unkown local flags: {}, unknown global flags: {}",
                                                                                                        if msg.features.supports_data_loss_protect() { "supported" } else { "not supported"},
                                                                                                        if msg.features.initial_routing_sync() { "requested" } else { "not requested" },
                                                                                                        if msg.features.supports_upfront_shutdown_script() { "supported" } else { "not supported"},
+                                                                                                       if msg.features.supports_static_remote_key() { "supported" } else { "not supported"},
                                                                                                        if msg.features.supports_unknown_bits() { "present" } else { "none" },
                                                                                                        if msg.features.supports_unknown_bits() { "present" } else { "none" });