@@ -34,6 +34,8 @@ use crate::ln::interactivetxs::{
34
34
InteractiveTxConstructorArgs, InteractiveTxSigningSession, InteractiveTxMessageSendResult,
35
35
TX_COMMON_FIELDS_WEIGHT,
36
36
};
37
+ #[cfg(splicing)]
38
+ use crate::ln::interactivetxs::InteractiveTxMessageSend;
37
39
use crate::ln::msgs;
38
40
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError};
39
41
use crate::ln::script::{self, ShutdownScript};
@@ -1186,6 +1188,10 @@ impl UnfundedChannelContext {
1186
1188
#[derive(Clone)]
1187
1189
struct PendingSpliceInfoPre {
1188
1190
pub our_funding_contribution: i64,
1191
+ pub funding_feerate_perkw: u32,
1192
+ pub locktime: u32,
1193
+ /// The funding inputs that we plan to contributing to the splice.
1194
+ pub our_funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
1189
1195
}
1190
1196
1191
1197
#[cfg(splicing)]
@@ -4144,6 +4150,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4144
4150
self.get_initial_counterparty_commitment_signature(logger)
4145
4151
}
4146
4152
4153
+ /// Splice process starting; update state, log, etc.
4154
+ #[cfg(splicing)]
4155
+ pub(crate) fn splice_start<L: Deref>(&mut self, is_outgoing: bool, logger: &L) where L::Target: Logger {
4156
+ // Set state, by this point splice_init/splice_ack handshake is complete
4157
+ // TODO(splicing)
4158
+ // self.channel_state = ChannelState::NegotiatingFunding(
4159
+ // NegotiatingFundingFlags::OUR_INIT_SENT | NegotiatingFundingFlags::THEIR_INIT_SENT
4160
+ // );
4161
+ log_info!(logger, "Splicing process started, old channel value {}, outgoing {}, channel_id {}",
4162
+ self.channel_value_satoshis, is_outgoing, self.channel_id);
4163
+ }
4164
+
4147
4165
/// Get the splice message that can be sent during splice initiation.
4148
4166
#[cfg(splicing)]
4149
4167
pub fn get_splice_init(&self, our_funding_contribution_satoshis: i64,
@@ -7936,10 +7954,15 @@ impl<SP: Deref> Channel<SP> where
7936
7954
// Note: post-splice channel value is not yet known at this point, counterpary contribution is not known
7937
7955
// (Cannot test for miminum required post-splice channel value)
7938
7956
7957
+ // Sum and convert inputs
7958
+ let mut sum_input = 0i64;
7959
+ let mut funding_inputs = Vec::new();
7960
+ for (tx_in, tx) in our_funding_inputs.into_iter() {
7961
+ sum_input += tx.output.get(tx_in.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0);
7962
+ let tx16 = TransactionU16LenLimited::new(tx).map_err(|_e| ChannelError::Warn(format!("Too large transaction")))?;
7963
+ funding_inputs.push((tx_in, tx16));
7964
+ }
7939
7965
// Check that inputs are sufficient to cover our contribution
7940
- let sum_input: i64 = our_funding_inputs.into_iter().fold(0, |acc, i|
7941
- acc + i.1.output.get(i.0.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0)
7942
- );
7943
7966
if sum_input < our_funding_contribution_satoshis {
7944
7967
return Err(ChannelError::Warn(format!(
7945
7968
"Provided inputs are insufficient for our contribution, {} {}",
@@ -7949,6 +7972,9 @@ impl<SP: Deref> Channel<SP> where
7949
7972
7950
7973
self.pending_splice_pre = Some(PendingSpliceInfoPre {
7951
7974
our_funding_contribution: our_funding_contribution_satoshis,
7975
+ funding_feerate_perkw,
7976
+ locktime,
7977
+ our_funding_inputs: funding_inputs,
7952
7978
});
7953
7979
7954
7980
let msg = self.context.get_splice_init(our_funding_contribution_satoshis, funding_feerate_perkw, locktime);
@@ -7957,7 +7983,9 @@ impl<SP: Deref> Channel<SP> where
7957
7983
7958
7984
/// Handle splice_init
7959
7985
#[cfg(splicing)]
7960
- pub fn splice_init(&mut self, msg: &msgs::SpliceInit) -> Result<msgs::SpliceAck, ChannelError> {
7986
+ pub fn splice_init<ES: Deref, L: Deref>(
7987
+ &mut self, msg: &msgs::SpliceInit, _signer_provider: &SP, _entropy_source: &ES, _holder_node_id: PublicKey, logger: &L,
7988
+ ) -> Result<msgs::SpliceAck, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
7961
7989
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
7962
7990
// TODO(splicing): Currently not possible to contribute on the splicing-acceptor side
7963
7991
let our_funding_contribution_satoshis = 0i64;
@@ -8000,16 +8028,24 @@ impl<SP: Deref> Channel<SP> where
8000
8028
let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
8001
8029
8002
8030
// TODO(splicing): Store msg.funding_pubkey
8003
- // TODO(splicing): Apply start of splice (splice_start)
8031
+
8032
+ // Apply start of splice change in the state
8033
+ self.context.splice_start(false, logger);
8004
8034
8005
8035
let splice_ack_msg = self.context.get_splice_ack(our_funding_contribution_satoshis);
8036
+
8006
8037
// TODO(splicing): start interactive funding negotiation
8038
+ // let _msg = self.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id)
8039
+ // .map_err(|err| ChannelError::Warn(format!("Failed to start interactive transaction construction, {:?}", err)))?;
8040
+
8007
8041
Ok(splice_ack_msg)
8008
8042
}
8009
8043
8010
8044
/// Handle splice_ack
8011
8045
#[cfg(splicing)]
8012
- pub fn splice_ack(&mut self, msg: &msgs::SpliceAck) -> Result<(), ChannelError> {
8046
+ pub fn splice_ack<ES: Deref, L: Deref>(
8047
+ &mut self, msg: &msgs::SpliceAck, _signer_provider: &SP, _entropy_source: &ES, _holder_node_id: PublicKey, logger: &L,
8048
+ ) -> Result<Option<InteractiveTxMessageSend>, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
8013
8049
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
8014
8050
8015
8051
// check if splice is pending
@@ -8027,7 +8063,15 @@ impl<SP: Deref> Channel<SP> where
8027
8063
// Early check for reserve requirement, assuming maximum balance of full channel value
8028
8064
// This will also be checked later at tx_complete
8029
8065
let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
8030
- Ok(())
8066
+
8067
+ // Apply start of splice change in the state
8068
+ self.context.splice_start(true, logger);
8069
+
8070
+ // TODO(splicing): start interactive funding negotiation
8071
+ // let tx_msg_opt = self.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id)
8072
+ // .map_err(|err| ChannelError::Warn(format!("V2 channel rejected due to sender error, {:?}", err)))?;
8073
+ // Ok(tx_msg_opt)
8074
+ Ok(None)
8031
8075
}
8032
8076
8033
8077
// Send stuff to our remote peers:
0 commit comments