Skip to content

Commit 5beaa01

Browse files
committed
Move *_max_commitment_tx_output to FundingScope
1 parent 1414f2d commit 5beaa01

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

lightning/src/ln/channel.rs

+26-27
Original file line numberDiff line numberDiff line change
@@ -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

15981605
/// Contains everything about the channel including state, and various flags.
@@ -1716,13 +1723,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
17161723
/// time.
17171724
update_time_counter: u32,
17181725

1719-
#[cfg(debug_assertions)]
1720-
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
1721-
holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1722-
#[cfg(debug_assertions)]
1723-
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1724-
counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1725-
17261726
// (fee_sats, skip_remote_output, fee_range, holder_sig)
17271727
last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
17281728
last_received_closing_sig: Option<Signature>,
@@ -2462,6 +2462,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
24622462
value_to_self_msat,
24632463
counterparty_selected_channel_reserve_satoshis: Some(msg_channel_reserve_satoshis),
24642464
holder_selected_channel_reserve_satoshis,
2465+
2466+
#[cfg(debug_assertions)]
2467+
holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2468+
#[cfg(debug_assertions)]
2469+
counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
24652470
};
24662471
let channel_context = ChannelContext {
24672472
user_id,
@@ -2518,12 +2523,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
25182523
signer_pending_closing: false,
25192524
signer_pending_channel_ready: false,
25202525

2521-
2522-
#[cfg(debug_assertions)]
2523-
holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2524-
#[cfg(debug_assertions)]
2525-
counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2526-
25272526
last_sent_closing_fee: None,
25282527
last_received_closing_sig: None,
25292528
pending_counterparty_closing_signed: None,
@@ -2696,6 +2695,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
26962695
value_to_self_msat,
26972696
counterparty_selected_channel_reserve_satoshis: None, // Filled in in accept_channel
26982697
holder_selected_channel_reserve_satoshis,
2698+
2699+
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2700+
// when we receive `accept_channel2`.
2701+
#[cfg(debug_assertions)]
2702+
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2703+
#[cfg(debug_assertions)]
2704+
counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
26992705
};
27002706
let channel_context = Self {
27012707
user_id,
@@ -2750,13 +2756,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27502756
signer_pending_closing: false,
27512757
signer_pending_channel_ready: false,
27522758

2753-
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2754-
// when we receive `accept_channel2`.
2755-
#[cfg(debug_assertions)]
2756-
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2757-
#[cfg(debug_assertions)]
2758-
counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2759-
27602759
last_sent_closing_fee: None,
27612760
last_received_closing_sig: None,
27622761
pending_counterparty_closing_signed: None,
@@ -3533,9 +3532,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
35333532
// Make sure that the to_self/to_remote is always either past the appropriate
35343533
// channel_reserve *or* it is making progress towards it.
35353534
let mut broadcaster_max_commitment_tx_output = if generated_by_local {
3536-
self.holder_max_commitment_tx_output.lock().unwrap()
3535+
funding.holder_max_commitment_tx_output.lock().unwrap()
35373536
} else {
3538-
self.counterparty_max_commitment_tx_output.lock().unwrap()
3537+
funding.counterparty_max_commitment_tx_output.lock().unwrap()
35393538
};
35403539
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);
35413540
broadcaster_max_commitment_tx_output.0 = cmp::max(broadcaster_max_commitment_tx_output.0, value_to_self_msat as u64);
@@ -10426,6 +10425,11 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1042610425
value_to_self_msat,
1042710426
counterparty_selected_channel_reserve_satoshis,
1042810427
holder_selected_channel_reserve_satoshis: holder_selected_channel_reserve_satoshis.unwrap(),
10428+
10429+
#[cfg(debug_assertions)]
10430+
holder_max_commitment_tx_output: Mutex::new((0, 0)),
10431+
#[cfg(debug_assertions)]
10432+
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
1042910433
},
1043010434
context: ChannelContext {
1043110435
user_id,
@@ -10481,11 +10485,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1048110485
update_time_counter,
1048210486
feerate_per_kw,
1048310487

10484-
#[cfg(debug_assertions)]
10485-
holder_max_commitment_tx_output: Mutex::new((0, 0)),
10486-
#[cfg(debug_assertions)]
10487-
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
10488-
1048910488
last_sent_closing_fee: None,
1049010489
last_received_closing_sig: None,
1049110490
pending_counterparty_closing_signed: None,

0 commit comments

Comments
 (0)