Skip to content

Commit af1b8eb

Browse files
committed
fix Change the order of the 2 check methods
1 parent 5d949ec commit af1b8eb

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
@@ -11092,44 +11092,6 @@ where
1109211092
))
1109311093
}
1109411094

11095-
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well.
11096-
/// In case of error, it returns the minimum channel reserve that was violated (in sats)
11097-
#[cfg(splicing)]
11098-
pub fn check_splice_balance_meets_v2_reserve_requirement(
11099-
&self, pre_balance_msat: u64, post_balance_msat: u64, pre_channel_value_sats: u64,
11100-
post_channel_value_sats: u64, dust_limit_sats: u64,
11101-
) -> Result<(), u64> {
11102-
let post_channel_reserve_sats =
11103-
get_v2_channel_reserve_satoshis(post_channel_value_sats, dust_limit_sats);
11104-
if post_balance_msat >= (post_channel_reserve_sats * 1000) {
11105-
return Ok(());
11106-
}
11107-
// We're not allowed to dip below the reserve once we've been above,
11108-
// check differently for originally v1 and v2 channels
11109-
if self.is_v2_established() {
11110-
let pre_channel_reserve_sats =
11111-
get_v2_channel_reserve_satoshis(pre_channel_value_sats, dust_limit_sats);
11112-
if pre_balance_msat >= (pre_channel_reserve_sats * 1000) {
11113-
return Err(post_channel_reserve_sats);
11114-
}
11115-
} else {
11116-
if pre_balance_msat >= (self.funding.holder_selected_channel_reserve_satoshis * 1000) {
11117-
return Err(post_channel_reserve_sats);
11118-
}
11119-
if let Some(cp_reserve) = self.funding.counterparty_selected_channel_reserve_satoshis {
11120-
if pre_balance_msat >= (cp_reserve * 1000) {
11121-
return Err(post_channel_reserve_sats);
11122-
}
11123-
}
11124-
}
11125-
// Make sure we either remain with the same balance or move towards the reserve.
11126-
if post_balance_msat >= pre_balance_msat {
11127-
Ok(())
11128-
} else {
11129-
Err(post_channel_reserve_sats)
11130-
}
11131-
}
11132-
1113311095
/// Check that balances (self and counterparty) meet the channel reserve requirements or violates them (below reserve).
1113411096
/// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
1113511097
/// to check with new channel value (before being committed to it).
@@ -11168,6 +11130,44 @@ where
1116811130
Ok(())
1116911131
}
1117011132

11133+
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well.
11134+
/// In case of error, it returns the minimum channel reserve that was violated (in sats)
11135+
#[cfg(splicing)]
11136+
pub fn check_splice_balance_meets_v2_reserve_requirement(
11137+
&self, pre_balance_msat: u64, post_balance_msat: u64, pre_channel_value_sats: u64,
11138+
post_channel_value_sats: u64, dust_limit_sats: u64,
11139+
) -> Result<(), u64> {
11140+
let post_channel_reserve_sats =
11141+
get_v2_channel_reserve_satoshis(post_channel_value_sats, dust_limit_sats);
11142+
if post_balance_msat >= (post_channel_reserve_sats * 1000) {
11143+
return Ok(());
11144+
}
11145+
// We're not allowed to dip below the reserve once we've been above,
11146+
// check differently for originally v1 and v2 channels
11147+
if self.is_v2_established() {
11148+
let pre_channel_reserve_sats =
11149+
get_v2_channel_reserve_satoshis(pre_channel_value_sats, dust_limit_sats);
11150+
if pre_balance_msat >= (pre_channel_reserve_sats * 1000) {
11151+
return Err(post_channel_reserve_sats);
11152+
}
11153+
} else {
11154+
if pre_balance_msat >= (self.funding.holder_selected_channel_reserve_satoshis * 1000) {
11155+
return Err(post_channel_reserve_sats);
11156+
}
11157+
if let Some(cp_reserve) = self.funding.counterparty_selected_channel_reserve_satoshis {
11158+
if pre_balance_msat >= (cp_reserve * 1000) {
11159+
return Err(post_channel_reserve_sats);
11160+
}
11161+
}
11162+
}
11163+
// Make sure we either remain with the same balance or move towards the reserve.
11164+
if post_balance_msat >= pre_balance_msat {
11165+
Ok(())
11166+
} else {
11167+
Err(post_channel_reserve_sats)
11168+
}
11169+
}
11170+
1117111171
// Send stuff to our remote peers:
1117211172

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

0 commit comments

Comments
 (0)