5252//! (see [BOLT-2](https://github.com/lightning/bolts/blob/master/02-peer-protocol.md) for more information).
5353//! - `Keysend` - send funds to a node without an invoice
5454//! (see the [`Keysend` feature assignment proposal](https://github.com/lightning/bolts/issues/605#issuecomment-606679798) for more information).
55+ //! - `AnchorsZeroFeeHtlcTx` - requires/supports that commitment transactions include anchor outputs
56+ //! and HTLC transactions are pre-signed with zero fee (see
57+ //! [BOLT-3](https://github.com/lightning/bolts/blob/master/03-transactions.md) for more
58+ //! information).
5559//!
5660//! [BOLT #9]: https://github.com/lightning/bolts/blob/master/09-features.md
5761//! [messages]: crate::ln::msgs
@@ -122,7 +126,7 @@ mod sealed {
122126 // Byte 1
123127 VariableLengthOnion | StaticRemoteKey | PaymentSecret ,
124128 // Byte 2
125- BasicMPP | Wumbo ,
129+ BasicMPP | Wumbo | AnchorsZeroFeeHtlcTx ,
126130 // Byte 3
127131 ShutdownAnySegwit ,
128132 // Byte 4
@@ -138,7 +142,7 @@ mod sealed {
138142 // Byte 1
139143 VariableLengthOnion | StaticRemoteKey | PaymentSecret ,
140144 // Byte 2
141- BasicMPP | Wumbo ,
145+ BasicMPP | Wumbo | AnchorsZeroFeeHtlcTx ,
142146 // Byte 3
143147 ShutdownAnySegwit ,
144148 // Byte 4
@@ -176,7 +180,7 @@ mod sealed {
176180 // Byte 1
177181 StaticRemoteKey ,
178182 // Byte 2
179- ,
183+ AnchorsZeroFeeHtlcTx ,
180184 // Byte 3
181185 ,
182186 // Byte 4
@@ -357,6 +361,9 @@ mod sealed {
357361 define_feature ! ( 19 , Wumbo , [ InitContext , NodeContext ] ,
358362 "Feature flags for `option_support_large_channel` (aka wumbo channels)." , set_wumbo_optional, set_wumbo_required,
359363 supports_wumbo, requires_wumbo) ;
364+ define_feature ! ( 23 , AnchorsZeroFeeHtlcTx , [ InitContext , NodeContext , ChannelTypeContext ] ,
365+ "Feature flags for `option_anchors_zero_fee_htlc_tx`." , set_anchors_zero_fee_htlc_tx_optional,
366+ set_anchors_zero_fee_htlc_tx_required, supports_anchors_zero_fee_htlc_tx, requires_anchors_zero_fee_htlc_tx) ;
360367 define_feature ! ( 27 , ShutdownAnySegwit , [ InitContext , NodeContext ] ,
361368 "Feature flags for `opt_shutdown_anysegwit`." , set_shutdown_any_segwit_optional,
362369 set_shutdown_any_segwit_required, supports_shutdown_anysegwit, requires_shutdown_anysegwit) ;
@@ -505,10 +512,10 @@ impl InvoiceFeatures {
505512}
506513
507514impl ChannelTypeFeatures {
508- /// Constructs the implicit channel type based on the common supported types between us and our
509- /// counterparty
510- pub ( crate ) fn from_counterparty_init ( counterparty_init : & InitFeatures ) -> Self {
511- let mut ret = counterparty_init . to_context_internal ( ) ;
515+ // Maps the relevant `InitFeatures` to `ChannelTypeFeatures`. Any unknown features to
516+ // `ChannelTypeFeatures` are not included in the result.
517+ pub ( crate ) fn from_init ( init : & InitFeatures ) -> Self {
518+ let mut ret = init . to_context_internal ( ) ;
512519 // ChannelTypeFeatures must only contain required bits, so we OR the required forms of all
513520 // optional bits and then AND out the optional ones.
514521 for byte in ret. flags . iter_mut ( ) {
@@ -678,6 +685,24 @@ impl<T: sealed::Context> Features<T> {
678685 ( byte & unknown_features) != 0
679686 } )
680687 }
688+
689+ // Returns true if the features within `self` are a subset of the features within `other`.
690+ pub ( crate ) fn is_subset ( & self , other : & Self ) -> bool {
691+ for ( idx, byte) in self . flags . iter ( ) . enumerate ( ) {
692+ if let Some ( other_byte) = other. flags . get ( idx) {
693+ if byte & other_byte != * byte {
694+ // `self` has bits set that `other` doesn't.
695+ return false ;
696+ }
697+ } else {
698+ if * byte > 0 {
699+ // `self` has a non-zero byte that `other` doesn't.
700+ return false ;
701+ }
702+ }
703+ }
704+ true
705+ }
681706}
682707
683708impl < T : sealed:: UpfrontShutdownScript > Features < T > {
@@ -704,6 +729,18 @@ impl<T: sealed::Wumbo> Features<T> {
704729 }
705730}
706731
732+ impl < T : sealed:: SCIDPrivacy > Features < T > {
733+ pub ( crate ) fn clear_scid_privacy ( & mut self ) {
734+ <T as sealed:: SCIDPrivacy >:: clear_bits ( & mut self . flags ) ;
735+ }
736+ }
737+
738+ impl < T : sealed:: AnchorsZeroFeeHtlcTx > Features < T > {
739+ pub ( crate ) fn clear_anchors_zero_fee_htlc_tx ( & mut self ) {
740+ <T as sealed:: AnchorsZeroFeeHtlcTx >:: clear_bits ( & mut self . flags ) ;
741+ }
742+ }
743+
707744#[ cfg( test) ]
708745impl < T : sealed:: UnknownFeature > Features < T > {
709746 pub ( crate ) fn unknown ( ) -> Self {
@@ -808,6 +845,7 @@ mod tests {
808845 init_features. set_channel_type_optional ( ) ;
809846 init_features. set_scid_privacy_optional ( ) ;
810847 init_features. set_zero_conf_optional ( ) ;
848+ init_features. set_anchors_zero_fee_htlc_tx_optional ( ) ;
811849
812850 assert ! ( init_features. initial_routing_sync( ) ) ;
813851 assert ! ( !init_features. supports_upfront_shutdown_script( ) ) ;
@@ -826,7 +864,7 @@ mod tests {
826864 assert_eq ! ( node_features. flags. len( ) , 7 ) ;
827865 assert_eq ! ( node_features. flags[ 0 ] , 0b00000010 ) ;
828866 assert_eq ! ( node_features. flags[ 1 ] , 0b01010001 ) ;
829- assert_eq ! ( node_features. flags[ 2 ] , 0b00001010 ) ;
867+ assert_eq ! ( node_features. flags[ 2 ] , 0b10001010 ) ;
830868 assert_eq ! ( node_features. flags[ 3 ] , 0b00001000 ) ;
831869 assert_eq ! ( node_features. flags[ 4 ] , 0b10000000 ) ;
832870 assert_eq ! ( node_features. flags[ 5 ] , 0b10100000 ) ;
@@ -917,7 +955,7 @@ mod tests {
917955 // required-StaticRemoteKey ChannelTypeFeatures.
918956 let mut init_features = InitFeatures :: empty ( ) ;
919957 init_features. set_static_remote_key_optional ( ) ;
920- let converted_features = ChannelTypeFeatures :: from_counterparty_init ( & init_features) ;
958+ let converted_features = ChannelTypeFeatures :: from_init ( & init_features) ;
921959 assert_eq ! ( converted_features, ChannelTypeFeatures :: only_static_remote_key( ) ) ;
922960 assert ! ( !converted_features. supports_any_optional_bits( ) ) ;
923961 assert ! ( converted_features. requires_static_remote_key( ) ) ;
0 commit comments