@@ -2068,10 +2068,10 @@ impl<Signer: Sign> Channel<Signer> {
2068
2068
2069
2069
// Get the fee cost of a commitment tx with a given number of HTLC outputs.
2070
2070
// Note that num_htlcs should not include dust HTLCs.
2071
- fn commit_tx_fee_msat ( & self , num_htlcs : usize ) -> u64 {
2071
+ fn commit_tx_fee_msat ( feerate_per_kw : u32 , num_htlcs : usize ) -> u64 {
2072
2072
// Note that we need to divide before multiplying to round properly,
2073
2073
// since the lowest denomination of bitcoin on-chain is the satoshi.
2074
- ( COMMITMENT_TX_BASE_WEIGHT + num_htlcs as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC ) * self . feerate_per_kw as u64 / 1000 * 1000
2074
+ ( COMMITMENT_TX_BASE_WEIGHT + num_htlcs as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC ) * feerate_per_kw as u64 / 1000 * 1000
2075
2075
}
2076
2076
2077
2077
// Get the commitment tx fee for the local's (i.e. our) next commitment transaction based on the
@@ -2138,12 +2138,12 @@ impl<Signer: Sign> Channel<Signer> {
2138
2138
}
2139
2139
2140
2140
let num_htlcs = included_htlcs + addl_htlcs;
2141
- let res = self . commit_tx_fee_msat ( num_htlcs) ;
2141
+ let res = Self :: commit_tx_fee_msat ( self . feerate_per_kw , num_htlcs) ;
2142
2142
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
2143
2143
{
2144
2144
let mut fee = res;
2145
2145
if fee_spike_buffer_htlc. is_some ( ) {
2146
- fee = self . commit_tx_fee_msat ( num_htlcs - 1 ) ;
2146
+ fee = Self :: commit_tx_fee_msat ( self . feerate_per_kw , num_htlcs - 1 ) ;
2147
2147
}
2148
2148
let total_pending_htlcs = self . pending_inbound_htlcs . len ( ) + self . pending_outbound_htlcs . len ( )
2149
2149
+ self . holding_cell_htlc_updates . len ( ) ;
@@ -2216,12 +2216,12 @@ impl<Signer: Sign> Channel<Signer> {
2216
2216
}
2217
2217
2218
2218
let num_htlcs = included_htlcs + addl_htlcs;
2219
- let res = self . commit_tx_fee_msat ( num_htlcs) ;
2219
+ let res = Self :: commit_tx_fee_msat ( self . feerate_per_kw , num_htlcs) ;
2220
2220
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
2221
2221
{
2222
2222
let mut fee = res;
2223
2223
if fee_spike_buffer_htlc. is_some ( ) {
2224
- fee = self . commit_tx_fee_msat ( num_htlcs - 1 ) ;
2224
+ fee = Self :: commit_tx_fee_msat ( self . feerate_per_kw , num_htlcs - 1 ) ;
2225
2225
}
2226
2226
let total_pending_htlcs = self . pending_inbound_htlcs . len ( ) + self . pending_outbound_htlcs . len ( ) ;
2227
2227
let commitment_tx_info = CommitmentTxInfoCached {
@@ -4827,7 +4827,7 @@ impl<Signer: Sign> Channel<Signer> {
4827
4827
&& info. next_holder_htlc_id == self . next_holder_htlc_id
4828
4828
&& info. next_counterparty_htlc_id == self . next_counterparty_htlc_id
4829
4829
&& info. feerate == self . feerate_per_kw {
4830
- let actual_fee = self . commit_tx_fee_msat ( counterparty_commitment_tx. 2 ) ;
4830
+ let actual_fee = Self :: commit_tx_fee_msat ( self . feerate_per_kw , counterparty_commitment_tx. 2 ) ;
4831
4831
assert_eq ! ( actual_fee, info. fee) ;
4832
4832
}
4833
4833
}
@@ -5852,13 +5852,13 @@ mod tests {
5852
5852
// the dust limit check.
5853
5853
let htlc_candidate = HTLCCandidate :: new ( htlc_amount_msat, HTLCInitiator :: LocalOffered ) ;
5854
5854
let local_commit_tx_fee = node_a_chan. next_local_commit_tx_fee_msat ( htlc_candidate, None ) ;
5855
- let local_commit_fee_0_htlcs = node_a_chan . commit_tx_fee_msat ( 0 ) ;
5855
+ let local_commit_fee_0_htlcs = Channel :: < EnforcingSigner > :: commit_tx_fee_msat ( node_a_chan . feerate_per_kw , 0 ) ;
5856
5856
assert_eq ! ( local_commit_tx_fee, local_commit_fee_0_htlcs) ;
5857
5857
5858
5858
// Finally, make sure that when Node A calculates the remote's commitment transaction fees, all
5859
5859
// of the HTLCs are seen to be above the dust limit.
5860
5860
node_a_chan. channel_transaction_parameters . is_outbound_from_holder = false ;
5861
- let remote_commit_fee_3_htlcs = node_a_chan . commit_tx_fee_msat ( 3 ) ;
5861
+ let remote_commit_fee_3_htlcs = Channel :: < EnforcingSigner > :: commit_tx_fee_msat ( node_a_chan . feerate_per_kw , 3 ) ;
5862
5862
let htlc_candidate = HTLCCandidate :: new ( htlc_amount_msat, HTLCInitiator :: LocalOffered ) ;
5863
5863
let remote_commit_tx_fee = node_a_chan. next_remote_commit_tx_fee_msat ( htlc_candidate, None ) ;
5864
5864
assert_eq ! ( remote_commit_tx_fee, remote_commit_fee_3_htlcs) ;
@@ -5880,8 +5880,8 @@ mod tests {
5880
5880
let config = UserConfig :: default ( ) ;
5881
5881
let mut chan = Channel :: < EnforcingSigner > :: new_outbound ( & & fee_est, & & keys_provider, node_id, & InitFeatures :: known ( ) , 10000000 , 100000 , 42 , & config, 0 ) . unwrap ( ) ;
5882
5882
5883
- let commitment_tx_fee_0_htlcs = chan . commit_tx_fee_msat ( 0 ) ;
5884
- let commitment_tx_fee_1_htlc = chan . commit_tx_fee_msat ( 1 ) ;
5883
+ let commitment_tx_fee_0_htlcs = Channel :: < EnforcingSigner > :: commit_tx_fee_msat ( chan . feerate_per_kw , 0 ) ;
5884
+ let commitment_tx_fee_1_htlc = Channel :: < EnforcingSigner > :: commit_tx_fee_msat ( chan . feerate_per_kw , 1 ) ;
5885
5885
5886
5886
// If HTLC_SUCCESS_TX_WEIGHT and HTLC_TIMEOUT_TX_WEIGHT were swapped: then this HTLC would be
5887
5887
// counted as dust when it shouldn't be.
0 commit comments