Skip to content

Commit 0904e98

Browse files
committed
Delete dead next_{local, remote}_commitment_tx_fee_info_cached
The cached fee is never checked in the current test suite.
1 parent dd46f9c commit 0904e98

File tree

1 file changed

+5
-119
lines changed

1 file changed

+5
-119
lines changed

lightning/src/ln/channel.rs

Lines changed: 5 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,14 +1976,9 @@ pub(super) struct FundingScope {
19761976
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
19771977
counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
19781978

1979-
// We save these values so we can make sure `next_local_commit_tx_fee_msat` and
1980-
// `next_remote_commit_tx_fee_msat` properly predict what the next commitment transaction fee will
1981-
// be, by comparing the cached values to the fee of the transaction generated by
1982-
// `build_commitment_transaction`.
1983-
#[cfg(any(test, fuzzing))]
1984-
next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1985-
#[cfg(any(test, fuzzing))]
1986-
next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1979+
// We save these values so we can make sure validation of channel updates properly predicts
1980+
// what the next commitment transaction fee will be, by comparing the cached values to the
1981+
// fee of the transaction generated by `build_commitment_transaction`.
19871982
#[cfg(any(test, fuzzing))]
19881983
next_local_fee: Mutex<PredictedNextFee>,
19891984
#[cfg(any(test, fuzzing))]
@@ -2061,10 +2056,6 @@ impl Readable for FundingScope {
20612056
short_channel_id,
20622057
minimum_depth_override,
20632058
#[cfg(any(test, fuzzing))]
2064-
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2065-
#[cfg(any(test, fuzzing))]
2066-
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2067-
#[cfg(any(test, fuzzing))]
20682059
next_local_fee: Mutex::new(PredictedNextFee::default()),
20692060
#[cfg(any(test, fuzzing))]
20702061
next_remote_fee: Mutex::new(PredictedNextFee::default()),
@@ -3210,10 +3201,6 @@ where
32103201
#[cfg(debug_assertions)]
32113202
counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
32123203

3213-
#[cfg(any(test, fuzzing))]
3214-
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
3215-
#[cfg(any(test, fuzzing))]
3216-
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
32173204
#[cfg(any(test, fuzzing))]
32183205
next_local_fee: Mutex::new(PredictedNextFee::default()),
32193206
#[cfg(any(test, fuzzing))]
@@ -3457,10 +3444,6 @@ where
34573444
#[cfg(debug_assertions)]
34583445
counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
34593446

3460-
#[cfg(any(test, fuzzing))]
3461-
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
3462-
#[cfg(any(test, fuzzing))]
3463-
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
34643447
#[cfg(any(test, fuzzing))]
34653448
next_local_fee: Mutex::new(PredictedNextFee::default()),
34663449
#[cfg(any(test, fuzzing))]
@@ -4451,20 +4434,6 @@ where
44514434
}
44524435
#[cfg(any(test, fuzzing))]
44534436
{
4454-
if funding.is_outbound() {
4455-
let projected_commit_tx_info = funding.next_local_commitment_tx_fee_info_cached.lock().unwrap().take();
4456-
*funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
4457-
if let Some(info) = projected_commit_tx_info {
4458-
let total_pending_htlcs = self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len()
4459-
+ self.holding_cell_htlc_updates.len();
4460-
if info.total_pending_htlcs == total_pending_htlcs
4461-
&& info.next_holder_htlc_id == self.next_holder_htlc_id
4462-
&& info.next_counterparty_htlc_id == self.next_counterparty_htlc_id
4463-
&& info.feerate == self.feerate_per_kw {
4464-
assert_eq!(commitment_data.stats.commit_tx_fee_sat, info.fee / 1000);
4465-
}
4466-
}
4467-
}
44684437
let PredictedNextFee { predicted_feerate, predicted_htlcs, predicted_fee_sat } = funding.next_local_fee.lock().unwrap().clone();
44694438
let mut actual_nondust_htlcs: Vec<_> = commitment_data.tx.nondust_htlcs().iter().map(|&HTLCOutputInCommitment { offered, amount_msat, .. } | HTLCAmountDirection { outbound: offered, amount_msat }).collect();
44704439
actual_nondust_htlcs.sort_unstable();
@@ -5339,31 +5308,7 @@ where
53395308
}
53405309

53415310
let num_htlcs = included_htlcs + addl_htlcs;
5342-
let commit_tx_fee_msat = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000;
5343-
#[cfg(any(test, fuzzing))]
5344-
{
5345-
let mut fee = commit_tx_fee_msat;
5346-
if fee_spike_buffer_htlc.is_some() {
5347-
fee = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type()) * 1000;
5348-
}
5349-
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len()
5350-
+ context.holding_cell_htlc_updates.len();
5351-
let commitment_tx_info = CommitmentTxInfoCached {
5352-
fee,
5353-
total_pending_htlcs,
5354-
next_holder_htlc_id: match htlc.origin {
5355-
HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
5356-
HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
5357-
},
5358-
next_counterparty_htlc_id: match htlc.origin {
5359-
HTLCInitiator::LocalOffered => context.next_counterparty_htlc_id,
5360-
HTLCInitiator::RemoteOffered => context.next_counterparty_htlc_id + 1,
5361-
},
5362-
feerate: context.feerate_per_kw,
5363-
};
5364-
*funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
5365-
}
5366-
commit_tx_fee_msat
5311+
SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000
53675312
}
53685313

