@@ -4273,60 +4273,62 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4273
4273
}
4274
4274
}
4275
4275
4276
- /// Check a balance against a channel reserver requirement
4276
+ /// Check a balance against a channel reserve requirement
4277
4277
#[cfg(splicing)]
4278
- pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> (bool, u64) {
4279
- let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
4278
+ pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> Result<(), u64> {
4280
4279
if balance == 0 {
4281
4280
// 0 balance is fine
4282
- (true, channel_reserve )
4281
+ Ok(() )
4283
4282
} else {
4284
- ((balance >= channel_reserve), channel_reserve)
4283
+ let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
4284
+ if balance >= channel_reserve {
4285
+ Ok(())
4286
+ } else {
4287
+ Err(channel_reserve)
4288
+ }
4285
4289
}
4286
4290
}
4287
4291
4288
- /// Check that post-splicing balance meets reserver requirements, but only if it met it pre-splice as well
4292
+ /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
4289
4293
#[cfg(splicing)]
4290
- 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) {
4294
+ 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> {
4291
4295
match Self::check_balance_meets_reserve_requirement(
4292
4296
post_balance, post_channel_value, dust_limit
4293
4297
) {
4294
- (true, channel_reserve ) => (true, channel_reserve ),
4295
- (false, channel_reserve ) =>
4298
+ Ok(_ ) => Ok(() ),
4299
+ Err(post_channel_reserve ) =>
4296
4300
// post is not OK, check pre
4297
4301
match Self::check_balance_meets_reserve_requirement(
4298
4302
pre_balance, pre_channel_value, dust_limit
4299
4303
) {
4300
- (true, _) =>
4301
- // pre OK, post not -> not
4302
- (false, channel_reserve),
4303
- (false, _) =>
4304
- // post not OK, but so was pre -> OK
4305
- (true, channel_reserve),
4304
+ // pre OK, post not -> not
4305
+ Ok(_) => Err(post_channel_reserve),
4306
+ // post not OK, but so was pre -> OK
4307
+ Err(_) => Ok(()),
4306
4308
}
4307
4309
}
4308
4310
}
4309
4311
4310
4312
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
4311
- /// The channel value is an input as opposed to using from self , so that this can be used in case of splicing
4312
- /// to check with new channel value (before being comitted to it).
4313
+ /// The channel value is an input as opposed to using from the FundingScope , so that this can be used in case of splicing
4314
+ /// to check with new channel value (before being committed to it).
4313
4315
#[cfg(splicing)]
4314
4316
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> {
4315
- let (is_ok, channel_reserve_self) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4317
+ let is_ok_self = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4316
4318
self_balance_pre, self_balance_post, channel_value_pre, channel_value_post,
4317
4319
self.holder_dust_limit_satoshis
4318
4320
);
4319
- if !is_ok {
4321
+ if let Err(channel_reserve_self) = is_ok_self {
4320
4322
return Err(ChannelError::Warn(format!(
4321
4323
"Balance below reserve, mandated by holder, {} vs {}",
4322
4324
self_balance_post, channel_reserve_self,
4323
4325
)));
4324
4326
}
4325
- let (is_ok, channel_reserve_cp) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4327
+ let is_ok_cp = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4326
4328
counterparty_balance_pre, counterparty_balance_post, channel_value_pre, channel_value_post,
4327
4329
self.counterparty_dust_limit_satoshis
4328
4330
);
4329
- if !is_ok {
4331
+ if let Err(channel_reserve_cp) = is_ok_cp {
4330
4332
return Err(ChannelError::Warn(format!(
4331
4333
"Balance below reserve mandated by counterparty, {} vs {}",
4332
4334
counterparty_balance_post, channel_reserve_cp,
0 commit comments