@@ -518,6 +518,8 @@ pub(super) struct MonitorRestoreUpdates {
518
518
/// The return value of `signer_maybe_unblocked`
519
519
pub(super) struct SignerResumeUpdates {
520
520
pub commitment_update: Option<msgs::CommitmentUpdate>,
521
+ pub raa: Option<msgs::RevokeAndACK>,
522
+ pub order: RAACommitmentOrder,
521
523
pub funding_signed: Option<msgs::FundingSigned>,
522
524
pub funding_created: Option<msgs::FundingCreated>,
523
525
pub channel_ready: Option<msgs::ChannelReady>,
@@ -744,6 +746,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
744
746
/// This flag is set in such a case. Note that we don't need to persist this as we'll end up
745
747
/// setting it again as a side-effect of [`Channel::channel_reestablish`].
746
748
signer_pending_commitment_update: bool,
749
+ signer_pending_revoke_and_ack: bool,
747
750
/// Similar to [`Self::signer_pending_commitment_update`] but we're waiting to send either a
748
751
/// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is
749
752
/// outbound or inbound.
@@ -3143,6 +3146,7 @@ impl<SP: Deref> Channel<SP> where
3143
3146
self.context.cur_holder_commitment_transaction_number -= 1;
3144
3147
// Note that if we need_commitment & !AwaitingRemoteRevoke we'll call
3145
3148
// build_commitment_no_status_check() next which will reset this to RAAFirst.
3149
+ log_debug!(logger, "setting resend_order to CommitmentFirst");
3146
3150
self.context.resend_order = RAACommitmentOrder::CommitmentFirst;
3147
3151
3148
3152
if (self.context.channel_state & ChannelState::MonitorUpdateInProgress as u32) != 0 {
@@ -3828,7 +3832,7 @@ impl<SP: Deref> Channel<SP> where
3828
3832
}
3829
3833
3830
3834
let raa = if self.context.monitor_pending_revoke_and_ack {
3831
- Some( self.get_last_revoke_and_ack() )
3835
+ self.get_last_revoke_and_ack(logger )
3832
3836
} else { None };
3833
3837
let commitment_update = if self.context.monitor_pending_commitment_signed {
3834
3838
self.get_last_commitment_update_for_send(logger).ok()
@@ -3837,13 +3841,25 @@ impl<SP: Deref> Channel<SP> where
3837
3841
self.mark_awaiting_response();
3838
3842
}
3839
3843
3844
+ if self.context.monitor_pending_commitment_signed && commitment_update.is_none() {
3845
+ log_debug!(logger, "Monitor was pending_commitment_signed with no commitment update available; setting signer_pending_commitment_update = true");
3846
+ self.context.signer_pending_commitment_update = true;
3847
+ }
3848
+ if self.context.monitor_pending_revoke_and_ack && raa.is_none() {
3849
+ log_debug!(logger, "Monitor was pending_revoke_and_ack with no RAA available; setting signer_pending_revoke_and_ack = true");
3850
+ self.context.signer_pending_revoke_and_ack = true;
3851
+ }
3852
+
3840
3853
self.context.monitor_pending_revoke_and_ack = false;
3841
3854
self.context.monitor_pending_commitment_signed = false;
3855
+
3842
3856
let order = self.context.resend_order.clone();
3843
- log_debug!(logger, "Restored monitor updating in channel {} resulting in {}{} commitment update and {} RAA, with {} first ",
3857
+ log_debug!(logger, "Restored monitor updating in channel {} resulting in {}{} commitment update and {} RAA{} ",
3844
3858
&self.context.channel_id(), if funding_broadcastable.is_some() { "a funding broadcastable, " } else { "" },
3845
3859
if commitment_update.is_some() { "a" } else { "no" }, if raa.is_some() { "an" } else { "no" },
3846
- match order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
3860
+ if commitment_update.is_some() && raa.is_some() {
3861
+ match order { RAACommitmentOrder::CommitmentFirst => ", with commitment first", RAACommitmentOrder::RevokeAndACKFirst => ", with RAA first"}
3862
+ } else { "" });
3847
3863
MonitorRestoreUpdates {
3848
3864
raa, commitment_update, order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs, funding_broadcastable, channel_ready, announcement_sigs
3849
3865
}
@@ -3890,6 +3906,9 @@ impl<SP: Deref> Channel<SP> where
3890
3906
let commitment_update = if self.context.signer_pending_commitment_update {
3891
3907
self.get_last_commitment_update_for_send(logger).ok()
3892
3908
} else { None };
3909
+ let raa = if self.context.signer_pending_revoke_and_ack {
3910
+ self.get_last_revoke_and_ack(logger)
3911
+ } else { None };
3893
3912
let funding_signed = if self.context.signer_pending_funding && !self.context.is_outbound() {
3894
3913
self.context.get_funding_signed_msg(logger).1
3895
3914
} else { None };
@@ -3899,24 +3918,48 @@ impl<SP: Deref> Channel<SP> where
3899
3918
let funding_created = if self.context.signer_pending_funding && self.context.is_outbound() {
3900
3919
self.context.get_funding_created_msg(logger)
3901
3920
} else { None };
3921
+ let order = self.context.resend_order.clone();
3922
+
3923
+ log_debug!(logger, "Signing unblocked in channel {} at sequence {} resulting in {} commitment update, {} RAA{}, {} funding signed, and {} funding created",
3924
+ &self.context.channel_id(), self.context.cur_holder_commitment_transaction_number,
3925
+ if commitment_update.is_some() { "a" } else { "no" },
3926
+ if raa.is_some() { "an" } else { "no" },
3927
+ if commitment_update.is_some() && raa.is_some() {
3928
+ if order == RAACommitmentOrder::CommitmentFirst { " (commitment first)" } else { " (RAA first)" }
3929
+ } else { "" },
3930
+ if funding_signed.is_some() { "a" } else { "no" },
3931
+ if funding_created.is_some() { "a" } else { "no" });
3932
+
3902
3933
SignerResumeUpdates {
3903
3934
commitment_update,
3935
+ raa,
3936
+ order,
3904
3937
funding_signed,
3905
3938
funding_created,
3906
3939
channel_ready,
3907
3940
}
3908
3941
}
3909
3942
3910
- fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
3943
+ fn get_last_revoke_and_ack<L: Deref>(&mut self, logger: &L) -> Option<msgs::RevokeAndACK> where L::Target: Logger {
3944
+ if self.context.signer_pending_commitment_update {
3945
+ log_debug!(logger, "Can't generate revoke-and-ack in channel {} while pending commitment update",
3946
+ self.context.channel_id());
3947
+ return None;
3948
+ }
3949
+
3950
+ log_debug!(logger, "Regenerated last revoke-and-ack in channel {} for next per-commitment point sequence number {}, releasing secret for {}",
3951
+ &self.context.channel_id(), self.context.cur_holder_commitment_transaction_number,
3952
+ self.context.cur_holder_commitment_transaction_number + 2);
3953
+ self.context.signer_pending_revoke_and_ack = false;
3911
3954
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.cur_holder_commitment_transaction_number, &self.context.secp_ctx);
3912
3955
let per_commitment_secret = self.context.holder_signer.as_ref().release_commitment_secret(self.context.cur_holder_commitment_transaction_number + 2);
3913
- msgs::RevokeAndACK {
3956
+ Some( msgs::RevokeAndACK {
3914
3957
channel_id: self.context.channel_id,
3915
3958
per_commitment_secret,
3916
3959
next_per_commitment_point,
3917
3960
#[cfg(taproot)]
3918
3961
next_local_nonce: None,
3919
- }
3962
+ })
3920
3963
}
3921
3964
3922
3965
/// Gets the last commitment update for immediate sending to our peer.
@@ -4112,7 +4155,7 @@ impl<SP: Deref> Channel<SP> where
4112
4155
self.context.monitor_pending_revoke_and_ack = true;
4113
4156
None
4114
4157
} else {
4115
- Some( self.get_last_revoke_and_ack() )
4158
+ self.get_last_revoke_and_ack(logger )
4116
4159
}
4117
4160
} else {
4118
4161
return Err(ChannelError::Close("Peer attempted to reestablish channel with a very old local commitment transaction".to_owned()));
@@ -5447,6 +5490,7 @@ impl<SP: Deref> Channel<SP> where
5447
5490
self.context.pending_update_fee = None;
5448
5491
}
5449
5492
}
5493
+ log_debug!(logger, "setting resend_order to RevokeAndACKFirst");
5450
5494
self.context.resend_order = RAACommitmentOrder::RevokeAndACKFirst;
5451
5495
5452
5496
let (mut htlcs_ref, counterparty_commitment_tx) =
@@ -5841,6 +5885,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5841
5885
monitor_pending_finalized_fulfills: Vec::new(),
5842
5886
5843
5887
signer_pending_commitment_update: false,
5888
+ signer_pending_revoke_and_ack: false,
5844
5889
signer_pending_funding: false,
5845
5890
5846
5891
#[cfg(debug_assertions)]
@@ -6463,6 +6508,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6463
6508
monitor_pending_finalized_fulfills: Vec::new(),
6464
6509
6465
6510
signer_pending_commitment_update: false,
6511
+ signer_pending_revoke_and_ack: false,
6466
6512
signer_pending_funding: false,
6467
6513
6468
6514
#[cfg(debug_assertions)]
@@ -7531,6 +7577,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7531
7577
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
7532
7578
7533
7579
signer_pending_commitment_update: false,
7580
+ signer_pending_revoke_and_ack: false,
7534
7581
signer_pending_funding: false,
7535
7582
7536
7583
pending_update_fee,
0 commit comments