@@ -1724,28 +1724,10 @@ impl FundingScope {
17241724
17251725/// Info about a pending splice, used in the pre-splice channel
17261726#[cfg(splicing)]
1727- #[derive(Clone)]
17281727struct PendingSplice {
17291728 pub our_funding_contribution: i64,
17301729}
17311730
1732- #[cfg(splicing)]
1733- impl PendingSplice {
1734- #[inline]
1735- fn add_checked(base: u64, delta: i64) -> u64 {
1736- if delta >= 0 {
1737- base.saturating_add(delta as u64)
1738- } else {
1739- base.saturating_sub(delta.abs() as u64)
1740- }
1741- }
1742-
1743- /// Compute the post-splice channel value from the pre-splice values and the peer contributions
1744- pub fn compute_post_value(pre_channel_value: u64, our_funding_contribution: i64, their_funding_contribution: i64) -> u64 {
1745- Self::add_checked(pre_channel_value, our_funding_contribution.saturating_add(their_funding_contribution))
1746- }
1747- }
1748-
17491731/// Contains everything about the channel including state, and various flags.
17501732pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
17511733 config: LegacyChannelConfig,
@@ -8408,7 +8390,7 @@ impl<SP: Deref> FundedChannel<SP> where
84088390 }
84098391
84108392 /// Initiate splicing.
8411- /// - our_funding_inputs: the inputs we contribute to the new funding transaction.
8393+ /// - ` our_funding_inputs` : the inputs we contribute to the new funding transaction.
84128394 /// Includes the witness weight for this input (e.g. P2WPKH_WITNESS_WEIGHT=109 for typical P2WPKH inputs).
84138395 #[cfg(splicing)]
84148396 pub fn splice_channel(&mut self, our_funding_contribution_satoshis: i64,
@@ -8447,7 +8429,6 @@ impl<SP: Deref> FundedChannel<SP> where
84478429 // (Cannot test for miminum required post-splice channel value)
84488430
84498431 // Check that inputs are sufficient to cover our contribution.
8450- // Extra common weight is the weight for spending the old funding
84518432 let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, true, funding_feerate_per_kw)
84528433 .map_err(|err| APIError::APIMisuseError { err: format!(
84538434 "Insufficient inputs for splicing; channel ID {}, err {}",
@@ -8464,7 +8445,7 @@ impl<SP: Deref> FundedChannel<SP> where
84648445
84658446 /// Get the splice message that can be sent during splice initiation.
84668447 #[cfg(splicing)]
8467- pub fn get_splice_init(&self, our_funding_contribution_satoshis: i64,
8448+ fn get_splice_init(&self, our_funding_contribution_satoshis: i64,
84688449 funding_feerate_per_kw: u32, locktime: u32,
84698450 ) -> msgs::SpliceInit {
84708451 // TODO(splicing): The exisiting pubkey is reused, but a new one should be generated. See #3542.
@@ -8519,23 +8500,16 @@ impl<SP: Deref> FundedChannel<SP> where
85198500 // TODO(splicing): Store msg.funding_pubkey
85208501 // TODO(splicing): Apply start of splice (splice_start)
85218502
8522- let splice_ack_msg = self.get_splice_ack(our_funding_contribution_satoshis);
8523- // TODO(splicing): start interactive funding negotiation
8524- Ok(splice_ack_msg)
8525- }
8526-
8527- /// Get the splice_ack message that can be sent in response to splice initiation.
8528- #[cfg(splicing)]
8529- pub fn get_splice_ack(&self, our_funding_contribution_satoshis: i64) -> msgs::SpliceAck {
85308503 // TODO(splicing): The exisiting pubkey is reused, but a new one should be generated. See #3542.
85318504 // Note that channel_keys_id is supposed NOT to change
8532- let funding_pubkey = self.funding.get_holder_pubkeys().funding_pubkey;
8533- msgs::SpliceAck {
8505+ let splice_ack_msg = msgs::SpliceAck {
85348506 channel_id: self.context.channel_id,
85358507 funding_contribution_satoshis: our_funding_contribution_satoshis,
8536- funding_pubkey,
8508+ funding_pubkey: self.funding.get_holder_pubkeys().funding_pubkey ,
85378509 require_confirmed_inputs: None,
8538- }
8510+ };
8511+ // TODO(splicing): start interactive funding negotiation
8512+ Ok(splice_ack_msg)
85398513 }
85408514
85418515 /// Handle splice_ack
@@ -13029,69 +13003,4 @@ mod tests {
1302913003 );
1303013004 }
1303113005 }
13032-
13033- #[cfg(splicing)]
13034- fn get_pre_and_post(pre_channel_value: u64, our_funding_contribution: i64, their_funding_contribution: i64) -> (u64, u64) {
13035- use crate::ln::channel::PendingSplice;
13036-
13037- let post_channel_value = PendingSplice::compute_post_value(pre_channel_value, our_funding_contribution, their_funding_contribution);
13038- (pre_channel_value, post_channel_value)
13039- }
13040-
13041- #[cfg(splicing)]
13042- #[test]
13043- fn test_splice_compute_post_value() {
13044- {
13045- // increase, small amounts
13046- let (pre_channel_value, post_channel_value) = get_pre_and_post(9_000, 6_000, 0);
13047- assert_eq!(pre_channel_value, 9_000);
13048- assert_eq!(post_channel_value, 15_000);
13049- }
13050- {
13051- // increase, small amounts
13052- let (pre_channel_value, post_channel_value) = get_pre_and_post(9_000, 4_000, 2_000);
13053- assert_eq!(pre_channel_value, 9_000);
13054- assert_eq!(post_channel_value, 15_000);
13055- }
13056- {
13057- // increase, small amounts
13058- let (pre_channel_value, post_channel_value) = get_pre_and_post(9_000, 0, 6_000);
13059- assert_eq!(pre_channel_value, 9_000);
13060- assert_eq!(post_channel_value, 15_000);
13061- }
13062- {
13063- // decrease, small amounts
13064- let (pre_channel_value, post_channel_value) = get_pre_and_post(15_000, -6_000, 0);
13065- assert_eq!(pre_channel_value, 15_000);
13066- assert_eq!(post_channel_value, 9_000);
13067- }
13068- {
13069- // decrease, small amounts
13070- let (pre_channel_value, post_channel_value) = get_pre_and_post(15_000, -4_000, -2_000);
13071- assert_eq!(pre_channel_value, 15_000);
13072- assert_eq!(post_channel_value, 9_000);
13073- }
13074- {
13075- // increase and decrease
13076- let (pre_channel_value, post_channel_value) = get_pre_and_post(15_000, 4_000, -2_000);
13077- assert_eq!(pre_channel_value, 15_000);
13078- assert_eq!(post_channel_value, 17_000);
13079- }
13080- let base2: u64 = 2;
13081- let huge63i3 = (base2.pow(63) - 3) as i64;
13082- assert_eq!(huge63i3, 9223372036854775805);
13083- assert_eq!(-huge63i3, -9223372036854775805);
13084- {
13085- // increase, large amount
13086- let (pre_channel_value, post_channel_value) = get_pre_and_post(9_000, huge63i3, 3);
13087- assert_eq!(pre_channel_value, 9_000);
13088- assert_eq!(post_channel_value, 9223372036854784807);
13089- }
13090- {
13091- // increase, large amounts
13092- let (pre_channel_value, post_channel_value) = get_pre_and_post(9_000, huge63i3, huge63i3);
13093- assert_eq!(pre_channel_value, 9_000);
13094- assert_eq!(post_channel_value, 9223372036854784807);
13095- }
13096- }
1309713006}
0 commit comments