53695314
/// Get the commitment tx fee for the remote's next commitment transaction based on the number of
@@ -5440,30 +5385,7 @@ where
54405385
}
54415386

54425387
let num_htlcs = included_htlcs + addl_htlcs;
5443-
let commit_tx_fee_msat = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000;
5444-
#[cfg(any(test, fuzzing))]
5445-
if let Some(htlc) = &htlc {
5446-
let mut fee = commit_tx_fee_msat;
5447-
if fee_spike_buffer_htlc.is_some() {
5448-
fee = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type()) * 1000;
5449-
}
5450-
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
5451-
let commitment_tx_info = CommitmentTxInfoCached {
5452-
fee,
5453-
total_pending_htlcs,
5454-
next_holder_htlc_id: match htlc.origin {
5455-
HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
5456-
HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
5457-
},
5458-
next_counterparty_htlc_id: match htlc.origin {
5459-
HTLCInitiator::LocalOffered => context.next_counterparty_htlc_id,
5460-
HTLCInitiator::RemoteOffered => context.next_counterparty_htlc_id + 1,
5461-
},
5462-
feerate: context.feerate_per_kw,
5463-
};
5464-
*funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
5465-
}
5466-
commit_tx_fee_msat
5388+
SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000
54675389
}
54685390

54695391
#[rustfmt::skip]
@@ -6118,15 +6040,6 @@ macro_rules! promote_splice_funding {
61186040
};
61196041
}
61206042

6121-
#[cfg(any(test, fuzzing))]
6122-
struct CommitmentTxInfoCached {
6123-
fee: u64,
6124-
total_pending_htlcs: usize,
6125-
next_holder_htlc_id: u64,
6126-
next_counterparty_htlc_id: u64,
6127-
feerate: u32,
6128-
}
6129-
61306043
#[cfg(any(test, fuzzing))]
61316044
#[derive(Clone, Default)]
61326045
struct PredictedNextFee {
@@ -7635,16 +7548,6 @@ where
76357548
return Err(ChannelError::close("Received an unexpected revoke_and_ack".to_owned()));
76367549
}
76377550

7638-
#[cfg(any(test, fuzzing))]
7639-
{
7640-
for funding in
7641-
core::iter::once(&mut self.funding).chain(self.pending_funding.iter_mut())
7642-
{
7643-
*funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
7644-
*funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
7645-
}
7646-
}
7647-
76487551
match &self.context.holder_signer {
76497552
ChannelSignerType::Ecdsa(ecdsa) => {
76507553
ecdsa
@@ -11086,19 +10989,6 @@ where
1108610989

1108710990
#[cfg(any(test, fuzzing))]
1108810991
{
11089-
if !funding.is_outbound() {
11090-
let projected_commit_tx_info = funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap().take();
11091-
*funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
11092-
if let Some(info) = projected_commit_tx_info {
11093-
let total_pending_htlcs = self.context.pending_inbound_htlcs.len() + self.context.pending_outbound_htlcs.len();
11094-
if info.total_pending_htlcs == total_pending_htlcs
11095-
&& info.next_holder_htlc_id == self.context.next_holder_htlc_id
11096-
&& info.next_counterparty_htlc_id == self.context.next_counterparty_htlc_id
11097-
&& info.feerate == self.context.feerate_per_kw {
11098-
assert_eq!(commitment_data.stats.commit_tx_fee_sat, info.fee);
11099-
}
11100-
}
11101-
}
1110210992
let PredictedNextFee { predicted_feerate, predicted_htlcs, predicted_fee_sat } = funding.next_remote_fee.lock().unwrap().clone();
1110310993
let mut actual_nondust_htlcs: Vec<_> = counterparty_commitment_tx.nondust_htlcs().iter().map(|&HTLCOutputInCommitment { offered, amount_msat, .. }| HTLCAmountDirection { outbound: !offered, amount_msat }).collect();
1110410994
actual_nondust_htlcs.sort_unstable();
@@ -13726,10 +13616,6 @@ where
1372613616
#[cfg(debug_assertions)]
1372713617
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
1372813618

13729-
#[cfg(any(test, fuzzing))]
13730-
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
13731-
#[cfg(any(test, fuzzing))]
13732-
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
1373313619
#[cfg(any(test, fuzzing))]
1373413620
next_local_fee: Mutex::new(PredictedNextFee::default()),
1373513621
#[cfg(any(test, fuzzing))]

0 commit comments

Comments
 (0)