Skip to content

Commit 83ff898

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 205c4fc commit 83ff898

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))]
@@ -4479,20 +4462,6 @@ where
44794462
}
44804463
#[cfg(any(test, fuzzing))]
44814464
{
4482-
if funding.is_outbound() {
4483-
let projected_commit_tx_info = funding.next_local_commitment_tx_fee_info_cached.lock().unwrap().take();
4484-
*funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
4485-
if let Some(info) = projected_commit_tx_info {
4486-
let total_pending_htlcs = self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len()
4487-
+ self.holding_cell_htlc_updates.len();
4488-
if info.total_pending_htlcs == total_pending_htlcs
4489-
&& info.next_holder_htlc_id == self.next_holder_htlc_id
4490-
&& info.next_counterparty_htlc_id == self.next_counterparty_htlc_id
4491-
&& info.feerate == self.feerate_per_kw {
4492-
assert_eq!(commitment_data.stats.commit_tx_fee_sat, info.fee / 1000);
4493-
}
4494-
}
4495-
}
44964465
let PredictedNextFee { predicted_feerate, predicted_nondust_htlc_count, predicted_fee_sat } = *funding.next_local_fee.lock().unwrap();
44974466
if predicted_feerate == commitment_data.tx.feerate_per_kw() && predicted_nondust_htlc_count == commitment_data.tx.nondust_htlcs().len() {
44984467
assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
@@ -5322,31 +5291,7 @@ where
53225291
}
53235292

53245293
let num_htlcs = included_htlcs + addl_htlcs;
5325-
let commit_tx_fee_msat = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000;
5326-
#[cfg(any(test, fuzzing))]
5327-
{
5328-
let mut fee = commit_tx_fee_msat;
5329-
if fee_spike_buffer_htlc.is_some() {
5330-
fee = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type()) * 1000;
5331-
}
5332-
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len()
5333-
+ context.holding_cell_htlc_updates.len();
5334-
let commitment_tx_info = CommitmentTxInfoCached {
5335-
fee,
5336-
total_pending_htlcs,
5337-
next_holder_htlc_id: match htlc.origin {
5338-
HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
5339-
HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
5340-
},
5341-
next_counterparty_htlc_id: match htlc.origin {
5342-
HTLCInitiator::LocalOffered => context.next_counterparty_htlc_id,
5343-
HTLCInitiator::RemoteOffered => context.next_counterparty_htlc_id + 1,
5344-
},
5345-
feerate: context.feerate_per_kw,
5346-
};
5347-
*funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
5348-
}
5349-
commit_tx_fee_msat
5294+
SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000
53505295
}
53515296

53525297
/// Get the commitment tx fee for the remote's next commitment transaction based on the number of
@@ -5423,30 +5368,7 @@ where
54235368
}
54245369

54255370
let num_htlcs = included_htlcs + addl_htlcs;
5426-
let commit_tx_fee_msat = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000;
5427-
#[cfg(any(test, fuzzing))]
5428-
if let Some(htlc) = &htlc {
5429-
let mut fee = commit_tx_fee_msat;
5430-
if fee_spike_buffer_htlc.is_some() {
5431-
fee = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type()) * 1000;
5432-
}
5433-
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
5434-
let commitment_tx_info = CommitmentTxInfoCached {
5435-
fee,
5436-
total_pending_htlcs,
5437-
next_holder_htlc_id: match htlc.origin {
5438-
HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
5439-
HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
5440-
},
5441-
next_counterparty_htlc_id: match htlc.origin {
5442-
HTLCInitiator::LocalOffered => context.next_counterparty_htlc_id,
5443-
HTLCInitiator::RemoteOffered => context.next_counterparty_htlc_id + 1,
5444-
},
5445-
feerate: context.feerate_per_kw,
5446-
};
5447-
*funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
5448-
}
5449-
commit_tx_fee_msat
5371+
SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000
54505372
}
54515373

54525374
#[rustfmt::skip]
@@ -6101,15 +6023,6 @@ macro_rules! promote_splice_funding {
61016023
};
61026024
}
61036025

6104-
#[cfg(any(test, fuzzing))]
6105-
struct CommitmentTxInfoCached {
6106-
fee: u64,
6107-
total_pending_htlcs: usize,
6108-
next_holder_htlc_id: u64,
6109-
next_counterparty_htlc_id: u64,
6110-
feerate: u32,
6111-
}
6112-
61136026
#[cfg(any(test, fuzzing))]
61146027
#[derive(Clone, Copy, Default)]
61156028
struct PredictedNextFee {
@@ -7618,16 +7531,6 @@ where
76187531
return Err(ChannelError::close("Received an unexpected revoke_and_ack".to_owned()));
76197532
}
76207533

7621-
#[cfg(any(test, fuzzing))]
7622-
{
7623-
for funding in
7624-
core::iter::once(&mut self.funding).chain(self.pending_funding.iter_mut())
7625-
{
7626-
*funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
7627-
*funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
7628-
}
7629-
}
7630-
76317534
match &self.context.holder_signer {
76327535
ChannelSignerType::Ecdsa(ecdsa) => {
76337536
ecdsa
@@ -11069,19 +10972,6 @@ where
1106910972

1107010973
#[cfg(any(test, fuzzing))]
1107110974
{
11072-
if !funding.is_outbound() {
11073-
let projected_commit_tx_info = funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap().take();
11074-
*funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
11075-
if let Some(info) = projected_commit_tx_info {
11076-
let total_pending_htlcs = self.context.pending_inbound_htlcs.len() + self.context.pending_outbound_htlcs.len();
11077-
if info.total_pending_htlcs == total_pending_htlcs
11078-
&& info.next_holder_htlc_id == self.context.next_holder_htlc_id
11079-
&& info.next_counterparty_htlc_id == self.context.next_counterparty_htlc_id
11080-
&& info.feerate == self.context.feerate_per_kw {
11081-
assert_eq!(commitment_data.stats.commit_tx_fee_sat, info.fee);
11082-
}
11083-
}
11084-
}
1108510975
let PredictedNextFee { predicted_feerate, predicted_nondust_htlc_count, predicted_fee_sat } = *funding.next_remote_fee.lock().unwrap();
1108610976
if predicted_feerate == counterparty_commitment_tx.feerate_per_kw() && predicted_nondust_htlc_count == counterparty_commitment_tx.nondust_htlcs().len() {
1108710977
assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
@@ -13707,10 +13597,6 @@ where
1370713597
#[cfg(debug_assertions)]
1370813598
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
1370913599

13710-
#[cfg(any(test, fuzzing))]
13711-
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
13712-
#[cfg(any(test, fuzzing))]
13713-
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
1371413600
#[cfg(any(test, fuzzing))]
1371513601
next_local_fee: Mutex::new(PredictedNextFee::default()),
1371613602
#[cfg(any(test, fuzzing))]

0 commit comments

Comments
 (0)