@@ -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 });
0 commit comments