Generate shutdown script at channel close
[rust-lightning] / lightning / src / chain / channelmonitor.rs
index fd097f30cc200cf6318297294cdc6867bd62970f..6c11703d3158fc86567a49b2c81d771a1b8517b0 100644 (file)
@@ -438,6 +438,9 @@ pub(crate) enum ChannelMonitorUpdateStep {
                /// think we've fallen behind!
                should_broadcast: bool,
        },
+       ShutdownScript {
+               scriptpubkey: Script,
+       },
 }
 
 impl_writeable_tlv_based_enum!(ChannelMonitorUpdateStep,
@@ -461,6 +464,9 @@ impl_writeable_tlv_based_enum!(ChannelMonitorUpdateStep,
        (4, ChannelForceClosed) => {
                (0, should_broadcast, required),
        },
+       (5, ShutdownScript) => {
+               (0, scriptpubkey, required),
+       },
 ;);
 
 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
@@ -1437,7 +1443,13 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
                                                // shouldn't print the scary warning above.
                                                log_info!(logger, "Channel off-chain state closed after we broadcasted our latest commitment transaction.");
                                        }
-                               }
+                               },
+                               ChannelMonitorUpdateStep::ShutdownScript { scriptpubkey } => {
+                                       log_trace!(logger, "Updating ChannelMonitor with shutdown script");
+                                       if let Some(shutdown_script) = self.shutdown_script.replace(scriptpubkey.clone()) {
+                                               panic!("Attempted to replace shutdown script {} with {}", shutdown_script, scriptpubkey);
+                                       }
+                               },
                        }
                }
                self.latest_update_id = updates.update_id;