@@ -1724,28 +1724,10 @@ impl FundingScope {
1724
1724
1725
1725
/// Info about a pending splice, used in the pre-splice channel
1726
1726
#[cfg(splicing)]
1727
- #[derive(Clone)]
1728
1727
struct PendingSplice {
1729
1728
pub our_funding_contribution: i64,
1730
1729
}
1731
1730
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
1731
/// Contains everything about the channel including state, and various flags.
1750
1732
pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1751
1733
config: LegacyChannelConfig,
@@ -8408,7 +8390,7 @@ impl<SP: Deref> FundedChannel<SP> where
8408
8390
}
8409
8391
8410
8392
/// 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.
8412
8394
/// Includes the witness weight for this input (e.g. P2WPKH_WITNESS_WEIGHT=109 for typical P2WPKH inputs).
8413
8395
#[cfg(splicing)]
8414
8396
pub fn splice_channel(&mut self, our_funding_contribution_satoshis: i64,
@@ -8447,7 +8429,6 @@ impl<SP: Deref> FundedChannel<SP> where
8447
8429
// (Cannot test for miminum required post-splice channel value)
8448
8430
8449
8431
// Check that inputs are sufficient to cover our contribution.
8450
- // Extra common weight is the weight for spending the old funding
8451
8432
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, true, funding_feerate_per_kw)
8452
8433
.map_err(|err| APIError::APIMisuseError { err: format!(
8453
8434
"Insufficient inputs for splicing; channel ID {}, err {}",
@@ -8464,7 +8445,7 @@ impl<SP: Deref> FundedChannel<SP> where
8464
8445
8465
8446
/// Get the splice message that can be sent during splice initiation.
8466
8447
#[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,
8468
8449
funding_feerate_per_kw: u32, locktime: u32,
8469
8450
) -> msgs::SpliceInit {
8470
8451
// 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
8519
8500
// TODO(splicing): Store msg.funding_pubkey
8520
8501
// TODO(splicing): Apply start of splice (splice_start)
8521
8502
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
8503
// TODO(splicing): The exisiting pubkey is reused, but a new one should be generated. See #3542.
8531
8504
// 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 {
8534
8506
channel_id: self.context.channel_id,
8535
8507
funding_contribution_satoshis: our_funding_contribution_satoshis,
8536
- funding_pubkey,
8508
+ funding_pubkey: self.funding.get_holder_pubkeys().funding_pubkey ,
8537
8509
require_confirmed_inputs: None,
8538
- }
8510
+ };
8511
+ // TODO(splicing): start interactive funding negotiation
8512
+ Ok(splice_ack_msg)
8539
8513
}
8540
8514
8541
8515
/// Handle splice_ack
@@ -13029,69 +13003,4 @@ mod tests {
13029
13003
);
13030
13004
}
13031
13005
}
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
13006
}
0 commit comments