@@ -756,6 +756,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
756
756
/// This flag is set in such a case. Note that we don't need to persist this as we'll end up
757
757
/// setting it again as a side-effect of [`Channel::channel_reestablish`].
758
758
signer_pending_commitment_update: bool,
759
+ /// Similar to [`Self::signer_pending_commitment_update`] but we're waiting to send either a
760
+ /// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is
761
+ /// outbound or inbound.
762
+ signer_pending_funding: bool,
759
763
760
764
// pending_update_fee is filled when sending and receiving update_fee.
761
765
//
@@ -5831,6 +5835,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5831
5835
monitor_pending_finalized_fulfills: Vec::new(),
5832
5836
5833
5837
signer_pending_commitment_update: false,
5838
+ signer_pending_funding: false,
5834
5839
5835
5840
#[cfg(debug_assertions)]
5836
5841
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
@@ -5912,15 +5917,14 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5912
5917
})
5913
5918
}
5914
5919
5915
- /// If an Err is returned, it is a ChannelError::Close (for get_funding_created)
5916
- fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ChannelError> where L::Target: Logger {
5920
+ fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ()> where L::Target: Logger {
5917
5921
let counterparty_keys = self.context.build_remote_transaction_keys();
5918
5922
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
5919
5923
match &self.context.holder_signer {
5920
5924
// TODO (taproot|arik): move match into calling method for Taproot
5921
5925
ChannelSignerType::Ecdsa(ecdsa) => {
5922
- Ok( ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5923
- .map_err(|_| ChannelError::Close("Failed to get signatures for new commitment_signed".to_owned()))?.0 )
5926
+ ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5927
+ .map(|(sig, _)| sig )
5924
5928
}
5925
5929
}
5926
5930
}
@@ -5933,7 +5937,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5933
5937
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
5934
5938
/// If an Err is returned, it is a ChannelError::Close.
5935
5939
pub fn get_funding_created<L: Deref>(mut self, funding_transaction: Transaction, funding_txo: OutPoint, is_batch_funding: bool, logger: &L)
5936
- -> Result<(Channel<SP>, msgs::FundingCreated), (Self, ChannelError)> where L::Target: Logger {
5940
+ -> Result<(Channel<SP>, Option< msgs::FundingCreated> ), (Self, ChannelError)> where L::Target: Logger {
5937
5941
if !self.context.is_outbound() {
5938
5942
panic!("Tried to create outbound funding_created message on an inbound channel!");
5939
5943
}
@@ -5949,15 +5953,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5949
5953
self.context.channel_transaction_parameters.funding_outpoint = Some(funding_txo);
5950
5954
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
5951
5955
5952
- let signature = match self.get_funding_created_signature(logger) {
5953
- Ok(res) => res,
5954
- Err(e) => {
5955
- log_error!(logger, "Got bad signatures: {:?}!", e);
5956
- self.context.channel_transaction_parameters.funding_outpoint = None;
5957
- return Err((self, e));
5958
- }
5959
- };
5960
-
5961
5956
let temporary_channel_id = self.context.channel_id;
5962
5957
5963
5958
// Now that we're past error-generating stuff, update our local state:
@@ -5976,20 +5971,27 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5976
5971
self.context.funding_transaction = Some(funding_transaction);
5977
5972
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
5978
5973
5974
+ let funding_created = if let Ok(signature) = self.get_funding_created_signature(logger) {
5975
+ Some(msgs::FundingCreated {
5976
+ temporary_channel_id,
5977
+ funding_txid: funding_txo.txid,
5978
+ funding_output_index: funding_txo.index,
5979
+ signature,
5980
+ #[cfg(taproot)]
5981
+ partial_signature_with_nonce: None,
5982
+ #[cfg(taproot)]
5983
+ next_local_nonce: None,
5984
+ })
5985
+ } else {
5986
+ self.context.signer_pending_funding = true;
5987
+ None
5988
+ };
5989
+
5979
5990
let channel = Channel {
5980
5991
context: self.context,
5981
5992
};
5982
5993
5983
- Ok((channel, msgs::FundingCreated {
5984
- temporary_channel_id,
5985
- funding_txid: funding_txo.txid,
5986
- funding_output_index: funding_txo.index,
5987
- signature,
5988
- #[cfg(taproot)]
5989
- partial_signature_with_nonce: None,
5990
- #[cfg(taproot)]
5991
- next_local_nonce: None,
5992
- }))
5994
+ Ok((channel, funding_created))
5993
5995
}
5994
5996
5995
5997
fn get_initial_channel_type(config: &UserConfig, their_features: &InitFeatures) -> ChannelTypeFeatures {
@@ -6482,6 +6484,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6482
6484
monitor_pending_finalized_fulfills: Vec::new(),
6483
6485
6484
6486
signer_pending_commitment_update: false,
6487
+ signer_pending_funding: false,
6485
6488
6486
6489
#[cfg(debug_assertions)]
6487
6490
holder_max_commitment_tx_output: Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
@@ -7575,6 +7578,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7575
7578
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
7576
7579
7577
7580
signer_pending_commitment_update: false,
7581
+ signer_pending_funding: false,
7578
7582
7579
7583
pending_update_fee,
7580
7584
holding_cell_update_fee,
@@ -7847,7 +7851,7 @@ mod tests {
7847
7851
}]};
7848
7852
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
7849
7853
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
7850
- let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7854
+ let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap() , best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7851
7855
7852
7856
// Node B --> Node A: funding signed
7853
7857
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -7974,7 +7978,7 @@ mod tests {
7974
7978
}]};
7975
7979
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
7976
7980
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
7977
- let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7981
+ 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();
7978
7982
7979
7983
// Node B --> Node A: funding signed
7980
7984
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -8162,7 +8166,7 @@ mod tests {
8162
8166
}]};
8163
8167
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
8164
8168
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
8165
- let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8169
+ let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap() , best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8166
8170
8167
8171
// Node B --> Node A: funding signed
8168
8172
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -9222,7 +9226,7 @@ mod tests {
9222
9226
&&logger,
9223
9227
).map_err(|_| ()).unwrap();
9224
9228
let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(
9225
- &funding_created_msg,
9229
+ &funding_created_msg.unwrap() ,
9226
9230
best_block,
9227
9231
&&keys_provider,
9228
9232
&&logger,
0 commit comments