@@ -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>,
@@ -8735,6 +8738,17 @@ where
87358738 }
87368739 }
87378740
8741+ // An active interactive signing session or an awaiting channel_ready state implies that a
8742+ // commitment_signed retransmission is an initial one for funding negotiation. Thus, the
8743+ // signatures should be sent before channel_ready.
8744+ let channel_ready_order = if self.interactive_tx_signing_session.is_some() {
8745+ ChannelReadyOrder::SignaturesFirst
8746+ } else if matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_)) {
8747+ ChannelReadyOrder::SignaturesFirst
8748+ } else {
8749+ ChannelReadyOrder::ChannelReadyFirst
8750+ };
8751+
87388752 // We will never broadcast the funding transaction when we're in MonitorUpdateInProgress
87398753 // (and we assume the user never directly broadcasts the funding transaction and waits for
87408754 // us to do it). Thus, we can only ever hit monitor_pending_channel_ready when we're
@@ -8763,9 +8777,10 @@ where
87638777 self.context.monitor_pending_revoke_and_ack = false;
87648778 self.context.monitor_pending_commitment_signed = false;
87658779 return MonitorRestoreUpdates {
8766- raa: None, commitment_update: None, order : RAACommitmentOrder::RevokeAndACKFirst,
8780+ raa: None, commitment_update: None, commitment_order : RAACommitmentOrder::RevokeAndACKFirst,
87678781 accepted_htlcs, failed_htlcs, finalized_claimed_htlcs, pending_update_adds,
8768- funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
8782+ funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None,
8783+ channel_ready_order,
87698784 };
87708785 }
87718786
@@ -8788,14 +8803,15 @@ where
87888803
87898804 self.context.monitor_pending_revoke_and_ack = false;
87908805 self.context.monitor_pending_commitment_signed = false;
8791- let order = self.context.resend_order.clone();
8806+ let commitment_order = self.context.resend_order.clone();
87928807 log_debug!(logger, "Restored monitor updating in channel {} resulting in {}{} commitment update and {} RAA, with {} first",
87938808 &self.context.channel_id(), if funding_broadcastable.is_some() { "a funding broadcastable, " } else { "" },
87948809 if commitment_update.is_some() { "a" } else { "no" }, if raa.is_some() { "an" } else { "no" },
8795- match order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
8810+ match commitment_order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
87968811 MonitorRestoreUpdates {
8797- raa, commitment_update, order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
8798- pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
8812+ raa, commitment_update, commitment_order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
8813+ pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None,
8814+ channel_ready_order,
87998815 }
88008816 }
88018817
@@ -9205,8 +9221,9 @@ where
92059221 // Short circuit the whole handler as there is nothing we can resend them
92069222 return Ok(ReestablishResponses {
92079223 channel_ready: None,
9224+ channel_ready_order: ChannelReadyOrder::ChannelReadyFirst,
92089225 raa: None, commitment_update: None,
9209- order : RAACommitmentOrder::CommitmentFirst,
9226+ commitment_order : RAACommitmentOrder::CommitmentFirst,
92109227 shutdown_msg, announcement_sigs,
92119228 tx_signatures: None,
92129229 tx_abort: None,
@@ -9216,8 +9233,9 @@ where
92169233 // We have OurChannelReady set!
92179234 return Ok(ReestablishResponses {
92189235 channel_ready: self.get_channel_ready(logger),
9236+ channel_ready_order: ChannelReadyOrder::ChannelReadyFirst,
92199237 raa: None, commitment_update: None,
9220- order : RAACommitmentOrder::CommitmentFirst,
9238+ commitment_order : RAACommitmentOrder::CommitmentFirst,
92219239 shutdown_msg, announcement_sigs,
92229240 tx_signatures: None,
92239241 tx_abort: None,
@@ -9343,10 +9361,13 @@ where
93439361 };
93449362
93459363 Ok(ReestablishResponses {
9346- channel_ready, shutdown_msg, announcement_sigs,
9364+ channel_ready,
9365+ channel_ready_order: ChannelReadyOrder::SignaturesFirst,
9366+ shutdown_msg,
9367+ announcement_sigs,
93479368 raa: required_revoke,
93489369 commitment_update,
9349- order : self.context.resend_order.clone(),
9370+ commitment_order : self.context.resend_order.clone(),
93509371 tx_signatures,
93519372 tx_abort,
93529373 })
@@ -9360,9 +9381,11 @@ where
93609381 if self.context.channel_state.is_monitor_update_in_progress() {
93619382 self.context.monitor_pending_commitment_signed = true;
93629383 Ok(ReestablishResponses {
9363- channel_ready, shutdown_msg, announcement_sigs,
9384+ channel_ready,
9385+ channel_ready_order: ChannelReadyOrder::ChannelReadyFirst,
9386+ shutdown_msg, announcement_sigs,
93649387 commitment_update: None, raa: None,
9365- order : self.context.resend_order.clone(),
9388+ commitment_order : self.context.resend_order.clone(),
93669389 tx_signatures: None,
93679390 tx_abort: None,
93689391 })
@@ -9384,9 +9407,11 @@ where
93849407 required_revoke
93859408 };
93869409 Ok(ReestablishResponses {
9387- channel_ready, shutdown_msg, announcement_sigs,
9410+ channel_ready,
9411+ channel_ready_order: ChannelReadyOrder::ChannelReadyFirst,
9412+ shutdown_msg, announcement_sigs,
93889413 raa, commitment_update,
9389- order : self.context.resend_order.clone(),
9414+ commitment_order : self.context.resend_order.clone(),
93909415 tx_signatures: None,
93919416 tx_abort: None,
93929417 })
0 commit comments