Skip to content

Commit 0b187cf

Browse files
committed
Pass FundingTxContributions to ChannelManager::splice_channel
Using FundingTxContributions for ChannelManager::splice_channel allows supporting both splice-in and splice-out using the same method, with a descriptive enum for the contributions.
1 parent 283e3c6 commit 0b187cf

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10637,8 +10637,8 @@ where
1063710637
#[cfg(splicing)]
1063810638
pub fn splice_channel(
1063910639
&mut self, our_funding_contribution_satoshis: i64,
10640-
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, change_script: Option<ScriptBuf>,
10641-
funding_feerate_per_kw: u32, locktime: u32,
10640+
funding_tx_contributions: FundingTxContributions, funding_feerate_per_kw: u32,
10641+
locktime: u32,
1064210642
) -> Result<msgs::SpliceInit, APIError> {
1064310643
// Check if a splice has been initiated already.
1064410644
// Note: only a single outstanding splice is supported (per spec)
@@ -10691,7 +10691,7 @@ where
1069110691
// Check that inputs are sufficient to cover our contribution.
1069210692
let _fee = check_v2_funding_inputs_sufficient(
1069310693
our_funding_contribution.to_sat(),
10694-
&our_funding_inputs,
10694+
funding_tx_contributions.inputs(),
1069510695
true,
1069610696
true,
1069710697
funding_feerate_per_kw,
@@ -10704,7 +10704,7 @@ where
1070410704
),
1070510705
})?;
1070610706

10707-
for (_, tx, _) in our_funding_inputs.iter() {
10707+
for (_, tx, _) in funding_tx_contributions.inputs().iter() {
1070810708
const MESSAGE_TEMPLATE: msgs::TxAddInput = msgs::TxAddInput {
1070910709
channel_id: ChannelId([0; 32]),
1071010710
serial_id: 0,
@@ -10721,9 +10721,6 @@ where
1072110721
}
1072210722
}
1072310723

10724-
let funding_tx_contributions =
10725-
FundingTxContributions::InputsOnly { inputs: our_funding_inputs, change_script };
10726-
1072710724
let prev_funding_input = self.funding.to_splice_funding_input();
1072810725
let funding_negotiation_context = FundingNegotiationContext {
1072910726
is_initiator: true,

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ use bitcoin::hashes::{Hash, HashEngine, HmacEngine};
3131
use bitcoin::secp256k1::Secp256k1;
3232
use bitcoin::secp256k1::{PublicKey, SecretKey};
3333
use bitcoin::{secp256k1, Sequence, SignedAmount};
34-
#[cfg(splicing)]
35-
use bitcoin::{ScriptBuf, TxIn, Weight};
3634

3735
use crate::blinded_path::message::MessageForwardNode;
3836
use crate::blinded_path::message::{AsyncPaymentsContext, OffersContext};
@@ -57,6 +55,8 @@ use crate::events::{
5755
};
5856
use crate::events::{FundingInfo, PaidBolt12Invoice};
5957
use crate::ln::chan_utils::selected_commitment_sat_per_1000_weight;
58+
#[cfg(splicing)]
59+
use crate::ln::channel::FundingTxContributions;
6060
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
6161
// construct one themselves.
6262
use crate::ln::channel::{
@@ -4437,13 +4437,12 @@ where
44374437
#[rustfmt::skip]
44384438
pub fn splice_channel(
44394439
&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64,
4440-
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, change_script: Option<ScriptBuf>,
4441-
funding_feerate_per_kw: u32, locktime: Option<u32>,
4440+
funding_tx_contributions: FundingTxContributions, funding_feerate_per_kw: u32, locktime: Option<u32>,
44424441
) -> Result<(), APIError> {
44434442
let mut res = Ok(());
44444443
PersistenceNotifierGuard::optionally_notify(self, || {
44454444
let result = self.internal_splice_channel(
4446-
channel_id, counterparty_node_id, our_funding_contribution_satoshis, our_funding_inputs, change_script, funding_feerate_per_kw, locktime
4445+
channel_id, counterparty_node_id, our_funding_contribution_satoshis, funding_tx_contributions, funding_feerate_per_kw, locktime
44474446
);
44484447
res = result;
44494448
match res {
@@ -4458,8 +4457,7 @@ where
44584457
#[cfg(splicing)]
44594458
fn internal_splice_channel(
44604459
&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey,
4461-
our_funding_contribution_satoshis: i64,
4462-
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, change_script: Option<ScriptBuf>,
4460+
our_funding_contribution_satoshis: i64, funding_tx_contributions: FundingTxContributions,
44634461
funding_feerate_per_kw: u32, locktime: Option<u32>,
44644462
) -> Result<(), APIError> {
44654463
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -4483,8 +4481,7 @@ where
44834481
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
44844482
let msg = chan.splice_channel(
44854483
our_funding_contribution_satoshis,
4486-
our_funding_inputs,
4487-
change_script,
4484+
funding_tx_contributions,
44884485
funding_feerate_per_kw,
44894486
locktime,
44904487
)?;

lightning/src/ln/splicing_tests.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// You may not use this file except in accordance with one or both of these
88
// licenses.
99

10+
use crate::ln::channel::FundingTxContributions;
1011
use crate::ln::functional_test_utils::*;
1112
use crate::ln::msgs::{BaseMessageHandler, ChannelMessageHandler, MessageSendEvent};
1213
use crate::util::errors::APIError;
@@ -66,15 +67,16 @@ fn test_v1_splice_in() {
6667
&initiator_node,
6768
&[extra_splice_funding_input_sats],
6869
);
70+
let funding_tx_contributions =
71+
FundingTxContributions::InputsOnly { inputs: funding_inputs, change_script: None };
6972
// Initiate splice-in
7073
let _res = initiator_node
7174
.node
7275
.splice_channel(
7376
&channel_id,
7477
&acceptor_node.node.get_our_node_id(),
7578
splice_in_sats as i64,
76-
funding_inputs,
77-
None, // change_script
79+
funding_tx_contributions,
7880
funding_feerate_per_kw,
7981
None, // locktime
8082
)
@@ -316,14 +318,15 @@ fn test_v1_splice_in_negative_insufficient_inputs() {
316318
let extra_splice_funding_input_sats = splice_in_sats - 1;
317319
let funding_inputs =
318320
create_dual_funding_utxos_with_prev_txs(&nodes[0], &[extra_splice_funding_input_sats]);
321+
let funding_tx_contributions =
322+
FundingTxContributions::InputsOnly { inputs: funding_inputs, change_script: None };
319323

320324
// Initiate splice-in, with insufficient input contribution
321325
let res = nodes[0].node.splice_channel(
322326
&channel_id,
323327
&nodes[1].node.get_our_node_id(),
324328
splice_in_sats as i64,
325-
funding_inputs,
326-
None, // change_script
329+
funding_tx_contributions,
327330
1024, // funding_feerate_per_kw,
328331
None, // locktime
329332
);

0 commit comments

Comments
 (0)