@@ -3423,7 +3423,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3423
3423
/// The channel value is an input as opposed to using from self, so that this can be used in case of splicing
3424
3424
/// to checks with new channel value (before being comitted to it).
3425
3425
#[cfg(any(dual_funding, splicing))]
3426
- pub fn check_balance_meets_reserve_requirements(&self, channel_value: u64, balance: u64) -> Result<(), ChannelError> {
3426
+ pub fn check_balance_meets_reserve_requirements(&self, balance: u64, channel_value: u64) -> Result<(), ChannelError> {
3427
+ if balance == 0 {
3428
+ return Ok(());
3429
+ }
3427
3430
let holder_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
3428
3431
channel_value, self.holder_dust_limit_satoshis);
3429
3432
if balance < holder_selected_channel_reserve_satoshis {
@@ -7485,9 +7488,11 @@ impl<SP: Deref> Channel<SP> where
7485
7488
7486
7489
/// Handle splice_init
7487
7490
#[cfg(splicing)]
7488
- pub fn splice_init(
7489
- &mut self, their_funding_contribution_satoshis: i64, our_funding_contribution_satoshis: i64,
7490
- ) -> Result<msgs::SpliceAck, ChannelError> {
7491
+ pub fn splice_init(&mut self, msg: &msgs::SpliceInit) -> Result<msgs::SpliceAck, ChannelError> {
7492
+ let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
7493
+ // TODO(splicing): Currently not possible to contribute on the splicing-acceptor side
7494
+ let our_funding_contribution_satoshis = 0i64;
7495
+
7491
7496
// Check if a splice has been initiated already.
7492
7497
// Note: this could be handled more nicely, and support multiple outstanding splice's, the incoming splice_ack matters anyways.
7493
7498
if let Some(splice_info) = &self.context.pending_splice_pre {
@@ -7520,11 +7525,12 @@ impl<SP: Deref> Channel<SP> where
7520
7525
}
7521
7526
7522
7527
let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, their_funding_contribution_satoshis, our_funding_contribution_satoshis);
7523
-
7528
+ let post_balance = PendingSpliceInfoPre::add_checked(self.context.value_to_self_msat, our_funding_contribution_satoshis);
7524
7529
// Early check for reserve requirement, assuming maximum balance of full channel value
7525
7530
// This will also be checked later at tx_complete
7526
- let _res = self.context.check_balance_meets_reserve_requirements(post_channel_value , post_channel_value)?;
7531
+ let _res = self.context.check_balance_meets_reserve_requirements(post_balance , post_channel_value)?;
7527
7532
7533
+ // TODO(splicing): Store msg.funding_pubkey
7528
7534
// TODO(splicing): Apply start of splice (splice_start)
7529
7535
7530
7536
let splice_ack_msg = self.context.get_splice_ack(our_funding_contribution_satoshis);
@@ -7534,22 +7540,24 @@ impl<SP: Deref> Channel<SP> where
7534
7540
7535
7541
/// Handle splice_ack
7536
7542
#[cfg(splicing)]
7537
- pub fn splice_ack(
7538
- &mut self, their_funding_contribution_satoshis: i64,
7539
- ) -> Result<(), ChannelError> {
7543
+ pub fn splice_ack(&mut self, msg: &msgs::SpliceAck) -> Result<(), ChannelError> {
7544
+ let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
7545
+
7540
7546
// check if splice is pending
7541
7547
let pending_splice = if let Some(pending_splice) = &self.context.pending_splice_pre {
7542
7548
pending_splice
7543
7549
} else {
7544
7550
return Err(ChannelError::Warn(format!("Channel is not in pending splice")));
7545
7551
};
7546
7552
7547
- let pre_channel_value = self.context.get_value_satoshis();
7548
- let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, pending_splice.our_funding_contribution, their_funding_contribution_satoshis);
7553
+ let our_funding_contribution = pending_splice.our_funding_contribution;
7549
7554
7555
+ let pre_channel_value = self.context.get_value_satoshis();
7556
+ let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, our_funding_contribution, their_funding_contribution_satoshis);
7557
+ let post_balance = PendingSpliceInfoPre::add_checked(self.context.value_to_self_msat, our_funding_contribution);
7550
7558
// Early check for reserve requirement, assuming maximum balance of full channel value
7551
7559
// This will also be checked later at tx_complete
7552
- let _res = self.context.check_balance_meets_reserve_requirements(post_channel_value , post_channel_value)?;
7560
+ let _res = self.context.check_balance_meets_reserve_requirements(post_balance , post_channel_value)?;
7553
7561
Ok(())
7554
7562
}
7555
7563
0 commit comments