@@ -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));
@@ -6039,7 +6054,7 @@ impl<Signer: WriteableEcdsaChannelSigner> InboundV1Channel<Signer> {
6039
6054
if msg.htlc_minimum_msat >= full_channel_value_msat {
6040
6055
return Err(ChannelError::Close(format!("Minimum htlc value ({}) was larger than full channel value ({})", msg.htlc_minimum_msat, full_channel_value_msat)));
6041
6056
}
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)?;
6043
6058
6044
6059
let max_counterparty_selected_contest_delay = u16::min(config.channel_handshake_limits.their_to_self_delay, MAX_LOCAL_BREAKDOWN_TIMEOUT);
6045
6060
if msg.to_self_delay > max_counterparty_selected_contest_delay {
@@ -7441,7 +7456,8 @@ mod tests {
7441
7456
// arithmetic, causing a panic with debug assertions enabled.
7442
7457
let fee_est = TestFeeEstimator { fee_est: 42 };
7443
7458
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,
7445
7461
u32::max_value(), None, &&test_utils::TestLogger::new()).is_err());
7446
7462
}
7447
7463
0 commit comments