Skip to content

Commit 697b41b

Browse files
committed
validate_update_fee
1 parent d239e94 commit 697b41b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,16 +4235,31 @@ where
42354235
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
42364236
&fee_estimator, funding.get_channel_type(),
42374237
);
4238-
let htlc_stats = self.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
4238+
let next_commitment_htlcs = self.next_commitment_htlcs(None);
4239+
let value_to_self_msat = self.get_next_commitment_value_to_self_msat(funding);
4240+
let next_commitment_stats = SpecTxBuilder {}.get_builder_stats(funding.is_outbound(), funding.get_value_satoshis(), value_to_self_msat, &next_commitment_htlcs, 0, msg.feerate_per_kw, dust_exposure_limiting_feerate, funding.get_channel_type(), self.holder_dust_limit_satoshis, self.counterparty_dust_limit_satoshis);
4241+
42394242
let max_dust_htlc_exposure_msat = self.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
4240-
if htlc_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
4243+
if next_commitment_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
42414244
return Err(ChannelError::close(format!("Peer sent update_fee with a feerate ({}) which may over-expose us to dust-in-flight on our own transactions (totaling {} msat)",
4242-
msg.feerate_per_kw, htlc_stats.on_holder_tx_dust_exposure_msat)));
4245+
msg.feerate_per_kw, next_commitment_stats.on_holder_tx_dust_exposure_msat)));
42434246
}
4244-
if htlc_stats.on_counterparty_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
4247+
if next_commitment_stats.on_counterparty_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
42454248
return Err(ChannelError::close(format!("Peer sent update_fee with a feerate ({}) which may over-expose us to dust-in-flight on our counterparty's transactions (totaling {} msat)",
4246-
msg.feerate_per_kw, htlc_stats.on_counterparty_tx_dust_exposure_msat)));
4249+
msg.feerate_per_kw, next_commitment_stats.on_counterparty_tx_dust_exposure_msat)));
4250+
}
4251+
4252+
#[cfg(any(test, fuzzing))]
4253+
{
4254+
let mut predicted_htlcs = next_commitment_htlcs;
4255+
predicted_htlcs.sort_unstable();
4256+
*funding.next_local_fee.lock().unwrap() = PredictedNextFee {
4257+
predicted_feerate: msg.feerate_per_kw,
4258+
predicted_htlcs,
4259+
predicted_fee_sat: next_commitment_stats.holder_commit_tx_fee_sat,
4260+
};
42474261
}
4262+
42484263
Ok(())
42494264
}
42504265

0 commit comments

Comments
 (0)