X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Ffeatures.rs;h=f573ac4c43abd910c96764e123913901a3af1f2e;hb=82f5a1cbdacd341a54bbf98f2835c0f8f6d8787a;hp=b65b9b1b245e0a8922a4b69a8dbebfe2f76a500e;hpb=ee27e8432ac13cdff5bc2d2db3245691facc2083;p=rust-lightning diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index b65b9b1b..f573ac4c 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -1,3 +1,12 @@ +// This file is Copyright its original authors, visible in version control +// history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in accordance with one or both of these +// licenses. + //! Feature flag definitions for the Lightning protocol according to [BOLT #9]. //! //! Lightning nodes advertise a supported set of operation through feature flags. Features are @@ -89,7 +98,7 @@ mod sealed { // Byte 0 , // Byte 1 - , + StaticRemoteKey, // Byte 2 , ], @@ -107,7 +116,7 @@ mod sealed { // Byte 0 , // Byte 1 - , + StaticRemoteKey, // Byte 2 , ], @@ -236,6 +245,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], @@ -268,6 +279,8 @@ mod sealed { /// Tracks the set of features which a node implements, templated by the context in which it /// appears. +/// +/// (C-not exported) as we map the concrete feature types below directly instead pub struct Features { /// Note that, for convenience, flags is LITTLE endian (despite being big-endian on the wire) flags: Vec, @@ -470,6 +483,16 @@ impl Features { } } +impl Features { + pub(crate) fn supports_static_remote_key(&self) -> bool { + ::supports_feature(&self.flags) + } + #[cfg(test)] + pub(crate) fn requires_static_remote_key(&self) -> bool { + ::requires_feature(&self.flags) + } +} + impl Features { pub(crate) fn initial_routing_sync(&self) -> bool { ::supports_feature(&self.flags) @@ -555,6 +578,11 @@ mod tests { assert!(!InitFeatures::known().requires_variable_length_onion()); assert!(!NodeFeatures::known().requires_variable_length_onion()); + assert!(InitFeatures::known().supports_static_remote_key()); + assert!(NodeFeatures::known().supports_static_remote_key()); + assert!(InitFeatures::known().requires_static_remote_key()); + assert!(NodeFeatures::known().requires_static_remote_key()); + assert!(InitFeatures::known().supports_payment_secret()); assert!(NodeFeatures::known().supports_payment_secret()); assert!(!InitFeatures::known().requires_payment_secret()); @@ -600,11 +628,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 (req) | 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], 0b10010010); assert_eq!(node_features.flags[2], 0b00000010); }