@@ -2583,10 +2583,10 @@ pub(super) struct FundingScope {
25832583
25842584 #[cfg(debug_assertions)]
25852585 /// Max to_local and to_remote outputs in a locally-generated commitment transaction
2586- holder_max_commitment_tx_output : Mutex<(u64, u64)>,
2586+ holder_prev_commitment_tx_balance : Mutex<(u64, u64)>,
25872587 #[cfg(debug_assertions)]
25882588 /// Max to_local and to_remote outputs in a remote-generated commitment transaction
2589- counterparty_max_commitment_tx_output : Mutex<(u64, u64)>,
2589+ counterparty_prev_commitment_tx_balance : Mutex<(u64, u64)>,
25902590
25912591 // We save these values so we can make sure validation of channel updates properly predicts
25922592 // what the next commitment transaction fee will be, by comparing the cached values to the
@@ -2658,9 +2658,9 @@ impl Readable for FundingScope {
26582658 counterparty_selected_channel_reserve_satoshis,
26592659 holder_selected_channel_reserve_satoshis: holder_selected_channel_reserve_satoshis.0.unwrap(),
26602660 #[cfg(debug_assertions)]
2661- holder_max_commitment_tx_output : Mutex::new((0, 0)),
2661+ holder_prev_commitment_tx_balance : Mutex::new((0, 0)),
26622662 #[cfg(debug_assertions)]
2663- counterparty_max_commitment_tx_output : Mutex::new((0, 0)),
2663+ counterparty_prev_commitment_tx_balance : Mutex::new((0, 0)),
26642664 channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
26652665 funding_transaction,
26662666 funding_tx_confirmed_in,
@@ -2847,16 +2847,16 @@ impl FundingScope {
28472847 counterparty_selected_channel_reserve_satoshis,
28482848 holder_selected_channel_reserve_satoshis,
28492849 #[cfg(debug_assertions)]
2850- holder_max_commitment_tx_output : {
2851- let prev = *prev_funding.holder_max_commitment_tx_output .lock().unwrap();
2850+ holder_prev_commitment_tx_balance : {
2851+ let prev = *prev_funding.holder_prev_commitment_tx_balance .lock().unwrap();
28522852 Mutex::new((
28532853 prev.0.saturating_add_signed(our_funding_contribution.to_sat() * 1000),
28542854 prev.1.saturating_add_signed(their_funding_contribution.to_sat() * 1000),
28552855 ))
28562856 },
28572857 #[cfg(debug_assertions)]
2858- counterparty_max_commitment_tx_output : {
2859- let prev = *prev_funding.counterparty_max_commitment_tx_output .lock().unwrap();
2858+ counterparty_prev_commitment_tx_balance : {
2859+ let prev = *prev_funding.counterparty_prev_commitment_tx_balance .lock().unwrap();
28602860 Mutex::new((
28612861 prev.0.saturating_add_signed(our_funding_contribution.to_sat() * 1000),
28622862 prev.1.saturating_add_signed(their_funding_contribution.to_sat() * 1000),
@@ -3805,9 +3805,9 @@ impl<SP: SignerProvider> ChannelContext<SP> {
38053805 holder_selected_channel_reserve_satoshis,
38063806
38073807 #[cfg(debug_assertions)]
3808- holder_max_commitment_tx_output : Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
3808+ holder_prev_commitment_tx_balance : Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
38093809 #[cfg(debug_assertions)]
3810- counterparty_max_commitment_tx_output : Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
3810+ counterparty_prev_commitment_tx_balance : Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
38113811
38123812 #[cfg(any(test, fuzzing))]
38133813 next_local_fee: Mutex::new(PredictedNextFee::default()),
@@ -4043,9 +4043,9 @@ impl<SP: SignerProvider> ChannelContext<SP> {
40434043 // We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
40444044 // when we receive `accept_channel2`.
40454045 #[cfg(debug_assertions)]
4046- holder_max_commitment_tx_output : Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
4046+ holder_prev_commitment_tx_balance : Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
40474047 #[cfg(debug_assertions)]
4048- counterparty_max_commitment_tx_output : Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
4048+ counterparty_prev_commitment_tx_balance : Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
40494049
40504050 #[cfg(any(test, fuzzing))]
40514051 next_local_fee: Mutex::new(PredictedNextFee::default()),
@@ -5594,17 +5594,26 @@ impl<SP: SignerProvider> ChannelContext<SP> {
55945594 {
55955595 // Make sure that the to_self/to_remote is always either past the appropriate
55965596 // channel_reserve *or* it is making progress towards it.
5597- let mut broadcaster_max_commitment_tx_output = if generated_by_local {
5598- funding.holder_max_commitment_tx_output .lock().unwrap()
5597+ let mut broadcaster_prev_commitment_balance = if generated_by_local {
5598+ funding.holder_prev_commitment_tx_balance .lock().unwrap()
55995599 } else {
5600- funding.counterparty_max_commitment_tx_output .lock().unwrap()
5600+ funding.counterparty_prev_commitment_tx_balance .lock().unwrap()
56015601 };
5602- debug_assert!(broadcaster_max_commitment_tx_output.0 <= stats.local_balance_before_fee_msat || stats.local_balance_before_fee_msat / 1000 >= funding.counterparty_selected_channel_reserve_satoshis.unwrap());
5603- broadcaster_max_commitment_tx_output.0 = cmp::max(broadcaster_max_commitment_tx_output.0, stats.local_balance_before_fee_msat);
5604- debug_assert!(broadcaster_max_commitment_tx_output.1 <= stats.remote_balance_before_fee_msat || stats.remote_balance_before_fee_msat / 1000 >= funding.holder_selected_channel_reserve_satoshis);
5605- broadcaster_max_commitment_tx_output.1 = cmp::max(broadcaster_max_commitment_tx_output.1, stats.remote_balance_before_fee_msat);
5606- }
56075602
5603+ if stats.local_balance_before_fee_msat / 1000 < funding.counterparty_selected_channel_reserve_satoshis.unwrap() {
5604+ // If the local balance is below the reserve on this new commitment, it MUST be
5605+ // greater than or equal to the one on the previous commitment.
5606+ debug_assert!(broadcaster_prev_commitment_balance.0 <= stats.local_balance_before_fee_msat);
5607+ }
5608+ broadcaster_prev_commitment_balance.0 = stats.local_balance_before_fee_msat;
5609+
5610+ if stats.remote_balance_before_fee_msat / 1000 < funding.holder_selected_channel_reserve_satoshis {
5611+ // If the remote balance is below the reserve on this new commitment, it MUST be
5612+ // greater than or equal to the one on the previous commitment.
5613+ debug_assert!(broadcaster_prev_commitment_balance.1 <= stats.remote_balance_before_fee_msat);
5614+ }
5615+ broadcaster_prev_commitment_balance.1 = stats.remote_balance_before_fee_msat;
5616+ }
56085617
56095618 // This populates the HTLC-source table with the indices from the HTLCs in the commitment
56105619 // transaction.
@@ -15983,9 +15992,9 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
1598315992 .unwrap(),
1598415993
1598515994 #[cfg(debug_assertions)]
15986- holder_max_commitment_tx_output : Mutex::new((0, 0)),
15995+ holder_prev_commitment_tx_balance : Mutex::new((0, 0)),
1598715996 #[cfg(debug_assertions)]
15988- counterparty_max_commitment_tx_output : Mutex::new((0, 0)),
15997+ counterparty_prev_commitment_tx_balance : Mutex::new((0, 0)),
1598915998
1599015999 #[cfg(any(test, fuzzing))]
1599116000 next_local_fee: Mutex::new(PredictedNextFee::default()),
@@ -18548,9 +18557,9 @@ mod tests {
1854818557 holder_selected_channel_reserve_satoshis: 0,
1854918558
1855018559 #[cfg(debug_assertions)]
18551- holder_max_commitment_tx_output : Mutex::new((0, 0)),
18560+ holder_prev_commitment_tx_balance : Mutex::new((0, 0)),
1855218561 #[cfg(debug_assertions)]
18553- counterparty_max_commitment_tx_output : Mutex::new((0, 0)),
18562+ counterparty_prev_commitment_tx_balance : Mutex::new((0, 0)),
1855418563
1855518564 #[cfg(any(test, fuzzing))]
1855618565 next_local_fee: Mutex::new(PredictedNextFee::default()),
0 commit comments