@@ -1593,6 +1593,13 @@ pub(super) struct FundingScope {
15931593 pub(super) holder_selected_channel_reserve_satoshis: u64,
15941594 #[cfg(not(test))]
15951595 holder_selected_channel_reserve_satoshis: u64,
1596+
1597+ #[cfg(debug_assertions)]
1598+ /// Max to_local and to_remote outputs in a locally-generated commitment transaction
1599+ holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1600+ #[cfg(debug_assertions)]
1601+ /// Max to_local and to_remote outputs in a remote-generated commitment transaction
1602+ counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
15961603}
15971604
15981605impl FundingScope {
@@ -1740,13 +1747,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
17401747 /// time.
17411748 update_time_counter: u32,
17421749
1743- #[cfg(debug_assertions)]
1744- /// Max to_local and to_remote outputs in a locally-generated commitment transaction
1745- holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1746- #[cfg(debug_assertions)]
1747- /// Max to_local and to_remote outputs in a remote-generated commitment transaction
1748- counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1749-
17501750 // (fee_sats, skip_remote_output, fee_range, holder_sig)
17511751 last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
17521752 last_received_closing_sig: Option<Signature>,
@@ -2486,6 +2486,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
24862486 value_to_self_msat,
24872487 counterparty_selected_channel_reserve_satoshis: Some(msg_channel_reserve_satoshis),
24882488 holder_selected_channel_reserve_satoshis,
2489+
2490+ #[cfg(debug_assertions)]
2491+ holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2492+ #[cfg(debug_assertions)]
2493+ counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
24892494 };
24902495 let channel_context = ChannelContext {
24912496 user_id,
@@ -2542,12 +2547,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
25422547 signer_pending_closing: false,
25432548 signer_pending_channel_ready: false,
25442549
2545-
2546- #[cfg(debug_assertions)]
2547- holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2548- #[cfg(debug_assertions)]
2549- counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2550-
25512550 last_sent_closing_fee: None,
25522551 last_received_closing_sig: None,
25532552 pending_counterparty_closing_signed: None,
@@ -2720,6 +2719,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27202719 value_to_self_msat,
27212720 counterparty_selected_channel_reserve_satoshis: None, // Filled in in accept_channel
27222721 holder_selected_channel_reserve_satoshis,
2722+
2723+ // We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2724+ // when we receive `accept_channel2`.
2725+ #[cfg(debug_assertions)]
2726+ holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2727+ #[cfg(debug_assertions)]
2728+ counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
27232729 };
27242730 let channel_context = Self {
27252731 user_id,
@@ -2774,13 +2780,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27742780 signer_pending_closing: false,
27752781 signer_pending_channel_ready: false,
27762782
2777- // We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2778- // when we receive `accept_channel2`.
2779- #[cfg(debug_assertions)]
2780- holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2781- #[cfg(debug_assertions)]
2782- counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2783-
27842783 last_sent_closing_fee: None,
27852784 last_received_closing_sig: None,
27862785 pending_counterparty_closing_signed: None,
@@ -3511,9 +3510,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
35113510 // Make sure that the to_self/to_remote is always either past the appropriate
35123511 // channel_reserve *or* it is making progress towards it.
35133512 let mut broadcaster_max_commitment_tx_output = if generated_by_local {
3514- self .holder_max_commitment_tx_output.lock().unwrap()
3513+ funding .holder_max_commitment_tx_output.lock().unwrap()
35153514 } else {
3516- self .counterparty_max_commitment_tx_output.lock().unwrap()
3515+ funding .counterparty_max_commitment_tx_output.lock().unwrap()
35173516 };
35183517 debug_assert!(broadcaster_max_commitment_tx_output.0 <= value_to_self_msat as u64 || value_to_self_msat / 1000 >= funding.counterparty_selected_channel_reserve_satoshis.unwrap() as i64);
35193518 broadcaster_max_commitment_tx_output.0 = cmp::max(broadcaster_max_commitment_tx_output.0, value_to_self_msat as u64);
@@ -10409,6 +10408,11 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1040910408 value_to_self_msat,
1041010409 counterparty_selected_channel_reserve_satoshis,
1041110410 holder_selected_channel_reserve_satoshis: holder_selected_channel_reserve_satoshis.unwrap(),
10411+
10412+ #[cfg(debug_assertions)]
10413+ holder_max_commitment_tx_output: Mutex::new((0, 0)),
10414+ #[cfg(debug_assertions)]
10415+ counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
1041210416 },
1041310417 context: ChannelContext {
1041410418 user_id,
@@ -10464,11 +10468,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1046410468 update_time_counter,
1046510469 feerate_per_kw,
1046610470
10467- #[cfg(debug_assertions)]
10468- holder_max_commitment_tx_output: Mutex::new((0, 0)),
10469- #[cfg(debug_assertions)]
10470- counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10471-
1047210471 last_sent_closing_fee: None,
1047310472 last_received_closing_sig: None,
1047410473 pending_counterparty_closing_signed: None,
0 commit comments