Skip to content

Commit 922ecf4

Browse files
committed
delete commitment tx fee info cached
1 parent 2580d94 commit 922ecf4

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))]
@@ -4456,20 +4439,6 @@ where
44564439
}
44574440
#[cfg(any(test, fuzzing))]
44584441
{
4459-
if funding.is_outbound() {
4460-
let projected_commit_tx_info = funding.next_local_commitment_tx_fee_info_cached.lock().unwrap().take();
4461-
*funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
4462-
if let Some(info) = projected_commit_tx_info {
4463-
let total_pending_htlcs = self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len()
4464-
+ self.holding_cell_htlc_updates.len();
4465-
if info.total_pending_htlcs == total_pending_htlcs
4466-
&& info.next_holder_htlc_id == self.next_holder_htlc_id
4467-
&& info.next_counterparty_htlc_id == self.next_counterparty_htlc_id
4468-
&& info.feerate == self.feerate_per_kw {
4469-
assert_eq!(commitment_data.stats.commit_tx_fee_sat, info.fee / 1000);
4470-
}
4471-
}
4472-
}
44734442
let PredictedNextFee { predicted_feerate, predicted_htlcs, predicted_fee_sat } = funding.next_local_fee.lock().unwrap().clone();
44744443
let mut actual_nondust_htlcs: Vec<_> = commitment_data.tx.nondust_htlcs().iter().map(|&HTLCOutputInCommitment { offered, amount_msat, .. } | HTLCAmountDirection { outbound: offered, amount_msat }).collect();
44754444
actual_nondust_htlcs.sort_unstable();
@@ -5350,31 +5319,7 @@ where
53505319
}
53515320

53525321
let num_htlcs = included_htlcs + addl_htlcs;
5353-
let commit_tx_fee_msat = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000;
5354-
#[cfg(any(test, fuzzing))]
5355-
{
5356-
let mut fee = commit_tx_fee_msat;
5357-
if fee_spike_buffer_htlc.is_some() {
5358-
fee = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type()) * 1000;
5359-
}
5360-
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len()
5361-
+ context.holding_cell_htlc_updates.len();
5362-
let commitment_tx_info = CommitmentTxInfoCached {
5363-
fee,
5364-
total_pending_htlcs,
5365-
next_holder_htlc_id: match htlc.origin {
5366-
HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
5367-
HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
5368-
},
5369-
next_counterparty_htlc_id: match htlc.origin {
5370-
HTLCInitiator::LocalOffered => context.next_counterparty_htlc_id,
5371-
HTLCInitiator::RemoteOffered => context.next_counterparty_htlc_id + 1,
5372-
},
5373-
feerate: context.feerate_per_kw,
5374-
};
5375-
*funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
5376-
}
5377-
commit_tx_fee_msat
5322+
SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000
53785323
}
53795324

53805325
/// Get the commitment tx fee for the remote's next commitment transaction based on the number of
@@ -5451,30 +5396,7 @@ where
54515396
}
54525397

54535398
let num_htlcs = included_htlcs + addl_htlcs;
5454-
let commit_tx_fee_msat = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000;
5455-
#[cfg(any(test, fuzzing))]
5456-
if let Some(htlc) = &htlc {
5457-
let mut fee = commit_tx_fee_msat;
5458-
if fee_spike_buffer_htlc.is_some() {
5459-
fee = SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs - 1, funding.get_channel_type()) * 1000;
5460-
}
5461-
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
5462-
let commitment_tx_info = CommitmentTxInfoCached {
5463-
fee,
5464-
total_pending_htlcs,
5465-
next_holder_htlc_id: match htlc.origin {
5466-
HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
5467-
HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
5468-
},
5469-
next_counterparty_htlc_id: match htlc.origin {
5470-
HTLCInitiator::LocalOffered => context.next_counterparty_htlc_id,
5471-
HTLCInitiator::RemoteOffered => context.next_counterparty_htlc_id + 1,
5472-
},
5473-
feerate: context.feerate_per_kw,
5474-
};
5475-
*funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
5476-
}
5477-
commit_tx_fee_msat
5399+
SpecTxBuilder {}.commit_tx_fee_sat(context.feerate_per_kw, num_htlcs, funding.get_channel_type()) * 1000
54785400
}
54795401

54805402
#[rustfmt::skip]
@@ -6129,15 +6051,6 @@ macro_rules! promote_splice_funding {
61296051
};
61306052
}
61316053

6132-
#[cfg(any(test, fuzzing))]
6133-
struct CommitmentTxInfoCached {
6134-
fee: u64,
6135-
total_pending_htlcs: usize,
6136-
next_holder_htlc_id: u64,
6137-
next_counterparty_htlc_id: u64,
6138-
feerate: u32,
6139-
}
6140-
61416054
#[cfg(any(test, fuzzing))]
61426055
#[derive(Clone, Default)]
61436056
struct PredictedNextFee {
@@ -7646,16 +7559,6 @@ where
76467559
return Err(ChannelError::close("Received an unexpected revoke_and_ack".to_owned()));
76477560
}
76487561

7649-
#[cfg(any(test, fuzzing))]
7650-
{
7651-
for funding in
7652-
core::iter::once(&mut self.funding).chain(self.pending_funding.iter_mut())
7653-
{
7654-
*funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
7655-
*funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
7656-
}
7657-
}
7658-
76597562
match &self.context.holder_signer {
76607563
ChannelSignerType::Ecdsa(ecdsa) => {
76617564
ecdsa
@@ -11097,19 +11000,6 @@ where
1109711000

1109811001
#[cfg(any(test, fuzzing))]
1109911002
{
11100-
if !funding.is_outbound() {
11101-
let projected_commit_tx_info = funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap().take();
11102-
*funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
11103-
if let Some(info) = projected_commit_tx_info {
11104-
let total_pending_htlcs = self.context.pending_inbound_htlcs.len() + self.context.pending_outbound_htlcs.len();
11105-
if info.total_pending_htlcs == total_pending_htlcs
11106-
&& info.next_holder_htlc_id == self.context.next_holder_htlc_id
11107-
&& info.next_counterparty_htlc_id == self.context.next_counterparty_htlc_id
11108-
&& info.feerate == self.context.feerate_per_kw {
11109-
assert_eq!(commitment_data.stats.commit_tx_fee_sat, info.fee);
11110-
}
11111-
}
11112-
}
1111311003
let PredictedNextFee { predicted_feerate, predicted_htlcs, predicted_fee_sat } = funding.next_remote_fee.lock().unwrap().clone();
1111411004
let mut actual_nondust_htlcs: Vec<_> = counterparty_commitment_tx.nondust_htlcs().iter().map(|&HTLCOutputInCommitment { offered, amount_msat, .. }| HTLCAmountDirection { outbound: !offered, amount_msat }).collect();
1111511005
actual_nondust_htlcs.sort_unstable();
@@ -13737,10 +13627,6 @@ where
1373713627
#[cfg(debug_assertions)]
1373813628
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
1373913629

13740-
#[cfg(any(test, fuzzing))]
13741-
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
13742-
#[cfg(any(test, fuzzing))]
13743-
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
1374413630
#[cfg(any(test, fuzzing))]
1374513631
next_local_fee: Mutex::new(PredictedNextFee::default()),
1374613632
#[cfg(any(test, fuzzing))]

0 commit comments

Comments
 (0)