+ let their_shutdown_scriptpubkey = if their_local_features.supports_upfront_shutdown_script() {
+ match &msg.shutdown_scriptpubkey {
+ &OptionalField::Present(ref script) => {
+ // Peer is signaling upfront_shutdown and has provided a non-accepted scriptpubkey format. We enforce it while receiving shutdown msg
+ if script.is_p2pkh() || script.is_p2sh() || script.is_v0_p2wsh() || script.is_v0_p2wpkh() {
+ Some(script.clone())
+ // Peer is signaling upfront_shutdown and has opt-out with a 0-length script. We don't enforce anything
+ } else if script.len() == 0 {
+ None
+ // Peer is signaling upfront_shutdown and has provided a non-accepted scriptpubkey format. Fail the channel
+ } else {
+ return Err(ChannelError::Close("Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format"));
+ }
+ },
+ // Peer is signaling upfront shutdown but don't opt-out with correct mechanism (a.k.a 0-length script). Peer looks buggy, we fail the channel
+ &OptionalField::Absent => {
+ return Err(ChannelError::Close("Peer is signaling upfront_shutdown but we don't get any script. Use 0-length script to opt-out"));
+ }
+ }
+ } else { None };
+