@@ -3652,7 +3652,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3652
3652
/// The channel value is an input as opposed to using from self, so that this can be used in case of splicing
3653
3653
/// to checks with new channel value (before being comitted to it).
3654
3654
#[cfg(any(dual_funding, splicing))]
3655
- pub fn check_balance_meets_reserve_requirements(&self, channel_value: u64, balance: u64) -> Result<(), ChannelError> {
3655
+ pub fn check_balance_meets_reserve_requirements(&self, balance: u64, channel_value: u64) -> Result<(), ChannelError> {
3656
+ if balance == 0 {
3657
+ return Ok(());
3658
+ }
3656
3659
let holder_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
3657
3660
channel_value, self.holder_dust_limit_satoshis);
3658
3661
if balance < holder_selected_channel_reserve_satoshis {
@@ -7954,9 +7957,11 @@ impl<SP: Deref> Channel<SP> where
7954
7957
7955
7958
/// Handle splice_init
7956
7959
#[cfg(splicing)]
7957
- pub fn splice_init(
7958
- &mut self, their_funding_contribution_satoshis: i64, our_funding_contribution_satoshis: i64,
7959
- ) -> Result<msgs::SpliceAck, ChannelError> {
7960
+ pub fn splice_init(&mut self, msg: &msgs::SpliceInit) -> Result<msgs::SpliceAck, ChannelError> {
7961
+ let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
7962
+ // TODO(splicing): Currently not possible to contribute on the splicing-acceptor side
7963
+ let our_funding_contribution_satoshis = 0i64;
7964
+
7960
7965
// Check if a splice has been initiated already.
7961
7966
// Note: this could be handled more nicely, and support multiple outstanding splice's, the incoming splice_ack matters anyways.
7962
7967
if let Some(splice_info) = &self.context.pending_splice_pre {
@@ -7989,11 +7994,12 @@ impl<SP: Deref> Channel<SP> where
7989
7994
}
7990
7995
7991
7996
let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, their_funding_contribution_satoshis, our_funding_contribution_satoshis);
7992
-
7997
+ let post_balance = PendingSpliceInfoPre::add_checked(self.context.value_to_self_msat, our_funding_contribution_satoshis);
7993
7998
// Early check for reserve requirement, assuming maximum balance of full channel value
7994
7999
// This will also be checked later at tx_complete
7995
- let _res = self.context.check_balance_meets_reserve_requirements(post_channel_value , post_channel_value)?;
8000
+ let _res = self.context.check_balance_meets_reserve_requirements(post_balance , post_channel_value)?;
7996
8001
8002
+ // TODO(splicing): Store msg.funding_pubkey
7997
8003
// TODO(splicing): Apply start of splice (splice_start)
7998
8004
7999
8005
let splice_ack_msg = self.context.get_splice_ack(our_funding_contribution_satoshis);
@@ -8003,22 +8009,24 @@ impl<SP: Deref> Channel<SP> where
8003
8009
8004
8010
/// Handle splice_ack
8005
8011
#[cfg(splicing)]
8006
- pub fn splice_ack(
8007
- &mut self, their_funding_contribution_satoshis: i64,
8008
- ) -> Result<(), ChannelError> {
8012
+ pub fn splice_ack(&mut self, msg: &msgs::SpliceAck) -> Result<(), ChannelError> {
8013
+ let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
8014
+
8009
8015
// check if splice is pending
8010
8016
let pending_splice = if let Some(pending_splice) = &self.context.pending_splice_pre {
8011
8017
pending_splice
8012
8018
} else {
8013
8019
return Err(ChannelError::Warn(format!("Channel is not in pending splice")));
8014
8020
};
8015
8021
8016
- let pre_channel_value = self.context.get_value_satoshis();
8017
- let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, pending_splice.our_funding_contribution, their_funding_contribution_satoshis);
8022
+ let our_funding_contribution = pending_splice.our_funding_contribution;
8018
8023
8024
+ let pre_channel_value = self.context.get_value_satoshis();
8025
+ let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, our_funding_contribution, their_funding_contribution_satoshis);
8026
+ let post_balance = PendingSpliceInfoPre::add_checked(self.context.value_to_self_msat, our_funding_contribution);
8019
8027
// Early check for reserve requirement, assuming maximum balance of full channel value
8020
8028
// This will also be checked later at tx_complete
8021
- let _res = self.context.check_balance_meets_reserve_requirements(post_channel_value , post_channel_value)?;
8029
+ let _res = self.context.check_balance_meets_reserve_requirements(post_balance , post_channel_value)?;
8022
8030
Ok(())
8023
8031
}
8024
8032
0 commit comments