@@ -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));
@@ -6039,7 +6054,7 @@ impl<Signer: WriteableEcdsaChannelSigner> InboundV1Channel<Signer> {
60396054 if msg.htlc_minimum_msat >= full_channel_value_msat {
60406055 return Err(ChannelError::Close(format!("Minimum htlc value ({}) was larger than full channel value ({})", msg.htlc_minimum_msat, full_channel_value_msat)));
60416056 }
6042- Channel::<Signer>::check_remote_fee(fee_estimator, msg.feerate_per_kw, None, logger)?;
6057+ Channel::<Signer>::check_remote_fee(&channel_type, fee_estimator, msg.feerate_per_kw, None, logger)?;
60436058
60446059 let max_counterparty_selected_contest_delay = u16::min(config.channel_handshake_limits.their_to_self_delay, MAX_LOCAL_BREAKDOWN_TIMEOUT);
60456060 if msg.to_self_delay > max_counterparty_selected_contest_delay {
@@ -7441,7 +7456,8 @@ mod tests {
74417456 // arithmetic, causing a panic with debug assertions enabled.
74427457 let fee_est = TestFeeEstimator { fee_est: 42 };
74437458 let bounded_fee_estimator = LowerBoundedFeeEstimator::new(&fee_est);
7444- assert!(Channel::<InMemorySigner>::check_remote_fee(&bounded_fee_estimator,
7459+ assert!(Channel::<InMemorySigner>::check_remote_fee(
7460+ &ChannelTypeFeatures::only_static_remote_key(), &bounded_fee_estimator,
74457461 u32::max_value(), None, &&test_utils::TestLogger::new()).is_err());
74467462 }
74477463
0 commit comments