52
52
//! (see [BOLT-2](https://github.com/lightning/bolts/blob/master/02-peer-protocol.md) for more information).
53
53
//! - `Keysend` - send funds to a node without an invoice
54
54
//! (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).
55
59
//!
56
60
//! [BOLT #9]: https://github.com/lightning/bolts/blob/master/09-features.md
57
61
//! [messages]: crate::ln::msgs
@@ -122,7 +126,7 @@ mod sealed {
122
126
// Byte 1
123
127
VariableLengthOnion | StaticRemoteKey | PaymentSecret ,
124
128
// Byte 2
125
- BasicMPP | Wumbo ,
129
+ BasicMPP | Wumbo | AnchorsZeroFeeHtlcTx ,
126
130
// Byte 3
127
131
ShutdownAnySegwit ,
128
132
// Byte 4
@@ -138,7 +142,7 @@ mod sealed {
138
142
// Byte 1
139
143
VariableLengthOnion | StaticRemoteKey | PaymentSecret ,
140
144
// Byte 2
141
- BasicMPP | Wumbo ,
145
+ BasicMPP | Wumbo | AnchorsZeroFeeHtlcTx ,
142
146
// Byte 3
143
147
ShutdownAnySegwit ,
144
148
// Byte 4
@@ -176,7 +180,7 @@ mod sealed {
176
180
// Byte 1
177
181
StaticRemoteKey ,
178
182
// Byte 2
179
- ,
183
+ AnchorsZeroFeeHtlcTx ,
180
184
// Byte 3
181
185
,
182
186
// Byte 4
@@ -357,6 +361,9 @@ mod sealed {
357
361
define_feature ! ( 19 , Wumbo , [ InitContext , NodeContext ] ,
358
362
"Feature flags for `option_support_large_channel` (aka wumbo channels)." , set_wumbo_optional, set_wumbo_required,
359
363
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) ;
360
367
define_feature ! ( 27 , ShutdownAnySegwit , [ InitContext , NodeContext ] ,
361
368
"Feature flags for `opt_shutdown_anysegwit`." , set_shutdown_any_segwit_optional,
362
369
set_shutdown_any_segwit_required, supports_shutdown_anysegwit, requires_shutdown_anysegwit) ;
@@ -505,10 +512,10 @@ impl InvoiceFeatures {
505
512
}
506
513
507
514
impl 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 ( ) ;
512
519
// ChannelTypeFeatures must only contain required bits, so we OR the required forms of all
513
520
// optional bits and then AND out the optional ones.
514
521
for byte in ret. flags . iter_mut ( ) {
@@ -678,6 +685,24 @@ impl<T: sealed::Context> Features<T> {
678
685
( byte & unknown_features) != 0
679
686
} )
680
687
}
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
+ }
681
706
}
682
707
683
708
impl < T : sealed:: UpfrontShutdownScript > Features < T > {
@@ -704,6 +729,18 @@ impl<T: sealed::Wumbo> Features<T> {
704
729
}
705
730
}
706
731
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
+
707
744
#[ cfg( test) ]
708
745
impl < T : sealed:: UnknownFeature > Features < T > {
709
746
pub ( crate ) fn unknown ( ) -> Self {
@@ -808,6 +845,7 @@ mod tests {
808
845
init_features. set_channel_type_optional ( ) ;
809
846
init_features. set_scid_privacy_optional ( ) ;
810
847
init_features. set_zero_conf_optional ( ) ;
848
+ init_features. set_anchors_zero_fee_htlc_tx_optional ( ) ;
811
849
812
850
assert ! ( init_features. initial_routing_sync( ) ) ;
813
851
assert ! ( !init_features. supports_upfront_shutdown_script( ) ) ;
@@ -826,7 +864,7 @@ mod tests {
826
864
assert_eq ! ( node_features. flags. len( ) , 7 ) ;
827
865
assert_eq ! ( node_features. flags[ 0 ] , 0b00000010 ) ;
828
866
assert_eq ! ( node_features. flags[ 1 ] , 0b01010001 ) ;
829
- assert_eq ! ( node_features. flags[ 2 ] , 0b00001010 ) ;
867
+ assert_eq ! ( node_features. flags[ 2 ] , 0b10001010 ) ;
830
868
assert_eq ! ( node_features. flags[ 3 ] , 0b00001000 ) ;
831
869
assert_eq ! ( node_features. flags[ 4 ] , 0b10000000 ) ;
832
870
assert_eq ! ( node_features. flags[ 5 ] , 0b10100000 ) ;
@@ -917,7 +955,7 @@ mod tests {
917
955
// required-StaticRemoteKey ChannelTypeFeatures.
918
956
let mut init_features = InitFeatures :: empty ( ) ;
919
957
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) ;
921
959
assert_eq ! ( converted_features, ChannelTypeFeatures :: only_static_remote_key( ) ) ;
922
960
assert ! ( !converted_features. supports_any_optional_bits( ) ) ;
923
961
assert ! ( converted_features. requires_static_remote_key( ) ) ;
0 commit comments