@@ -1984,6 +1984,10 @@ pub(super) struct FundingScope {
1984
1984
next_local_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1985
1985
#[cfg(any(test, fuzzing))]
1986
1986
next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
1987
+ #[cfg(any(test, fuzzing))]
1988
+ next_local_fee: Mutex<PredictedNextFee>,
1989
+ #[cfg(any(test, fuzzing))]
1990
+ next_remote_fee: Mutex<PredictedNextFee>,
1987
1991
1988
1992
pub(super) channel_transaction_parameters: ChannelTransactionParameters,
1989
1993
@@ -2060,6 +2064,10 @@ impl Readable for FundingScope {
2060
2064
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2061
2065
#[cfg(any(test, fuzzing))]
2062
2066
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2067
+ #[cfg(any(test, fuzzing))]
2068
+ next_local_fee: Mutex::new(PredictedNextFee::default()),
2069
+ #[cfg(any(test, fuzzing))]
2070
+ next_remote_fee: Mutex::new(PredictedNextFee::default()),
2063
2071
})
2064
2072
}
2065
2073
}
@@ -3206,6 +3214,10 @@ where
3206
3214
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
3207
3215
#[cfg(any(test, fuzzing))]
3208
3216
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
3217
+ #[cfg(any(test, fuzzing))]
3218
+ next_local_fee: Mutex::new(PredictedNextFee::default()),
3219
+ #[cfg(any(test, fuzzing))]
3220
+ next_remote_fee: Mutex::new(PredictedNextFee::default()),
3209
3221
3210
3222
channel_transaction_parameters: ChannelTransactionParameters {
3211
3223
holder_pubkeys: pubkeys,
@@ -3449,6 +3461,10 @@ where
3449
3461
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
3450
3462
#[cfg(any(test, fuzzing))]
3451
3463
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
3464
+ #[cfg(any(test, fuzzing))]
3465
+ next_local_fee: Mutex::new(PredictedNextFee::default()),
3466
+ #[cfg(any(test, fuzzing))]
3467
+ next_remote_fee: Mutex::new(PredictedNextFee::default()),
3452
3468
3453
3469
channel_transaction_parameters: ChannelTransactionParameters {
3454
3470
holder_pubkeys: pubkeys,
@@ -4322,6 +4338,25 @@ where
4322
4338
}
4323
4339
}
4324
4340
4341
+ #[cfg(any(test, fuzzing))]
4342
+ {
4343
+ let mut local_predicted_htlcs = next_local_commitment_stats.next_commitment_htlcs;
4344
+ local_predicted_htlcs.sort_unstable();
4345
+ *funding.next_local_fee.lock().unwrap() = PredictedNextFee {
4346
+ predicted_feerate: self.feerate_per_kw,
4347
+ predicted_htlcs: local_predicted_htlcs,
4348
+ predicted_fee_sat: next_local_commitment_stats.commit_tx_fee_sat,
4349
+ };
4350
+
4351
+ let mut remote_predicted_htlcs = next_remote_commitment_stats.next_commitment_htlcs;
4352
+ remote_predicted_htlcs.sort_unstable();
4353
+ *funding.next_remote_fee.lock().unwrap() = PredictedNextFee {
4354
+ predicted_feerate: self.feerate_per_kw,
4355
+ predicted_htlcs: remote_predicted_htlcs,
4356
+ predicted_fee_sat: next_remote_commitment_stats.commit_tx_fee_sat,
4357
+ };
4358
+ }
4359
+
4325
4360
Ok(())
4326
4361
}
4327
4362
@@ -4352,6 +4387,25 @@ where
4352
4387
msg.feerate_per_kw, next_remote_commitment_stats.dust_exposure_msat)));
4353
4388
}
4354
4389
4390
+ #[cfg(any(test, fuzzing))]
4391
+ {
4392
+ let mut local_predicted_htlcs = next_local_commitment_stats.next_commitment_htlcs;
4393
+ local_predicted_htlcs.sort_unstable();
4394
+ *funding.next_local_fee.lock().unwrap() = PredictedNextFee {
4395
+ predicted_feerate: msg.feerate_per_kw,
4396
+ predicted_htlcs: local_predicted_htlcs,
4397
+ predicted_fee_sat: next_local_commitment_stats.commit_tx_fee_sat,
4398
+ };
4399
+
4400
+ let mut remote_predicted_htlcs = next_remote_commitment_stats.next_commitment_htlcs;
4401
+ remote_predicted_htlcs.sort_unstable();
4402
+ *funding.next_remote_fee.lock().unwrap() = PredictedNextFee {
4403
+ predicted_feerate: msg.feerate_per_kw,
4404
+ predicted_htlcs: remote_predicted_htlcs,
4405
+ predicted_fee_sat: next_remote_commitment_stats.commit_tx_fee_sat,
4406
+ };
4407
+ }
4408
+
4355
4409
Ok(())
4356
4410
}
4357
4411
@@ -4411,6 +4465,12 @@ where
4411
4465
}
4412
4466
}
4413
4467
}
4468
+ let PredictedNextFee { predicted_feerate, predicted_htlcs, predicted_fee_sat } = funding.next_local_fee.lock().unwrap().clone();
4469
+ let mut actual_nondust_htlcs: Vec<_> = commitment_data.tx.nondust_htlcs().iter().map(|&HTLCOutputInCommitment { offered, amount_msat, .. } | HTLCAmountDirection { outbound: offered, amount_msat }).collect();
4470
+ actual_nondust_htlcs.sort_unstable();
4471
+ if predicted_feerate == commitment_data.tx.feerate_per_kw() && predicted_htlcs == actual_nondust_htlcs {
4472
+ assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
4473
+ }
4414
4474
}
4415
4475
4416
4476
if msg.htlc_signatures.len() != commitment_data.tx.nondust_htlcs().len() {
@@ -4483,6 +4543,18 @@ where
4483
4543
return false;
4484
4544
}
4485
4545
4546
+ #[cfg(any(test, fuzzing))]
4547
+ {
4548
+ let next_remote_commitment_stats = self.get_next_remote_commitment_stats(funding, None, include_counterparty_unknown_htlcs, 0, feerate_per_kw, dust_exposure_limiting_feerate);
4549
+ let mut remote_predicted_htlcs = next_remote_commitment_stats.next_commitment_htlcs;
4550
+ remote_predicted_htlcs.sort_unstable();
4551
+ *funding.next_remote_fee.lock().unwrap() = PredictedNextFee {
4552
+ predicted_feerate: feerate_per_kw,
4553
+ predicted_htlcs: remote_predicted_htlcs,
4554
+ predicted_fee_sat: next_remote_commitment_stats.commit_tx_fee_sat,
4555
+ };
4556
+ }
4557
+
4486
4558
return true;
4487
4559
}
4488
4560
@@ -4537,6 +4609,35 @@ where
4537
4609
}
4538
4610
}
4539
4611
4612
+ #[cfg(any(test, fuzzing))]
4613
+ {
4614
+ let next_local_commitment_stats = if fee_spike_buffer_htlc == 1 {
4615
+ self.get_next_local_commitment_stats(funding, None, do_not_include_counterparty_unknown_htlcs, 0, self.feerate_per_kw, dust_exposure_limiting_feerate)
4616
+ } else {
4617
+ next_local_commitment_stats
4618
+ };
4619
+ let mut local_predicted_htlcs = next_local_commitment_stats.next_commitment_htlcs;
4620
+ local_predicted_htlcs.sort_unstable();
4621
+ *funding.next_local_fee.lock().unwrap() = PredictedNextFee {
4622
+ predicted_feerate: self.feerate_per_kw,
4623
+ predicted_htlcs: local_predicted_htlcs,
4624
+ predicted_fee_sat: next_local_commitment_stats.commit_tx_fee_sat,
4625
+ };
4626
+
4627
+ let next_remote_commitment_stats = if fee_spike_buffer_htlc == 1 {
4628
+ self.get_next_remote_commitment_stats(funding, None, do_not_include_counterparty_unknown_htlcs, 0, self.feerate_per_kw, dust_exposure_limiting_feerate)
4629
+ } else {
4630
+ next_remote_commitment_stats
4631
+ };
4632
+ let mut remote_predicted_htlcs = next_remote_commitment_stats.next_commitment_htlcs;
4633
+ remote_predicted_htlcs.sort_unstable();
4634
+ *funding.next_remote_fee.lock().unwrap() = PredictedNextFee {
4635
+ predicted_feerate: self.feerate_per_kw,
4636
+ predicted_htlcs: remote_predicted_htlcs,
4637
+ predicted_fee_sat: next_remote_commitment_stats.commit_tx_fee_sat,
4638
+ };
4639
+ }
4640
+
4540
4641
Ok(())
4541
4642
}
4542
4643
@@ -6026,6 +6127,14 @@ struct CommitmentTxInfoCached {
6026
6127
feerate: u32,
6027
6128
}
6028
6129
6130
+ #[cfg(any(test, fuzzing))]
6131
+ #[derive(Clone, Default)]
6132
+ struct PredictedNextFee {
6133
+ predicted_feerate: u32,
6134
+ predicted_htlcs: Vec<HTLCAmountDirection>,
6135
+ predicted_fee_sat: u64,
6136
+ }
6137
+
6029
6138
/// Contents of a wire message that fails an HTLC backwards. Useful for [`FundedChannel::fail_htlc`] to
6030
6139
/// fail with either [`msgs::UpdateFailMalformedHTLC`] or [`msgs::UpdateFailHTLC`] as needed.
6031
6140
trait FailHTLCContents {
@@ -10990,6 +11099,12 @@ where
10990
11099
}
10991
11100
}
10992
11101
}
11102
+ let PredictedNextFee { predicted_feerate, predicted_htlcs, predicted_fee_sat } = funding.next_remote_fee.lock().unwrap().clone();
11103
+ let mut actual_nondust_htlcs: Vec<_> = counterparty_commitment_tx.nondust_htlcs().iter().map(|&HTLCOutputInCommitment { offered, amount_msat, .. }| HTLCAmountDirection { outbound: !offered, amount_msat }).collect();
11104
+ actual_nondust_htlcs.sort_unstable();
11105
+ if predicted_feerate == counterparty_commitment_tx.feerate_per_kw() && predicted_htlcs == actual_nondust_htlcs {
11106
+ assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
11107
+ }
10993
11108
}
10994
11109
10995
11110
(commitment_data.htlcs_included, counterparty_commitment_tx)
@@ -13615,6 +13730,10 @@ where
13615
13730
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
13616
13731
#[cfg(any(test, fuzzing))]
13617
13732
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
13733
+ #[cfg(any(test, fuzzing))]
13734
+ next_local_fee: Mutex::new(PredictedNextFee::default()),
13735
+ #[cfg(any(test, fuzzing))]
13736
+ next_remote_fee: Mutex::new(PredictedNextFee::default()),
13618
13737
13619
13738
channel_transaction_parameters: channel_parameters,
13620
13739
funding_transaction,
0 commit comments