@@ -2054,14 +2054,9 @@ pub(super) struct FundingScope {
20542054 /// Max to_local and to_remote outputs in a remote-generated commitment transaction
20552055 counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
20562056
2057- // We save these values so we can make sure `next_local_commit_tx_fee_msat` and
2058- // `next_remote_commit_tx_fee_msat` properly predict what the next commitment transaction fee will
2059- // be, by comparing the cached values to the fee of the transaction generated by
2060- // `build_commitment_transaction`.
2061- #[cfg(any(test, fuzzing))]
2062- next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
2063- #[cfg(any(test, fuzzing))]
2064- next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
2057+ // We save these values so we can make sure validation of channel updates properly predicts
2058+ // what the next commitment transaction fee will be, by comparing the cached values to the
2059+ // fee of the transaction generated by `build_commitment_transaction`.
20652060 #[cfg(any(test, fuzzing))]
20662061 next_local_fee: Mutex<PredictedNextFee>,
20672062 #[cfg(any(test, fuzzing))]
@@ -2139,10 +2134,6 @@ impl Readable for FundingScope {
21392134 short_channel_id,
21402135 minimum_depth_override,
21412136 #[cfg(any(test, fuzzing))]
2142- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2143- #[cfg(any(test, fuzzing))]
2144- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2145- #[cfg(any(test, fuzzing))]
21462137 next_local_fee: Mutex::new(PredictedNextFee::default()),
21472138 #[cfg(any(test, fuzzing))]
21482139 next_remote_fee: Mutex::new(PredictedNextFee::default()),
@@ -2319,10 +2310,6 @@ impl FundingScope {
23192310 (post_channel_value * 1000).saturating_sub(post_value_to_self_msat),
23202311 )),
23212312 #[cfg(any(test, fuzzing))]
2322- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2323- #[cfg(any(test, fuzzing))]
2324- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2325- #[cfg(any(test, fuzzing))]
23262313 next_local_fee: Mutex::new(PredictedNextFee::default()),
23272314 #[cfg(any(test, fuzzing))]
23282315 next_remote_fee: Mutex::new(PredictedNextFee::default()),
@@ -3205,10 +3192,6 @@ where
32053192 #[cfg(debug_assertions)]
32063193 counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
32073194
3208- #[cfg(any(test, fuzzing))]
3209- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
3210- #[cfg(any(test, fuzzing))]
3211- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
32123195 #[cfg(any(test, fuzzing))]
32133196 next_local_fee: Mutex::new(PredictedNextFee::default()),
32143197 #[cfg(any(test, fuzzing))]
@@ -3449,10 +3432,6 @@ where
34493432 #[cfg(debug_assertions)]
34503433 counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
34513434
3452- #[cfg(any(test, fuzzing))]
3453- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
3454- #[cfg(any(test, fuzzing))]
3455- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
34563435 #[cfg(any(test, fuzzing))]
34573436 next_local_fee: Mutex::new(PredictedNextFee::default()),
34583437 #[cfg(any(test, fuzzing))]
@@ -4480,20 +4459,6 @@ where
44804459 }
44814460 #[cfg(any(test, fuzzing))]
44824461 {
4483- if funding.is_outbound() {
4484- let projected_commit_tx_info = funding.next_local_commitment_tx_fee_info_cached.lock().unwrap().take();
4485- *funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
4486- if let Some(info) = projected_commit_tx_info {
4487- let total_pending_htlcs = self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len()
4488- + self.holding_cell_htlc_updates.len();
4489- if info.total_pending_htlcs == total_pending_htlcs
4490- && info.next_holder_htlc_id == self.next_holder_htlc_id
4491- && info.next_counterparty_htlc_id == self.next_counterparty_htlc_id
4492- && info.feerate == self.feerate_per_kw {
4493- assert_eq!(commitment_data.stats.commit_tx_fee_sat, info.fee / 1000);
4494- }
4495- }
4496- }
44974462 let PredictedNextFee { predicted_feerate, predicted_nondust_htlc_count, predicted_fee_sat } = *funding.next_local_fee.lock().unwrap();
44984463 if predicted_feerate == commitment_data.tx.feerate_per_kw() && predicted_nondust_htlc_count == commitment_data.tx.nondust_htlcs().len() {
44994464 assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
@@ -5327,31 +5292,7 @@ where
53275292 }
53285293
53295294 let num_htlcs = included_htlcs + addl_htlcs;
5330- let commit_tx_fee_msat = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000;
5331- #[cfg(any(test, fuzzing))]
5332- {
5333- let mut fee = commit_tx_fee_msat;
5334- if fee_spike_buffer_htlc.is_some() {
5335- fee = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type()) * 1000;
5336- }
5337- let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len()
5338- + context.holding_cell_htlc_updates.len();
5339- let commitment_tx_info = CommitmentTxInfoCached {
5340- fee,
5341- total_pending_htlcs,
5342- next_holder_htlc_id: match htlc.origin {
5343- HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
5344- HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
5345- },
5346- next_counterparty_htlc_id: match htlc.origin {
5347- HTLCInitiator::LocalOffered => context.next_counterparty_htlc_id,
5348- HTLCInitiator::RemoteOffered => context.next_counterparty_htlc_id + 1,
5349- },
5350- feerate: context.feerate_per_kw,
5351- };
5352- *funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
5353- }
5354- commit_tx_fee_msat
5295+ SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000
53555296 }
53565297
53575298 /// Get the commitment tx fee for the remote's next commitment transaction based on the number of
@@ -5428,30 +5369,7 @@ where
54285369 }
54295370
54305371 let num_htlcs = included_htlcs + addl_htlcs;
5431- let commit_tx_fee_msat = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000;
5432- #[cfg(any(test, fuzzing))]
5433- if let Some(htlc) = &htlc {
5434- let mut fee = commit_tx_fee_msat;
5435- if fee_spike_buffer_htlc.is_some() {
5436- fee = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type()) * 1000;
5437- }
5438- let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
5439- let commitment_tx_info = CommitmentTxInfoCached {
5440- fee,
5441- total_pending_htlcs,
5442- next_holder_htlc_id: match htlc.origin {
5443- HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
5444- HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
5445- },
5446- next_counterparty_htlc_id: match htlc.origin {
5447- HTLCInitiator::LocalOffered => context.next_counterparty_htlc_id,
5448- HTLCInitiator::RemoteOffered => context.next_counterparty_htlc_id + 1,
5449- },
5450- feerate: context.feerate_per_kw,
5451- };
5452- *funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
5453- }
5454- commit_tx_fee_msat
5372+ SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000
54555373 }
54565374
54575375 #[rustfmt::skip]
@@ -6295,15 +6213,6 @@ macro_rules! promote_splice_funding {
62956213 };
62966214}
62976215
6298- #[cfg(any(test, fuzzing))]
6299- struct CommitmentTxInfoCached {
6300- fee: u64,
6301- total_pending_htlcs: usize,
6302- next_holder_htlc_id: u64,
6303- next_counterparty_htlc_id: u64,
6304- feerate: u32,
6305- }
6306-
63076216#[cfg(any(test, fuzzing))]
63086217#[derive(Clone, Copy, Default)]
63096218struct PredictedNextFee {
@@ -7839,16 +7748,6 @@ where
78397748 return Err(ChannelError::close("Received an unexpected revoke_and_ack".to_owned()));
78407749 }
78417750
7842- #[cfg(any(test, fuzzing))]
7843- {
7844- for funding in
7845- core::iter::once(&mut self.funding).chain(self.pending_funding.iter_mut())
7846- {
7847- *funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
7848- *funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
7849- }
7850- }
7851-
78527751 match &self.context.holder_signer {
78537752 ChannelSignerType::Ecdsa(ecdsa) => {
78547753 ecdsa
@@ -11469,19 +11368,6 @@ where
1146911368
1147011369 #[cfg(any(test, fuzzing))]
1147111370 {
11472- if !funding.is_outbound() {
11473- let projected_commit_tx_info = funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap().take();
11474- *funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
11475- if let Some(info) = projected_commit_tx_info {
11476- let total_pending_htlcs = self.context.pending_inbound_htlcs.len() + self.context.pending_outbound_htlcs.len();
11477- if info.total_pending_htlcs == total_pending_htlcs
11478- && info.next_holder_htlc_id == self.context.next_holder_htlc_id
11479- && info.next_counterparty_htlc_id == self.context.next_counterparty_htlc_id
11480- && info.feerate == self.context.feerate_per_kw {
11481- assert_eq!(commitment_data.stats.commit_tx_fee_sat, info.fee);
11482- }
11483- }
11484- }
1148511371 let PredictedNextFee { predicted_feerate, predicted_nondust_htlc_count, predicted_fee_sat } = *funding.next_remote_fee.lock().unwrap();
1148611372 if predicted_feerate == counterparty_commitment_tx.feerate_per_kw() && predicted_nondust_htlc_count == counterparty_commitment_tx.nondust_htlcs().len() {
1148711373 assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
@@ -14128,10 +14014,6 @@ where
1412814014 #[cfg(debug_assertions)]
1412914015 counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
1413014016
14131- #[cfg(any(test, fuzzing))]
14132- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
14133- #[cfg(any(test, fuzzing))]
14134- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
1413514017 #[cfg(any(test, fuzzing))]
1413614018 next_local_fee: Mutex::new(PredictedNextFee::default()),
1413714019 #[cfg(any(test, fuzzing))]
@@ -16208,11 +16090,6 @@ mod tests {
1620816090 #[cfg(debug_assertions)]
1620916091 counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
1621016092
16211- #[cfg(any(test, fuzzing))]
16212- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
16213- #[cfg(any(test, fuzzing))]
16214- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
16215-
1621616093 #[cfg(any(test, fuzzing))]
1621716094 next_local_fee: Mutex::new(PredictedNextFee::default()),
1621816095 #[cfg(any(test, fuzzing))]
0 commit comments