@@ -750,6 +750,14 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
750
750
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
751
751
monitor_pending_finalized_fulfills: Vec<HTLCSource>,
752
752
753
+ /// If we went to send a commitment update (ie some messages then [`msgs::CommitmentSigned`])
754
+ /// but our signer (initially) refused to give us a signature, we should retry at some point in
755
+ /// the future when the signer indicates it may have a signature for us.
756
+ ///
757
+ /// This flag is set in such a case. Note that we don't need to persist this as we'll end up
758
+ /// setting it again as a side-effect of [`Channel::channel_reestablish`].
759
+ signer_pending_commitment_update: bool,
760
+
753
761
// pending_update_fee is filled when sending and receiving update_fee.
754
762
//
755
763
// Because it follows the same commitment flow as HTLCs, `FeeUpdateState` is either `Outbound`
@@ -3163,8 +3171,8 @@ impl<SP: Deref> Channel<SP> where
3163
3171
self.context.monitor_pending_revoke_and_ack = true;
3164
3172
if need_commitment && (self.context.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == 0 {
3165
3173
// If we were going to send a commitment_signed after the RAA, go ahead and do all
3166
- // the corresponding HTLC status updates so that get_last_commitment_update
3167
- // includes the right HTLCs.
3174
+ // the corresponding HTLC status updates so that
3175
+ // get_last_commitment_update_for_send includes the right HTLCs.
3168
3176
self.context.monitor_pending_commitment_signed = true;
3169
3177
let mut additional_update = self.build_commitment_no_status_check(logger);
3170
3178
// build_commitment_no_status_check may bump latest_monitor_id but we want them to be
@@ -3538,9 +3546,10 @@ impl<SP: Deref> Channel<SP> where
3538
3546
// cells) while we can't update the monitor, so we just return what we have.
3539
3547
if require_commitment {
3540
3548
self.context.monitor_pending_commitment_signed = true;
3541
- // When the monitor updating is restored we'll call get_last_commitment_update(),
3542
- // which does not update state, but we're definitely now awaiting a remote revoke
3543
- // before we can step forward any more, so set it here.
3549
+ // When the monitor updating is restored we'll call
3550
+ // get_last_commitment_update_for_send(), which does not update state, but we're
3551
+ // definitely now awaiting a remote revoke before we can step forward any more, so
3552
+ // set it here.
3544
3553
let mut additional_update = self.build_commitment_no_status_check(logger);
3545
3554
// build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3546
3555
// strictly increasing by one, so decrement it here.
@@ -3843,9 +3852,11 @@ impl<SP: Deref> Channel<SP> where
3843
3852
Some(self.get_last_revoke_and_ack())
3844
3853
} else { None };
3845
3854
let commitment_update = if self.context.monitor_pending_commitment_signed {
3846
- self.mark_awaiting_response();
3847
- Some(self.get_last_commitment_update(logger))
3855
+ self.get_last_commitment_update_for_send(logger).ok()
3848
3856
} else { None };
3857
+ if commitment_update.is_some() {
3858
+ self.mark_awaiting_response();
3859
+ }
3849
3860
3850
3861
self.context.monitor_pending_revoke_and_ack = false;
3851
3862
self.context.monitor_pending_commitment_signed = false;
@@ -3906,7 +3917,8 @@ impl<SP: Deref> Channel<SP> where
3906
3917
}
3907
3918
}
3908
3919
3909
- fn get_last_commitment_update<L: Deref>(&self, logger: &L) -> msgs::CommitmentUpdate where L::Target: Logger {
3920
+ /// Gets the last commitment update for immediate sending to our peer.
3921
+ fn get_last_commitment_update_for_send<L: Deref>(&mut self, logger: &L) -> Result<msgs::CommitmentUpdate, ()> where L::Target: Logger {
3910
3922
let mut update_add_htlcs = Vec::new();
3911
3923
let mut update_fulfill_htlcs = Vec::new();
3912
3924
let mut update_fail_htlcs = Vec::new();
@@ -3965,10 +3977,17 @@ impl<SP: Deref> Channel<SP> where
3965
3977
log_trace!(logger, "Regenerated latest commitment update in channel {} with{} {} update_adds, {} update_fulfills, {} update_fails, and {} update_fail_malformeds",
3966
3978
&self.context.channel_id(), if update_fee.is_some() { " update_fee," } else { "" },
3967
3979
update_add_htlcs.len(), update_fulfill_htlcs.len(), update_fail_htlcs.len(), update_fail_malformed_htlcs.len());
3968
- msgs::CommitmentUpdate {
3980
+ let commitment_signed = if let Ok(update) = self.send_commitment_no_state_update(logger).map(|(cu, _)| cu) {
3981
+ self.context.signer_pending_commitment_update = false;
3982
+ update
3983
+ } else {
3984
+ self.context.signer_pending_commitment_update = true;
3985
+ return Err(());
3986
+ };
3987
+ Ok(msgs::CommitmentUpdate {
3969
3988
update_add_htlcs, update_fulfill_htlcs, update_fail_htlcs, update_fail_malformed_htlcs, update_fee,
3970
- commitment_signed: self.send_commitment_no_state_update(logger).expect("It looks like we failed to re-generate a commitment_signed we had previously sent?").0 ,
3971
- }
3989
+ commitment_signed,
3990
+ })
3972
3991
}
3973
3992
3974
3993
/// Gets the `Shutdown` message we should send our peer on reconnect, if any.
@@ -4148,7 +4167,7 @@ impl<SP: Deref> Channel<SP> where
4148
4167
Ok(ReestablishResponses {
4149
4168
channel_ready, shutdown_msg, announcement_sigs,
4150
4169
raa: required_revoke,
4151
- commitment_update: Some( self.get_last_commitment_update (logger)),
4170
+ commitment_update: self.get_last_commitment_update_for_send (logger).ok( ),
4152
4171
order: self.context.resend_order.clone(),
4153
4172
})
4154
4173
}
@@ -5511,7 +5530,7 @@ impl<SP: Deref> Channel<SP> where
5511
5530
}
5512
5531
5513
5532
let res = ecdsa.sign_counterparty_commitment(&commitment_stats.tx, commitment_stats.preimages, &self.context.secp_ctx)
5514
- .map_err(|_| ChannelError::Close ("Failed to get signatures for new commitment_signed".to_owned()))?;
5533
+ .map_err(|_| ChannelError::Ignore ("Failed to get signatures for new commitment_signed".to_owned()))?;
5515
5534
signature = res.0;
5516
5535
htlc_signatures = res.1;
5517
5536
@@ -5827,6 +5846,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5827
5846
monitor_pending_failures: Vec::new(),
5828
5847
monitor_pending_finalized_fulfills: Vec::new(),
5829
5848
5849
+ signer_pending_commitment_update: false,
5850
+
5830
5851
#[cfg(debug_assertions)]
5831
5852
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
5832
5853
#[cfg(debug_assertions)]
@@ -6481,6 +6502,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6481
6502
monitor_pending_failures: Vec::new(),
6482
6503
monitor_pending_finalized_fulfills: Vec::new(),
6483
6504
6505
+ signer_pending_commitment_update: false,
6506
+
6484
6507
#[cfg(debug_assertions)]
6485
6508
holder_max_commitment_tx_output: Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
6486
6509
#[cfg(debug_assertions)]
@@ -7572,6 +7595,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7572
7595
monitor_pending_failures,
7573
7596
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
7574
7597
7598
+ signer_pending_commitment_update: false,
7599
+
7575
7600
pending_update_fee,
7576
7601
holding_cell_update_fee,
7577
7602
next_holder_htlc_id,
0 commit comments