@@ -1986,6 +1986,10 @@ pub(super) struct FundingScope {
1986
1986
next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1987
1987
#[cfg(any(test, fuzzing))]
1988
1988
next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1989
+ #[cfg(any(test, fuzzing))]
1990
+ next_local_fee: Mutex<PredictedNextFee>,
1991
+ #[cfg(any(test, fuzzing))]
1992
+ next_remote_fee: Mutex<PredictedNextFee>,
1989
1993
1990
1994
pub(super) channel_transaction_parameters: ChannelTransactionParameters,
1991
1995
@@ -2062,6 +2066,10 @@ impl Readable for FundingScope {
2062
2066
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2063
2067
#[cfg(any(test, fuzzing))]
2064
2068
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2069
+ #[cfg(any(test, fuzzing))]
2070
+ next_local_fee: Mutex::new(PredictedNextFee::default()),
2071
+ #[cfg(any(test, fuzzing))]
2072
+ next_remote_fee: Mutex::new(PredictedNextFee::default()),
2065
2073
})
2066
2074
}
2067
2075
}
@@ -3208,6 +3216,10 @@ where
3208
3216
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
3209
3217
#[cfg(any(test, fuzzing))]
3210
3218
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
3219
+ #[cfg(any(test, fuzzing))]
3220
+ next_local_fee: Mutex::new(PredictedNextFee::default()),
3221
+ #[cfg(any(test, fuzzing))]
3222
+ next_remote_fee: Mutex::new(PredictedNextFee::default()),
3211
3223
3212
3224
channel_transaction_parameters: ChannelTransactionParameters {
3213
3225
holder_pubkeys: pubkeys,
@@ -3451,6 +3463,10 @@ where
3451
3463
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
3452
3464
#[cfg(any(test, fuzzing))]
3453
3465
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
3466
+ #[cfg(any(test, fuzzing))]
3467
+ next_local_fee: Mutex::new(PredictedNextFee::default()),
3468
+ #[cfg(any(test, fuzzing))]
3469
+ next_remote_fee: Mutex::new(PredictedNextFee::default()),
3454
3470
3455
3471
channel_transaction_parameters: ChannelTransactionParameters {
3456
3472
holder_pubkeys: pubkeys,
@@ -4187,6 +4203,23 @@ where
4187
4203
}
4188
4204
}
4189
4205
4206
+ #[cfg(any(test, fuzzing))]
4207
+ {
4208
+ let mut predicted_htlcs = next_commitment_htlcs;
4209
+ predicted_htlcs.sort_unstable();
4210
+ *funding.next_local_fee.lock().unwrap() = PredictedNextFee {
4211
+ predicted_feerate: self.feerate_per_kw,
4212
+ predicted_htlcs: predicted_htlcs.clone(),
4213
+ predicted_fee_sat: next_commitment_stats.holder_commit_tx_fee_sat,
4214
+ };
4215
+
4216
+ *funding.next_remote_fee.lock().unwrap() = PredictedNextFee {
4217
+ predicted_feerate: self.feerate_per_kw,
4218
+ predicted_htlcs,
4219
+ predicted_fee_sat: next_commitment_stats.counterparty_commit_tx_fee_sat,
4220
+ };
4221
+ }
4222
+
4190
4223
Ok(())
4191
4224
}
4192
4225
@@ -4271,6 +4304,12 @@ where
4271
4304
}
4272
4305
}
4273
4306
}
4307
+ let PredictedNextFee { predicted_feerate, predicted_htlcs, predicted_fee_sat } = funding.next_local_fee.lock().unwrap().clone();
4308
+ let mut actual_nondust_htlcs: Vec<_> = commitment_data.tx.nondust_htlcs().iter().map(|htlc| HTLCAmountDirection { outbound: htlc.offered, amount_msat: htlc.amount_msat }).collect();
4309
+ actual_nondust_htlcs.sort_unstable();
4310
+ if predicted_feerate == commitment_data.tx.feerate_per_kw() && predicted_htlcs == actual_nondust_htlcs {
4311
+ assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
4312
+ }
4274
4313
}
4275
4314
4276
4315
if msg.htlc_signatures.len() != commitment_data.tx.nondust_htlcs().len() {
@@ -5921,6 +5960,14 @@ struct CommitmentTxInfoCached {
5921
5960
feerate: u32,
5922
5961
}
5923
5962
5963
+ #[cfg(any(test, fuzzing))]
5964
+ #[derive(Clone, Default)]
5965
+ struct PredictedNextFee {
5966
+ predicted_feerate: u32,
5967
+ predicted_htlcs: Vec<HTLCAmountDirection>,
5968
+ predicted_fee_sat: u64,
5969
+ }
5970
+
5924
5971
/// Contents of a wire message that fails an HTLC backwards. Useful for [`FundedChannel::fail_htlc`] to
5925
5972
/// fail with either [`msgs::UpdateFailMalformedHTLC`] or [`msgs::UpdateFailHTLC`] as needed.
5926
5973
trait FailHTLCContents {
@@ -10885,6 +10932,12 @@ where
10885
10932
}
10886
10933
}
10887
10934
}
10935
+ let PredictedNextFee { predicted_feerate, predicted_htlcs, predicted_fee_sat } = funding.next_remote_fee.lock().unwrap().clone();
10936
+ let mut actual_nondust_htlcs: Vec<_> = counterparty_commitment_tx.nondust_htlcs().iter().map(|htlc| HTLCAmountDirection { outbound: !htlc.offered, amount_msat: htlc.amount_msat }).collect();
10937
+ actual_nondust_htlcs.sort_unstable();
10938
+ if predicted_feerate == counterparty_commitment_tx.feerate_per_kw() && predicted_htlcs == actual_nondust_htlcs {
10939
+ assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
10940
+ }
10888
10941
}
10889
10942
10890
10943
(commitment_data.htlcs_included, counterparty_commitment_tx)
@@ -13510,6 +13563,10 @@ where
13510
13563
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
13511
13564
#[cfg(any(test, fuzzing))]
13512
13565
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
13566
+ #[cfg(any(test, fuzzing))]
13567
+ next_local_fee: Mutex::new(PredictedNextFee::default()),
13568
+ #[cfg(any(test, fuzzing))]
13569
+ next_remote_fee: Mutex::new(PredictedNextFee::default()),
13513
13570
13514
13571
channel_transaction_parameters: channel_parameters,
13515
13572
funding_transaction,
0 commit comments