@@ -54,9 +54,10 @@ use crate::ln::channel_state::{
5454 OutboundHTLCDetails, OutboundHTLCStateDetails,
5555};
5656use crate::ln::channelmanager::{
57- self, FundingConfirmedMessage, HTLCFailureMsg, HTLCSource, OpenChannelMessage,
58- PaymentClaimDetails, PendingHTLCInfo, PendingHTLCStatus, RAACommitmentOrder, SentHTLCId,
59- BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA,
57+ self, ChannelReadyOrder, FundingConfirmedMessage, HTLCFailureMsg, HTLCSource,
58+ OpenChannelMessage, PaymentClaimDetails, PendingHTLCInfo, PendingHTLCStatus,
59+ RAACommitmentOrder, SentHTLCId, BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT,
60+ MIN_CLTV_EXPIRY_DELTA,
6061};
6162use crate::ln::funding::FundingTxInput;
6263#[cfg(splicing)]
@@ -1181,13 +1182,14 @@ pub enum UpdateFulfillCommitFetch {
11811182pub(super) struct MonitorRestoreUpdates {
11821183 pub raa: Option<msgs::RevokeAndACK>,
11831184 pub commitment_update: Option<msgs::CommitmentUpdate>,
1184- pub order : RAACommitmentOrder,
1185+ pub commitment_order : RAACommitmentOrder,
11851186 pub accepted_htlcs: Vec<(PendingHTLCInfo, u64)>,
11861187 pub failed_htlcs: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
11871188 pub finalized_claimed_htlcs: Vec<(HTLCSource, Option<AttributionData>)>,
11881189 pub pending_update_adds: Vec<msgs::UpdateAddHTLC>,
11891190 pub funding_broadcastable: Option<Transaction>,
11901191 pub channel_ready: Option<msgs::ChannelReady>,
1192+ pub channel_ready_order: ChannelReadyOrder,
11911193 pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
11921194 pub tx_signatures: Option<msgs::TxSignatures>,
11931195}
@@ -1210,9 +1212,10 @@ pub(super) struct SignerResumeUpdates {
12101212/// The return value of `channel_reestablish`
12111213pub(super) struct ReestablishResponses {
12121214 pub channel_ready: Option<msgs::ChannelReady>,
1215+ pub channel_ready_order: ChannelReadyOrder,
12131216 pub raa: Option<msgs::RevokeAndACK>,
12141217 pub commitment_update: Option<msgs::CommitmentUpdate>,
1215- pub order : RAACommitmentOrder,
1218+ pub commitment_order : RAACommitmentOrder,
12161219 pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
12171220 pub shutdown_msg: Option<msgs::Shutdown>,
12181221 pub tx_signatures: Option<msgs::TxSignatures>,
@@ -8705,6 +8708,17 @@ where
87058708 }
87068709 }
87078710
8711+ // An active interactive signing session or an awaiting channel_ready state implies that a
8712+ // commitment_signed retransmission is an initial one for funding negotiation. Thus, the
8713+ // signatures should be sent before channel_ready.
8714+ let channel_ready_order = if self.interactive_tx_signing_session.is_some() {
8715+ ChannelReadyOrder::SignaturesFirst
8716+ } else if matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_)) {
8717+ ChannelReadyOrder::SignaturesFirst
8718+ } else {
8719+ ChannelReadyOrder::ChannelReadyFirst
8720+ };
8721+
87088722 // We will never broadcast the funding transaction when we're in MonitorUpdateInProgress
87098723 // (and we assume the user never directly broadcasts the funding transaction and waits for
87108724 // us to do it). Thus, we can only ever hit monitor_pending_channel_ready when we're
@@ -8733,9 +8747,10 @@ where
87338747 self.context.monitor_pending_revoke_and_ack = false;
87348748 self.context.monitor_pending_commitment_signed = false;
87358749 return MonitorRestoreUpdates {
8736- raa: None, commitment_update: None, order : RAACommitmentOrder::RevokeAndACKFirst,
8750+ raa: None, commitment_update: None, commitment_order : RAACommitmentOrder::RevokeAndACKFirst,
87378751 accepted_htlcs, failed_htlcs, finalized_claimed_htlcs, pending_update_adds,
8738- funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
8752+ funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None,
8753+ channel_ready_order,
87398754 };
87408755 }
87418756
@@ -8758,14 +8773,15 @@ where
87588773
87598774 self.context.monitor_pending_revoke_and_ack = false;
87608775 self.context.monitor_pending_commitment_signed = false;
8761- let order = self.context.resend_order.clone();
8776+ let commitment_order = self.context.resend_order.clone();
87628777 log_debug!(logger, "Restored monitor updating in channel {} resulting in {}{} commitment update and {} RAA, with {} first",
87638778 &self.context.channel_id(), if funding_broadcastable.is_some() { "a funding broadcastable, " } else { "" },
87648779 if commitment_update.is_some() { "a" } else { "no" }, if raa.is_some() { "an" } else { "no" },
8765- match order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
8780+ match commitment_order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
87668781 MonitorRestoreUpdates {
8767- raa, commitment_update, order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
8768- pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
8782+ raa, commitment_update, commitment_order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
8783+ pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None,
8784+ channel_ready_order,
87698785 }
87708786 }
87718787
@@ -9168,8 +9184,9 @@ where
91689184 // Short circuit the whole handler as there is nothing we can resend them
91699185 return Ok(ReestablishResponses {
91709186 channel_ready: None,
9187+ channel_ready_order: ChannelReadyOrder::ChannelReadyFirst,
91719188 raa: None, commitment_update: None,
9172- order : RAACommitmentOrder::CommitmentFirst,
9189+ commitment_order : RAACommitmentOrder::CommitmentFirst,
91739190 shutdown_msg, announcement_sigs,
91749191 tx_signatures: None,
91759192 tx_abort: None,
@@ -9179,8 +9196,9 @@ where
91799196 // We have OurChannelReady set!
91809197 return Ok(ReestablishResponses {
91819198 channel_ready: self.get_channel_ready(logger),
9199+ channel_ready_order: ChannelReadyOrder::ChannelReadyFirst,
91829200 raa: None, commitment_update: None,
9183- order : RAACommitmentOrder::CommitmentFirst,
9201+ commitment_order : RAACommitmentOrder::CommitmentFirst,
91849202 shutdown_msg, announcement_sigs,
91859203 tx_signatures: None,
91869204 tx_abort: None,
@@ -9306,10 +9324,13 @@ where
93069324 };
93079325
93089326 Ok(ReestablishResponses {
9309- channel_ready, shutdown_msg, announcement_sigs,
9327+ channel_ready,
9328+ channel_ready_order: ChannelReadyOrder::SignaturesFirst,
9329+ shutdown_msg,
9330+ announcement_sigs,
93109331 raa: required_revoke,
93119332 commitment_update,
9312- order : self.context.resend_order.clone(),
9333+ commitment_order : self.context.resend_order.clone(),
93139334 tx_signatures,
93149335 tx_abort,
93159336 })
@@ -9323,9 +9344,11 @@ where
93239344 if self.context.channel_state.is_monitor_update_in_progress() {
93249345 self.context.monitor_pending_commitment_signed = true;
93259346 Ok(ReestablishResponses {
9326- channel_ready, shutdown_msg, announcement_sigs,
9347+ channel_ready,
9348+ channel_ready_order: ChannelReadyOrder::ChannelReadyFirst,
9349+ shutdown_msg, announcement_sigs,
93279350 commitment_update: None, raa: None,
9328- order : self.context.resend_order.clone(),
9351+ commitment_order : self.context.resend_order.clone(),
93299352 tx_signatures: None,
93309353 tx_abort: None,
93319354 })
@@ -9347,9 +9370,11 @@ where
93479370 required_revoke
93489371 };
93499372 Ok(ReestablishResponses {
9350- channel_ready, shutdown_msg, announcement_sigs,
9373+ channel_ready,
9374+ channel_ready_order: ChannelReadyOrder::ChannelReadyFirst,
9375+ shutdown_msg, announcement_sigs,
93519376 raa, commitment_update,
9352- order : self.context.resend_order.clone(),
9377+ commitment_order : self.context.resend_order.clone(),
93539378 tx_signatures: None,
93549379 tx_abort: None,
93559380 })
0 commit comments