@@ -1009,16 +1009,6 @@ impl ChannelError {
10091009 pub(super) fn close(err: String) -> Self {
10101010 ChannelError::Close((err.clone(), ClosureReason::ProcessingError { err }))
10111011 }
1012-
1013- pub(super) fn message(&self) -> &str {
1014- match self {
1015- &ChannelError::Ignore(ref e) => &e,
1016- &ChannelError::Warn(ref e) => &e,
1017- &ChannelError::WarnAndDisconnect(ref e) => &e,
1018- &ChannelError::Close((ref e, _)) => &e,
1019- &ChannelError::SendError(ref e) => &e,
1020- }
1021- }
10221012}
10231013
10241014pub(super) struct WithChannelContext<'a, L: Deref>
@@ -1888,7 +1878,7 @@ where
18881878 #[cfg(splicing)]
18891879 pending_splice: None,
18901880 };
1891- let res = funded_channel.commitment_signed_initial_v2 (msg, best_block, signer_provider, logger)
1881+ let res = funded_channel.initial_commitment_signed_v2 (msg, best_block, signer_provider, logger)
18921882 .map(|monitor| (Some(monitor), None))
18931883 // TODO: Change to `inspect_err` when MSRV is high enough.
18941884 .map_err(|err| {
@@ -5517,6 +5507,9 @@ where
55175507 funding
55185508 .channel_transaction_parameters.funding_outpoint = Some(outpoint);
55195509
5510+ self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
5511+ self.channel_state.set_interactive_signing();
5512+
55205513 if is_splice {
55215514 debug_assert_eq!(
55225515 holder_commitment_transaction_number,
@@ -5531,14 +5524,15 @@ where
55315524 self.assert_no_commitment_advancement(holder_commitment_transaction_number, "initial commitment_signed");
55325525 }
55335526
5534- let commitment_signed = self.get_initial_commitment_signed (&funding, logger);
5527+ let commitment_signed = self.get_initial_commitment_signed_v2 (&funding, logger);
55355528 let commitment_signed = match commitment_signed {
5536- Ok(commitment_signed) => commitment_signed,
5537- Err(e) => {
5529+ Some(commitment_signed) => commitment_signed,
5530+ // TODO(splicing): Support async signing
5531+ None => {
55385532 funding.channel_transaction_parameters.funding_outpoint = None;
55395533 return Err(msgs::TxAbort {
55405534 channel_id: self.channel_id(),
5541- data: e.message() .to_owned().into_bytes(),
5535+ data: "Failed to get signature for commitment_signed" .to_owned().into_bytes(),
55425536 });
55435537 },
55445538 };
@@ -5580,98 +5574,99 @@ where
55805574 });
55815575 };
55825576
5583- let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
5584- channel_state.set_interactive_signing();
5585- self.channel_state = channel_state;
5586-
55875577 Ok((commitment_signed, funding_ready_for_sig_event))
55885578 }
55895579
55905580 /// Asserts that the commitment tx numbers have not advanced from their initial number.
5591- #[rustfmt::skip]
5592- fn assert_no_commitment_advancement(&self, holder_commitment_transaction_number: u64, msg_name: &str) {
5593- if self.commitment_secrets.get_min_seen_secret() != (1 << 48) ||
5594- self.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER ||
5595- holder_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER {
5596- debug_assert!(false, "Should not have advanced channel commitment tx numbers prior to {}",
5597- msg_name);
5581+ fn assert_no_commitment_advancement(
5582+ &self, holder_commitment_transaction_number: u64, msg_name: &str,
5583+ ) {
5584+ if self.commitment_secrets.get_min_seen_secret() != (1 << 48)
5585+ || self.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER
5586+ || holder_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER
5587+ {
5588+ debug_assert!(
5589+ false,
5590+ "Should not have advanced channel commitment tx numbers prior to {}",
5591+ msg_name
5592+ );
55985593 }
55995594 }
56005595
5601- #[rustfmt::skip]
56025596 fn get_initial_counterparty_commitment_signature<L: Deref>(
5603- &self, funding: &FundingScope, logger: &L
5604- ) -> Result <Signature, ChannelError >
5597+ &self, funding: &FundingScope, logger: &L,
5598+ ) -> Option <Signature>
56055599 where
56065600 SP::Target: SignerProvider,
5607- L::Target: Logger
5601+ L::Target: Logger,
56085602 {
5609- let commitment_data = self.build_commitment_transaction(funding,
5603+ let commitment_data = self.build_commitment_transaction(
5604+ funding,
56105605 self.cur_counterparty_commitment_transaction_number,
5611- &self.counterparty_cur_commitment_point.unwrap(), false, false, logger);
5606+ &self.counterparty_cur_commitment_point.unwrap(),
5607+ false,
5608+ false,
5609+ logger,
5610+ );
56125611 let counterparty_initial_commitment_tx = commitment_data.tx;
56135612 match self.holder_signer {
56145613 // TODO (taproot|arik): move match into calling method for Taproot
56155614 ChannelSignerType::Ecdsa(ref ecdsa) => {
56165615 let channel_parameters = &funding.channel_transaction_parameters;
5617- ecdsa.sign_counterparty_commitment(channel_parameters, &counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx)
5616+ ecdsa
5617+ .sign_counterparty_commitment(
5618+ channel_parameters,
5619+ &counterparty_initial_commitment_tx,
5620+ Vec::new(),
5621+ Vec::new(),
5622+ &self.secp_ctx,
5623+ )
56185624 .map(|(signature, _)| signature)
5619- .map_err(|()| {
5620- let msg = "Failed to get signatures for new commitment_signed";
5621- let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
5622- ChannelError::Close((msg.to_owned(), reason))
5623- })
5625+ .ok()
56245626 },
56255627 // TODO (taproot|arik)
56265628 #[cfg(taproot)]
56275629 _ => todo!(),
56285630 }
56295631 }
56305632
5631- #[rustfmt::skip]
5632- fn get_initial_commitment_signed<L: Deref>(
5633- &mut self, funding: &FundingScope, logger: &L
5634- ) -> Result<msgs::CommitmentSigned, ChannelError>
5633+ fn get_initial_commitment_signed_v2<L: Deref>(
5634+ &mut self, funding: &FundingScope, logger: &L,
5635+ ) -> Option<msgs::CommitmentSigned>
56355636 where
56365637 SP::Target: SignerProvider,
5637- L::Target: Logger
5638+ L::Target: Logger,
56385639 {
5639- if !matches!(
5640- self.channel_state, ChannelState::NegotiatingFunding(flags)
5641- if flags == (NegotiatingFundingFlags::OUR_INIT_SENT | NegotiatingFundingFlags::THEIR_INIT_SENT)
5642- ) {
5643- debug_assert!(false);
5644- let msg = "Tried to get an initial commitment_signed messsage at a time other than \
5645- immediately after initial handshake completion (or tried to get funding_created twice)";
5646- let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
5647- return Err(ChannelError::Close((msg.to_owned(), reason)));
5648- }
5649-
5650- let signature = match self.get_initial_counterparty_commitment_signature(funding, logger) {
5651- Ok(res) => res,
5652- Err(e) => {
5653- log_error!(logger, "Got bad signatures: {:?}!", e);
5654- return Err(e);
5655- }
5656- };
5657-
5658- log_info!(logger, "Generated commitment_signed for peer for channel {}", &self.channel_id());
5640+ assert!(
5641+ matches!(self.channel_state, ChannelState::FundingNegotiated(flags) if flags.is_interactive_signing())
5642+ );
56595643
5660- Ok(msgs::CommitmentSigned {
5661- channel_id: self.channel_id,
5662- htlc_signatures: vec![],
5663- signature,
5664- funding_txid: funding.get_funding_txo().map(|funding_txo| funding_txo.txid),
5665- #[cfg(taproot)]
5666- partial_signature_with_nonce: None,
5667- })
5644+ let signature = self.get_initial_counterparty_commitment_signature(funding, logger);
5645+ if let Some(signature) = signature {
5646+ log_info!(
5647+ logger,
5648+ "Generated commitment_signed for peer for channel {}",
5649+ &self.channel_id()
5650+ );
5651+ Some(msgs::CommitmentSigned {
5652+ channel_id: self.channel_id,
5653+ htlc_signatures: vec![],
5654+ signature,
5655+ funding_txid: funding.get_funding_txo().map(|funding_txo| funding_txo.txid),
5656+ #[cfg(taproot)]
5657+ partial_signature_with_nonce: None,
5658+ })
5659+ } else {
5660+ // TODO(splicing): Support async signing
5661+ None
5662+ }
56685663 }
56695664
56705665 #[cfg(all(test))]
56715666 pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
56725667 &mut self, funding: &mut FundingScope, logger: &L,
56735668 counterparty_cur_commitment_point_override: PublicKey,
5674- ) -> Result <Signature, ChannelError >
5669+ ) -> Option <Signature>
56755670 where
56765671 SP::Target: SignerProvider,
56775672 L::Target: Logger,
@@ -6955,7 +6950,7 @@ where
69556950 }
69566951
69576952 #[rustfmt::skip]
6958- pub fn commitment_signed_initial_v2 <L: Deref>(
6953+ pub fn initial_commitment_signed_v2 <L: Deref>(
69596954 &mut self, msg: &msgs::CommitmentSigned, best_block: BestBlock, signer_provider: &SP, logger: &L
69606955 ) -> Result<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, ChannelError>
69616956 where L::Target: Logger
@@ -8824,7 +8819,16 @@ where
88248819 // if it has not received tx_signatures for that funding transaction AND
88258820 // if next_commitment_number is zero:
88268821 // MUST retransmit its commitment_signed for that funding transaction.
8827- let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)?;
8822+ let commitment_signed = self.context.get_initial_commitment_signed_v2(&self.funding, logger)
8823+ // TODO(splicing): Support async signing
8824+ .ok_or_else(|| {
8825+ let message = "Failed to get signatures for new commitment_signed".to_owned();
8826+ ChannelError::Close(
8827+ (
8828+ message.clone(),
8829+ ClosureReason::HolderForceClosed { message, broadcasted_latest_txn: Some(false) },
8830+ )
8831+ )})?;
88288832 Some(msgs::CommitmentUpdate {
88298833 commitment_signed: vec![commitment_signed],
88308834 update_add_htlcs: vec![],
@@ -12880,6 +12884,7 @@ where
1288012884 channel_state.clear_remote_stfu_sent();
1288112885 channel_state.clear_quiescent();
1288212886 },
12887+ ChannelState::FundingNegotiated(flags) if flags.is_interactive_signing() => {},
1288312888 _ => debug_assert!(false, "Pre-funded/shutdown channels should not be written"),
1288412889 }
1288512890 channel_state.set_peer_disconnected();
0 commit comments