Skip to content

Commit ecf097a

Browse files
committed
fix Change the order of the 2 check methods
1 parent 508b91a commit ecf097a

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

lightning/src/ln/channel.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10699,44 +10699,6 @@ where
1069910699
))
1070010700
}
1070110701

10702-
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well.
10703-
/// In case of error, it returns the minimum channel reserve that was violated (in sats)
10704-
#[cfg(splicing)]
10705-
pub fn check_splice_balance_meets_v2_reserve_requirement(
10706-
&self, pre_balance_msat: u64, post_balance_msat: u64, pre_channel_value_sats: u64,
10707-
post_channel_value_sats: u64, dust_limit_sats: u64,
10708-
) -> Result<(), u64> {
10709-
let post_channel_reserve_sats =
10710-
get_v2_channel_reserve_satoshis(post_channel_value_sats, dust_limit_sats);
10711-
if post_balance_msat >= (post_channel_reserve_sats * 1000) {
10712-
return Ok(());
10713-
}
10714-
// We're not allowed to dip below the reserve once we've been above,
10715-
// check differently for originally v1 and v2 channels
10716-
if self.is_v2_established() {
10717-
let pre_channel_reserve_sats =
10718-
get_v2_channel_reserve_satoshis(pre_channel_value_sats, dust_limit_sats);
10719-
if pre_balance_msat >= (pre_channel_reserve_sats * 1000) {
10720-
return Err(post_channel_reserve_sats);
10721-
}
10722-
} else {
10723-
if pre_balance_msat >= (self.funding.holder_selected_channel_reserve_satoshis * 1000) {
10724-
return Err(post_channel_reserve_sats);
10725-
}
10726-
if let Some(cp_reserve) = self.funding.counterparty_selected_channel_reserve_satoshis {
10727-
if pre_balance_msat >= (cp_reserve * 1000) {
10728-
return Err(post_channel_reserve_sats);
10729-
}
10730-
}
10731-
}
10732-
// Make sure we either remain with the same balance or move towards the reserve.
10733-
if post_balance_msat >= pre_balance_msat {
10734-
Ok(())
10735-
} else {
10736-
Err(post_channel_reserve_sats)
10737-
}
10738-
}
10739-
1074010702
/// Check that balances (self and counterparty) meet the channel reserve requirements or violates them (below reserve).
1074110703
/// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
1074210704
/// to check with new channel value (before being committed to it).
@@ -10775,6 +10737,44 @@ where
1077510737
Ok(())
1077610738
}
1077710739

10740+
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well.
10741+
/// In case of error, it returns the minimum channel reserve that was violated (in sats)
10742+
#[cfg(splicing)]
10743+
pub fn check_splice_balance_meets_v2_reserve_requirement(
10744+
&self, pre_balance_msat: u64, post_balance_msat: u64, pre_channel_value_sats: u64,
10745+
post_channel_value_sats: u64, dust_limit_sats: u64,
10746+
) -> Result<(), u64> {
10747+
let post_channel_reserve_sats =
10748+
get_v2_channel_reserve_satoshis(post_channel_value_sats, dust_limit_sats);
10749+
if post_balance_msat >= (post_channel_reserve_sats * 1000) {
10750+
return Ok(());
10751+
}
10752+
// We're not allowed to dip below the reserve once we've been above,
10753+
// check differently for originally v1 and v2 channels
10754+
if self.is_v2_established() {
10755+
let pre_channel_reserve_sats =
10756+
get_v2_channel_reserve_satoshis(pre_channel_value_sats, dust_limit_sats);
10757+
if pre_balance_msat >= (pre_channel_reserve_sats * 1000) {
10758+
return Err(post_channel_reserve_sats);
10759+
}
10760+
} else {
10761+
if pre_balance_msat >= (self.funding.holder_selected_channel_reserve_satoshis * 1000) {
10762+
return Err(post_channel_reserve_sats);
10763+
}
10764+
if let Some(cp_reserve) = self.funding.counterparty_selected_channel_reserve_satoshis {
10765+
if pre_balance_msat >= (cp_reserve * 1000) {
10766+
return Err(post_channel_reserve_sats);
10767+
}
10768+
}
10769+
}
10770+
// Make sure we either remain with the same balance or move towards the reserve.
10771+
if post_balance_msat >= pre_balance_msat {
10772+
Ok(())
10773+
} else {
10774+
Err(post_channel_reserve_sats)
10775+
}
10776+
}
10777+
1077810778
// Send stuff to our remote peers:
1077910779

1078010780
/// Queues up an outbound HTLC to send by placing it in the holding cell. You should call

0 commit comments

Comments
 (0)