@@ -902,6 +902,7 @@ pub(super) struct MonitorRestoreUpdates {
902902 pub funding_broadcastable: Option<Transaction>,
903903 pub channel_ready: Option<msgs::ChannelReady>,
904904 pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
905+ pub tx_signatures: Option<msgs::TxSignatures>,
905906}
906907
907908/// The return value of `signer_maybe_unblocked`
@@ -1253,6 +1254,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
12531254 monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
12541255 monitor_pending_finalized_fulfills: Vec<HTLCSource>,
12551256 monitor_pending_update_adds: Vec<msgs::UpdateAddHTLC>,
1257+ monitor_pending_tx_signatures: Option<msgs::TxSignatures>,
12561258
12571259 /// If we went to send a revoke_and_ack but our signer was unable to give us a signature,
12581260 /// we should retry at some point in the future when the signer indicates it may have a
@@ -2092,6 +2094,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
20922094 monitor_pending_failures: Vec::new(),
20932095 monitor_pending_finalized_fulfills: Vec::new(),
20942096 monitor_pending_update_adds: Vec::new(),
2097+ monitor_pending_tx_signatures: None,
20952098
20962099 signer_pending_revoke_and_ack: false,
20972100 signer_pending_commitment_update: false,
@@ -2328,6 +2331,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23282331 monitor_pending_failures: Vec::new(),
23292332 monitor_pending_finalized_fulfills: Vec::new(),
23302333 monitor_pending_update_adds: Vec::new(),
2334+ monitor_pending_tx_signatures: None,
23312335
23322336 signer_pending_revoke_and_ack: false,
23332337 signer_pending_commitment_update: false,
@@ -5663,7 +5667,13 @@ impl<SP: Deref> Channel<SP> where
56635667 }
56645668 }
56655669
5666- pub fn tx_signatures(&mut self, msg: &msgs::TxSignatures) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), ChannelError> {
5670+ pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), ChannelError>
5671+ where L::Target: Logger
5672+ {
5673+ if !matches!(self.context.channel_state, ChannelState::FundingNegotiated) {
5674+ return Err(ChannelError::close("Received tx_signatures in strange state!".to_owned()));
5675+ }
5676+
56675677 if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
56685678 if msg.witnesses.len() != signing_session.remote_inputs_count() {
56695679 return Err(ChannelError::Close(
@@ -5707,13 +5717,18 @@ impl<SP: Deref> Channel<SP> where
57075717 // Clear out the signing session
57085718 self.interactive_tx_signing_session = None;
57095719
5720+ if tx_signatures_opt.is_some() && self.context.channel_state.is_monitor_update_in_progress() {
5721+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
5722+ self.context.monitor_pending_tx_signatures = tx_signatures_opt;
5723+ return Ok((None, None));
5724+ }
5725+
57105726 Ok((tx_signatures_opt, funding_tx_opt))
57115727 } else {
5712- return Err(ChannelError::Close(
5713- (
5728+ Err(ChannelError::Close((
57145729 "Unexpected tx_signatures. No funding transaction awaiting signatures".to_string(),
57155730 ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
5716- )));
5731+ )))
57175732 }
57185733 }
57195734
@@ -5950,14 +5965,18 @@ impl<SP: Deref> Channel<SP> where
59505965 mem::swap(&mut finalized_claimed_htlcs, &mut self.context.monitor_pending_finalized_fulfills);
59515966 let mut pending_update_adds = Vec::new();
59525967 mem::swap(&mut pending_update_adds, &mut self.context.monitor_pending_update_adds);
5968+ // For channels established with V2 establishment we won't send a `tx_signatures` when we're in
5969+ // MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
5970+ // transaction and waits for us to do it).
5971+ let tx_signatures = self.context.monitor_pending_tx_signatures.take();
59535972
59545973 if self.context.channel_state.is_peer_disconnected() {
59555974 self.context.monitor_pending_revoke_and_ack = false;
59565975 self.context.monitor_pending_commitment_signed = false;
59575976 return MonitorRestoreUpdates {
59585977 raa: None, commitment_update: None, order: RAACommitmentOrder::RevokeAndACKFirst,
59595978 accepted_htlcs, failed_htlcs, finalized_claimed_htlcs, pending_update_adds,
5960- funding_broadcastable, channel_ready, announcement_sigs
5979+ funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
59615980 };
59625981 }
59635982
@@ -5991,7 +6010,7 @@ impl<SP: Deref> Channel<SP> where
59916010 match order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
59926011 MonitorRestoreUpdates {
59936012 raa, commitment_update, order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
5994- pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs
6013+ pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
59956014 }
59966015 }
59976016
@@ -9989,6 +10008,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
998910008 monitor_pending_failures,
999010009 monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
999110010 monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or_default(),
10011+ monitor_pending_tx_signatures: None,
999210012
999310013 signer_pending_revoke_and_ack: false,
999410014 signer_pending_commitment_update: false,
0 commit comments