@@ -1009,16 +1009,6 @@ impl ChannelError {
1009
1009
pub(super) fn close(err: String) -> Self {
1010
1010
ChannelError::Close((err.clone(), ClosureReason::ProcessingError { err }))
1011
1011
}
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
- }
1022
1012
}
1023
1013
1024
1014
pub(super) struct WithChannelContext<'a, L: Deref>
@@ -1888,7 +1878,7 @@ where
1888
1878
#[cfg(splicing)]
1889
1879
pending_splice: None,
1890
1880
};
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)
1892
1882
.map(|monitor| (Some(monitor), None))
1893
1883
// TODO: Change to `inspect_err` when MSRV is high enough.
1894
1884
.map_err(|err| {
@@ -5517,6 +5507,9 @@ where
5517
5507
funding
5518
5508
.channel_transaction_parameters.funding_outpoint = Some(outpoint);
5519
5509
5510
+ self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
5511
+ self.channel_state.set_interactive_signing();
5512
+
5520
5513
if is_splice {
5521
5514
debug_assert_eq!(
5522
5515
holder_commitment_transaction_number,
@@ -5531,14 +5524,15 @@ where
5531
5524
self.assert_no_commitment_advancement(holder_commitment_transaction_number, "initial commitment_signed");
5532
5525
}
5533
5526
5534
- let commitment_signed = self.get_initial_commitment_signed (&funding, logger);
5527
+ let commitment_signed = self.get_initial_commitment_signed_v2 (&funding, logger);
5535
5528
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 => {
5538
5532
funding.channel_transaction_parameters.funding_outpoint = None;
5539
5533
return Err(msgs::TxAbort {
5540
5534
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(),
5542
5536
});
5543
5537
},
5544
5538
};
@@ -5580,98 +5574,99 @@ where
5580
5574
});
5581
5575
};
5582
5576
5583
- let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
5584
- channel_state.set_interactive_signing();
5585
- self.channel_state = channel_state;
5586
-
5587
5577
Ok((commitment_signed, funding_ready_for_sig_event))
5588
5578
}
5589
5579
5590
5580
/// 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
+ );
5598
5593
}
5599
5594
}
5600
5595
5601
- #[rustfmt::skip]
5602
5596
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>
5605
5599
where
5606
5600
SP::Target: SignerProvider,
5607
- L::Target: Logger
5601
+ L::Target: Logger,
5608
5602
{
5609
- let commitment_data = self.build_commitment_transaction(funding,
5603
+ let commitment_data = self.build_commitment_transaction(
5604
+ funding,
5610
5605
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
+ );
5612
5611
let counterparty_initial_commitment_tx = commitment_data.tx;
5613
5612
match self.holder_signer {
5614
5613
// TODO (taproot|arik): move match into calling method for Taproot
5615
5614
ChannelSignerType::Ecdsa(ref ecdsa) => {
5616
5615
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
+ )
5618
5624
.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()
5624
5626
},
5625
5627
// TODO (taproot|arik)
5626
5628
#[cfg(taproot)]
5627
5629
_ => todo!(),
5628
5630
}
5629
5631
}
5630
5632
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>
5635
5636
where
5636
5637
SP::Target: SignerProvider,
5637
- L::Target: Logger
5638
+ L::Target: Logger,
5638
5639
{
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
+ );
5659
5643
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
+ }
5668
5663
}
5669
5664
5670
5665
#[cfg(all(test))]
5671
5666
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
5672
5667
&mut self, funding: &mut FundingScope, logger: &L,
5673
5668
counterparty_cur_commitment_point_override: PublicKey,
5674
- ) -> Result <Signature, ChannelError >
5669
+ ) -> Option <Signature>
5675
5670
where
5676
5671
SP::Target: SignerProvider,
5677
5672
L::Target: Logger,
@@ -6955,7 +6950,7 @@ where
6955
6950
}
6956
6951
6957
6952
#[rustfmt::skip]
6958
- pub fn commitment_signed_initial_v2 <L: Deref>(
6953
+ pub fn initial_commitment_signed_v2 <L: Deref>(
6959
6954
&mut self, msg: &msgs::CommitmentSigned, best_block: BestBlock, signer_provider: &SP, logger: &L
6960
6955
) -> Result<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, ChannelError>
6961
6956
where L::Target: Logger
@@ -8824,7 +8819,16 @@ where
8824
8819
// if it has not received tx_signatures for that funding transaction AND
8825
8820
// if next_commitment_number is zero:
8826
8821
// 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
+ )})?;
8828
8832
Some(msgs::CommitmentUpdate {
8829
8833
commitment_signed: vec![commitment_signed],
8830
8834
update_add_htlcs: vec![],
@@ -12880,6 +12884,7 @@ where
12880
12884
channel_state.clear_remote_stfu_sent();
12881
12885
channel_state.clear_quiescent();
12882
12886
},
12887
+ ChannelState::FundingNegotiated(flags) if flags.is_interactive_signing() => {},
12883
12888
_ => debug_assert!(false, "Pre-funded/shutdown channels should not be written"),
12884
12889
}
12885
12890
channel_state.set_peer_disconnected();
0 commit comments