Skip to content

Commit d5e636a

Browse files
committed
Remove commit_tx_fee_sat in send_update_fee
1 parent e390ee2 commit d5e636a

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

lightning/src/ln/channel.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use crate::ln::chan_utils::{
4545
HolderCommitmentTransaction, ChannelTransactionParameters,
4646
CounterpartyChannelTransactionParameters, max_htlcs,
4747
get_commitment_transaction_number_obscure_factor,
48-
ClosingTransaction, commit_tx_fee_sat,
48+
ClosingTransaction,
4949
};
5050
#[cfg(splicing)]
5151
use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
@@ -3865,14 +3865,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
38653865
/// Builds stats on a potential commitment transaction build, without actually building the
38663866
/// commitment transaction. See `build_commitment_transaction` for further docs.
38673867
#[inline]
3868-
fn build_commitment_stats(&self, funding: &FundingScope, local: bool, generated_by_local: bool) -> CommitmentStats {
3868+
fn build_commitment_stats(&self, funding: &FundingScope, local: bool, generated_by_local: bool, feerate_per_kw: Option<u32>, fee_buffer_nondust_htlcs: Option<usize>) -> CommitmentStats {
38693869
let broadcaster_dust_limit_sat = if local { self.holder_dust_limit_satoshis } else { self.counterparty_dust_limit_satoshis };
38703870
let mut nondust_htlc_count = 0;
38713871
let mut remote_htlc_total_msat = 0;
38723872
let mut local_htlc_total_msat = 0;
38733873
let mut value_to_self_msat_offset = 0;
38743874

3875-
let feerate_per_kw = self.get_commitment_feerate(funding, generated_by_local);
3875+
let feerate_per_kw = feerate_per_kw.unwrap_or_else(|| self.get_commitment_feerate(funding, generated_by_local));
38763876

38773877
for htlc in self.pending_inbound_htlcs.iter() {
38783878
if htlc.state.included_in_commitment(generated_by_local) {
@@ -3935,7 +3935,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
39353935
);
39363936

39373937
CommitmentStats {
3938-
total_fee_sat: builder.commit_tx_fee_sat(feerate_per_kw, nondust_htlc_count, &funding.channel_transaction_parameters.channel_type_features),
3938+
total_fee_sat: builder.commit_tx_fee_sat(feerate_per_kw, nondust_htlc_count + fee_buffer_nondust_htlcs.unwrap_or(0), &funding.channel_transaction_parameters.channel_type_features),
39393939
local_balance_before_fee_msat,
39403940
remote_balance_before_fee_msat,
39413941
}
@@ -3961,7 +3961,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
39613961
let broadcaster_dust_limit_sat = if local { self.holder_dust_limit_satoshis } else { self.counterparty_dust_limit_satoshis };
39623962
let feerate_per_kw = self.get_commitment_feerate(funding, generated_by_local);
39633963

3964-
let stats = self.build_commitment_stats(funding, local, generated_by_local);
3964+
let stats = self.build_commitment_stats(funding, local, generated_by_local, None, None);
39653965
let CommitmentStats {
39663966
total_fee_sat,
39673967
local_balance_before_fee_msat,
@@ -6656,13 +6656,9 @@ impl<SP: Deref> FundedChannel<SP> where
66566656
// Before proposing a feerate update, check that we can actually afford the new fee.
66576657
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
66586658
let htlc_stats = self.context.get_pending_htlc_stats(&self.funding, Some(feerate_per_kw), dust_exposure_limiting_feerate);
6659-
let commitment_data = self.context.build_commitment_transaction(
6660-
&self.funding, self.holder_commitment_point.transaction_number(),
6661-
&self.holder_commitment_point.current_point(), true, true, logger,
6662-
);
6663-
let buffer_fee_msat = commit_tx_fee_sat(feerate_per_kw, commitment_data.tx.nondust_htlcs().len() + htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, self.funding.get_channel_type()) * 1000;
6664-
let holder_balance_msat = commitment_data.stats.local_balance_before_fee_msat - htlc_stats.outbound_holding_cell_msat;
6665-
if holder_balance_msat < buffer_fee_msat + self.funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
6659+
let stats = self.context.build_commitment_stats(&self.funding, true, true, Some(feerate_per_kw), Some(htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize));
6660+
let holder_balance_msat = stats.local_balance_before_fee_msat - htlc_stats.outbound_holding_cell_msat;
6661+
if holder_balance_msat < stats.total_fee_sat * 1000 + self.funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
66666662
//TODO: auto-close after a number of failures?
66676663
log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
66686664
return None;
@@ -11614,13 +11610,13 @@ mod tests {
1161411610
use crate::ln::channel_keys::{RevocationKey, RevocationBasepoint};
1161511611
use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
1161611612
use crate::ln::channel::InitFeatures;
11617-
use crate::ln::channel::{AwaitingChannelReadyFlags, ChannelState, FundedChannel, InboundHTLCOutput, OutboundV1Channel, InboundV1Channel, OutboundHTLCOutput, InboundHTLCState, OutboundHTLCState, HTLCCandidate, HTLCInitiator, HTLCUpdateAwaitingACK, commit_tx_fee_sat};
11613+
use crate::ln::channel::{AwaitingChannelReadyFlags, ChannelState, FundedChannel, InboundHTLCOutput, OutboundV1Channel, InboundV1Channel, OutboundHTLCOutput, InboundHTLCState, OutboundHTLCState, HTLCCandidate, HTLCInitiator, HTLCUpdateAwaitingACK};
1161811614
use crate::ln::channel::{MAX_FUNDING_SATOSHIS_NO_WUMBO, TOTAL_BITCOIN_SUPPLY_SATOSHIS, MIN_THEIR_CHAN_RESERVE_SATOSHIS};
1161911615
use crate::types::features::{ChannelFeatures, ChannelTypeFeatures, NodeFeatures};
1162011616
use crate::ln::msgs;
1162111617
use crate::ln::msgs::{ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
1162211618
use crate::ln::script::ShutdownScript;
11623-
use crate::ln::chan_utils::{self, htlc_success_tx_weight, htlc_timeout_tx_weight};
11619+
use crate::ln::chan_utils::{self, commit_tx_fee_sat, htlc_success_tx_weight, htlc_timeout_tx_weight};
1162411620
use crate::chain::BestBlock;
1162511621
use crate::chain::chaininterface::{FeeEstimator, LowerBoundedFeeEstimator, ConfirmationTarget};
1162611622
use crate::sign::{ChannelSigner, InMemorySigner, EntropySource, SignerProvider};

0 commit comments

Comments
 (0)