@@ -1431,6 +1431,10 @@ impl UnfundedChannelContext {
14311431#[derive(Clone)]
14321432struct PendingSpliceInfoPre {
14331433 pub our_funding_contribution: i64,
1434+ pub funding_feerate_perkw: u32,
1435+ pub locktime: u32,
1436+ /// The funding inputs that we plan to contributing to the splice.
1437+ pub our_funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
14341438}
14351439
14361440#[cfg(splicing)]
@@ -4441,6 +4445,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
44414445 self.get_initial_counterparty_commitment_signature(logger)
44424446 }
44434447
4448+ /// Splice process starting; update state, log, etc.
4449+ #[cfg(splicing)]
4450+ pub(crate) fn splice_start<L: Deref>(&mut self, is_outgoing: bool, logger: &L) where L::Target: Logger {
4451+ // Set state, by this point splice_init/splice_ack handshake is complete
4452+ // TODO(splicing)
4453+ // self.channel_state = ChannelState::NegotiatingFunding(
4454+ // NegotiatingFundingFlags::OUR_INIT_SENT | NegotiatingFundingFlags::THEIR_INIT_SENT
4455+ // );
4456+ log_info!(logger, "Splicing process started, old channel value {}, outgoing {}, channel_id {}",
4457+ self.channel_value_satoshis, is_outgoing, self.channel_id);
4458+ }
4459+
44444460 /// Get the splice message that can be sent during splice initiation.
44454461 #[cfg(splicing)]
44464462 pub fn get_splice_init(&self, our_funding_contribution_satoshis: i64,
@@ -8253,10 +8269,15 @@ impl<SP: Deref> FundedChannel<SP> where
82538269 // Note: post-splice channel value is not yet known at this point, counterpary contribution is not known
82548270 // (Cannot test for miminum required post-splice channel value)
82558271
8272+ // Sum and convert inputs
8273+ let mut sum_input = 0i64;
8274+ let mut funding_inputs = Vec::new();
8275+ for (tx_in, tx) in our_funding_inputs.into_iter() {
8276+ sum_input += tx.output.get(tx_in.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0);
8277+ let tx16 = TransactionU16LenLimited::new(tx).map_err(|_e| ChannelError::Warn(format!("Too large transaction")))?;
8278+ funding_inputs.push((tx_in, tx16));
8279+ }
82568280 // Check that inputs are sufficient to cover our contribution
8257- let sum_input: i64 = our_funding_inputs.into_iter().fold(0, |acc, i|
8258- acc + i.1.output.get(i.0.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0)
8259- );
82608281 if sum_input < our_funding_contribution_satoshis {
82618282 return Err(ChannelError::Warn(format!(
82628283 "Provided inputs are insufficient for our contribution, {} {}",
@@ -8266,6 +8287,9 @@ impl<SP: Deref> FundedChannel<SP> where
82668287
82678288 self.pending_splice_pre = Some(PendingSpliceInfoPre {
82688289 our_funding_contribution: our_funding_contribution_satoshis,
8290+ funding_feerate_perkw,
8291+ locktime,
8292+ our_funding_inputs: funding_inputs,
82698293 });
82708294
82718295 let msg = self.context.get_splice_init(our_funding_contribution_satoshis, funding_feerate_perkw, locktime);
@@ -8274,7 +8298,9 @@ impl<SP: Deref> FundedChannel<SP> where
82748298
82758299 /// Handle splice_init
82768300 #[cfg(splicing)]
8277- pub fn splice_init(&mut self, msg: &msgs::SpliceInit) -> Result<msgs::SpliceAck, ChannelError> {
8301+ pub fn splice_init<ES: Deref, L: Deref>(
8302+ &mut self, msg: &msgs::SpliceInit, _signer_provider: &SP, _entropy_source: &ES, _holder_node_id: PublicKey, logger: &L,
8303+ ) -> Result<msgs::SpliceAck, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
82788304 let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
82798305 // TODO(splicing): Currently not possible to contribute on the splicing-acceptor side
82808306 let our_funding_contribution_satoshis = 0i64;
@@ -8317,16 +8343,24 @@ impl<SP: Deref> FundedChannel<SP> where
83178343 let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
83188344
83198345 // TODO(splicing): Store msg.funding_pubkey
8320- // TODO(splicing): Apply start of splice (splice_start)
8346+
8347+ // Apply start of splice change in the state
8348+ self.context.splice_start(false, logger);
83218349
83228350 let splice_ack_msg = self.context.get_splice_ack(our_funding_contribution_satoshis);
8351+
83238352 // TODO(splicing): start interactive funding negotiation
8353+ // let _msg = self.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id)
8354+ // .map_err(|err| ChannelError::Warn(format!("Failed to start interactive transaction construction, {:?}", err)))?;
8355+
83248356 Ok(splice_ack_msg)
83258357 }
83268358
83278359 /// Handle splice_ack
83288360 #[cfg(splicing)]
8329- pub fn splice_ack(&mut self, msg: &msgs::SpliceAck) -> Result<(), ChannelError> {
8361+ pub fn splice_ack<ES: Deref, L: Deref>(
8362+ &mut self, msg: &msgs::SpliceAck, _signer_provider: &SP, _entropy_source: &ES, _holder_node_id: PublicKey, logger: &L,
8363+ ) -> Result<Option<InteractiveTxMessageSend>, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
83308364 let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
83318365
83328366 // check if splice is pending
@@ -8344,7 +8378,15 @@ impl<SP: Deref> FundedChannel<SP> where
83448378 // Early check for reserve requirement, assuming maximum balance of full channel value
83458379 // This will also be checked later at tx_complete
83468380 let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
8347- Ok(())
8381+
8382+ // Apply start of splice change in the state
8383+ self.context.splice_start(true, logger);
8384+
8385+ // TODO(splicing): start interactive funding negotiation
8386+ // let tx_msg_opt = self.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id)
8387+ // .map_err(|err| ChannelError::Warn(format!("V2 channel rejected due to sender error, {:?}", err)))?;
8388+ // Ok(tx_msg_opt)
8389+ Ok(None)
83488390 }
83498391
83508392 // Send stuff to our remote peers:
0 commit comments