@@ -749,6 +749,14 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
749
749
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
750
750
monitor_pending_finalized_fulfills: Vec<HTLCSource>,
751
751
752
+ /// If we went to send a commitment update (ie some messages then [`msgs::CommitmentSigned`])
753
+ /// but our signer (initially) refused to give us a signature, we should retry at some point in
754
+ /// the future when the signer indicates it may have a signature for us.
755
+ ///
756
+ /// This flag is set in such a case. Note that we don't need to persist this as we'll end up
757
+ /// setting it again as a side-effect of [`Channel::channel_reestablish`].
758
+ signer_pending_commitment_update: bool,
759
+
752
760
// pending_update_fee is filled when sending and receiving update_fee.
753
761
//
754
762
// Because it follows the same commitment flow as HTLCs, `FeeUpdateState` is either `Outbound`
@@ -3149,8 +3157,8 @@ impl<SP: Deref> Channel<SP> where
3149
3157
self.context.monitor_pending_revoke_and_ack = true;
3150
3158
if need_commitment && (self.context.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == 0 {
3151
3159
// If we were going to send a commitment_signed after the RAA, go ahead and do all
3152
- // the corresponding HTLC status updates so that get_last_commitment_update
3153
- // includes the right HTLCs.
3160
+ // the corresponding HTLC status updates so that
3161
+ // get_last_commitment_update_for_send includes the right HTLCs.
3154
3162
self.context.monitor_pending_commitment_signed = true;
3155
3163
let mut additional_update = self.build_commitment_no_status_check(logger);
3156
3164
// build_commitment_no_status_check may bump latest_monitor_id but we want them to be
@@ -3524,9 +3532,10 @@ impl<SP: Deref> Channel<SP> where
3524
3532
// cells) while we can't update the monitor, so we just return what we have.
3525
3533
if require_commitment {
3526
3534
self.context.monitor_pending_commitment_signed = true;
3527
- // When the monitor updating is restored we'll call get_last_commitment_update(),
3528
- // which does not update state, but we're definitely now awaiting a remote revoke
3529
- // before we can step forward any more, so set it here.
3535
+ // When the monitor updating is restored we'll call
3536
+ // get_last_commitment_update_for_send(), which does not update state, but we're
3537
+ // definitely now awaiting a remote revoke before we can step forward any more, so
3538
+ // set it here.
3530
3539
let mut additional_update = self.build_commitment_no_status_check(logger);
3531
3540
// build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3532
3541
// strictly increasing by one, so decrement it here.
@@ -3829,9 +3838,11 @@ impl<SP: Deref> Channel<SP> where
3829
3838
Some(self.get_last_revoke_and_ack())
3830
3839
} else { None };
3831
3840
let commitment_update = if self.context.monitor_pending_commitment_signed {
3832
- self.mark_awaiting_response();
3833
- Some(self.get_last_commitment_update(logger))
3841
+ self.get_last_commitment_update_for_send(logger).ok()
3834
3842
} else { None };
3843
+ if commitment_update.is_some() {
3844
+ self.mark_awaiting_response();
3845
+ }
3835
3846
3836
3847
self.context.monitor_pending_revoke_and_ack = false;
3837
3848
self.context.monitor_pending_commitment_signed = false;
@@ -3892,7 +3903,8 @@ impl<SP: Deref> Channel<SP> where
3892
3903
}
3893
3904
}
3894
3905
3895
- fn get_last_commitment_update<L: Deref>(&self, logger: &L) -> msgs::CommitmentUpdate where L::Target: Logger {
3906
+ /// Gets the last commitment update for immediate sending to our peer.
3907
+ fn get_last_commitment_update_for_send<L: Deref>(&mut self, logger: &L) -> Result<msgs::CommitmentUpdate, ()> where L::Target: Logger {
3896
3908
let mut update_add_htlcs = Vec::new();
3897
3909
let mut update_fulfill_htlcs = Vec::new();
3898
3910
let mut update_fail_htlcs = Vec::new();
@@ -3951,10 +3963,17 @@ impl<SP: Deref> Channel<SP> where
3951
3963
log_trace!(logger, "Regenerated latest commitment update in channel {} with{} {} update_adds, {} update_fulfills, {} update_fails, and {} update_fail_malformeds",
3952
3964
&self.context.channel_id(), if update_fee.is_some() { " update_fee," } else { "" },
3953
3965
update_add_htlcs.len(), update_fulfill_htlcs.len(), update_fail_htlcs.len(), update_fail_malformed_htlcs.len());
3954
- msgs::CommitmentUpdate {
3966
+ let commitment_signed = if let Ok(update) = self.send_commitment_no_state_update(logger).map(|(cu, _)| cu) {
3967
+ self.context.signer_pending_commitment_update = false;
3968
+ update
3969
+ } else {
3970
+ self.context.signer_pending_commitment_update = true;
3971
+ return Err(());
3972
+ };
3973
+ Ok(msgs::CommitmentUpdate {
3955
3974
update_add_htlcs, update_fulfill_htlcs, update_fail_htlcs, update_fail_malformed_htlcs, update_fee,
3956
- 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 ,
3957
- }
3975
+ commitment_signed,
3976
+ })
3958
3977
}
3959
3978
3960
3979
/// Gets the `Shutdown` message we should send our peer on reconnect, if any.
@@ -4134,7 +4153,7 @@ impl<SP: Deref> Channel<SP> where
4134
4153
Ok(ReestablishResponses {
4135
4154
channel_ready, shutdown_msg, announcement_sigs,
4136
4155
raa: required_revoke,
4137
- commitment_update: Some( self.get_last_commitment_update (logger)),
4156
+ commitment_update: self.get_last_commitment_update_for_send (logger).ok( ),
4138
4157
order: self.context.resend_order.clone(),
4139
4158
})
4140
4159
}
@@ -5495,7 +5514,7 @@ impl<SP: Deref> Channel<SP> where
5495
5514
}
5496
5515
5497
5516
let res = ecdsa.sign_counterparty_commitment(&commitment_stats.tx, commitment_stats.preimages, &self.context.secp_ctx)
5498
- .map_err(|_| ChannelError::Close ("Failed to get signatures for new commitment_signed".to_owned()))?;
5517
+ .map_err(|_| ChannelError::Ignore ("Failed to get signatures for new commitment_signed".to_owned()))?;
5499
5518
signature = res.0;
5500
5519
htlc_signatures = res.1;
5501
5520
@@ -5811,6 +5830,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5811
5830
monitor_pending_failures: Vec::new(),
5812
5831
monitor_pending_finalized_fulfills: Vec::new(),
5813
5832
5833
+ signer_pending_commitment_update: false,
5834
+
5814
5835
#[cfg(debug_assertions)]
5815
5836
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
5816
5837
#[cfg(debug_assertions)]
@@ -6460,6 +6481,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6460
6481
monitor_pending_failures: Vec::new(),
6461
6482
monitor_pending_finalized_fulfills: Vec::new(),
6462
6483
6484
+ signer_pending_commitment_update: false,
6485
+
6463
6486
#[cfg(debug_assertions)]
6464
6487
holder_max_commitment_tx_output: Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
6465
6488
#[cfg(debug_assertions)]
@@ -7551,6 +7574,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7551
7574
monitor_pending_failures,
7552
7575
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
7553
7576
7577
+ signer_pending_commitment_update: false,
7578
+
7554
7579
pending_update_fee,
7555
7580
holding_cell_update_fee,
7556
7581
next_holder_htlc_id,
0 commit comments