@@ -2050,10 +2050,10 @@ impl<Signer: Sign> Channel<Signer> {
2050
2050
2051
2051
// Get the fee cost of a commitment tx with a given number of HTLC outputs.
2052
2052
// Note that num_htlcs should not include dust HTLCs.
2053
- fn commit_tx_fee_msat ( & self , num_htlcs : usize ) -> u64 {
2053
+ fn commit_tx_fee_msat ( feerate_per_kw : u32 , num_htlcs : usize ) -> u64 {
2054
2054
// Note that we need to divide before multiplying to round properly,
2055
2055
// since the lowest denomination of bitcoin on-chain is the satoshi.
2056
- ( COMMITMENT_TX_BASE_WEIGHT + num_htlcs as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC ) * self . feerate_per_kw as u64 / 1000 * 1000
2056
+ ( COMMITMENT_TX_BASE_WEIGHT + num_htlcs as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC ) * feerate_per_kw as u64 / 1000 * 1000
2057
2057
}
2058
2058
2059
2059
// Get the commitment tx fee for the local's (i.e. our) next commitment transaction based on the
@@ -2120,12 +2120,12 @@ impl<Signer: Sign> Channel<Signer> {
2120
2120
}
2121
2121
2122
2122
let num_htlcs = included_htlcs + addl_htlcs;
2123
- let res = self . commit_tx_fee_msat ( num_htlcs) ;
2123
+ let res = Self :: commit_tx_fee_msat ( self . feerate_per_kw , num_htlcs) ;
2124
2124
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
2125
2125
{
2126
2126
let mut fee = res;
2127
2127
if fee_spike_buffer_htlc. is_some ( ) {
2128
- fee = self . commit_tx_fee_msat ( num_htlcs - 1 ) ;
2128
+ fee = Self :: commit_tx_fee_msat ( self . feerate_per_kw , num_htlcs - 1 ) ;
2129
2129
}
2130
2130
let total_pending_htlcs = self . pending_inbound_htlcs . len ( ) + self . pending_outbound_htlcs . len ( )
2131
2131
+ self . holding_cell_htlc_updates . len ( ) ;
@@ -2198,12 +2198,12 @@ impl<Signer: Sign> Channel<Signer> {
2198
2198
}
2199
2199
2200
2200
let num_htlcs = included_htlcs + addl_htlcs;
2201
- let res = self . commit_tx_fee_msat ( num_htlcs) ;
2201
+ let res = Self :: commit_tx_fee_msat ( self . feerate_per_kw , num_htlcs) ;
2202
2202
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
2203
2203
{
2204
2204
let mut fee = res;
2205
2205
if fee_spike_buffer_htlc. is_some ( ) {
2206
- fee = self . commit_tx_fee_msat ( num_htlcs - 1 ) ;
2206
+ fee = Self :: commit_tx_fee_msat ( self . feerate_per_kw , num_htlcs - 1 ) ;
2207
2207
}
2208
2208
let total_pending_htlcs = self . pending_inbound_htlcs . len ( ) + self . pending_outbound_htlcs . len ( ) ;
2209
2209
let commitment_tx_info = CommitmentTxInfoCached {
@@ -4805,7 +4805,7 @@ impl<Signer: Sign> Channel<Signer> {
4805
4805
&& info. next_holder_htlc_id == self . next_holder_htlc_id
4806
4806
&& info. next_counterparty_htlc_id == self . next_counterparty_htlc_id
4807
4807
&& info. feerate == self . feerate_per_kw {
4808
- let actual_fee = self . commit_tx_fee_msat ( counterparty_commitment_tx. 2 ) ;
4808
+ let actual_fee = Self :: commit_tx_fee_msat ( self . feerate_per_kw , counterparty_commitment_tx. 2 ) ;
4809
4809
assert_eq ! ( actual_fee, info. fee) ;
4810
4810
}
4811
4811
}
@@ -5818,13 +5818,13 @@ mod tests {
5818
5818
// the dust limit check.
5819
5819
let htlc_candidate = HTLCCandidate :: new ( htlc_amount_msat, HTLCInitiator :: LocalOffered ) ;
5820
5820
let local_commit_tx_fee = node_a_chan. next_local_commit_tx_fee_msat ( htlc_candidate, None ) ;
5821
- let local_commit_fee_0_htlcs = node_a_chan . commit_tx_fee_msat ( 0 ) ;
5821
+ let local_commit_fee_0_htlcs = Channel :: < EnforcingSigner > :: commit_tx_fee_msat ( node_a_chan . feerate_per_kw , 0 ) ;
5822
5822
assert_eq ! ( local_commit_tx_fee, local_commit_fee_0_htlcs) ;
5823
5823
5824
5824
// Finally, make sure that when Node A calculates the remote's commitment transaction fees, all
5825
5825
// of the HTLCs are seen to be above the dust limit.
5826
5826
node_a_chan. channel_transaction_parameters . is_outbound_from_holder = false ;
5827
- let remote_commit_fee_3_htlcs = node_a_chan . commit_tx_fee_msat ( 3 ) ;
5827
+ let remote_commit_fee_3_htlcs = Channel :: < EnforcingSigner > :: commit_tx_fee_msat ( node_a_chan . feerate_per_kw , 3 ) ;
5828
5828
let htlc_candidate = HTLCCandidate :: new ( htlc_amount_msat, HTLCInitiator :: LocalOffered ) ;
5829
5829
let remote_commit_tx_fee = node_a_chan. next_remote_commit_tx_fee_msat ( htlc_candidate, None ) ;
5830
5830
assert_eq ! ( remote_commit_tx_fee, remote_commit_fee_3_htlcs) ;
@@ -5846,8 +5846,8 @@ mod tests {
5846
5846
let config = UserConfig :: default ( ) ;
5847
5847
let mut chan = Channel :: < EnforcingSigner > :: new_outbound ( & & fee_est, & & keys_provider, node_id, & InitFeatures :: known ( ) , 10000000 , 100000 , 42 , & config) . unwrap ( ) ;
5848
5848
5849
- let commitment_tx_fee_0_htlcs = chan . commit_tx_fee_msat ( 0 ) ;
5850
- let commitment_tx_fee_1_htlc = chan . commit_tx_fee_msat ( 1 ) ;
5849
+ let commitment_tx_fee_0_htlcs = Channel :: < EnforcingSigner > :: commit_tx_fee_msat ( chan . feerate_per_kw , 0 ) ;
5850
+ let commitment_tx_fee_1_htlc = Channel :: < EnforcingSigner > :: commit_tx_fee_msat ( chan . feerate_per_kw , 1 ) ;
5851
5851
5852
5852
// If HTLC_SUCCESS_TX_WEIGHT and HTLC_TIMEOUT_TX_WEIGHT were swapped: then this HTLC would be
5853
5853
// counted as dust when it shouldn't be.
0 commit comments