@@ -880,6 +880,9 @@ impl<Signer: Sign> Channel<Signer> {
880
880
if !config. channel_handshake_config . announced_channel && config. channel_handshake_config . negotiate_scid_privacy {
881
881
ret. set_scid_privacy_required ( ) ;
882
882
}
883
+ if config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx {
884
+ ret. set_anchors_zero_fee_htlc_tx_required ( ) ;
885
+ }
883
886
ret
884
887
}
885
888
@@ -905,7 +908,8 @@ impl<Signer: Sign> Channel<Signer> {
905
908
where K :: Target : KeysInterface < Signer = Signer > ,
906
909
F :: Target : FeeEstimator ,
907
910
{
908
- let opt_anchors = false ; // TODO - should be based on features
911
+ let opt_anchors = config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx &&
912
+ their_features. supports_anchors_zero_fee_htlc_tx ( ) ;
909
913
910
914
let holder_selected_contest_delay = config. channel_handshake_config . our_to_self_delay ;
911
915
let holder_signer = keys_provider. get_channel_signer ( false , channel_value_satoshis) ;
@@ -1104,7 +1108,6 @@ impl<Signer: Sign> Channel<Signer> {
1104
1108
F :: Target : FeeEstimator ,
1105
1109
L :: Target : Logger ,
1106
1110
{
1107
- let opt_anchors = false ; // TODO - should be based on features
1108
1111
let announced_channel = if ( msg. channel_flags & 1 ) == 1 { true } else { false } ;
1109
1112
1110
1113
// First check the channel type is known, failing before we do anything else if we don't
@@ -1118,13 +1121,24 @@ impl<Signer: Sign> Channel<Signer> {
1118
1121
return Err ( ChannelError :: Close ( "Channel Type field contains unknown bits" . to_owned ( ) ) ) ;
1119
1122
}
1120
1123
1121
- // We currently only allow four channel types, so write it all out here - we allow
1122
- // `only_static_remote_key` or `static_remote_key | zero_conf` in all contexts, and
1123
- // further allow `static_remote_key | scid_privacy` or
1124
- // `static_remote_key | scid_privacy | zero_conf`, if the channel is not
1125
- // publicly announced.
1124
+ // We currently only allow 8 channel types, and all must support `static_remote_key`, so
1125
+ // write it all out here - we allow
1126
+ // - `only_static_remote_key`
1127
+ // - `static_remote_key | zero_conf`
1128
+ // - `static_remote_key | scid_privacy`
1129
+ // - `static_remote_key | scid_privacy | zero_conf`
1130
+ // - `static_remote_key | anchors_zero_fee_htlc_tx`
1131
+ // - `static_remote_key | anchors_zero_fee_htlc_tx | zero_conf`
1132
+ // - `static_remote_key | anchors_zero_fee_htlc_tx | scid_privacy`
1133
+ // - `static_remote_key | anchors_zero_fee_htlc_tx | scid_privacy | zero_conf`
1134
+ if !channel_type. requires_static_remote_key ( ) {
1135
+ return Err ( ChannelError :: Close ( "Channel Type was not understood - we require static remote key" . to_owned ( ) ) ) ;
1136
+ }
1126
1137
if * channel_type != ChannelTypeFeatures :: only_static_remote_key ( ) {
1127
- if !channel_type. requires_scid_privacy ( ) && !channel_type. requires_zero_conf ( ) {
1138
+ // If we have more features than just `static_remote_key`, make sure we only allow
1139
+ // those we support.
1140
+ if !channel_type. requires_scid_privacy ( ) && !channel_type. requires_zero_conf ( ) &&
1141
+ !channel_type. requires_anchors_zero_fee_htlc_tx ( ) {
1128
1142
return Err ( ChannelError :: Close ( "Channel Type was not understood" . to_owned ( ) ) ) ;
1129
1143
}
1130
1144
@@ -1136,9 +1150,7 @@ impl<Signer: Sign> Channel<Signer> {
1136
1150
} else {
1137
1151
ChannelTypeFeatures :: from_counterparty_init ( & their_features)
1138
1152
} ;
1139
- if !channel_type. supports_static_remote_key ( ) {
1140
- return Err ( ChannelError :: Close ( "Channel Type was not understood - we require static remote key" . to_owned ( ) ) ) ;
1141
- }
1153
+ let opt_anchors = channel_type. supports_anchors_zero_fee_htlc_tx ( ) ;
1142
1154
1143
1155
let holder_signer = keys_provider. get_channel_signer ( true , msg. funding_satoshis ) ;
1144
1156
let pubkeys = holder_signer. pubkeys ( ) . clone ( ) ;
@@ -2081,7 +2093,12 @@ impl<Signer: Sign> Channel<Signer> {
2081
2093
} else if their_features. supports_channel_type ( ) {
2082
2094
// Assume they've accepted the channel type as they said they understand it.
2083
2095
} else {
2084
- self . channel_type = ChannelTypeFeatures :: from_counterparty_init ( & their_features)
2096
+ self . channel_type = ChannelTypeFeatures :: from_counterparty_init ( & their_features) ;
2097
+ self . channel_transaction_parameters . opt_anchors = if self . channel_type . supports_anchors_zero_fee_htlc_tx ( ) {
2098
+ Some ( ( ) )
2099
+ } else {
2100
+ None
2101
+ } ;
2085
2102
}
2086
2103
2087
2104
let counterparty_shutdown_scriptpubkey = if their_features. supports_upfront_shutdown_script ( ) {
@@ -6554,11 +6571,6 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6554
6571
return Err ( DecodeError :: UnknownRequiredFeature ) ;
6555
6572
}
6556
6573
6557
- if channel_parameters. opt_anchors . is_some ( ) {
6558
- // Relax this check when ChannelTypeFeatures supports anchors.
6559
- return Err ( DecodeError :: InvalidValue ) ;
6560
- }
6561
-
6562
6574
let mut secp_ctx = Secp256k1 :: new ( ) ;
6563
6575
secp_ctx. seeded_randomize ( & keys_source. get_secure_random_bytes ( ) ) ;
6564
6576
0 commit comments