@@ -1545,6 +1545,10 @@ impl UnfundedChannelContext {
1545
1545
#[derive(Clone)]
1546
1546
struct PendingSpliceInfoPre {
1547
1547
pub our_funding_contribution: i64,
1548
+ pub funding_feerate_perkw: u32,
1549
+ pub locktime: u32,
1550
+ /// The funding inputs that we plan to contributing to the splice.
1551
+ pub our_funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
1548
1552
}
1549
1553
1550
1554
#[cfg(splicing)]
@@ -4566,6 +4570,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4566
4570
self.get_initial_counterparty_commitment_signature(logger)
4567
4571
}
4568
4572
4573
+ /// Splice process starting; update state, log, etc.
4574
+ #[cfg(splicing)]
4575
+ pub(crate) fn splice_start<L: Deref>(&mut self, is_outgoing: bool, logger: &L) where L::Target: Logger {
4576
+ // Set state, by this point splice_init/splice_ack handshake is complete
4577
+ // TODO(splicing)
4578
+ // self.channel_state = ChannelState::NegotiatingFunding(
4579
+ // NegotiatingFundingFlags::OUR_INIT_SENT | NegotiatingFundingFlags::THEIR_INIT_SENT
4580
+ // );
4581
+ log_info!(logger, "Splicing process started, old channel value {}, outgoing {}, channel_id {}",
4582
+ self.channel_value_satoshis, is_outgoing, self.channel_id);
4583
+ }
4584
+
4569
4585
/// Get the splice message that can be sent during splice initiation.
4570
4586
#[cfg(splicing)]
4571
4587
pub fn get_splice_init(&self, our_funding_contribution_satoshis: i64,
@@ -8343,10 +8359,15 @@ impl<SP: Deref> FundedChannel<SP> where
8343
8359
// Note: post-splice channel value is not yet known at this point, counterpary contribution is not known
8344
8360
// (Cannot test for miminum required post-splice channel value)
8345
8361
8362
+ // Sum and convert inputs
8363
+ let mut sum_input = 0i64;
8364
+ let mut funding_inputs = Vec::new();
8365
+ for (tx_in, tx) in our_funding_inputs.into_iter() {
8366
+ sum_input += tx.output.get(tx_in.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0);
8367
+ let tx16 = TransactionU16LenLimited::new(tx).map_err(|_e| ChannelError::Warn(format!("Too large transaction")))?;
8368
+ funding_inputs.push((tx_in, tx16));
8369
+ }
8346
8370
// Check that inputs are sufficient to cover our contribution
8347
- let sum_input: i64 = our_funding_inputs.into_iter().fold(0, |acc, i|
8348
- acc + i.1.output.get(i.0.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0)
8349
- );
8350
8371
if sum_input < our_funding_contribution_satoshis {
8351
8372
return Err(ChannelError::Warn(format!(
8352
8373
"Provided inputs are insufficient for our contribution, {} {}",
@@ -8356,6 +8377,9 @@ impl<SP: Deref> FundedChannel<SP> where
8356
8377
8357
8378
self.pending_splice_pre = Some(PendingSpliceInfoPre {
8358
8379
our_funding_contribution: our_funding_contribution_satoshis,
8380
+ funding_feerate_perkw,
8381
+ locktime,
8382
+ our_funding_inputs: funding_inputs,
8359
8383
});
8360
8384
8361
8385
let msg = self.context.get_splice_init(our_funding_contribution_satoshis, funding_feerate_perkw, locktime);
@@ -8364,7 +8388,9 @@ impl<SP: Deref> FundedChannel<SP> where
8364
8388
8365
8389
/// Handle splice_init
8366
8390
#[cfg(splicing)]
8367
- pub fn splice_init(&mut self, msg: &msgs::SpliceInit) -> Result<msgs::SpliceAck, ChannelError> {
8391
+ pub fn splice_init<ES: Deref, L: Deref>(
8392
+ &mut self, msg: &msgs::SpliceInit, _signer_provider: &SP, _entropy_source: &ES, _holder_node_id: PublicKey, logger: &L,
8393
+ ) -> Result<msgs::SpliceAck, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
8368
8394
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
8369
8395
// TODO(splicing): Currently not possible to contribute on the splicing-acceptor side
8370
8396
let our_funding_contribution_satoshis = 0i64;
@@ -8407,16 +8433,24 @@ impl<SP: Deref> FundedChannel<SP> where
8407
8433
let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
8408
8434
8409
8435
// TODO(splicing): Store msg.funding_pubkey
8410
- // TODO(splicing): Apply start of splice (splice_start)
8436
+
8437
+ // Apply start of splice change in the state
8438
+ self.context.splice_start(false, logger);
8411
8439
8412
8440
let splice_ack_msg = self.context.get_splice_ack(our_funding_contribution_satoshis);
8441
+
8413
8442
// TODO(splicing): start interactive funding negotiation
8443
+ // let _msg = self.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id)
8444
+ // .map_err(|err| ChannelError::Warn(format!("Failed to start interactive transaction construction, {:?}", err)))?;
8445
+
8414
8446
Ok(splice_ack_msg)
8415
8447
}
8416
8448
8417
8449
/// Handle splice_ack
8418
8450
#[cfg(splicing)]
8419
- pub fn splice_ack(&mut self, msg: &msgs::SpliceAck) -> Result<(), ChannelError> {
8451
+ pub fn splice_ack<ES: Deref, L: Deref>(
8452
+ &mut self, msg: &msgs::SpliceAck, _signer_provider: &SP, _entropy_source: &ES, _holder_node_id: PublicKey, logger: &L,
8453
+ ) -> Result<Option<InteractiveTxMessageSend>, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
8420
8454
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
8421
8455
8422
8456
// check if splice is pending
@@ -8434,7 +8468,15 @@ impl<SP: Deref> FundedChannel<SP> where
8434
8468
// Early check for reserve requirement, assuming maximum balance of full channel value
8435
8469
// This will also be checked later at tx_complete
8436
8470
let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
8437
- Ok(())
8471
+
8472
+ // Apply start of splice change in the state
8473
+ self.context.splice_start(true, logger);
8474
+
8475
+ // TODO(splicing): start interactive funding negotiation
8476
+ // let tx_msg_opt = self.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id)
8477
+ // .map_err(|err| ChannelError::Warn(format!("V2 channel rejected due to sender error, {:?}", err)))?;
8478
+ // Ok(tx_msg_opt)
8479
+ Ok(None)
8438
8480
}
8439
8481
8440
8482
// Send stuff to our remote peers:
0 commit comments