Skip to content

Commit f59873d

Browse files
committed
In splice_channel() check if provided inputs are sufficient
1 parent 7fcbcb4 commit f59873d

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8517,7 +8517,7 @@ impl<SP: Deref> FundedChannel<SP> where
85178517
/// Initiate splicing
85188518
#[cfg(splicing)]
85198519
pub fn splice_channel(&mut self, our_funding_contribution_satoshis: i64,
8520-
funding_feerate_perkw: u32, locktime: u32,
8520+
our_funding_inputs: Vec<(TxIn, Transaction)>, funding_feerate_perkw: u32, locktime: u32,
85218521
) -> Result<msgs::SpliceInit, ChannelError> {
85228522
// Check if a splice has been initiated already.
85238523
// Note: this could be handled more nicely, and support multiple outstanding splice's, the incoming splice_ack matters anyways.
@@ -8550,6 +8550,17 @@ impl<SP: Deref> FundedChannel<SP> where
85508550
// Note: post-splice channel value is not yet known at this point, counterpary contribution is not known
85518551
// (Cannot test for miminum required post-splice channel value)
85528552

8553+
// Check that inputs are sufficient to cover our contribution
8554+
let sum_input: i64 = our_funding_inputs.into_iter().fold(0, |acc, i|
8555+
acc + i.1.output.get(i.0.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0)
8556+
);
8557+
if sum_input < our_funding_contribution_satoshis {
8558+
return Err(ChannelError::Warn(format!(
8559+
"Provided inputs are insufficient for our contribution, {} {}",
8560+
sum_input, our_funding_contribution_satoshis,
8561+
)));
8562+
}
8563+
85538564
self.pending_splice_pre = Some(PendingSpliceInfoPre {
85548565
our_funding_contribution: our_funding_contribution_satoshis,
85558566
});

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4290,7 +4290,7 @@ where
42904290
#[cfg(splicing)]
42914291
pub fn splice_channel(
42924292
&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64,
4293-
_our_funding_inputs: Vec<(TxIn, Transaction)>, funding_feerate_perkw: u32, locktime: u32,
4293+
our_funding_inputs: Vec<(TxIn, Transaction)>, funding_feerate_perkw: u32, locktime: u32,
42944294
) -> Result<(), APIError> {
42954295
let per_peer_state = self.per_peer_state.read().unwrap();
42964296

@@ -4304,7 +4304,7 @@ where
43044304
match peer_state.channel_by_id.entry(*channel_id) {
43054305
hash_map::Entry::Occupied(mut chan_phase_entry) => {
43064306
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
4307-
let msg = chan.splice_channel(our_funding_contribution_satoshis, funding_feerate_perkw, locktime)
4307+
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, funding_feerate_perkw, locktime)
43084308
.map_err(|err| APIError::APIMisuseError {
43094309
err: format!(
43104310
"Cannot initiate Splicing, {}, channel ID {}", err, channel_id

lightning/src/ln/functional_tests_splice.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,17 @@ fn test_v1_splice_in() {
229229
let funding_feerate_perkw = 1024; // TODO
230230
let locktime = 0; // TODO
231231

232+
// Create additional inputs
233+
let extra_splice_funding_input_sats = 35_000;
234+
let funding_inputs = create_dual_funding_utxos_with_prev_txs(&initiator_node, &[extra_splice_funding_input_sats]);
232235
// Initiate splice-in (on initiator_node)
233236
let _res = initiator_node
234237
.node
235238
.splice_channel(
236239
&channel_id2,
237240
&acceptor_node.node.get_our_node_id(),
238241
splice_in_sats as i64,
239-
Vec::new(),
242+
funding_inputs,
240243
funding_feerate_perkw,
241244
locktime,
242245
)

0 commit comments

Comments
 (0)