Skip to content

Commit 9ffe4b1

Browse files
committed
In splice_channel() check if provided inputs are sufficient
1 parent 4972b25 commit 9ffe4b1

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

lightning/src/ln/channel.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -7895,7 +7895,7 @@ impl<SP: Deref> Channel<SP> where
78957895
/// Initiate splicing
78967896
#[cfg(splicing)]
78977897
pub fn splice_channel(&mut self, our_funding_contribution_satoshis: i64,
7898-
funding_feerate_perkw: u32, locktime: u32,
7898+
our_funding_inputs: Vec<(TxIn, Transaction)>, funding_feerate_perkw: u32, locktime: u32,
78997899
) -> Result<msgs::SpliceInit, ChannelError> {
79007900
// Check if a splice has been initiated already.
79017901
// Note: this could be handled more nicely, and support multiple outstanding splice's, the incoming splice_ack matters anyways.
@@ -7928,6 +7928,17 @@ impl<SP: Deref> Channel<SP> where
79287928
// Note: post-splice channel value is not yet known at this point, counterpary contribution is not known
79297929
// (Cannot test for miminum required post-splice channel value)
79307930

7931+
// Check that inputs are sufficient to cover our contribution
7932+
let sum_input: i64 = our_funding_inputs.into_iter().fold(0, |acc, i|
7933+
acc + i.1.output.get(i.0.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0)
7934+
);
7935+
if sum_input < our_funding_contribution_satoshis {
7936+
return Err(ChannelError::Warn(format!(
7937+
"Provided inputs are insufficient for our contribution, {} {}",
7938+
sum_input, our_funding_contribution_satoshis,
7939+
)));
7940+
}
7941+
79317942
self.pending_splice_pre = Some(PendingSpliceInfoPre {
79327943
our_funding_contribution: our_funding_contribution_satoshis,
79337944
});

lightning/src/ln/channelmanager.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4128,7 +4128,7 @@ where
41284128
#[cfg(splicing)]
41294129
pub fn splice_channel(
41304130
&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64,
4131-
_our_funding_inputs: Vec<(TxIn, Transaction)>, funding_feerate_perkw: u32, locktime: u32,
4131+
our_funding_inputs: Vec<(TxIn, Transaction)>, funding_feerate_perkw: u32, locktime: u32,
41324132
) -> Result<(), APIError> {
41334133
let per_peer_state = self.per_peer_state.read().unwrap();
41344134

@@ -4142,7 +4142,7 @@ where
41424142
match peer_state.channel_by_id.entry(*channel_id) {
41434143
hash_map::Entry::Occupied(mut chan_phase_entry) => {
41444144
if let ChannelPhase::Funded(chan) = chan_phase_entry.get_mut() {
4145-
let msg = chan.splice_channel(our_funding_contribution_satoshis, funding_feerate_perkw, locktime)
4145+
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, funding_feerate_perkw, locktime)
41464146
.map_err(|err| APIError::APIMisuseError {
41474147
err: format!(
41484148
"Cannot initiate Splicing, {}, channel ID {}", err, channel_id

lightning/src/ln/functional_tests_splice.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,20 @@ 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(
235+
&initiator_node,
236+
&[extra_splice_funding_input_sats],
237+
);
232238
// Initiate splice-in (on initiator_node)
233239
let _res = initiator_node
234240
.node
235241
.splice_channel(
236242
&channel_id2,
237243
&acceptor_node.node.get_our_node_id(),
238244
splice_in_sats as i64,
239-
Vec::new(),
245+
funding_inputs,
240246
funding_feerate_perkw,
241247
locktime,
242248
)

0 commit comments

Comments
 (0)