@@ -906,8 +906,10 @@ pub(super) struct MonitorRestoreUpdates {
906
906
#[allow(unused)]
907
907
pub(super) struct SignerResumeUpdates {
908
908
pub commitment_update: Option<msgs::CommitmentUpdate>,
909
+ pub revoke_and_ack: Option<msgs::RevokeAndACK>,
909
910
pub funding_signed: Option<msgs::FundingSigned>,
910
911
pub channel_ready: Option<msgs::ChannelReady>,
912
+ pub order: RAACommitmentOrder,
911
913
}
912
914
913
915
/// The return value of `channel_reestablish`
@@ -1215,6 +1217,14 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1215
1217
monitor_pending_finalized_fulfills: Vec<HTLCSource>,
1216
1218
monitor_pending_update_adds: Vec<msgs::UpdateAddHTLC>,
1217
1219
1220
+ /// If we went to send a revoke_and_ack but our signer was unable to give us a signature,
1221
+ /// we should retry at some point in the future when the signer indicates it may have a
1222
+ /// signature for us.
1223
+ ///
1224
+ /// This may also be used to make sure we send a `revoke_and_ack` after a `commitment_signed`
1225
+ /// if we need to maintain ordering of messages, but are pending the signer on a previous
1226
+ /// message.
1227
+ signer_pending_revoke_and_ack: bool,
1218
1228
/// If we went to send a commitment update (ie some messages then [`msgs::CommitmentSigned`])
1219
1229
/// but our signer (initially) refused to give us a signature, we should retry at some point in
1220
1230
/// the future when the signer indicates it may have a signature for us.
@@ -1683,6 +1693,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1683
1693
monitor_pending_finalized_fulfills: Vec::new(),
1684
1694
monitor_pending_update_adds: Vec::new(),
1685
1695
1696
+ signer_pending_revoke_and_ack: false,
1686
1697
signer_pending_commitment_update: false,
1687
1698
signer_pending_funding: false,
1688
1699
@@ -1908,6 +1919,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1908
1919
monitor_pending_finalized_fulfills: Vec::new(),
1909
1920
monitor_pending_update_adds: Vec::new(),
1910
1921
1922
+ signer_pending_revoke_and_ack: false,
1911
1923
signer_pending_commitment_update: false,
1912
1924
signer_pending_funding: false,
1913
1925
@@ -5376,34 +5388,57 @@ impl<SP: Deref> Channel<SP> where
5376
5388
/// blocked.
5377
5389
#[cfg(async_signing)]
5378
5390
pub fn signer_maybe_unblocked<L: Deref>(&mut self, logger: &L) -> SignerResumeUpdates where L::Target: Logger {
5379
- let commitment_update = if self.context.signer_pending_commitment_update {
5380
- self.get_last_commitment_update_for_send(logger).ok()
5381
- } else { None };
5382
5391
let funding_signed = if self.context.signer_pending_funding && !self.context.is_outbound() {
5383
5392
self.context.get_funding_signed_msg(logger).1
5384
5393
} else { None };
5385
5394
let channel_ready = if funding_signed.is_some() {
5386
5395
self.check_get_channel_ready(0, logger)
5387
5396
} else { None };
5388
5397
5389
- log_trace!(logger, "Signer unblocked with {} commitment_update, {} funding_signed and {} channel_ready",
5398
+ let mut commitment_update = if self.context.signer_pending_commitment_update {
5399
+ log_trace!(logger, "Attempting to generate pending commitment update...");
5400
+ self.get_last_commitment_update_for_send(logger).ok()
5401
+ } else { None };
5402
+ let mut revoke_and_ack = if self.context.signer_pending_revoke_and_ack {
5403
+ log_trace!(logger, "Attempting to generate pending revoke and ack...");
5404
+ Some(self.get_last_revoke_and_ack())
5405
+ } else { None };
5406
+
5407
+ if self.context.resend_order == RAACommitmentOrder::CommitmentFirst
5408
+ && self.context.signer_pending_commitment_update && revoke_and_ack.is_some() {
5409
+ log_trace!(logger, "Signer unblocked for revoke and ack, but unable to send due to resend order, waiting on signer for commitment update");
5410
+ self.context.signer_pending_revoke_and_ack = true;
5411
+ revoke_and_ack = None;
5412
+ }
5413
+ if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
5414
+ && self.context.signer_pending_revoke_and_ack && commitment_update.is_some() {
5415
+ log_trace!(logger, "Signer unblocked for commitment update, but unable to send due to resend order, waiting on signer for revoke and ack");
5416
+ self.context.signer_pending_commitment_update = true;
5417
+ commitment_update = None;
5418
+ }
5419
+
5420
+ log_trace!(logger, "Signer unblocked with {} commitment_update, {} revoke_and_ack, {} funding_signed and {} channel_ready",
5390
5421
if commitment_update.is_some() { "a" } else { "no" },
5422
+ if revoke_and_ack.is_some() { "a" } else { "no" },
5391
5423
if funding_signed.is_some() { "a" } else { "no" },
5392
5424
if channel_ready.is_some() { "a" } else { "no" });
5393
5425
5394
5426
SignerResumeUpdates {
5395
5427
commitment_update,
5428
+ revoke_and_ack,
5396
5429
funding_signed,
5397
5430
channel_ready,
5431
+ order: self.context.resend_order.clone(),
5398
5432
}
5399
5433
}
5400
5434
5401
- fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
5435
+ fn get_last_revoke_and_ack(&mut self) -> msgs::RevokeAndACK {
5402
5436
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
5403
5437
// TODO: handle non-available case when get_per_commitment_point becomes async
5404
5438
debug_assert!(self.context.holder_commitment_point.is_available());
5405
5439
let next_per_commitment_point = self.context.holder_commitment_point.current_point();
5406
5440
let per_commitment_secret = self.context.holder_signer.as_ref().release_commitment_secret(self.context.holder_commitment_point.transaction_number() + 2);
5441
+ self.context.signer_pending_revoke_and_ack = false;
5407
5442
msgs::RevokeAndACK {
5408
5443
channel_id: self.context.channel_id,
5409
5444
per_commitment_secret,
@@ -9279,6 +9314,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9279
9314
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
9280
9315
monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or(Vec::new()),
9281
9316
9317
+ signer_pending_revoke_and_ack: false,
9282
9318
signer_pending_commitment_update: false,
9283
9319
signer_pending_funding: false,
9284
9320
0 commit comments