Skip to content

Commit 2d452fb

Browse files
committed
Move *_max_commitment_tx_output to FundingScope
1 parent 6bfb5fb commit 2d452fb

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
@@ -1572,6 +1572,13 @@ pub(super) struct FundingScope {
15721572
pub(super) holder_selected_channel_reserve_satoshis: u64,
15731573
#[cfg(not(test))]
15741574
holder_selected_channel_reserve_satoshis: u64,
1575+
1576+
#[cfg(debug_assertions)]
1577+
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
1578+
holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1579+
#[cfg(debug_assertions)]
1580+
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1581+
counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
15751582
}
15761583

15771584
impl FundingScope {
@@ -1719,13 +1726,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
17191726
/// time.
17201727
update_time_counter: u32,
17211728

1722-
#[cfg(debug_assertions)]
1723-
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
1724-
holder_max_commitment_tx_output: Mutex<(u64, u64)>,
1725-
#[cfg(debug_assertions)]
1726-
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1727-
counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1728-
17291729
// (fee_sats, skip_remote_output, fee_range, holder_sig)
17301730
last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
17311731
last_received_closing_sig: Option<Signature>,
@@ -2465,6 +2465,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
24652465
value_to_self_msat,
24662466
counterparty_selected_channel_reserve_satoshis: Some(msg_channel_reserve_satoshis),
24672467
holder_selected_channel_reserve_satoshis,
2468+
2469+
#[cfg(debug_assertions)]
2470+
holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2471+
#[cfg(debug_assertions)]
2472+
counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
24682473
};
24692474
let channel_context = ChannelContext {
24702475
user_id,
@@ -2521,12 +2526,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
25212526
signer_pending_closing: false,
25222527
signer_pending_channel_ready: false,
25232528

2524-
2525-
#[cfg(debug_assertions)]
2526-
holder_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2527-
#[cfg(debug_assertions)]
2528-
counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
2529-
25302529
last_sent_closing_fee: None,
25312530
last_received_closing_sig: None,
25322531
pending_counterparty_closing_signed: None,
@@ -2699,6 +2698,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
26992698
value_to_self_msat,
27002699
counterparty_selected_channel_reserve_satoshis: None, // Filled in in accept_channel
27012700
holder_selected_channel_reserve_satoshis,
2701+
2702+
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2703+
// when we receive `accept_channel2`.
2704+
#[cfg(debug_assertions)]
2705+
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2706+
#[cfg(debug_assertions)]
2707+
counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
27022708
};
27032709
let channel_context = Self {
27042710
user_id,
@@ -2753,13 +2759,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27532759
signer_pending_closing: false,
27542760
signer_pending_channel_ready: false,
27552761

2756-
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
2757-
// when we receive `accept_channel2`.
2758-
#[cfg(debug_assertions)]
2759-
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2760-
#[cfg(debug_assertions)]
2761-
counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
2762-
27632762
last_sent_closing_fee: None,
27642763
last_received_closing_sig: None,
27652764
pending_counterparty_closing_signed: None,
@@ -3490,9 +3489,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
34903489
// Make sure that the to_self/to_remote is always either past the appropriate
34913490
// channel_reserve *or* it is making progress towards it.
34923491
let mut broadcaster_max_commitment_tx_output = if generated_by_local {
3493-
self.holder_max_commitment_tx_output.lock().unwrap()
3492+
funding.holder_max_commitment_tx_output.lock().unwrap()
34943493
} else {
3495-
self.counterparty_max_commitment_tx_output.lock().unwrap()
3494+
funding.counterparty_max_commitment_tx_output.lock().unwrap()
34963495
};
34973496
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);
34983497
broadcaster_max_commitment_tx_output.0 = cmp::max(broadcaster_max_commitment_tx_output.0, value_to_self_msat as u64);
@@ -10371,6 +10370,11 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1037110370
value_to_self_msat,
1037210371
counterparty_selected_channel_reserve_satoshis,
1037310372
holder_selected_channel_reserve_satoshis: holder_selected_channel_reserve_satoshis.unwrap(),
10373+
10374+
#[cfg(debug_assertions)]
10375+
holder_max_commitment_tx_output: Mutex::new((0, 0)),
10376+
#[cfg(debug_assertions)]
10377+
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
1037410378
},
1037510379
context: ChannelContext {
1037610380
user_id,
@@ -10426,11 +10430,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1042610430
update_time_counter,
1042710431
feerate_per_kw,
1042810432

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)),
10433-
1043410433
last_sent_closing_fee: None,
1043510434
last_received_closing_sig: None,
1043610435
pending_counterparty_closing_signed: None,

0 commit comments

Comments
 (0)