Skip to content

Commit 7f9c8a1

Browse files
committed
Allow sending RAA upon unblocking the signer
1 parent c761a59 commit 7f9c8a1

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

lightning/src/ln/channel.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ pub(super) struct MonitorRestoreUpdates {
906906
#[allow(unused)]
907907
pub(super) struct SignerResumeUpdates {
908908
pub commitment_update: Option<msgs::CommitmentUpdate>,
909+
pub revoke_and_ack: Option<msgs::RevokeAndACK>,
909910
pub funding_signed: Option<msgs::FundingSigned>,
910911
pub channel_ready: Option<msgs::ChannelReady>,
911912
}
@@ -1215,6 +1216,14 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
12151216
monitor_pending_finalized_fulfills: Vec<HTLCSource>,
12161217
monitor_pending_update_adds: Vec<msgs::UpdateAddHTLC>,
12171218

1219+
/// If we went to send a revoke_and_ack but our signer was unable to give us a signature,
1220+
/// we should retry at some point in the future when the signer indicates it may have a
1221+
/// signature for us.
1222+
///
1223+
/// This may also be used to make sure we send a `revoke_and_ack` after a `commitment_signed`
1224+
/// if we need to maintain ordering of messages, but are pending the signer on a previous
1225+
/// message.
1226+
signer_pending_revoke_and_ack: bool,
12181227
/// If we went to send a commitment update (ie some messages then [`msgs::CommitmentSigned`])
12191228
/// but our signer (initially) refused to give us a signature, we should retry at some point in
12201229
/// the future when the signer indicates it may have a signature for us.
@@ -1683,6 +1692,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
16831692
monitor_pending_finalized_fulfills: Vec::new(),
16841693
monitor_pending_update_adds: Vec::new(),
16851694

1695+
signer_pending_revoke_and_ack: false,
16861696
signer_pending_commitment_update: false,
16871697
signer_pending_funding: false,
16881698

@@ -1908,6 +1918,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19081918
monitor_pending_finalized_fulfills: Vec::new(),
19091919
monitor_pending_update_adds: Vec::new(),
19101920

1921+
signer_pending_revoke_and_ack: false,
19111922
signer_pending_commitment_update: false,
19121923
signer_pending_funding: false,
19131924

@@ -5373,11 +5384,6 @@ impl<SP: Deref> Channel<SP> where
53735384
/// blocked.
53745385
#[cfg(async_signing)]
53755386
pub fn signer_maybe_unblocked<L: Deref>(&mut self, logger: &L) -> SignerResumeUpdates where L::Target: Logger {
5376-
let commitment_update = if self.context.signer_pending_commitment_update {
5377-
log_trace!(logger, "Attempting to generate pending commitment update...");
5378-
self.context.signer_pending_commitment_update = false;
5379-
self.get_last_commitment_update_for_send(logger).ok()
5380-
} else { None };
53815387
let funding_signed = if self.context.signer_pending_funding && !self.context.is_outbound() {
53825388
log_trace!(logger, "Attempting to generate pending funding signed...");
53835389
self.context.signer_pending_funding = false;
@@ -5387,13 +5393,39 @@ impl<SP: Deref> Channel<SP> where
53875393
self.check_get_channel_ready(0, logger)
53885394
} else { None };
53895395

5390-
log_trace!(logger, "Signer unblocked with {} commitment_update, {} funding_signed and {} channel_ready",
5396+
let mut commitment_update = if self.context.signer_pending_commitment_update {
5397+
log_trace!(logger, "Attempting to generate pending commitment update...");
5398+
self.context.signer_pending_commitment_update = false;
5399+
self.get_last_commitment_update_for_send(logger).ok()
5400+
} else { None };
5401+
let mut revoke_and_ack = if self.context.signer_pending_revoke_and_ack {
5402+
log_trace!(logger, "Attempting to generate pending revoke and ack...");
5403+
self.context.signer_pending_revoke_and_ack = false;
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",
53915421
if commitment_update.is_some() { "a" } else { "no" },
5422+
if revoke_and_ack.is_some() { "a" } else { "no" },
53925423
if funding_signed.is_some() { "a" } else { "no" },
53935424
if channel_ready.is_some() { "a" } else { "no" });
53945425

53955426
SignerResumeUpdates {
53965427
commitment_update,
5428+
revoke_and_ack,
53975429
funding_signed,
53985430
channel_ready,
53995431
}
@@ -9272,6 +9304,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
92729304
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
92739305
monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or(Vec::new()),
92749306

9307+
signer_pending_revoke_and_ack: false,
92759308
signer_pending_commitment_update: false,
92769309
signer_pending_funding: false,
92779310

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8202,6 +8202,12 @@ where
82028202
updates,
82038203
});
82048204
}
8205+
if let Some(msg) = msgs.revoke_and_ack {
8206+
pending_msg_events.push(events::MessageSendEvent::SendRevokeAndACK {
8207+
node_id,
8208+
msg,
8209+
});
8210+
}
82058211
if let Some(msg) = msgs.funding_signed {
82068212
pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
82078213
node_id,

0 commit comments

Comments
 (0)