@@ -1557,6 +1557,7 @@ impl<SP: Deref> Channel<SP> where
1557
1557
1558
1558
pub fn maybe_handle_error_without_close<F: Deref, L: Deref>(
1559
1559
&mut self, chain_hash: ChainHash, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1560
+ user_config: &UserConfig, their_features: &InitFeatures,
1560
1561
) -> Result<Option<OpenChannelMessage>, ()>
1561
1562
where
1562
1563
F::Target: FeeEstimator,
@@ -1567,13 +1568,17 @@ impl<SP: Deref> Channel<SP> where
1567
1568
ChannelPhase::Funded(_) => Ok(None),
1568
1569
ChannelPhase::UnfundedOutboundV1(chan) => {
1569
1570
let logger = WithChannelContext::from(logger, &chan.context, None);
1570
- chan.maybe_handle_error_without_close(chain_hash, fee_estimator, &&logger)
1571
+ chan.maybe_handle_error_without_close(
1572
+ chain_hash, fee_estimator, &&logger, user_config, their_features,
1573
+ )
1571
1574
.map(|msg| Some(OpenChannelMessage::V1(msg)))
1572
1575
},
1573
1576
ChannelPhase::UnfundedInboundV1(_) => Ok(None),
1574
1577
ChannelPhase::UnfundedV2(chan) => {
1575
1578
if chan.funding.is_outbound() {
1576
- chan.maybe_handle_error_without_close(chain_hash, fee_estimator)
1579
+ chan.maybe_handle_error_without_close(
1580
+ chain_hash, fee_estimator, user_config, their_features,
1581
+ )
1577
1582
.map(|msg| Some(OpenChannelMessage::V2(msg)))
1578
1583
} else {
1579
1584
Ok(None)
@@ -4868,7 +4873,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4868
4873
/// of the channel type we tried, not of our ability to open any channel at all. We can see if a
4869
4874
/// downgrade of channel features would be possible so that we can still open the channel.
4870
4875
pub(crate) fn maybe_downgrade_channel_features<F: Deref>(
4871
- &mut self, funding: &mut FundingScope, fee_estimator: &LowerBoundedFeeEstimator<F>
4876
+ &mut self, funding: &mut FundingScope, fee_estimator: &LowerBoundedFeeEstimator<F>,
4877
+ user_config: &UserConfig, their_features: &InitFeatures,
4872
4878
) -> Result<(), ()>
4873
4879
where
4874
4880
F::Target: FeeEstimator
@@ -4889,21 +4895,35 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4889
4895
// features one by one until we've either arrived at our default or the counterparty has
4890
4896
// accepted one.
4891
4897
//
4892
- // Due to the order below, we may not negotiate `option_anchors_zero_fee_htlc_tx` if the
4893
- // counterparty doesn't support `option_scid_privacy`. Since `get_initial_channel_type`
4894
- // checks whether the counterparty supports every feature, this would only happen if the
4895
- // counterparty is advertising the feature, but rejecting channels proposing the feature for
4896
- // whatever reason.
4897
- let channel_type = &mut funding.channel_transaction_parameters.channel_type_features;
4898
+ // To downgrade the current channel type, we start with the remote party's full set of
4899
+ // feature bits and un-set any features that are set for the current channel type or any
4900
+ // channel types that come before it in our order of preference. This will allow us to
4901
+ // negotiate the "next best" channel type per our ranking in `get_initial_channel_type`.
4902
+ let channel_type = &funding.channel_transaction_parameters.channel_type_features;
4903
+ let mut eligible_features = their_features.clone();
4904
+
4898
4905
if channel_type.supports_anchors_zero_fee_htlc_tx() {
4899
- channel_type .clear_anchors_zero_fee_htlc_tx();
4900
- self.feerate_per_kw = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee );
4901
- assert!(!channel_type.supports_anchors_nonzero_fee_htlc_tx ());
4906
+ eligible_features .clear_anchors_zero_fee_htlc_tx();
4907
+ assert!(!eligible_features.supports_anchors_nonzero_fee_htlc_tx() );
4908
+ assert!(!eligible_features.supports_anchors_zero_fee_htlc_tx ());
4902
4909
} else if channel_type.supports_scid_privacy() {
4903
- channel_type.clear_scid_privacy();
4904
- } else {
4905
- *channel_type = ChannelTypeFeatures::only_static_remote_key();
4910
+ eligible_features.clear_scid_privacy();
4911
+ eligible_features.clear_anchors_zero_fee_htlc_tx();
4912
+ assert!(!eligible_features.supports_scid_privacy());
4913
+ assert!(!eligible_features.supports_anchors_nonzero_fee_htlc_tx());
4914
+ assert!(!eligible_features.supports_anchors_zero_fee_htlc_tx());
4906
4915
}
4916
+
4917
+ let next_channel_type = get_initial_channel_type(user_config, &eligible_features);
4918
+
4919
+ let conf_target = if next_channel_type.supports_anchors_zero_fee_htlc_tx() {
4920
+ ConfirmationTarget::AnchorChannelFee
4921
+ } else {
4922
+ ConfirmationTarget::NonAnchorChannelFee
4923
+ };
4924
+ self.feerate_per_kw = fee_estimator.bounded_sat_per_1000_weight(conf_target);
4925
+ funding.channel_transaction_parameters.channel_type_features = next_channel_type;
4926
+
4907
4927
Ok(())
4908
4928
}
4909
4929
@@ -9893,13 +9913,16 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
9893
9913
/// not of our ability to open any channel at all. Thus, on error, we should first call this
9894
9914
/// and see if we get a new `OpenChannel` message, otherwise the channel is failed.
9895
9915
pub(crate) fn maybe_handle_error_without_close<F: Deref, L: Deref>(
9896
- &mut self, chain_hash: ChainHash, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
9916
+ &mut self, chain_hash: ChainHash, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
9917
+ user_config: &UserConfig, their_features: &InitFeatures,
9897
9918
) -> Result<msgs::OpenChannel, ()>
9898
9919
where
9899
9920
F::Target: FeeEstimator,
9900
9921
L::Target: Logger,
9901
9922
{
9902
- self.context.maybe_downgrade_channel_features(&mut self.funding, fee_estimator)?;
9923
+ self.context.maybe_downgrade_channel_features(
9924
+ &mut self.funding, fee_estimator, user_config, their_features,
9925
+ )?;
9903
9926
self.get_open_channel(chain_hash, logger).ok_or(())
9904
9927
}
9905
9928
@@ -10405,12 +10428,15 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
10405
10428
/// not of our ability to open any channel at all. Thus, on error, we should first call this
10406
10429
/// and see if we get a new `OpenChannelV2` message, otherwise the channel is failed.
10407
10430
pub(crate) fn maybe_handle_error_without_close<F: Deref>(
10408
- &mut self, chain_hash: ChainHash, fee_estimator: &LowerBoundedFeeEstimator<F>
10431
+ &mut self, chain_hash: ChainHash, fee_estimator: &LowerBoundedFeeEstimator<F>,
10432
+ user_config: &UserConfig, their_features: &InitFeatures,
10409
10433
) -> Result<msgs::OpenChannelV2, ()>
10410
10434
where
10411
10435
F::Target: FeeEstimator
10412
10436
{
10413
- self.context.maybe_downgrade_channel_features(&mut self.funding, fee_estimator)?;
10437
+ self.context.maybe_downgrade_channel_features(
10438
+ &mut self.funding, fee_estimator, user_config, their_features,
10439
+ )?;
10414
10440
Ok(self.get_open_channel_v2(chain_hash))
10415
10441
}
10416
10442
0 commit comments