Skip to content

Commit b7c2d45

Browse files
committed
fix Renames and removes
1 parent df4e030 commit b7c2d45

File tree

4 files changed

+39
-129
lines changed

4 files changed

+39
-129
lines changed

lightning/src/ln/channel.rs

+6-96
Original file line numberDiff line numberDiff line change
@@ -1729,23 +1729,6 @@ struct PendingSplice {
17291729
pub our_funding_contribution: i64,
17301730
}
17311731

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-
17491732
/// Contains everything about the channel including state, and various flags.
17501733
pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
17511734
config: LegacyChannelConfig,
@@ -8447,7 +8430,6 @@ impl<SP: Deref> FundedChannel<SP> where
84478430
// (Cannot test for miminum required post-splice channel value)
84488431

84498432
// Check that inputs are sufficient to cover our contribution.
8450-
// Extra common weight is the weight for spending the old funding
84518433
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, true, funding_feerate_per_kw)
84528434
.map_err(|err| APIError::APIMisuseError { err: format!(
84538435
"Insufficient inputs for splicing; channel ID {}, err {}",
@@ -8464,7 +8446,7 @@ impl<SP: Deref> FundedChannel<SP> where
84648446

84658447
/// Get the splice message that can be sent during splice initiation.
84668448
#[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,
84688450
funding_feerate_per_kw: u32, locktime: u32,
84698451
) -> msgs::SpliceInit {
84708452
// 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
85198501
// TODO(splicing): Store msg.funding_pubkey
85208502
// TODO(splicing): Apply start of splice (splice_start)
85218503

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 {
85308504
// TODO(splicing): The exisiting pubkey is reused, but a new one should be generated. See #3542.
85318505
// 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 {
85348507
channel_id: self.context.channel_id,
85358508
funding_contribution_satoshis: our_funding_contribution_satoshis,
8536-
funding_pubkey,
8509+
funding_pubkey: self.funding.get_holder_pubkeys().funding_pubkey,
85378510
require_confirmed_inputs: None,
8538-
}
8511+
};
8512+
// TODO(splicing): start interactive funding negotiation
8513+
Ok(splice_ack_msg)
85398514
}
85408515

85418516
/// Handle splice_ack
@@ -13029,69 +13004,4 @@ mod tests {
1302913004
);
1303013005
}
1303113006
}
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-
}
1309713007
}

lightning/src/ln/channelmanager.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -4283,6 +4283,37 @@ where
42834283
}
42844284
}
42854285

4286+
/// Initiate a splice, to change the channel capacity of an existing funded channel.
4287+
/// After completion of splicing, the funding transaction will be replaced by a new one, spending the old funding transaction,
4288+
/// with optional extra inputs (splice-in) and/or extra outputs (splice-out or change).
4289+
/// TODO(splicing): Implementation is currently incomplete.
4290+
///
4291+
/// Note: Currently only splice-in is supported (increase in channel capacity), splice-out is not.
4292+
///
4293+
/// - `our_funding_contribution_satoshis`: the amount contributed by us to the channel. This will increase our channel balance.
4294+
/// - `our_funding_inputs`: the funding inputs provided by us. If our contribution is positive, our funding inputs must cover at least that amount.
4295+
/// Includes the witness weight for this input (e.g. P2WPKH_WITNESS_WEIGHT=109 for typical P2WPKH inputs).
4296+
/// - `locktime`: Optional locktime for the new funding transaction. If None, set to the current block height.
4297+
#[cfg(splicing)]
4298+
pub fn splice_channel(
4299+
&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64,
4300+
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>,
4301+
funding_feerate_per_kw: u32, locktime: Option<u32>,
4302+
) -> Result<(), APIError> {
4303+
let mut res = Ok(());
4304+
PersistenceNotifierGuard::optionally_notify(self, || {
4305+
let result = self.internal_splice_channel(
4306+
channel_id, counterparty_node_id, our_funding_contribution_satoshis, &our_funding_inputs, funding_feerate_per_kw, locktime
4307+
);
4308+
res = result;
4309+
match res {
4310+
Ok(_) => NotifyOption::SkipPersistHandleEvents,
4311+
Err(_) => NotifyOption::SkipPersistNoEvents,
4312+
}
4313+
});
4314+
res
4315+
}
4316+
42864317
/// See [`splice_channel`]
42874318
#[cfg(splicing)]
42884319
fn internal_splice_channel(
@@ -4304,7 +4335,7 @@ where
43044335
// Look for the channel
43054336
match peer_state.channel_by_id.entry(*channel_id) {
43064337
hash_map::Entry::Occupied(mut chan_phase_entry) => {
4307-
let locktime = locktime.unwrap_or(self.current_best_block().height);
4338+
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
43084339
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
43094340
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, funding_feerate_per_kw, locktime)?;
43104341
peer_state.pending_msg_events.push(events::MessageSendEvent::SendSpliceInit {
@@ -4332,37 +4363,6 @@ where
43324363
}
43334364
}
43344365

4335-
/// Initiate a splice, to change the channel capacity of an existing funded channel.
4336-
/// After completion of splicing, the funding transaction will be replaced by a new one, spending the old funding transaction,
4337-
/// with optional extra inputs (splice-in) and/or extra outputs (splice-out or change).
4338-
/// TODO(splicing): Implementation is currently incomplete.
4339-
///
4340-
/// Note: Currently only splice-in is supported (increase in channel capacity), splice-out is not.
4341-
///
4342-
/// - our_funding_contribution_satoshis: the amount contributed by us to the channel. This will increase our channel balance.
4343-
/// - our_funding_inputs: the funding inputs provided by us. If our contribution is positive, our funding inputs must cover at least that amount.
4344-
/// Includes the witness weight for this input (e.g. P2WPKH_WITNESS_WEIGHT=109 for typical P2WPKH inputs).
4345-
/// - locktime: Optional locktime for the new funding transaction. If None, set to the current block height.
4346-
#[cfg(splicing)]
4347-
pub fn splice_channel(
4348-
&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64,
4349-
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>,
4350-
funding_feerate_per_kw: u32, locktime: Option<u32>,
4351-
) -> Result<(), APIError> {
4352-
let mut res = Ok(());
4353-
PersistenceNotifierGuard::optionally_notify(self, || {
4354-
let result = self.internal_splice_channel(
4355-
channel_id, counterparty_node_id, our_funding_contribution_satoshis, &our_funding_inputs, funding_feerate_per_kw, locktime
4356-
);
4357-
res = result;
4358-
match res {
4359-
Ok(_) => NotifyOption::SkipPersistHandleEvents,
4360-
Err(_) => NotifyOption::SkipPersistNoEvents,
4361-
}
4362-
});
4363-
res
4364-
}
4365-
43664366
fn can_forward_htlc_to_outgoing_channel(
43674367
&self, chan: &mut FundedChannel<SP>, msg: &msgs::UpdateAddHTLC, next_packet: &NextPacketDetails
43684368
) -> Result<(), (&'static str, u16)> {

lightning/src/ln/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ mod async_payments_tests;
6363
pub mod functional_tests;
6464
#[cfg(all(test, splicing))]
6565
#[allow(unused_mut)]
66-
mod functional_tests_splice;
66+
mod splicing_tests;
6767
#[cfg(test)]
6868
#[allow(unused_mut)]
6969
mod max_payment_path_len_tests;

0 commit comments

Comments
 (0)