@@ -2054,14 +2054,9 @@ pub(super) struct FundingScope {
2054
2054
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
2055
2055
counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
2056
2056
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`.
2065
2060
#[cfg(any(test, fuzzing))]
2066
2061
next_local_fee: Mutex<PredictedNextFee>,
2067
2062
#[cfg(any(test, fuzzing))]
@@ -2139,10 +2134,6 @@ impl Readable for FundingScope {
2139
2134
short_channel_id,
2140
2135
minimum_depth_override,
2141
2136
#[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))]
2146
2137
next_local_fee: Mutex::new(PredictedNextFee::default()),
2147
2138
#[cfg(any(test, fuzzing))]
2148
2139
next_remote_fee: Mutex::new(PredictedNextFee::default()),
@@ -2319,10 +2310,6 @@ impl FundingScope {
2319
2310
(post_channel_value * 1000).saturating_sub(post_value_to_self_msat),
2320
2311
)),
2321
2312
#[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))]
2326
2313
next_local_fee: Mutex::new(PredictedNextFee::default()),
2327
2314
#[cfg(any(test, fuzzing))]
2328
2315
next_remote_fee: Mutex::new(PredictedNextFee::default()),
@@ -3205,10 +3192,6 @@ where
3205
3192
#[cfg(debug_assertions)]
3206
3193
counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
3207
3194
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),
3212
3195
#[cfg(any(test, fuzzing))]
3213
3196
next_local_fee: Mutex::new(PredictedNextFee::default()),
3214
3197
#[cfg(any(test, fuzzing))]
@@ -3449,10 +3432,6 @@ where
3449
3432
#[cfg(debug_assertions)]
3450
3433
counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
3451
3434
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),
3456
3435
#[cfg(any(test, fuzzing))]
3457
3436
next_local_fee: Mutex::new(PredictedNextFee::default()),
3458
3437
#[cfg(any(test, fuzzing))]
@@ -4480,20 +4459,6 @@ where
4480
4459
}
4481
4460
#[cfg(any(test, fuzzing))]
4482
4461
{
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
- }
4497
4462
let PredictedNextFee { predicted_feerate, predicted_nondust_htlc_count, predicted_fee_sat } = *funding.next_local_fee.lock().unwrap();
4498
4463
if predicted_feerate == commitment_data.tx.feerate_per_kw() && predicted_nondust_htlc_count == commitment_data.tx.nondust_htlcs().len() {
4499
4464
assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
@@ -5327,31 +5292,7 @@ where
5327
5292
}
5328
5293
5329
5294
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
5355
5296
}
5356
5297
5357
5298
/// Get the commitment tx fee for the remote's next commitment transaction based on the number of
@@ -5428,30 +5369,7 @@ where
5428
5369
}
5429
5370
5430
5371
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
5455
5373
}
5456
5374
5457
5375
#[rustfmt::skip]
@@ -6295,15 +6213,6 @@ macro_rules! promote_splice_funding {
6295
6213
};
6296
6214
}
6297
6215
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
-
6307
6216
#[cfg(any(test, fuzzing))]
6308
6217
#[derive(Clone, Copy, Default)]
6309
6218
struct PredictedNextFee {
@@ -7839,16 +7748,6 @@ where
7839
7748
return Err(ChannelError::close("Received an unexpected revoke_and_ack".to_owned()));
7840
7749
}
7841
7750
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
-
7852
7751
match &self.context.holder_signer {
7853
7752
ChannelSignerType::Ecdsa(ecdsa) => {
7854
7753
ecdsa
@@ -11469,19 +11368,6 @@ where
11469
11368
11470
11369
#[cfg(any(test, fuzzing))]
11471
11370
{
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
- }
11485
11371
let PredictedNextFee { predicted_feerate, predicted_nondust_htlc_count, predicted_fee_sat } = *funding.next_remote_fee.lock().unwrap();
11486
11372
if predicted_feerate == counterparty_commitment_tx.feerate_per_kw() && predicted_nondust_htlc_count == counterparty_commitment_tx.nondust_htlcs().len() {
11487
11373
assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
@@ -14128,10 +14014,6 @@ where
14128
14014
#[cfg(debug_assertions)]
14129
14015
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
14130
14016
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),
14135
14017
#[cfg(any(test, fuzzing))]
14136
14018
next_local_fee: Mutex::new(PredictedNextFee::default()),
14137
14019
#[cfg(any(test, fuzzing))]
@@ -16208,11 +16090,6 @@ mod tests {
16208
16090
#[cfg(debug_assertions)]
16209
16091
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
16210
16092
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
-
16216
16093
#[cfg(any(test, fuzzing))]
16217
16094
next_local_fee: Mutex::new(PredictedNextFee::default()),
16218
16095
#[cfg(any(test, fuzzing))]
0 commit comments