@@ -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
//
@@ -4817,6 +4821,12 @@ impl<SP: Deref> Channel<SP> where
4817
4821
return None;
4818
4822
}
4819
4823
4824
+ // If we're still pending the signature on a funding transaction, then we're not ready to send a
4825
+ // channel_ready yet.
4826
+ if self.context.signer_pending_funding {
4827
+ return None;
4828
+ }
4829
+
4820
4830
// Note that we don't include ChannelState::WaitingForBatch as we don't want to send
4821
4831
// channel_ready until the entire batch is ready.
4822
4832
let non_shutdown_state = self.context.channel_state & (!MULTI_STATE_FLAGS);
@@ -5874,6 +5884,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5874
5884
monitor_pending_finalized_fulfills: Vec::new(),
5875
5885
5876
5886
signer_pending_commitment_update: false,
5887
+ signer_pending_funding: false,
5877
5888
5878
5889
#[cfg(debug_assertions)]
5879
5890
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
@@ -5955,15 +5966,14 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5955
5966
})
5956
5967
}
5957
5968
5958
- /// If an Err is returned, it is a ChannelError::Close (for get_funding_created)
5959
- fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ChannelError> where L::Target: Logger {
5969
+ fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ()> where L::Target: Logger {
5960
5970
let counterparty_keys = self.context.build_remote_transaction_keys();
5961
5971
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
5962
5972
match &self.context.holder_signer {
5963
5973
// TODO (taproot|arik): move match into calling method for Taproot
5964
5974
ChannelSignerType::Ecdsa(ecdsa) => {
5965
- Ok( ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5966
- .map_err(|_| ChannelError::Close("Failed to get signatures for new commitment_signed".to_owned()))?.0 )
5975
+ ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5976
+ .map(|(sig, _)| sig )
5967
5977
}
5968
5978
}
5969
5979
}
@@ -5976,7 +5986,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5976
5986
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
5977
5987
/// If an Err is returned, it is a ChannelError::Close.
5978
5988
pub fn get_funding_created<L: Deref>(mut self, funding_transaction: Transaction, funding_txo: OutPoint, is_batch_funding: bool, logger: &L)
5979
- -> Result<(Channel<SP>, msgs::FundingCreated), (Self, ChannelError)> where L::Target: Logger {
5989
+ -> Result<(Channel<SP>, Option< msgs::FundingCreated> ), (Self, ChannelError)> where L::Target: Logger {
5980
5990
if !self.context.is_outbound() {
5981
5991
panic!("Tried to create outbound funding_created message on an inbound channel!");
5982
5992
}
@@ -5992,15 +6002,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5992
6002
self.context.channel_transaction_parameters.funding_outpoint = Some(funding_txo);
5993
6003
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
5994
6004
5995
- let signature = match self.get_funding_created_signature(logger) {
5996
- Ok(res) => res,
5997
- Err(e) => {
5998
- log_error!(logger, "Got bad signatures: {:?}!", e);
5999
- self.context.channel_transaction_parameters.funding_outpoint = None;
6000
- return Err((self, e));
6001
- }
6002
- };
6003
-
6004
6005
let temporary_channel_id = self.context.channel_id;
6005
6006
6006
6007
// Now that we're past error-generating stuff, update our local state:
@@ -6019,20 +6020,27 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
6019
6020
self.context.funding_transaction = Some(funding_transaction);
6020
6021
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
6021
6022
6023
+ let funding_created = if let Ok(signature) = self.get_funding_created_signature(logger) {
6024
+ Some(msgs::FundingCreated {
6025
+ temporary_channel_id,
6026
+ funding_txid: funding_txo.txid,
6027
+ funding_output_index: funding_txo.index,
6028
+ signature,
6029
+ #[cfg(taproot)]
6030
+ partial_signature_with_nonce: None,
6031
+ #[cfg(taproot)]
6032
+ next_local_nonce: None,
6033
+ })
6034
+ } else {
6035
+ self.context.signer_pending_funding = true;
6036
+ None
6037
+ };
6038
+
6022
6039
let channel = Channel {
6023
6040
context: self.context,
6024
6041
};
6025
6042
6026
- Ok((channel, msgs::FundingCreated {
6027
- temporary_channel_id,
6028
- funding_txid: funding_txo.txid,
6029
- funding_output_index: funding_txo.index,
6030
- signature,
6031
- #[cfg(taproot)]
6032
- partial_signature_with_nonce: None,
6033
- #[cfg(taproot)]
6034
- next_local_nonce: None,
6035
- }))
6043
+ Ok((channel, funding_created))
6036
6044
}
6037
6045
6038
6046
fn get_initial_channel_type(config: &UserConfig, their_features: &InitFeatures) -> ChannelTypeFeatures {
@@ -6530,6 +6538,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6530
6538
monitor_pending_finalized_fulfills: Vec::new(),
6531
6539
6532
6540
signer_pending_commitment_update: false,
6541
+ signer_pending_funding: false,
6533
6542
6534
6543
#[cfg(debug_assertions)]
6535
6544
holder_max_commitment_tx_output: Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
@@ -7623,6 +7632,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7623
7632
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
7624
7633
7625
7634
signer_pending_commitment_update: false,
7635
+ signer_pending_funding: false,
7626
7636
7627
7637
pending_update_fee,
7628
7638
holding_cell_update_fee,
@@ -7895,7 +7905,7 @@ mod tests {
7895
7905
}]};
7896
7906
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
7897
7907
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
7898
- let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7908
+ let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap() , best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7899
7909
7900
7910
// Node B --> Node A: funding signed
7901
7911
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -8022,7 +8032,7 @@ mod tests {
8022
8032
}]};
8023
8033
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
8024
8034
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
8025
- let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8035
+ 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();
8026
8036
8027
8037
// Node B --> Node A: funding signed
8028
8038
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -8210,7 +8220,7 @@ mod tests {
8210
8220
}]};
8211
8221
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
8212
8222
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
8213
- let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8223
+ let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap() , best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8214
8224
8215
8225
// Node B --> Node A: funding signed
8216
8226
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -9282,7 +9292,7 @@ mod tests {
9282
9292
&&logger,
9283
9293
).map_err(|_| ()).unwrap();
9284
9294
let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(
9285
- &funding_created_msg,
9295
+ &funding_created_msg.unwrap() ,
9286
9296
best_block,
9287
9297
&&keys_provider,
9288
9298
&&logger,
0 commit comments