@@ -736,6 +736,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
736
736
/// This flag is set in such a case. Note that we don't need to persist this as we'll end up
737
737
/// setting it again as a side-effect of [`Channel::channel_reestablish`].
738
738
signer_pending_commitment_update: bool,
739
+ /// Similar to [`Self::signer_pending_commitment_update`] but we're waiting to send either a
740
+ /// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is
741
+ /// outbound or inbound.
742
+ signer_pending_funding: bool,
739
743
740
744
// pending_update_fee is filled when sending and receiving update_fee.
741
745
//
@@ -5746,6 +5750,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5746
5750
monitor_pending_finalized_fulfills: Vec::new(),
5747
5751
5748
5752
signer_pending_commitment_update: false,
5753
+ signer_pending_funding: false,
5749
5754
5750
5755
#[cfg(debug_assertions)]
5751
5756
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
@@ -5826,15 +5831,14 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5826
5831
})
5827
5832
}
5828
5833
5829
- /// If an Err is returned, it is a ChannelError::Close (for get_funding_created)
5830
- fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ChannelError> where L::Target: Logger {
5834
+ fn get_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ()> where L::Target: Logger {
5831
5835
let counterparty_keys = self.context.build_remote_transaction_keys();
5832
5836
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
5833
5837
match &self.context.holder_signer {
5834
5838
// TODO (taproot|arik): move match into calling method for Taproot
5835
5839
ChannelSignerType::Ecdsa(ecdsa) => {
5836
- Ok( ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5837
- .map_err(|_| ChannelError::Close("Failed to get signatures for new commitment_signed".to_owned()))?.0 )
5840
+ ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
5841
+ .map(|(sig, _)| sig )
5838
5842
}
5839
5843
}
5840
5844
}
@@ -5847,7 +5851,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5847
5851
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
5848
5852
/// If an Err is returned, it is a ChannelError::Close.
5849
5853
pub fn get_funding_created<L: Deref>(mut self, funding_transaction: Transaction, funding_txo: OutPoint, logger: &L)
5850
- -> Result<(Channel<SP>, msgs::FundingCreated), (Self, ChannelError)> where L::Target: Logger {
5854
+ -> Result<(Channel<SP>, Option< msgs::FundingCreated> ), (Self, ChannelError)> where L::Target: Logger {
5851
5855
if !self.context.is_outbound() {
5852
5856
panic!("Tried to create outbound funding_created message on an inbound channel!");
5853
5857
}
@@ -5863,15 +5867,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5863
5867
self.context.channel_transaction_parameters.funding_outpoint = Some(funding_txo);
5864
5868
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
5865
5869
5866
- let signature = match self.get_funding_created_signature(logger) {
5867
- Ok(res) => res,
5868
- Err(e) => {
5869
- log_error!(logger, "Got bad signatures: {:?}!", e);
5870
- self.context.channel_transaction_parameters.funding_outpoint = None;
5871
- return Err((self, e));
5872
- }
5873
- };
5874
-
5875
5870
let temporary_channel_id = self.context.channel_id;
5876
5871
5877
5872
// Now that we're past error-generating stuff, update our local state:
@@ -5889,20 +5884,27 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5889
5884
5890
5885
self.context.funding_transaction = Some(funding_transaction);
5891
5886
5887
+ let funding_created = if let Ok(signature) = self.get_funding_created_signature(logger) {
5888
+ Some(msgs::FundingCreated {
5889
+ temporary_channel_id,
5890
+ funding_txid: funding_txo.txid,
5891
+ funding_output_index: funding_txo.index,
5892
+ signature,
5893
+ #[cfg(taproot)]
5894
+ partial_signature_with_nonce: None,
5895
+ #[cfg(taproot)]
5896
+ next_local_nonce: None,
5897
+ })
5898
+ } else {
5899
+ self.context.signer_pending_funding = true;
5900
+ None
5901
+ };
5902
+
5892
5903
let channel = Channel {
5893
5904
context: self.context,
5894
5905
};
5895
5906
5896
- Ok((channel, msgs::FundingCreated {
5897
- temporary_channel_id,
5898
- funding_txid: funding_txo.txid,
5899
- funding_output_index: funding_txo.index,
5900
- signature,
5901
- #[cfg(taproot)]
5902
- partial_signature_with_nonce: None,
5903
- #[cfg(taproot)]
5904
- next_local_nonce: None,
5905
- }))
5907
+ Ok((channel, funding_created))
5906
5908
}
5907
5909
5908
5910
fn get_initial_channel_type(config: &UserConfig, their_features: &InitFeatures) -> ChannelTypeFeatures {
@@ -6395,6 +6397,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6395
6397
monitor_pending_finalized_fulfills: Vec::new(),
6396
6398
6397
6399
signer_pending_commitment_update: false,
6400
+ signer_pending_funding: false,
6398
6401
6399
6402
#[cfg(debug_assertions)]
6400
6403
holder_max_commitment_tx_output: Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
@@ -7483,6 +7486,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7483
7486
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
7484
7487
7485
7488
signer_pending_commitment_update: false,
7489
+ signer_pending_funding: false,
7486
7490
7487
7491
pending_update_fee,
7488
7492
holding_cell_update_fee,
@@ -7754,7 +7758,7 @@ mod tests {
7754
7758
}]};
7755
7759
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
7756
7760
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, &&logger).map_err(|_| ()).unwrap();
7757
- let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7761
+ let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap() , best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7758
7762
7759
7763
// Node B --> Node A: funding signed
7760
7764
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -7881,7 +7885,7 @@ mod tests {
7881
7885
}]};
7882
7886
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
7883
7887
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, &&logger).map_err(|_| ()).unwrap();
7884
- let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7888
+ 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();
7885
7889
7886
7890
// Node B --> Node A: funding signed
7887
7891
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
@@ -8069,7 +8073,7 @@ mod tests {
8069
8073
}]};
8070
8074
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
8071
8075
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, &&logger).map_err(|_| ()).unwrap();
8072
- let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8076
+ let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap() , best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8073
8077
8074
8078
// Node B --> Node A: funding signed
8075
8079
let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
0 commit comments