@@ -707,6 +707,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
707
707
/// This flag is set in such a case. Note that we don't need to persist this as we'll end up
708
708
/// setting it again as a side-effect of [`Channel::channel_reestablish`].
709
709
signer_pending_commitment_update: bool,
710
+ /// Similar to [`Self::signer_pending_commitment_update`] but we're waiting to send either a
711
+ /// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is
712
+ /// outbound or inbound.
713
+ signer_pending_funding: bool,
710
714
711
715
// pending_update_fee is filled when sending and receiving update_fee.
712
716
//
@@ -5722,6 +5726,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5722
5726
monitor_pending_finalized_fulfills: Vec::new(),
5723
5727
5724
5728
signer_pending_commitment_update: false,
5729
+ signer_pending_funding: false,
5725
5730
5726
5731
#[cfg(debug_assertions)]
5727
5732
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
@@ -5802,15 +5807,14 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5802
5807
})
5803
5808
}
5804
5809
5805
- /// If an Err is returned, it is a ChannelError::Close (for get_funding_created)
5806
- fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ChannelError> where L::Target: Logger {
5810
+ fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ()> where L::Target: Logger {
5807
5811
let counterparty_keys = self.context.build_remote_transaction_keys();
5808
5812
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
5809
5813
match &self.context.holder_signer {
5810
5814
// TODO (taproot|arik): move match into calling method for Taproot
5811
5815
ChannelSignerType::Ecdsa(ecdsa) => {
5812
- Ok( ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5813
- .map_err(|_| ChannelError::Close("Failed to get signatures for new commitment_signed".to_owned()))?.0 )
5816
+ ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5817
+ .map(|(sig, _)| sig )
5814
5818
}
5815
5819
}
5816
5820
}
@@ -5823,7 +5827,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5823
5827
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
5824
5828
/// If an Err is returned, it is a ChannelError::Close.
5825
5829
pub fn get_funding_created<L: Deref>(mut self, funding_transaction: Transaction, funding_txo: OutPoint, logger: &L)
5826
- -> Result<(Channel<SP>, msgs::FundingCreated), (Self, ChannelError)> where L::Target: Logger {
5830
+ -> Result<(Channel<SP>, Option< msgs::FundingCreated> ), (Self, ChannelError)> where L::Target: Logger {
5827
5831
if !self.context.is_outbound() {
5828
5832
panic!("Tried to create outbound funding_created message on an inbound channel!");
5829
5833
}
@@ -5839,15 +5843,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5839
5843
self.context.channel_transaction_parameters.funding_outpoint = Some(funding_txo);
5840
5844
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
5841
5845
5842
- let signature = match self.get_funding_created_signature(logger) {
5843
- Ok(res) => res,
5844
- Err(e) => {
5845
- log_error!(logger, "Got bad signatures: {:?}!", e);
5846
- self.context.channel_transaction_parameters.funding_outpoint = None;
5847
- return Err((self, e));
5848
- }
5849
- };
5850
-
5851
5846
let temporary_channel_id = self.context.channel_id;
5852
5847
5853
5848
// Now that we're past error-generating stuff, update our local state:
@@ -5865,20 +5860,27 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5865
5860
5866
5861
self.context.funding_transaction = Some(funding_transaction);
5867
5862
5863
+ let funding_created = if let Ok(signature) = self.get_funding_created_signature(logger) {
5864
+ Some(msgs::FundingCreated {
5865
+ temporary_channel_id,
5866
+ funding_txid: funding_txo.txid,
5867
+ funding_output_index: funding_txo.index,
5868
+ signature,
5869
+ #[cfg(taproot)]
5870
+ partial_signature_with_nonce: None,
5871
+ #[cfg(taproot)]
5872
+ next_local_nonce: None,
5873
+ })
5874
+ } else {
5875
+ self.context.signer_pending_funding = true;
5876
+ None
5877
+ };
5878
+
5868
5879
let channel = Channel {
5869
5880
context: self.context,
5870
5881
};
5871
5882
5872
- Ok((channel, msgs::FundingCreated {
5873
- temporary_channel_id,
5874
- funding_txid: funding_txo.txid,
5875
- funding_output_index: funding_txo.index,
5876
- signature,
5877
- #[cfg(taproot)]
5878
- partial_signature_with_nonce: None,
5879
- #[cfg(taproot)]
5880
- next_local_nonce: None,
5881
- }))
5883
+ Ok((channel, funding_created))
5882
5884
}
5883
5885
5884
5886
fn get_initial_channel_type(config: &UserConfig, their_features: &InitFeatures) -> ChannelTypeFeatures {
@@ -6371,6 +6373,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6371
6373
monitor_pending_finalized_fulfills: Vec::new(),
6372
6374
6373
6375
signer_pending_commitment_update: false,
6376
+ signer_pending_funding: false,
6374
6377
6375
6378
#[cfg(debug_assertions)]
6376
6379
holder_max_commitment_tx_output: Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
@@ -7459,6 +7462,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7459
7462
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
7460
7463
7461
7464
signer_pending_commitment_update: false,
7465
+ signer_pending_funding: false,
7462
7466
7463
7467
pending_update_fee,
7464
7468
holding_cell_update_fee,
@@ -7730,7 +7734,7 @@ mod tests {
7730
7734
}]};
7731
7735
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
7732
7736
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, &&logger).map_err(|_| ()).unwrap();
7733
- let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7737
+ let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap() , best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7734
7738
7735
7739
// Node B --> Node A: funding signed
7736
7740
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -7857,7 +7861,7 @@ mod tests {
7857
7861
}]};
7858
7862
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
7859
7863
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, &&logger).map_err(|_| ()).unwrap();
7860
- let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7864
+ let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap() , best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7861
7865
7862
7866
// Node B --> Node A: funding signed
7863
7867
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -8045,7 +8049,7 @@ mod tests {
8045
8049
}]};
8046
8050
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
8047
8051
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, &&logger).map_err(|_| ()).unwrap();
8048
- let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8052
+ let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap() , best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8049
8053
8050
8054
// Node B --> Node A: funding signed
8051
8055
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
0 commit comments