@@ -1724,6 +1724,10 @@ impl FundingScope {
1724
1724
#[derive(Clone)]
1725
1725
struct PendingSpliceInfoPre {
1726
1726
pub our_funding_contribution: i64,
1727
+ pub funding_feerate_perkw: u32,
1728
+ pub locktime: u32,
1729
+ /// The funding inputs that we plan to contributing to the splice.
1730
+ pub our_funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
1727
1731
}
1728
1732
1729
1733
#[cfg(splicing)]
@@ -4733,6 +4737,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4733
4737
self.get_initial_counterparty_commitment_signature(funding, logger)
4734
4738
}
4735
4739
4740
+ /// Splice process starting; update state, log, etc.
4741
+ #[cfg(splicing)]
4742
+ pub(crate) fn splice_start<L: Deref>(&mut self, is_outgoing: bool, logger: &L) where L::Target: Logger {
4743
+ // Set state, by this point splice_init/splice_ack handshake is complete
4744
+ // TODO(splicing)
4745
+ // self.channel_state = ChannelState::NegotiatingFunding(
4746
+ // NegotiatingFundingFlags::OUR_INIT_SENT | NegotiatingFundingFlags::THEIR_INIT_SENT
4747
+ // );
4748
+ log_info!(logger, "Splicing process started, old channel value {}, outgoing {}, channel_id {}",
4749
+ self.channel_value_satoshis, is_outgoing, self.channel_id);
4750
+ }
4751
+
4736
4752
/// Get the splice message that can be sent during splice initiation.
4737
4753
#[cfg(splicing)]
4738
4754
pub fn get_splice_init(&self, our_funding_contribution_satoshis: i64,
@@ -8550,10 +8566,15 @@ impl<SP: Deref> FundedChannel<SP> where
8550
8566
// Note: post-splice channel value is not yet known at this point, counterpary contribution is not known
8551
8567
// (Cannot test for miminum required post-splice channel value)
8552
8568
8569
+ // Sum and convert inputs
8570
+ let mut sum_input = 0i64;
8571
+ let mut funding_inputs = Vec::new();
8572
+ for (tx_in, tx) in our_funding_inputs.into_iter() {
8573
+ sum_input += tx.output.get(tx_in.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0);
8574
+ let tx16 = TransactionU16LenLimited::new(tx).map_err(|_e| ChannelError::Warn(format!("Too large transaction")))?;
8575
+ funding_inputs.push((tx_in, tx16));
8576
+ }
8553
8577
// 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
8578
if sum_input < our_funding_contribution_satoshis {
8558
8579
return Err(ChannelError::Warn(format!(
8559
8580
"Provided inputs are insufficient for our contribution, {} {}",
@@ -8563,6 +8584,9 @@ impl<SP: Deref> FundedChannel<SP> where
8563
8584
8564
8585
self.pending_splice_pre = Some(PendingSpliceInfoPre {
8565
8586
our_funding_contribution: our_funding_contribution_satoshis,
8587
+ funding_feerate_perkw,
8588
+ locktime,
8589
+ our_funding_inputs: funding_inputs,
8566
8590
});
8567
8591
8568
8592
let msg = self.context.get_splice_init(our_funding_contribution_satoshis, funding_feerate_perkw, locktime);
@@ -8571,7 +8595,9 @@ impl<SP: Deref> FundedChannel<SP> where
8571
8595
8572
8596
/// Handle splice_init
8573
8597
#[cfg(splicing)]
8574
- pub fn splice_init(&mut self, msg: &msgs::SpliceInit) -> Result<msgs::SpliceAck, ChannelError> {
8598
+ pub fn splice_init<ES: Deref, L: Deref>(
8599
+ &mut self, msg: &msgs::SpliceInit, _signer_provider: &SP, _entropy_source: &ES, _holder_node_id: PublicKey, logger: &L,
8600
+ ) -> Result<msgs::SpliceAck, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
8575
8601
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
8576
8602
// TODO(splicing): Currently not possible to contribute on the splicing-acceptor side
8577
8603
let our_funding_contribution_satoshis = 0i64;
@@ -8614,16 +8640,24 @@ impl<SP: Deref> FundedChannel<SP> where
8614
8640
let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
8615
8641
8616
8642
// TODO(splicing): Store msg.funding_pubkey
8617
- // TODO(splicing): Apply start of splice (splice_start)
8643
+
8644
+ // Apply start of splice change in the state
8645
+ self.context.splice_start(false, logger);
8618
8646
8619
8647
let splice_ack_msg = self.context.get_splice_ack(our_funding_contribution_satoshis);
8648
+
8620
8649
// TODO(splicing): start interactive funding negotiation
8650
+ // let _msg = self.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id)
8651
+ // .map_err(|err| ChannelError::Warn(format!("Failed to start interactive transaction construction, {:?}", err)))?;
8652
+
8621
8653
Ok(splice_ack_msg)
8622
8654
}
8623
8655
8624
8656
/// Handle splice_ack
8625
8657
#[cfg(splicing)]
8626
- pub fn splice_ack(&mut self, msg: &msgs::SpliceAck) -> Result<(), ChannelError> {
8658
+ pub fn splice_ack<ES: Deref, L: Deref>(
8659
+ &mut self, msg: &msgs::SpliceAck, _signer_provider: &SP, _entropy_source: &ES, _holder_node_id: PublicKey, logger: &L,
8660
+ ) -> Result<Option<InteractiveTxMessageSend>, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
8627
8661
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
8628
8662
8629
8663
// check if splice is pending
@@ -8641,7 +8675,15 @@ impl<SP: Deref> FundedChannel<SP> where
8641
8675
// Early check for reserve requirement, assuming maximum balance of full channel value
8642
8676
// This will also be checked later at tx_complete
8643
8677
let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
8644
- Ok(())
8678
+
8679
+ // Apply start of splice change in the state
8680
+ self.context.splice_start(true, logger);
8681
+
8682
+ // TODO(splicing): start interactive funding negotiation
8683
+ // let tx_msg_opt = self.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id)
8684
+ // .map_err(|err| ChannelError::Warn(format!("V2 channel rejected due to sender error, {:?}", err)))?;
8685
+ // Ok(tx_msg_opt)
8686
+ Ok(None)
8645
8687
}
8646
8688
8647
8689
// Send stuff to our remote peers:
0 commit comments