@@ -2045,20 +2045,35 @@ struct CommitmentTxInfoCached {
2045
2045
}
2046
2046
2047
2047
impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2048
- fn check_remote_fee<F: Deref, L: Deref>(fee_estimator: &LowerBoundedFeeEstimator<F>,
2049
- feerate_per_kw: u32, cur_feerate_per_kw: Option<u32>, logger: &L)
2050
- -> Result<(), ChannelError> where F::Target: FeeEstimator, L::Target: Logger,
2048
+ fn check_remote_fee<F: Deref, L: Deref>(
2049
+ channel_type: &ChannelTypeFeatures, fee_estimator: &LowerBoundedFeeEstimator<F>,
2050
+ feerate_per_kw: u32, cur_feerate_per_kw: Option<u32>, logger: &L
2051
+ ) -> Result<(), ChannelError> where F::Target: FeeEstimator, L::Target: Logger,
2051
2052
{
2052
2053
// We only bound the fee updates on the upper side to prevent completely absurd feerates,
2053
2054
// always accepting up to 25 sat/vByte or 10x our fee estimator's "High Priority" fee.
2054
2055
// We generally don't care too much if they set the feerate to something very high, but it
2055
- // could result in the channel being useless due to everything being dust.
2056
- let upper_limit = cmp::max(250 * 25,
2057
- fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::HighPriority) as u64 * 10);
2058
- if feerate_per_kw as u64 > upper_limit {
2059
- return Err(ChannelError::Close(format!("Peer's feerate much too high. Actual: {}. Our expected upper limit: {}", feerate_per_kw, upper_limit)));
2060
- }
2061
- let lower_limit = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Background);
2056
+ // could result in the channel being useless due to everything being dust. This doesn't
2057
+ // apply to channels supporting anchor outputs since HTLC transactions are pre-signed with a
2058
+ // zero fee, so their fee is no longer considered to determine dust limits.
2059
+ if !channel_type.supports_anchors_zero_fee_htlc_tx() {
2060
+ let upper_limit = cmp::max(250 * 25,
2061
+ fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::HighPriority) as u64 * 10);
2062
+ if feerate_per_kw as u64 > upper_limit {
2063
+ return Err(ChannelError::Close(format!("Peer's feerate much too high. Actual: {}. Our expected upper limit: {}", feerate_per_kw, upper_limit)));
2064
+ }
2065
+ }
2066
+
2067
+ // We can afford to use a lower bound with anchors than previously since we can now bump
2068
+ // fees when broadcasting our commitment. However, we must still make sure we meet the
2069
+ // minimum mempool feerate, until package relay is deployed, such that we can ensure the
2070
+ // commitment transaction propagates throughout node mempools on its own.
2071
+ let lower_limit_conf_target = if channel_type.supports_anchors_zero_fee_htlc_tx() {
2072
+ ConfirmationTarget::MempoolMinimum
2073
+ } else {
2074
+ ConfirmationTarget::Background
2075
+ };
2076
+ let lower_limit = fee_estimator.bounded_sat_per_1000_weight(lower_limit_conf_target);
2062
2077
// Some fee estimators round up to the next full sat/vbyte (ie 250 sats per kw), causing
2063
2078
// occasional issues with feerate disagreements between an initiator that wants a feerate
2064
2079
// of 1.1 sat/vbyte and a receiver that wants 1.1 rounded up to 2. Thus, we always add 250
@@ -3688,7 +3703,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
3688
3703
if self.context.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 {
3689
3704
return Err(ChannelError::Close("Peer sent update_fee when we needed a channel_reestablish".to_owned()));
3690
3705
}
3691
- Channel::<Signer>::check_remote_fee(fee_estimator, msg.feerate_per_kw, Some(self.context.feerate_per_kw), logger)?;
3706
+ Channel::<Signer>::check_remote_fee(&self.context.channel_type, fee_estimator, msg.feerate_per_kw, Some(self.context.feerate_per_kw), logger)?;
3692
3707
let feerate_over_dust_buffer = msg.feerate_per_kw > self.context.get_dust_buffer_feerate(None);
3693
3708
3694
3709
self.context.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
@@ -5502,10 +5517,15 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
5502
5517
let channel_type = Self::get_initial_channel_type(&config, their_features);
5503
5518
debug_assert!(channel_type.is_subset(&channelmanager::provided_channel_type_features(&config)));
5504
5519
5505
- let feerate = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
5520
+ let commitment_conf_target = if channel_type.supports_anchors_zero_fee_htlc_tx() {
5521
+ ConfirmationTarget::MempoolMinimum
5522
+ } else {
5523
+ ConfirmationTarget::Normal
5524
+ };
5525
+ let commitment_feerate = fee_estimator.bounded_sat_per_1000_weight(commitment_conf_target);
5506
5526
5507
5527
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
5508
- let commitment_tx_fee = commit_tx_fee_msat(feerate , MIN_AFFORDABLE_HTLC_COUNT, &channel_type);
5528
+ let commitment_tx_fee = commit_tx_fee_msat(commitment_feerate , MIN_AFFORDABLE_HTLC_COUNT, &channel_type);
5509
5529
if value_to_self_msat < commitment_tx_fee {
5510
5530
return Err(APIError::APIMisuseError{ err: format!("Funding amount ({}) can't even pay fee for initial commitment transaction fee of {}.", value_to_self_msat / 1000, commitment_tx_fee / 1000) });
5511
5531
}
@@ -5599,7 +5619,7 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
5599
5619
short_channel_id: None,
5600
5620
channel_creation_height: current_chain_height,
5601
5621
5602
- feerate_per_kw: feerate ,
5622
+ feerate_per_kw: commitment_feerate ,
5603
5623
counterparty_dust_limit_satoshis: 0,
5604
5624
holder_dust_limit_satoshis: MIN_CHAN_DUST_LIMIT_SATOSHIS,
5605
5625
counterparty_max_htlc_value_in_flight_msat: 0,
@@ -5753,7 +5773,12 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
5753
5773
/// If we receive an error message, it may only be a rejection of the channel type we tried,
5754
5774
/// not of our ability to open any channel at all. Thus, on error, we should first call this
5755
5775
/// and see if we get a new `OpenChannel` message, otherwise the channel is failed.
5756
- pub(crate) fn maybe_handle_error_without_close(&mut self, chain_hash: BlockHash) -> Result<msgs::OpenChannel, ()> {
5776
+ pub(crate) fn maybe_handle_error_without_close<F: Deref>(
5777
+ &mut self, chain_hash: BlockHash, fee_estimator: &LowerBoundedFeeEstimator<F>
5778
+ ) -> Result<msgs::OpenChannel, ()>
5779
+ where
5780
+ F::Target: FeeEstimator
5781
+ {
5757
5782
if !self.context.is_outbound() || self.context.channel_state != ChannelState::OurInitSent as u32 { return Err(()); }
5758
5783
if self.context.channel_type == ChannelTypeFeatures::only_static_remote_key() {
5759
5784
// We've exhausted our options
@@ -5770,6 +5795,7 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
5770
5795
// whatever reason.
5771
5796
if self.context.channel_type.supports_anchors_zero_fee_htlc_tx() {
5772
5797
self.context.channel_type.clear_anchors_zero_fee_htlc_tx();
5798
+ self.context.feerate_per_kw = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
5773
5799
assert!(!self.context.channel_transaction_parameters.channel_type_features.supports_anchors_nonzero_fee_htlc_tx());
5774
5800
} else if self.context.channel_type.supports_scid_privacy() {
5775
5801
self.context.channel_type.clear_scid_privacy();
@@ -6039,7 +6065,7 @@ impl<Signer: WriteableEcdsaChannelSigner> InboundV1Channel<Signer> {
6039
6065
if msg.htlc_minimum_msat >= full_channel_value_msat {
6040
6066
return Err(ChannelError::Close(format!("Minimum htlc value ({}) was larger than full channel value ({})", msg.htlc_minimum_msat, full_channel_value_msat)));
6041
6067
}
6042
- Channel::<Signer>::check_remote_fee(fee_estimator, msg.feerate_per_kw, None, logger)?;
6068
+ Channel::<Signer>::check_remote_fee(&channel_type, fee_estimator, msg.feerate_per_kw, None, logger)?;
6043
6069
6044
6070
let max_counterparty_selected_contest_delay = u16::min(config.channel_handshake_limits.their_to_self_delay, MAX_LOCAL_BREAKDOWN_TIMEOUT);
6045
6071
if msg.to_self_delay > max_counterparty_selected_contest_delay {
@@ -7441,7 +7467,8 @@ mod tests {
7441
7467
// arithmetic, causing a panic with debug assertions enabled.
7442
7468
let fee_est = TestFeeEstimator { fee_est: 42 };
7443
7469
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(&fee_est);
7444
- assert!(Channel::<InMemorySigner>::check_remote_fee(&bounded_fee_estimator,
7470
+ assert!(Channel::<InMemorySigner>::check_remote_fee(
7471
+ &ChannelTypeFeatures::only_static_remote_key(), &bounded_fee_estimator,
7445
7472
u32::max_value(), None, &&test_utils::TestLogger::new()).is_err());
7446
7473
}
7447
7474
0 commit comments