@@ -4095,29 +4095,30 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4095
4095
}
4096
4096
}
4097
4097
4098
- /// Check that a balance value meets the channel reserve requirements or violates them (below reserve).
4098
+ /// Check that balances meet the channel reserve requirements or violates them (below reserve).
4099
4099
/// The channel value is an input as opposed to using from self, so that this can be used in case of splicing
4100
4100
/// to checks with new channel value (before being comitted to it).
4101
4101
#[cfg(splicing)]
4102
- pub fn check_balance_meets_v2_reserve_requirements(&self, balance: u64, channel_value: u64) -> Result<(), ChannelError> {
4103
- if balance == 0 {
4104
- return Ok(());
4105
- }
4106
- let holder_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
4107
- channel_value, self.holder_dust_limit_satoshis);
4108
- if balance < holder_selected_channel_reserve_satoshis {
4109
- return Err(ChannelError::Warn(format!(
4110
- "Balance below reserve mandated by holder, {} vs {}",
4111
- balance, holder_selected_channel_reserve_satoshis,
4112
- )));
4102
+ pub fn check_balance_meets_v2_reserve_requirements(&self, self_balance: u64, counterparty_balance: u64, channel_value: u64) -> Result<(), ChannelError> {
4103
+ if self_balance > 0 {
4104
+ let holder_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
4105
+ channel_value, self.holder_dust_limit_satoshis);
4106
+ if self_balance < holder_selected_channel_reserve_satoshis {
4107
+ return Err(ChannelError::Warn(format!(
4108
+ "Balance below reserve mandated by holder, {} vs {}",
4109
+ self_balance, holder_selected_channel_reserve_satoshis,
4110
+ )));
4111
+ }
4113
4112
}
4114
- let counterparty_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
4115
- channel_value, self.counterparty_dust_limit_satoshis);
4116
- if balance < counterparty_selected_channel_reserve_satoshis {
4117
- return Err(ChannelError::Warn(format!(
4118
- "Balance below reserve mandated by counterparty, {} vs {}",
4119
- balance, counterparty_selected_channel_reserve_satoshis,
4120
- )));
4113
+ if counterparty_balance > 0 {
4114
+ let counterparty_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
4115
+ channel_value, self.counterparty_dust_limit_satoshis);
4116
+ if counterparty_balance < counterparty_selected_channel_reserve_satoshis {
4117
+ return Err(ChannelError::Warn(format!(
4118
+ "Balance below reserve mandated by counterparty, {} vs {}",
4119
+ counterparty_balance, counterparty_selected_channel_reserve_satoshis,
4120
+ )));
4121
+ }
4121
4122
}
4122
4123
Ok(())
4123
4124
}
@@ -8554,10 +8555,11 @@ impl<SP: Deref> FundedChannel<SP> where
8554
8555
8555
8556
let pre_channel_value = self.funding.get_value_satoshis();
8556
8557
let post_channel_value = PendingSplice::compute_post_value(pre_channel_value, our_funding_contribution, their_funding_contribution_satoshis);
8557
- let post_balance = PendingSplice::add_checked(self.funding.value_to_self_msat, our_funding_contribution);
8558
- // Pre-check for reserve requirement, assuming maximum balance of full channel value
8558
+ let post_balance_self = PendingSplice::add_checked(self.funding.value_to_self_msat, our_funding_contribution);
8559
+ let post_balance_counterparty = post_channel_value.saturating_sub(post_balance_self);
8560
+ // Pre-check for reserve requirement
8559
8561
// This will also be checked later at tx_complete
8560
- let _res = self.context.check_balance_meets_v2_reserve_requirements(post_balance , post_channel_value)?;
8562
+ let _res = self.context.check_balance_meets_v2_reserve_requirements(post_balance_self, post_balance_counterparty , post_channel_value)?;
8561
8563
Ok(())
8562
8564
}
8563
8565
0 commit comments