@@ -1431,6 +1431,10 @@ impl UnfundedChannelContext {
1431
1431
#[derive(Clone)]
1432
1432
struct PendingSpliceInfoPre {
1433
1433
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)>,
1434
1438
}
1435
1439
1436
1440
#[cfg(splicing)]
@@ -4441,6 +4445,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4441
4445
self.get_initial_counterparty_commitment_signature(logger)
4442
4446
}
4443
4447
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
+
4444
4460
/// Get the splice message that can be sent during splice initiation.
4445
4461
#[cfg(splicing)]
4446
4462
pub fn get_splice_init(&self, our_funding_contribution_satoshis: i64,
@@ -8253,10 +8269,15 @@ impl<SP: Deref> FundedChannel<SP> where
8253
8269
// Note: post-splice channel value is not yet known at this point, counterpary contribution is not known
8254
8270
// (Cannot test for miminum required post-splice channel value)
8255
8271
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
+ }
8256
8280
// 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
- );
8260
8281
if sum_input < our_funding_contribution_satoshis {
8261
8282
return Err(ChannelError::Warn(format!(
8262
8283
"Provided inputs are insufficient for our contribution, {} {}",
@@ -8266,6 +8287,9 @@ impl<SP: Deref> FundedChannel<SP> where
8266
8287
8267
8288
self.pending_splice_pre = Some(PendingSpliceInfoPre {
8268
8289
our_funding_contribution: our_funding_contribution_satoshis,
8290
+ funding_feerate_perkw,
8291
+ locktime,
8292
+ our_funding_inputs: funding_inputs,
8269
8293
});
8270
8294
8271
8295
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
8274
8298
8275
8299
/// Handle splice_init
8276
8300
#[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 {
8278
8304
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
8279
8305
// TODO(splicing): Currently not possible to contribute on the splicing-acceptor side
8280
8306
let our_funding_contribution_satoshis = 0i64;
@@ -8317,16 +8343,24 @@ impl<SP: Deref> FundedChannel<SP> where
8317
8343
let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
8318
8344
8319
8345
// 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);
8321
8349
8322
8350
let splice_ack_msg = self.context.get_splice_ack(our_funding_contribution_satoshis);
8351
+
8323
8352
// 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
+
8324
8356
Ok(splice_ack_msg)
8325
8357
}
8326
8358
8327
8359
/// Handle splice_ack
8328
8360
#[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 {
8330
8364
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
8331
8365
8332
8366
// check if splice is pending
@@ -8344,7 +8378,15 @@ impl<SP: Deref> FundedChannel<SP> where
8344
8378
// Early check for reserve requirement, assuming maximum balance of full channel value
8345
8379
// This will also be checked later at tx_complete
8346
8380
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)
8348
8390
}
8349
8391
8350
8392
// Send stuff to our remote peers:
0 commit comments