@@ -4131,60 +4131,62 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4131
4131
}
4132
4132
}
4133
4133
4134
- /// Check a balance against a channel reserver requirement
4134
+ /// Check a balance against a channel reserve requirement
4135
4135
#[cfg(splicing)]
4136
- pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> (bool, u64) {
4137
- let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
4136
+ pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> Result<(), u64> {
4138
4137
if balance == 0 {
4139
4138
// 0 balance is fine
4140
- (true, channel_reserve )
4139
+ Ok(() )
4141
4140
} else {
4142
- ((balance >= channel_reserve), channel_reserve)
4141
+ let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
4142
+ if balance >= channel_reserve {
4143
+ Ok(())
4144
+ } else {
4145
+ Err(channel_reserve)
4146
+ }
4143
4147
}
4144
4148
}
4145
4149
4146
- /// Check that post-splicing balance meets reserver requirements, but only if it met it pre-splice as well
4150
+ /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
4147
4151
#[cfg(splicing)]
4148
- pub fn check_splice_balance_meets_v2_reserve_requirement_noerr(pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64, dust_limit: u64) -> (bool , u64) {
4152
+ pub fn check_splice_balance_meets_v2_reserve_requirement_noerr(pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64, dust_limit: u64) -> Result<() , u64> {
4149
4153
match Self::check_balance_meets_reserve_requirement(
4150
4154
post_balance, post_channel_value, dust_limit
4151
4155
) {
4152
- (true, channel_reserve ) => (true, channel_reserve ),
4153
- (false, channel_reserve ) =>
4156
+ Ok(_ ) => Ok(() ),
4157
+ Err(post_channel_reserve ) =>
4154
4158
// post is not OK, check pre
4155
4159
match Self::check_balance_meets_reserve_requirement(
4156
4160
pre_balance, pre_channel_value, dust_limit
4157
4161
) {
4158
- (true, _) =>
4159
- // pre OK, post not -> not
4160
- (false, channel_reserve),
4161
- (false, _) =>
4162
- // post not OK, but so was pre -> OK
4163
- (true, channel_reserve),
4162
+ // pre OK, post not -> not
4163
+ Ok(_) => Err(post_channel_reserve),
4164
+ // post not OK, but so was pre -> OK
4165
+ Err(_) => Ok(()),
4164
4166
}
4165
4167
}
4166
4168
}
4167
4169
4168
4170
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
4169
- /// The channel value is an input as opposed to using from self , so that this can be used in case of splicing
4170
- /// to check with new channel value (before being comitted to it).
4171
+ /// The channel value is an input as opposed to using from the FundingScope , so that this can be used in case of splicing
4172
+ /// to check with new channel value (before being committed to it).
4171
4173
#[cfg(splicing)]
4172
4174
pub fn check_splice_balances_meet_v2_reserve_requirements(&self, self_balance_pre: u64, self_balance_post: u64, counterparty_balance_pre: u64, counterparty_balance_post: u64, channel_value_pre: u64, channel_value_post: u64) -> Result<(), ChannelError> {
4173
- let (is_ok, channel_reserve_self) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4175
+ let is_ok_self = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4174
4176
self_balance_pre, self_balance_post, channel_value_pre, channel_value_post,
4175
4177
self.holder_dust_limit_satoshis
4176
4178
);
4177
- if !is_ok {
4179
+ if let Err(channel_reserve_self) = is_ok_self {
4178
4180
return Err(ChannelError::Warn(format!(
4179
4181
"Balance below reserve, mandated by holder, {} vs {}",
4180
4182
self_balance_post, channel_reserve_self,
4181
4183
)));
4182
4184
}
4183
- let (is_ok, channel_reserve_cp) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4185
+ let is_ok_cp = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4184
4186
counterparty_balance_pre, counterparty_balance_post, channel_value_pre, channel_value_post,
4185
4187
self.counterparty_dust_limit_satoshis
4186
4188
);
4187
- if !is_ok {
4189
+ if let Err(channel_reserve_cp) = is_ok_cp {
4188
4190
return Err(ChannelError::Warn(format!(
4189
4191
"Balance below reserve mandated by counterparty, {} vs {}",
4190
4192
counterparty_balance_post, channel_reserve_cp,
@@ -8563,7 +8565,8 @@ impl<SP: Deref> FundedChannel<SP> where
8563
8565
8564
8566
if their_funding_contribution_satoshis.saturating_add(our_funding_contribution_satoshis) < 0 {
8565
8567
return Err(ChannelError::Warn(format!(
8566
- "Splice-out not supported, only splice in, relative {} + {}",
8568
+ "Splice-out not supported, only splice in, contribution is {} ({} + {})",
8569
+ their_funding_contribution_satoshis + our_funding_contribution_satoshis,
8567
8570
their_funding_contribution_satoshis, our_funding_contribution_satoshis,
8568
8571
)));
8569
8572
}
0 commit comments