+ // If we have any LocalAnnounced updates we'll probably just get back a update_fail_htlc
+ // immediately after the commitment dance, but we can send a Shutdown cause we won't send
+ // any further commitment updates after we set LocalShutdownSent.
+ let send_shutdown = (self.channel_state & ChannelState::LocalShutdownSent as u32) != ChannelState::LocalShutdownSent as u32;
+
+ let shutdown_scriptpubkey = match self.shutdown_scriptpubkey {
+ Some(_) => None,
+ None => {
+ assert!(send_shutdown);
+ let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
+ if !shutdown_scriptpubkey.is_compatible(their_features) {
+ return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex())));
+ }
+ Some(shutdown_scriptpubkey)
+ },
+ };
+