@@ -10853,6 +10853,7 @@ where
10853
10853
10854
10854
/// Compute the channel balances (local & remote, in msats) by taking into account fees,
10855
10855
/// anchor values, and dust limits.
10856
+ /// Pending HTLCs are not taken into account, this method should be used when there is no such,
10856
10857
/// e.g. in quiescence state
10857
10858
#[cfg(splicing)]
10858
10859
fn compute_balances_less_fees(
@@ -11091,59 +11092,58 @@ where
11091
11092
))
11092
11093
}
11093
11094
11094
- /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
11095
11095
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well.
11096
- /// Returns the minimum channel reserve ( sats)
11096
+ /// In case of error, it returns the minimum channel reserve that was violated (in sats)
11097
11097
#[cfg(splicing)]
11098
- pub fn check_splice_balance_meets_v2_reserve_requirement_noerr (
11099
- &self, pre_balance : u64, post_balance : u64, pre_channel_value : u64,
11100
- post_channel_value : u64, dust_limit : u64,
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
11101
) -> Result<(), u64> {
11102
11102
let post_channel_reserve_sats =
11103
- get_v2_channel_reserve_satoshis(post_channel_value, dust_limit );
11104
- if post_balance >= post_channel_reserve_sats * 1000 {
11103
+ get_v2_channel_reserve_satoshis(post_channel_value_sats, dust_limit_sats );
11104
+ if post_balance_msat >= ( post_channel_reserve_sats * 1000) {
11105
11105
return Ok(());
11106
11106
}
11107
11107
// We're not allowed to dip below the reserve once we've been above,
11108
11108
// check differently for originally v1 and v2 channels
11109
11109
if self.is_v2_established() {
11110
11110
let pre_channel_reserve_sats =
11111
- get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit );
11112
- if pre_balance >= pre_channel_reserve_sats * 1000 {
11111
+ get_v2_channel_reserve_satoshis(pre_channel_value_sats, dust_limit_sats );
11112
+ if pre_balance_msat >= ( pre_channel_reserve_sats * 1000) {
11113
11113
return Err(post_channel_reserve_sats);
11114
11114
}
11115
11115
} else {
11116
- if pre_balance >= self.funding.holder_selected_channel_reserve_satoshis * 1000 {
11116
+ if pre_balance_msat >= ( self.funding.holder_selected_channel_reserve_satoshis * 1000) {
11117
11117
return Err(post_channel_reserve_sats);
11118
11118
}
11119
11119
if let Some(cp_reserve) = self.funding.counterparty_selected_channel_reserve_satoshis {
11120
- if pre_balance >= cp_reserve * 1000 {
11120
+ if pre_balance_msat >= ( cp_reserve * 1000) {
11121
11121
return Err(post_channel_reserve_sats);
11122
11122
}
11123
11123
}
11124
11124
}
11125
11125
// Make sure we either remain with the same balance or move towards the reserve.
11126
- if post_balance >= pre_balance {
11126
+ if post_balance_msat >= pre_balance_msat {
11127
11127
Ok(())
11128
11128
} else {
11129
11129
Err(post_channel_reserve_sats)
11130
11130
}
11131
11131
}
11132
11132
11133
- /// Check that balances meet the channel reserve requirements or violates them (below reserve).
11133
+ /// Check that balances (self and counterparty) meet the channel reserve requirements or violates them (below reserve).
11134
11134
/// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
11135
11135
/// to check with new channel value (before being committed to it).
11136
11136
#[cfg(splicing)]
11137
11137
pub fn check_splice_balances_meet_v2_reserve_requirements(
11138
11138
&self, self_balance_pre_msat: u64, self_balance_post_msat: u64,
11139
11139
counterparty_balance_pre_msat: u64, counterparty_balance_post_msat: u64,
11140
- channel_value_pre : u64, channel_value_post : u64,
11140
+ channel_value_pre_sats : u64, channel_value_post_sats : u64,
11141
11141
) -> Result<(), ChannelError> {
11142
- let is_ok_self = self.check_splice_balance_meets_v2_reserve_requirement_noerr (
11142
+ let is_ok_self = self.check_splice_balance_meets_v2_reserve_requirement (
11143
11143
self_balance_pre_msat,
11144
11144
self_balance_post_msat,
11145
- channel_value_pre ,
11146
- channel_value_post ,
11145
+ channel_value_pre_sats ,
11146
+ channel_value_post_sats ,
11147
11147
self.context.holder_dust_limit_satoshis,
11148
11148
);
11149
11149
if let Err(channel_reserve_self) = is_ok_self {
@@ -11152,11 +11152,11 @@ where
11152
11152
self_balance_post_msat, channel_reserve_self,
11153
11153
)));
11154
11154
}
11155
- let is_ok_cp = self.check_splice_balance_meets_v2_reserve_requirement_noerr (
11155
+ let is_ok_cp = self.check_splice_balance_meets_v2_reserve_requirement (
11156
11156
counterparty_balance_pre_msat,
11157
11157
counterparty_balance_post_msat,
11158
- channel_value_pre ,
11159
- channel_value_post ,
11158
+ channel_value_pre_sats ,
11159
+ channel_value_post_sats ,
11160
11160
self.context.counterparty_dust_limit_satoshis,
11161
11161
);
11162
11162
if let Err(channel_reserve_cp) = is_ok_cp {
0 commit comments