Skip to content

Commit ee00a6a

Browse files
committed
Move debug asserts on reserve tracking out of build_commitment_stats
1 parent 694d72b commit ee00a6a

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

lightning/src/ln/channel.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4636,21 +4636,6 @@ where
46364636
value_to_self_msat = value_to_self_msat.checked_sub(local_htlc_total_msat).unwrap();
46374637
value_to_remote_msat = value_to_remote_msat.checked_sub(remote_htlc_total_msat).unwrap();
46384638

4639-
#[cfg(debug_assertions)]
4640-
{
4641-
// Make sure that the to_self/to_remote is always either past the appropriate
4642-
// channel_reserve *or* it is making progress towards it.
4643-
let mut broadcaster_max_commitment_tx_output = if generated_by_local {
4644-
funding.holder_max_commitment_tx_output.lock().unwrap()
4645-
} else {
4646-
funding.counterparty_max_commitment_tx_output.lock().unwrap()
4647-
};
4648-
debug_assert!(broadcaster_max_commitment_tx_output.0 <= value_to_self_msat || value_to_self_msat / 1000 >= funding.counterparty_selected_channel_reserve_satoshis.unwrap());
4649-
broadcaster_max_commitment_tx_output.0 = cmp::max(broadcaster_max_commitment_tx_output.0, value_to_self_msat);
4650-
debug_assert!(broadcaster_max_commitment_tx_output.1 <= value_to_remote_msat || value_to_remote_msat / 1000 >= funding.holder_selected_channel_reserve_satoshis);
4651-
broadcaster_max_commitment_tx_output.1 = cmp::max(broadcaster_max_commitment_tx_output.1, value_to_remote_msat);
4652-
}
4653-
46544639
let commit_tx_fee_sat = SpecTxBuilder {}.commit_tx_fee_sat(feerate_per_kw, nondust_htlc_count + fee_buffer_nondust_htlcs.unwrap_or(0), funding.get_channel_type());
46554640
// Subtract any non-HTLC outputs from the local and remote balances
46564641
let (local_balance_before_fee_msat, remote_balance_before_fee_msat) = SpecTxBuilder {}.subtract_non_htlc_outputs(
@@ -4763,7 +4748,21 @@ where
47634748
broadcaster_dust_limit_sat,
47644749
logger,
47654750
);
4766-
debug_assert_eq!(stats, self.build_commitment_stats(funding, local, generated_by_local, None, None), "Caught an inconsistency between `TxBuilder::build_commitment_transaction` and the rest of the `TxBuilder` methods");
4751+
4752+
#[cfg(debug_assertions)]
4753+
{
4754+
// Make sure that the to_self/to_remote is always either past the appropriate
4755+
// channel_reserve *or* it is making progress towards it.
4756+
let mut broadcaster_max_commitment_tx_output = if generated_by_local {
4757+
funding.holder_max_commitment_tx_output.lock().unwrap()
4758+
} else {
4759+
funding.counterparty_max_commitment_tx_output.lock().unwrap()
4760+
};
4761+
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());
4762+
broadcaster_max_commitment_tx_output.0 = cmp::max(broadcaster_max_commitment_tx_output.0, stats.local_balance_before_fee_msat);
4763+
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);
4764+
broadcaster_max_commitment_tx_output.1 = cmp::max(broadcaster_max_commitment_tx_output.1, stats.remote_balance_before_fee_msat);
4765+
}
47674766

47684767
// This populates the HTLC-source table with the indices from the HTLCs in the commitment
47694768
// transaction.

0 commit comments

Comments
 (0)