@@ -757,6 +757,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
757
757
/// This flag is set in such a case. Note that we don't need to persist this as we'll end up
758
758
/// setting it again as a side-effect of [`Channel::channel_reestablish`].
759
759
signer_pending_commitment_update: bool,
760
+ /// Similar to [`Self::signer_pending_commitment_update`] but we're waiting to send either a
761
+ /// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is
762
+ /// outbound or inbound.
763
+ signer_pending_funding: bool,
760
764
761
765
// pending_update_fee is filled when sending and receiving update_fee.
762
766
//
@@ -5847,6 +5851,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5847
5851
monitor_pending_finalized_fulfills: Vec::new(),
5848
5852
5849
5853
signer_pending_commitment_update: false,
5854
+ signer_pending_funding: false,
5850
5855
5851
5856
#[cfg(debug_assertions)]
5852
5857
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
@@ -5928,15 +5933,14 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5928
5933
})
5929
5934
}
5930
5935
5931
- /// If an Err is returned, it is a ChannelError::Close (for get_funding_created)
5932
- fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ChannelError> where L::Target: Logger {
5936
+ fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ()> where L::Target: Logger {
5933
5937
let counterparty_keys = self.context.build_remote_transaction_keys();
5934
5938
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
5935
5939
match &self.context.holder_signer {
5936
5940
// TODO (taproot|arik): move match into calling method for Taproot
5937
5941
ChannelSignerType::Ecdsa(ecdsa) => {
5938
- Ok( ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5939
- .map_err(|_| ChannelError::Close("Failed to get signatures for new commitment_signed".to_owned()))?.0 )
5942
+ ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5943
+ .map(|(sig, _)| sig )
5940
5944
}
5941
5945
}
5942
5946
}
@@ -5949,7 +5953,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5949
5953
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
5950
5954
/// If an Err is returned, it is a ChannelError::Close.
5951
5955
pub fn get_funding_created<L: Deref>(mut self, funding_transaction: Transaction, funding_txo: OutPoint, is_batch_funding: bool, logger: &L)
5952
- -> Result<(Channel<SP>, msgs::FundingCreated), (Self, ChannelError)> where L::Target: Logger {
5956
+ -> Result<(Channel<SP>, Option< msgs::FundingCreated> ), (Self, ChannelError)> where L::Target: Logger {
5953
5957
if !self.context.is_outbound() {
5954
5958
panic!("Tried to create outbound funding_created message on an inbound channel!");
5955
5959
}
@@ -5965,15 +5969,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5965
5969
self.context.channel_transaction_parameters.funding_outpoint = Some(funding_txo);
5966
5970
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
5967
5971
5968
- let signature = match self.get_funding_created_signature(logger) {
5969
- Ok(res) => res,
5970
- Err(e) => {
5971
- log_error!(logger, "Got bad signatures: {:?}!", e);
5972
- self.context.channel_transaction_parameters.funding_outpoint = None;
5973
- return Err((self, e));
5974
- }
5975
- };
5976
-
5977
5972
let temporary_channel_id = self.context.channel_id;
5978
5973
5979
5974
// Now that we're past error-generating stuff, update our local state:
@@ -5992,20 +5987,27 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5992
5987
self.context.funding_transaction = Some(funding_transaction);
5993
5988
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
5994
5989
5990
+ let funding_created = if let Ok(signature) = self.get_funding_created_signature(logger) {
5991
+ Some(msgs::FundingCreated {
5992
+ temporary_channel_id,
5993
+ funding_txid: funding_txo.txid,
5994
+ funding_output_index: funding_txo.index,
5995
+ signature,
5996
+ #[cfg(taproot)]
5997
+ partial_signature_with_nonce: None,
5998
+ #[cfg(taproot)]
5999
+ next_local_nonce: None,
6000
+ })
6001
+ } else {
6002
+ self.context.signer_pending_funding = true;
6003
+ None
6004
+ };
6005
+
5995
6006
let channel = Channel {
5996
6007
context: self.context,
5997
6008
};
5998
6009
5999
- Ok((channel, msgs::FundingCreated {
6000
- temporary_channel_id,
6001
- funding_txid: funding_txo.txid,
6002
- funding_output_index: funding_txo.index,
6003
- signature,
6004
- #[cfg(taproot)]
6005
- partial_signature_with_nonce: None,
6006
- #[cfg(taproot)]
6007
- next_local_nonce: None,
6008
- }))
6010
+ Ok((channel, funding_created))
6009
6011
}
6010
6012
6011
6013
fn get_initial_channel_type(config: &UserConfig, their_features: &InitFeatures) -> ChannelTypeFeatures {
@@ -6503,6 +6505,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6503
6505
monitor_pending_finalized_fulfills: Vec::new(),
6504
6506
6505
6507
signer_pending_commitment_update: false,
6508
+ signer_pending_funding: false,
6506
6509
6507
6510
#[cfg(debug_assertions)]
6508
6511
holder_max_commitment_tx_output: Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
@@ -7596,6 +7599,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7596
7599
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
7597
7600
7598
7601
signer_pending_commitment_update: false,
7602
+ signer_pending_funding: false,
7599
7603
7600
7604
pending_update_fee,
7601
7605
holding_cell_update_fee,
@@ -7868,7 +7872,7 @@ mod tests {
7868
7872
}]};
7869
7873
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
7870
7874
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
7871
- let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7875
+ let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap() , best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7872
7876
7873
7877
// Node B --> Node A: funding signed
7874
7878
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -7995,7 +7999,7 @@ mod tests {
7995
7999
}]};
7996
8000
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
7997
8001
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
7998
- let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8002
+ 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();
7999
8003
8000
8004
// Node B --> Node A: funding signed
8001
8005
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -8183,7 +8187,7 @@ mod tests {
8183
8187
}]};
8184
8188
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
8185
8189
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
8186
- let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8190
+ let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap() , best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8187
8191
8188
8192
// Node B --> Node A: funding signed
8189
8193
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -9255,7 +9259,7 @@ mod tests {
9255
9259
&&logger,
9256
9260
).map_err(|_| ()).unwrap();
9257
9261
let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(
9258
- &funding_created_msg,
9262
+ &funding_created_msg.unwrap() ,
9259
9263
best_block,
9260
9264
&&keys_provider,
9261
9265
&&logger,
0 commit comments