@@ -1729,23 +1729,6 @@ struct PendingSplice {
1729
1729
pub our_funding_contribution: i64,
1730
1730
}
1731
1731
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
-
1749
1732
/// Contains everything about the channel including state, and various flags.
1750
1733
pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1751
1734
config: LegacyChannelConfig,
@@ -8447,7 +8430,6 @@ impl<SP: Deref> FundedChannel<SP> where
8447
8430
// (Cannot test for miminum required post-splice channel value)
8448
8431
8449
8432
// Check that inputs are sufficient to cover our contribution.
8450
- // Extra common weight is the weight for spending the old funding
8451
8433
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, true, funding_feerate_per_kw)
8452
8434
.map_err(|err| APIError::APIMisuseError { err: format!(
8453
8435
"Insufficient inputs for splicing; channel ID {}, err {}",
@@ -8464,7 +8446,7 @@ impl<SP: Deref> FundedChannel<SP> where
8464
8446
8465
8447
/// Get the splice message that can be sent during splice initiation.
8466
8448
#[cfg(splicing)]
8467
- pub fn get_splice_init(&self, our_funding_contribution_satoshis: i64,
8449
+ fn get_splice_init(&self, our_funding_contribution_satoshis: i64,
8468
8450
funding_feerate_per_kw: u32, locktime: u32,
8469
8451
) -> msgs::SpliceInit {
8470
8452
// TODO(splicing): The exisiting pubkey is reused, but a new one should be generated. See #3542.
@@ -8519,23 +8501,16 @@ impl<SP: Deref> FundedChannel<SP> where
8519
8501
// TODO(splicing): Store msg.funding_pubkey
8520
8502
// TODO(splicing): Apply start of splice (splice_start)
8521
8503
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 {
8530
8504
// TODO(splicing): The exisiting pubkey is reused, but a new one should be generated. See #3542.
8531
8505
// Note that channel_keys_id is supposed NOT to change
8532
- let funding_pubkey = self.funding.get_holder_pubkeys().funding_pubkey;
8533
- msgs::SpliceAck {
8506
+ let splice_ack_msg = msgs::SpliceAck {
8534
8507
channel_id: self.context.channel_id,
8535
8508
funding_contribution_satoshis: our_funding_contribution_satoshis,
8536
- funding_pubkey,
8509
+ funding_pubkey: self.funding.get_holder_pubkeys().funding_pubkey ,
8537
8510
require_confirmed_inputs: None,
8538
- }
8511
+ };
8512
+ // TODO(splicing): start interactive funding negotiation
8513
+ Ok(splice_ack_msg)
8539
8514
}
8540
8515
8541
8516
/// Handle splice_ack
@@ -13029,69 +13004,4 @@ mod tests {
13029
13004
);
13030
13005
}
13031
13006
}
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
- }
13097
13007
}
0 commit comments