@@ -700,6 +700,14 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
700
700
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
701
701
monitor_pending_finalized_fulfills: Vec<HTLCSource>,
702
702
703
+ /// If we went to send a commitment update (ie some messages then [`msgs::CommitmentSigned`])
704
+ /// but our signer (initially) refused to give us a signature, we should retry at some point in
705
+ /// the future when the signer indicates it may have a signature for us.
706
+ ///
707
+ /// This flag is set in such a case. Note that we don't need to persist this as we'll end up
708
+ /// setting it again as a side-effect of [`Channel::channel_reestablish`].
709
+ signer_pending_commitment_update: bool,
710
+
703
711
// pending_update_fee is filled when sending and receiving update_fee.
704
712
//
705
713
// Because it follows the same commitment flow as HTLCs, `FeeUpdateState` is either `Outbound`
@@ -3047,8 +3055,8 @@ impl<SP: Deref> Channel<SP> where
3047
3055
self.context.monitor_pending_revoke_and_ack = true;
3048
3056
if need_commitment && (self.context.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == 0 {
3049
3057
// If we were going to send a commitment_signed after the RAA, go ahead and do all
3050
- // the corresponding HTLC status updates so that get_last_commitment_update
3051
- // includes the right HTLCs.
3058
+ // the corresponding HTLC status updates so that
3059
+ // get_last_commitment_update_for_send includes the right HTLCs.
3052
3060
self.context.monitor_pending_commitment_signed = true;
3053
3061
let mut additional_update = self.build_commitment_no_status_check(logger);
3054
3062
// build_commitment_no_status_check may bump latest_monitor_id but we want them to be
@@ -3422,9 +3430,10 @@ impl<SP: Deref> Channel<SP> where
3422
3430
// cells) while we can't update the monitor, so we just return what we have.
3423
3431
if require_commitment {
3424
3432
self.context.monitor_pending_commitment_signed = true;
3425
- // When the monitor updating is restored we'll call get_last_commitment_update(),
3426
- // which does not update state, but we're definitely now awaiting a remote revoke
3427
- // before we can step forward any more, so set it here.
3433
+ // When the monitor updating is restored we'll call
3434
+ // get_last_commitment_update_for_send(), which does not update state, but we're
3435
+ // definitely now awaiting a remote revoke before we can step forward any more, so
3436
+ // set it here.
3428
3437
let mut additional_update = self.build_commitment_no_status_check(logger);
3429
3438
// build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3430
3439
// strictly increasing by one, so decrement it here.
@@ -3726,9 +3735,11 @@ impl<SP: Deref> Channel<SP> where
3726
3735
Some(self.get_last_revoke_and_ack())
3727
3736
} else { None };
3728
3737
let commitment_update = if self.context.monitor_pending_commitment_signed {
3729
- self.mark_awaiting_response();
3730
- Some(self.get_last_commitment_update(logger))
3738
+ self.get_last_commitment_update_for_send(logger).ok()
3731
3739
} else { None };
3740
+ if commitment_update.is_some() {
3741
+ self.mark_awaiting_response();
3742
+ }
3732
3743
3733
3744
self.context.monitor_pending_revoke_and_ack = false;
3734
3745
self.context.monitor_pending_commitment_signed = false;
@@ -3789,7 +3800,8 @@ impl<SP: Deref> Channel<SP> where
3789
3800
}
3790
3801
}
3791
3802
3792
- fn get_last_commitment_update<L: Deref>(&self, logger: &L) -> msgs::CommitmentUpdate where L::Target: Logger {
3803
+ /// Gets the last commitment update for immediate sending to our peer.
3804
+ fn get_last_commitment_update_for_send<L: Deref>(&mut self, logger: &L) -> Result<msgs::CommitmentUpdate, ()> where L::Target: Logger {
3793
3805
let mut update_add_htlcs = Vec::new();
3794
3806
let mut update_fulfill_htlcs = Vec::new();
3795
3807
let mut update_fail_htlcs = Vec::new();
@@ -3848,10 +3860,17 @@ impl<SP: Deref> Channel<SP> where
3848
3860
log_trace!(logger, "Regenerated latest commitment update in channel {} with{} {} update_adds, {} update_fulfills, {} update_fails, and {} update_fail_malformeds",
3849
3861
&self.context.channel_id(), if update_fee.is_some() { " update_fee," } else { "" },
3850
3862
update_add_htlcs.len(), update_fulfill_htlcs.len(), update_fail_htlcs.len(), update_fail_malformed_htlcs.len());
3851
- msgs::CommitmentUpdate {
3863
+ let commitment_signed = if let Ok(update) = self.send_commitment_no_state_update(logger).map(|(cu, _)| cu) {
3864
+ self.context.signer_pending_commitment_update = false;
3865
+ update
3866
+ } else {
3867
+ self.context.signer_pending_commitment_update = true;
3868
+ return Err(());
3869
+ };
3870
+ Ok(msgs::CommitmentUpdate {
3852
3871
update_add_htlcs, update_fulfill_htlcs, update_fail_htlcs, update_fail_malformed_htlcs, update_fee,
3853
- 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 ,
3854
- }
3872
+ commitment_signed,
3873
+ })
3855
3874
}
3856
3875
3857
3876
/// Gets the `Shutdown` message we should send our peer on reconnect, if any.
@@ -4031,7 +4050,7 @@ impl<SP: Deref> Channel<SP> where
4031
4050
Ok(ReestablishResponses {
4032
4051
channel_ready, shutdown_msg, announcement_sigs,
4033
4052
raa: required_revoke,
4034
- commitment_update: Some( self.get_last_commitment_update (logger)),
4053
+ commitment_update: self.get_last_commitment_update_for_send (logger).ok( ),
4035
4054
order: self.context.resend_order.clone(),
4036
4055
})
4037
4056
}
@@ -5389,7 +5408,7 @@ impl<SP: Deref> Channel<SP> where
5389
5408
}
5390
5409
5391
5410
let res = ecdsa.sign_counterparty_commitment(&commitment_stats.tx, commitment_stats.preimages, &self.context.secp_ctx)
5392
- .map_err(|_| ChannelError::Close ("Failed to get signatures for new commitment_signed".to_owned()))?;
5411
+ .map_err(|_| ChannelError::Ignore ("Failed to get signatures for new commitment_signed".to_owned()))?;
5393
5412
signature = res.0;
5394
5413
htlc_signatures = res.1;
5395
5414
@@ -5702,6 +5721,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5702
5721
monitor_pending_failures: Vec::new(),
5703
5722
monitor_pending_finalized_fulfills: Vec::new(),
5704
5723
5724
+ signer_pending_commitment_update: false,
5725
+
5705
5726
#[cfg(debug_assertions)]
5706
5727
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
5707
5728
#[cfg(debug_assertions)]
@@ -6349,6 +6370,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6349
6370
monitor_pending_failures: Vec::new(),
6350
6371
monitor_pending_finalized_fulfills: Vec::new(),
6351
6372
6373
+ signer_pending_commitment_update: false,
6374
+
6352
6375
#[cfg(debug_assertions)]
6353
6376
holder_max_commitment_tx_output: Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
6354
6377
#[cfg(debug_assertions)]
@@ -7435,6 +7458,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7435
7458
monitor_pending_failures,
7436
7459
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
7437
7460
7461
+ signer_pending_commitment_update: false,
7462
+
7438
7463
pending_update_fee,
7439
7464
holding_cell_update_fee,
7440
7465
next_holder_htlc_id,
0 commit comments