+ /// Indicates that a ChannelMonitor update failed to be stored by the client and further
+ /// updates are partially paused.
+ /// This must be called immediately after the call which generated the ChannelMonitor update
+ /// which failed, with the order argument set to the type of call it represented (ie a
+ /// commitment update or a revoke_and_ack generation). The messages which were generated from
+ /// that original call must *not* have been sent to the remote end, and must instead have been
+ /// dropped. They will be regenerated when monitor_updating_restored is called.
+ pub fn monitor_update_failed(&mut self, order: RAACommitmentOrder) {
+ assert_eq!(self.channel_state & ChannelState::MonitorUpdateFailed as u32, 0);
+ match order {
+ RAACommitmentOrder::CommitmentFirst => {
+ self.monitor_pending_revoke_and_ack = false;
+ self.monitor_pending_commitment_signed = true;
+ },
+ RAACommitmentOrder::RevokeAndACKFirst => {
+ self.monitor_pending_revoke_and_ack = true;
+ self.monitor_pending_commitment_signed = false;
+ },
+ }
+ self.monitor_pending_order = Some(order);
+ self.channel_state |= ChannelState::MonitorUpdateFailed as u32;
+ }
+
+ /// Indicates that the latest ChannelMonitor update has been committed by the client
+ /// successfully and we should restore normal operation. Returns messages which should be sent
+ /// to the remote side.
+ pub fn monitor_updating_restored(&mut self) -> (Option<msgs::RevokeAndACK>, Option<msgs::CommitmentUpdate>, RAACommitmentOrder, Vec<(PendingForwardHTLCInfo, u64)>, Vec<(HTLCSource, [u8; 32], HTLCFailReason)>) {
+ assert_eq!(self.channel_state & ChannelState::MonitorUpdateFailed as u32, ChannelState::MonitorUpdateFailed as u32);
+ self.channel_state &= !(ChannelState::MonitorUpdateFailed as u32);
+
+ let mut forwards = Vec::new();
+ mem::swap(&mut forwards, &mut self.monitor_pending_forwards);
+ let mut failures = Vec::new();
+ mem::swap(&mut failures, &mut self.monitor_pending_failures);
+
+ if self.channel_state & (ChannelState::PeerDisconnected as u32) != 0 {
+ // Leave monitor_pending_order so we can order our channel_reestablish responses
+ self.monitor_pending_revoke_and_ack = false;
+ self.monitor_pending_commitment_signed = false;
+ return (None, None, RAACommitmentOrder::RevokeAndACKFirst, forwards, failures);
+ }
+
+ let raa = if self.monitor_pending_revoke_and_ack {
+ Some(self.get_last_revoke_and_ack())
+ } else { None };
+ let commitment_update = if self.monitor_pending_commitment_signed {
+ Some(self.get_last_commitment_update())
+ } else { None };
+
+ self.monitor_pending_revoke_and_ack = false;
+ self.monitor_pending_commitment_signed = false;
+ (raa, commitment_update, self.monitor_pending_order.clone().unwrap(), forwards, failures)
+ }
+