@@ -729,6 +729,14 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
729
729
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
730
730
monitor_pending_finalized_fulfills: Vec<HTLCSource>,
731
731
732
+ /// If we went to send a commitment update (ie some messages then [`msgs::CommitmentSigned`])
733
+ /// but our signer (initially) refused to give us a signature, we should retry at some point in
734
+ /// the future when the signer indicates it may have a signature for us.
735
+ ///
736
+ /// This flag is set in such a case. Note that we don't need to persist this as we'll end up
737
+ /// setting it again as a side-effect of [`Channel::channel_reestablish`].
738
+ signer_pending_commitment_update: bool,
739
+
732
740
// pending_update_fee is filled when sending and receiving update_fee.
733
741
//
734
742
// Because it follows the same commitment flow as HTLCs, `FeeUpdateState` is either `Outbound`
@@ -3071,8 +3079,8 @@ impl<SP: Deref> Channel<SP> where
3071
3079
self.context.monitor_pending_revoke_and_ack = true;
3072
3080
if need_commitment && (self.context.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == 0 {
3073
3081
// If we were going to send a commitment_signed after the RAA, go ahead and do all
3074
- // the corresponding HTLC status updates so that get_last_commitment_update
3075
- // includes the right HTLCs.
3082
+ // the corresponding HTLC status updates so that
3083
+ // get_last_commitment_update_for_send includes the right HTLCs.
3076
3084
self.context.monitor_pending_commitment_signed = true;
3077
3085
let mut additional_update = self.build_commitment_no_status_check(logger);
3078
3086
// build_commitment_no_status_check may bump latest_monitor_id but we want them to be
@@ -3446,9 +3454,10 @@ impl<SP: Deref> Channel<SP> where
3446
3454
// cells) while we can't update the monitor, so we just return what we have.
3447
3455
if require_commitment {
3448
3456
self.context.monitor_pending_commitment_signed = true;
3449
- // When the monitor updating is restored we'll call get_last_commitment_update(),
3450
- // which does not update state, but we're definitely now awaiting a remote revoke
3451
- // before we can step forward any more, so set it here.
3457
+ // When the monitor updating is restored we'll call
3458
+ // get_last_commitment_update_for_send(), which does not update state, but we're
3459
+ // definitely now awaiting a remote revoke before we can step forward any more, so
3460
+ // set it here.
3452
3461
let mut additional_update = self.build_commitment_no_status_check(logger);
3453
3462
// build_commitment_no_status_check may bump latest_monitor_id but we want them to be
3454
3463
// strictly increasing by one, so decrement it here.
@@ -3750,9 +3759,11 @@ impl<SP: Deref> Channel<SP> where
3750
3759
Some(self.get_last_revoke_and_ack())
3751
3760
} else { None };
3752
3761
let commitment_update = if self.context.monitor_pending_commitment_signed {
3753
- self.mark_awaiting_response();
3754
- Some(self.get_last_commitment_update(logger))
3762
+ self.get_last_commitment_update_for_send(logger).ok()
3755
3763
} else { None };
3764
+ if commitment_update.is_some() {
3765
+ self.mark_awaiting_response();
3766
+ }
3756
3767
3757
3768
self.context.monitor_pending_revoke_and_ack = false;
3758
3769
self.context.monitor_pending_commitment_signed = false;
@@ -3813,7 +3824,8 @@ impl<SP: Deref> Channel<SP> where
3813
3824
}
3814
3825
}
3815
3826
3816
- fn get_last_commitment_update<L: Deref>(&self, logger: &L) -> msgs::CommitmentUpdate where L::Target: Logger {
3827
+ /// Gets the last commitment update for immediate sending to our peer.
3828
+ fn get_last_commitment_update_for_send<L: Deref>(&mut self, logger: &L) -> Result<msgs::CommitmentUpdate, ()> where L::Target: Logger {
3817
3829
let mut update_add_htlcs = Vec::new();
3818
3830
let mut update_fulfill_htlcs = Vec::new();
3819
3831
let mut update_fail_htlcs = Vec::new();
@@ -3872,10 +3884,17 @@ impl<SP: Deref> Channel<SP> where
3872
3884
log_trace!(logger, "Regenerated latest commitment update in channel {} with{} {} update_adds, {} update_fulfills, {} update_fails, and {} update_fail_malformeds",
3873
3885
&self.context.channel_id(), if update_fee.is_some() { " update_fee," } else { "" },
3874
3886
update_add_htlcs.len(), update_fulfill_htlcs.len(), update_fail_htlcs.len(), update_fail_malformed_htlcs.len());
3875
- msgs::CommitmentUpdate {
3887
+ let commitment_signed = if let Ok(update) = self.send_commitment_no_state_update(logger).map(|(cu, _)| cu) {
3888
+ self.context.signer_pending_commitment_update = false;
3889
+ update
3890
+ } else {
3891
+ self.context.signer_pending_commitment_update = true;
3892
+ return Err(());
3893
+ };
3894
+ Ok(msgs::CommitmentUpdate {
3876
3895
update_add_htlcs, update_fulfill_htlcs, update_fail_htlcs, update_fail_malformed_htlcs, update_fee,
3877
- 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 ,
3878
- }
3896
+ commitment_signed,
3897
+ })
3879
3898
}
3880
3899
3881
3900
/// Gets the `Shutdown` message we should send our peer on reconnect, if any.
@@ -4055,7 +4074,7 @@ impl<SP: Deref> Channel<SP> where
4055
4074
Ok(ReestablishResponses {
4056
4075
channel_ready, shutdown_msg, announcement_sigs,
4057
4076
raa: required_revoke,
4058
- commitment_update: Some( self.get_last_commitment_update (logger)),
4077
+ commitment_update: self.get_last_commitment_update_for_send (logger).ok( ),
4059
4078
order: self.context.resend_order.clone(),
4060
4079
})
4061
4080
}
@@ -5413,7 +5432,7 @@ impl<SP: Deref> Channel<SP> where
5413
5432
}
5414
5433
5415
5434
let res = ecdsa.sign_counterparty_commitment(&commitment_stats.tx, commitment_stats.preimages, &self.context.secp_ctx)
5416
- .map_err(|_| ChannelError::Close ("Failed to get signatures for new commitment_signed".to_owned()))?;
5435
+ .map_err(|_| ChannelError::Ignore ("Failed to get signatures for new commitment_signed".to_owned()))?;
5417
5436
signature = res.0;
5418
5437
htlc_signatures = res.1;
5419
5438
@@ -5726,6 +5745,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5726
5745
monitor_pending_failures: Vec::new(),
5727
5746
monitor_pending_finalized_fulfills: Vec::new(),
5728
5747
5748
+ signer_pending_commitment_update: false,
5749
+
5729
5750
#[cfg(debug_assertions)]
5730
5751
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
5731
5752
#[cfg(debug_assertions)]
@@ -6373,6 +6394,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6373
6394
monitor_pending_failures: Vec::new(),
6374
6395
monitor_pending_finalized_fulfills: Vec::new(),
6375
6396
6397
+ signer_pending_commitment_update: false,
6398
+
6376
6399
#[cfg(debug_assertions)]
6377
6400
holder_max_commitment_tx_output: Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
6378
6401
#[cfg(debug_assertions)]
@@ -7459,6 +7482,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7459
7482
monitor_pending_failures,
7460
7483
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
7461
7484
7485
+ signer_pending_commitment_update: false,
7486
+
7462
7487
pending_update_fee,
7463
7488
holding_cell_update_fee,
7464
7489
next_holder_htlc_id,
0 commit comments