@@ -34,6 +34,8 @@ use crate::ln::interactivetxs::{
34
34
InteractiveTxConstructorArgs, InteractiveTxMessageSend, InteractiveTxSigningSession, InteractiveTxMessageSendResult,
35
35
OutputOwned, SharedOwnedOutput, 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};
@@ -1187,6 +1189,10 @@ impl UnfundedChannelContext {
1187
1189
#[derive(Clone)]
1188
1190
struct PendingSpliceInfoPre {
1189
1191
pub our_funding_contribution: i64,
1192
+ pub funding_feerate_perkw: u32,
1193
+ pub locktime: u32,
1194
+ /// The funding inputs that we plan to contributing to the splice.
1195
+ pub our_funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
1190
1196
}
1191
1197
1192
1198
#[cfg(splicing)]
@@ -4265,6 +4271,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4265
4271
self.get_initial_counterparty_commitment_signature(logger)
4266
4272
}
4267
4273
4274
+ /// Splice process starting; update state, log, etc.
4275
+ #[cfg(splicing)]
4276
+ pub(crate) fn splice_start<L: Deref>(&mut self, is_outgoing: bool, logger: &L) where L::Target: Logger {
4277
+ // Set state, by this point splice_init/splice_ack handshake is complete
4278
+ // TODO(splicing)
4279
+ // self.channel_state = ChannelState::NegotiatingFunding(
4280
+ // NegotiatingFundingFlags::OUR_INIT_SENT | NegotiatingFundingFlags::THEIR_INIT_SENT
4281
+ // );
4282
+ log_info!(logger, "Splicing process started, old channel value {}, outgoing {}, channel_id {}",
4283
+ self.channel_value_satoshis, is_outgoing, self.channel_id);
4284
+ }
4285
+
4268
4286
/// Get the splice message that can be sent during splice initiation.
4269
4287
#[cfg(splicing)]
4270
4288
pub fn get_splice_init(&self, our_funding_contribution_satoshis: i64,
@@ -8062,10 +8080,15 @@ impl<SP: Deref> Channel<SP> where
8062
8080
// Note: post-splice channel value is not yet known at this point, counterpary contribution is not known
8063
8081
// (Cannot test for miminum required post-splice channel value)
8064
8082
8083
+ // Sum and convert inputs
8084
+ let mut sum_input = 0i64;
8085
+ let mut funding_inputs = Vec::new();
8086
+ for (tx_in, tx) in our_funding_inputs.into_iter() {
8087
+ sum_input += tx.output.get(tx_in.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0);
8088
+ let tx16 = TransactionU16LenLimited::new(tx).map_err(|_e| ChannelError::Warn(format!("Too large transaction")))?;
8089
+ funding_inputs.push((tx_in, tx16));
8090
+ }
8065
8091
// Check that inputs are sufficient to cover our contribution
8066
- let sum_input: i64 = our_funding_inputs.into_iter().fold(0, |acc, i|
8067
- acc + i.1.output.get(i.0.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0)
8068
- );
8069
8092
if sum_input < our_funding_contribution_satoshis {
8070
8093
return Err(ChannelError::Warn(format!(
8071
8094
"Provided inputs are insufficient for our contribution, {} {}",
@@ -8075,6 +8098,9 @@ impl<SP: Deref> Channel<SP> where
8075
8098
8076
8099
self.pending_splice_pre = Some(PendingSpliceInfoPre {
8077
8100
our_funding_contribution: our_funding_contribution_satoshis,
8101
+ funding_feerate_perkw,
8102
+ locktime,
8103
+ our_funding_inputs: funding_inputs,
8078
8104
});
8079
8105
8080
8106
let msg = self.context.get_splice_init(our_funding_contribution_satoshis, funding_feerate_perkw, locktime);
@@ -8083,7 +8109,9 @@ impl<SP: Deref> Channel<SP> where
8083
8109
8084
8110
/// Handle splice_init
8085
8111
#[cfg(splicing)]
8086
- pub fn splice_init(&mut self, msg: &msgs::SpliceInit) -> Result<msgs::SpliceAck, ChannelError> {
8112
+ pub fn splice_init<ES: Deref, L: Deref>(
8113
+ &mut self, msg: &msgs::SpliceInit, _signer_provider: &SP, _entropy_source: &ES, _holder_node_id: PublicKey, logger: &L,
8114
+ ) -> Result<msgs::SpliceAck, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
8087
8115
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
8088
8116
// TODO(splicing): Currently not possible to contribute on the splicing-acceptor side
8089
8117
let our_funding_contribution_satoshis = 0i64;
@@ -8126,16 +8154,24 @@ impl<SP: Deref> Channel<SP> where
8126
8154
let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
8127
8155
8128
8156
// TODO(splicing): Store msg.funding_pubkey
8129
- // TODO(splicing): Apply start of splice (splice_start)
8157
+
8158
+ // Apply start of splice change in the state
8159
+ self.context.splice_start(false, logger);
8130
8160
8131
8161
let splice_ack_msg = self.context.get_splice_ack(our_funding_contribution_satoshis);
8162
+
8132
8163
// TODO(splicing): start interactive funding negotiation
8164
+ // let _msg = self.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id)
8165
+ // .map_err(|err| ChannelError::Warn(format!("Failed to start interactive transaction construction, {:?}", err)))?;
8166
+
8133
8167
Ok(splice_ack_msg)
8134
8168
}
8135
8169
8136
8170
/// Handle splice_ack
8137
8171
#[cfg(splicing)]
8138
- pub fn splice_ack(&mut self, msg: &msgs::SpliceAck) -> Result<(), ChannelError> {
8172
+ pub fn splice_ack<ES: Deref, L: Deref>(
8173
+ &mut self, msg: &msgs::SpliceAck, _signer_provider: &SP, _entropy_source: &ES, _holder_node_id: PublicKey, logger: &L,
8174
+ ) -> Result<Option<InteractiveTxMessageSend>, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
8139
8175
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
8140
8176
8141
8177
// check if splice is pending
@@ -8153,7 +8189,15 @@ impl<SP: Deref> Channel<SP> where
8153
8189
// Early check for reserve requirement, assuming maximum balance of full channel value
8154
8190
// This will also be checked later at tx_complete
8155
8191
let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
8156
- Ok(())
8192
+
8193
+ // Apply start of splice change in the state
8194
+ self.context.splice_start(true, logger);
8195
+
8196
+ // TODO(splicing): start interactive funding negotiation
8197
+ // let tx_msg_opt = self.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id)
8198
+ // .map_err(|err| ChannelError::Warn(format!("V2 channel rejected due to sender error, {:?}", err)))?;
8199
+ // Ok(tx_msg_opt)
8200
+ Ok(None)
8157
8201
}
8158
8202
8159
8203
// Send stuff to our remote peers:
0 commit comments