Skip to content

Commit a3c594f

Browse files
committed
Move debug asserts on reserve tracking out of build_commitment_stats
1 parent 3b4a077 commit a3c594f

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
@@ -4631,21 +4631,6 @@ where
46314631
value_to_self_msat = value_to_self_msat.checked_sub(local_htlc_total_msat).unwrap();
46324632
value_to_remote_msat = value_to_remote_msat.checked_sub(remote_htlc_total_msat).unwrap();
46334633

4634-
#[cfg(debug_assertions)]
4635-
{
4636-
// Make sure that the to_self/to_remote is always either past the appropriate
4637-
// channel_reserve *or* it is making progress towards it.
4638-
let mut broadcaster_max_commitment_tx_output = if generated_by_local {
4639-
funding.holder_max_commitment_tx_output.lock().unwrap()
4640-
} else {
4641-
funding.counterparty_max_commitment_tx_output.lock().unwrap()
4642-
};
4643-
debug_assert!(broadcaster_max_commitment_tx_output.0 <= value_to_self_msat || value_to_self_msat / 1000 >= funding.counterparty_selected_channel_reserve_satoshis.unwrap());
4644-
broadcaster_max_commitment_tx_output.0 = cmp::max(broadcaster_max_commitment_tx_output.0, value_to_self_msat);
4645-
debug_assert!(broadcaster_max_commitment_tx_output.1 <= value_to_remote_msat || value_to_remote_msat / 1000 >= funding.holder_selected_channel_reserve_satoshis);
4646-
broadcaster_max_commitment_tx_output.1 = cmp::max(broadcaster_max_commitment_tx_output.1, value_to_remote_msat);
4647-
}
4648-
46494634
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());
46504635
// Subtract any non-HTLC outputs from the local and remote balances
46514636
let (local_balance_before_fee_msat, remote_balance_before_fee_msat) = SpecTxBuilder {}.subtract_non_htlc_outputs(
@@ -4758,7 +4743,21 @@ where
47584743
broadcaster_dust_limit_sat,
47594744
logger,
47604745
);
4761-
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");
4746+
4747+
#[cfg(debug_assertions)]
4748+
{
4749+
// Make sure that the to_self/to_remote is always either past the appropriate
4750+
// channel_reserve *or* it is making progress towards it.
4751+
let mut broadcaster_max_commitment_tx_output = if generated_by_local {
4752+
funding.holder_max_commitment_tx_output.lock().unwrap()
4753+
} else {
4754+
funding.counterparty_max_commitment_tx_output.lock().unwrap()
4755+
};
4756+
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());
4757+
broadcaster_max_commitment_tx_output.0 = cmp::max(broadcaster_max_commitment_tx_output.0, stats.local_balance_before_fee_msat);
4758+
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);
4759+
broadcaster_max_commitment_tx_output.1 = cmp::max(broadcaster_max_commitment_tx_output.1, stats.remote_balance_before_fee_msat);
4760+
}
47624761

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

0 commit comments

Comments
 (0)