@@ -2045,20 +2045,35 @@ struct CommitmentTxInfoCached {
20452045}
20462046
20472047impl<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,
20512052 {
20522053 // We only bound the fee updates on the upper side to prevent completely absurd feerates,
20532054 // always accepting up to 25 sat/vByte or 10x our fee estimator's "High Priority" fee.
20542055 // 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);
20622077 // Some fee estimators round up to the next full sat/vbyte (ie 250 sats per kw), causing
20632078 // occasional issues with feerate disagreements between an initiator that wants a feerate
20642079 // 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> {
36883703 if self.context.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 {
36893704 return Err(ChannelError::Close("Peer sent update_fee when we needed a channel_reestablish".to_owned()));
36903705 }
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)?;
36923707 let feerate_over_dust_buffer = msg.feerate_per_kw > self.context.get_dust_buffer_feerate(None);
36933708
36943709 self.context.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
@@ -5502,10 +5517,15 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
55025517 let channel_type = Self::get_initial_channel_type(&config, their_features);
55035518 debug_assert!(channel_type.is_subset(&channelmanager::provided_channel_type_features(&config)));
55045519
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);
55065526
55075527 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);
55095529 if value_to_self_msat < commitment_tx_fee {
55105530 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) });
55115531 }
@@ -5599,7 +5619,7 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
55995619 short_channel_id: None,
56005620 channel_creation_height: current_chain_height,
56015621
5602- feerate_per_kw: feerate ,
5622+ feerate_per_kw: commitment_feerate ,
56035623 counterparty_dust_limit_satoshis: 0,
56045624 holder_dust_limit_satoshis: MIN_CHAN_DUST_LIMIT_SATOSHIS,
56055625 counterparty_max_htlc_value_in_flight_msat: 0,
@@ -5753,7 +5773,12 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
57535773 /// If we receive an error message, it may only be a rejection of the channel type we tried,
57545774 /// not of our ability to open any channel at all. Thus, on error, we should first call this
57555775 /// 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+ {
57575782 if !self.context.is_outbound() || self.context.channel_state != ChannelState::OurInitSent as u32 { return Err(()); }
57585783 if self.context.channel_type == ChannelTypeFeatures::only_static_remote_key() {
57595784 // We've exhausted our options
@@ -5770,6 +5795,7 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
57705795 // whatever reason.
57715796 if self.context.channel_type.supports_anchors_zero_fee_htlc_tx() {
57725797 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);
57735799 assert!(!self.context.channel_transaction_parameters.channel_type_features.supports_anchors_nonzero_fee_htlc_tx());
57745800 } else if self.context.channel_type.supports_scid_privacy() {
57755801 self.context.channel_type.clear_scid_privacy();
@@ -6039,7 +6065,7 @@ impl<Signer: WriteableEcdsaChannelSigner> InboundV1Channel<Signer> {
60396065 if msg.htlc_minimum_msat >= full_channel_value_msat {
60406066 return Err(ChannelError::Close(format!("Minimum htlc value ({}) was larger than full channel value ({})", msg.htlc_minimum_msat, full_channel_value_msat)));
60416067 }
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)?;
60436069
60446070 let max_counterparty_selected_contest_delay = u16::min(config.channel_handshake_limits.their_to_self_delay, MAX_LOCAL_BREAKDOWN_TIMEOUT);
60456071 if msg.to_self_delay > max_counterparty_selected_contest_delay {
@@ -7441,7 +7467,8 @@ mod tests {
74417467 // arithmetic, causing a panic with debug assertions enabled.
74427468 let fee_est = TestFeeEstimator { fee_est: 42 };
74437469 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,
74457472 u32::max_value(), None, &&test_utils::TestLogger::new()).is_err());
74467473 }
74477474
0 commit comments