@@ -4266,54 +4266,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4266
4266
}
4267
4267
}
4268
4268
4269
- /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
4270
- #[cfg(splicing)]
4271
- 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> {
4272
- let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
4273
- if post_balance >= post_channel_reserve {
4274
- return Ok(());
4275
- }
4276
- let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
4277
- if pre_balance >= pre_channel_reserve {
4278
- // We're not allowed to dip below the reserve once we've been above.
4279
- return Err(post_channel_reserve);
4280
- }
4281
- // Make sure we either remain with the same balance or move towards the reserve.
4282
- if post_balance >= pre_balance {
4283
- Ok(())
4284
- } else {
4285
- Err(post_channel_reserve)
4286
- }
4287
- }
4288
-
4289
- /// Check that balances meet the channel reserve requirements or violates them (below reserve).
4290
- /// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
4291
- /// to check with new channel value (before being committed to it).
4292
- #[cfg(splicing)]
4293
- 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> {
4294
- let is_ok_self = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4295
- self_balance_pre, self_balance_post, channel_value_pre, channel_value_post,
4296
- self.holder_dust_limit_satoshis
4297
- );
4298
- if let Err(channel_reserve_self) = is_ok_self {
4299
- return Err(ChannelError::Warn(format!(
4300
- "Balance below reserve, mandated by holder, {} vs {}",
4301
- self_balance_post, channel_reserve_self,
4302
- )));
4303
- }
4304
- let is_ok_cp = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4305
- counterparty_balance_pre, counterparty_balance_post, channel_value_pre, channel_value_post,
4306
- self.counterparty_dust_limit_satoshis
4307
- );
4308
- if let Err(channel_reserve_cp) = is_ok_cp {
4309
- return Err(ChannelError::Warn(format!(
4310
- "Balance below reserve mandated by counterparty, {} vs {}",
4311
- counterparty_balance_post, channel_reserve_cp,
4312
- )));
4313
- }
4314
- Ok(())
4315
- }
4316
-
4317
4269
/// Get the commitment tx fee for the local's (i.e. our) next commitment transaction based on the
4318
4270
/// number of pending HTLCs that are on track to be in our next commitment tx.
4319
4271
///
@@ -8671,14 +8623,62 @@ impl<SP: Deref> FundedChannel<SP> where
8671
8623
let (post_balance_self_less_fees, post_balance_counterparty_less_fees) = self.compute_balances_less_fees(post_channel_value, post_balance_self, true);
8672
8624
// Pre-check for reserve requirement
8673
8625
// This will also be checked later at tx_complete
8674
- let _res = self.context. check_splice_balances_meet_v2_reserve_requirements(
8626
+ let _res = self.check_splice_balances_meet_v2_reserve_requirements(
8675
8627
pre_balance_self_less_fees, post_balance_self_less_fees,
8676
8628
pre_balance_counterparty_less_fees, post_balance_counterparty_less_fees,
8677
8629
pre_channel_value, post_channel_value
8678
8630
)?;
8679
8631
Ok(())
8680
8632
}
8681
8633
8634
+ /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
8635
+ #[cfg(splicing)]
8636
+ pub fn check_splice_balance_meets_v2_reserve_requirement_noerr(&self, pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64, dust_limit: u64) -> Result<(), u64> {
8637
+ let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
8638
+ if post_balance >= post_channel_reserve {
8639
+ return Ok(());
8640
+ }
8641
+ let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
8642
+ if pre_balance >= pre_channel_reserve {
8643
+ // We're not allowed to dip below the reserve once we've been above.
8644
+ return Err(post_channel_reserve);
8645
+ }
8646
+ // Make sure we either remain with the same balance or move towards the reserve.
8647
+ if post_balance >= pre_balance {
8648
+ Ok(())
8649
+ } else {
8650
+ Err(post_channel_reserve)
8651
+ }
8652
+ }
8653
+
8654
+ /// Check that balances meet the channel reserve requirements or violates them (below reserve).
8655
+ /// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
8656
+ /// to check with new channel value (before being committed to it).
8657
+ #[cfg(splicing)]
8658
+ 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> {
8659
+ let is_ok_self = self.check_splice_balance_meets_v2_reserve_requirement_noerr(
8660
+ self_balance_pre, self_balance_post, channel_value_pre, channel_value_post,
8661
+ self.context.holder_dust_limit_satoshis
8662
+ );
8663
+ if let Err(channel_reserve_self) = is_ok_self {
8664
+ return Err(ChannelError::Warn(format!(
8665
+ "Balance below reserve, mandated by holder, {} vs {}",
8666
+ self_balance_post, channel_reserve_self,
8667
+ )));
8668
+ }
8669
+ let is_ok_cp = self.check_splice_balance_meets_v2_reserve_requirement_noerr(
8670
+ counterparty_balance_pre, counterparty_balance_post, channel_value_pre, channel_value_post,
8671
+ self.context.counterparty_dust_limit_satoshis
8672
+ );
8673
+ if let Err(channel_reserve_cp) = is_ok_cp {
8674
+ return Err(ChannelError::Warn(format!(
8675
+ "Balance below reserve mandated by counterparty, {} vs {}",
8676
+ counterparty_balance_post, channel_reserve_cp,
8677
+ )));
8678
+ }
8679
+ Ok(())
8680
+ }
8681
+
8682
8682
// Send stuff to our remote peers:
8683
8683
8684
8684
/// Queues up an outbound HTLC to send by placing it in the holding cell. You should call
0 commit comments