From: Matt Corallo Date: Sun, 19 Apr 2020 01:36:33 +0000 (-0400) Subject: Drop ChannelMonitor::write_for_watchtower X-Git-Tag: v0.0.12~78^2~6 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=rust-lightning;a=commitdiff_plain;h=b04219a7670f38f31342aedc5ad06597d2f42cca Drop ChannelMonitor::write_for_watchtower Not only was watchtower mode never implemented, but the bits that we had were removed some time ago. It doesn't seem likely we'll move forward with a "watchtower-mode" ChannelMonitor, instead we'll likely have some other, separate struct for this. --- diff --git a/fuzz/src/chanmon_deser.rs b/fuzz/src/chanmon_deser.rs index c9042dd4..dc12f5e7 100644 --- a/fuzz/src/chanmon_deser.rs +++ b/fuzz/src/chanmon_deser.rs @@ -32,8 +32,6 @@ pub fn do_test(data: &[u8]) { let deserialized_copy = <(Sha256dHash, channelmonitor::ChannelMonitor)>::read(&mut Cursor::new(&w.0), logger.clone()).unwrap(); assert!(latest_block_hash == deserialized_copy.0); assert!(monitor == deserialized_copy.1); - w.0.clear(); - monitor.write_for_watchtower(&mut w).unwrap(); } } diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index 7a6bac9c..503a358e 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -833,8 +833,14 @@ impl PartialEq for ChannelMonitor { } impl ChannelMonitor { - /// Serializes into a vec, with various modes for the exposed pub fns - fn write(&self, writer: &mut W, for_local_storage: bool) -> Result<(), ::std::io::Error> { + /// Writes this monitor into the given writer, suitable for writing to disk. + /// + /// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which + /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along + /// the "reorg path" (ie not just starting at the same height but starting at the highest + /// common block that appears on your best chain as well as on the chain which contains the + /// last block hash returned) upon deserializing the object! + pub fn write_for_disk(&self, writer: &mut W) -> Result<(), ::std::io::Error> { //TODO: We still write out all the serialization here manually instead of using the fancy //serialization framework we have, we should migrate things over to it. writer.write_all(&[SERIALIZATION_VERSION; 1])?; @@ -929,14 +935,10 @@ impl ChannelMonitor { } } - if for_local_storage { - writer.write_all(&byte_utils::be64_to_array(self.remote_hash_commitment_number.len() as u64))?; - for (ref payment_hash, commitment_number) in self.remote_hash_commitment_number.iter() { - writer.write_all(&payment_hash.0[..])?; - writer.write_all(&byte_utils::be48_to_array(*commitment_number))?; - } - } else { - writer.write_all(&byte_utils::be64_to_array(0))?; + writer.write_all(&byte_utils::be64_to_array(self.remote_hash_commitment_number.len() as u64))?; + for (ref payment_hash, commitment_number) in self.remote_hash_commitment_number.iter() { + writer.write_all(&payment_hash.0[..])?; + writer.write_all(&byte_utils::be48_to_array(*commitment_number))?; } macro_rules! serialize_local_tx { @@ -977,17 +979,8 @@ impl ChannelMonitor { writer.write_all(&[0; 1])?; } - if for_local_storage { - writer.write_all(&byte_utils::be48_to_array(self.current_remote_commitment_number))?; - } else { - writer.write_all(&byte_utils::be48_to_array(0))?; - } - - if for_local_storage { - writer.write_all(&byte_utils::be48_to_array(self.current_local_commitment_number))?; - } else { - writer.write_all(&byte_utils::be48_to_array(0))?; - } + writer.write_all(&byte_utils::be48_to_array(self.current_remote_commitment_number))?; + writer.write_all(&byte_utils::be48_to_array(self.current_local_commitment_number))?; writer.write_all(&byte_utils::be64_to_array(self.payment_preimages.len() as u64))?; for payment_preimage in self.payment_preimages.values() { @@ -1039,28 +1032,6 @@ impl ChannelMonitor { Ok(()) } - - /// Writes this monitor into the given writer, suitable for writing to disk. - /// - /// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which - /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along - /// the "reorg path" (ie not just starting at the same height but starting at the highest - /// common block that appears on your best chain as well as on the chain which contains the - /// last block hash returned) upon deserializing the object! - pub fn write_for_disk(&self, writer: &mut W) -> Result<(), ::std::io::Error> { - self.write(writer, true) - } - - /// Encodes this monitor into the given writer, suitable for sending to a remote watchtower - /// - /// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which - /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along - /// the "reorg path" (ie not just starting at the same height but starting at the highest - /// common block that appears on your best chain as well as on the chain which contains the - /// last block hash returned) upon deserializing the object! - pub fn write_for_watchtower(&self, writer: &mut W) -> Result<(), ::std::io::Error> { - self.write(writer, false) - } } impl ChannelMonitor { diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 13cbde4a..4fcaf803 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -71,8 +71,6 @@ impl<'a> channelmonitor::ManyChannelMonitor for TestChanne let new_monitor = <(Sha256dHash, channelmonitor::ChannelMonitor)>::read( &mut ::std::io::Cursor::new(&w.0), Arc::new(TestLogger::new())).unwrap().1; assert!(new_monitor == monitor); - w.0.clear(); - monitor.write_for_watchtower(&mut w).unwrap(); // This at least shouldn't crash... self.latest_monitor_update_id.lock().unwrap().insert(funding_txo.to_channel_id(), (funding_txo, monitor.get_latest_update_id())); self.added_monitors.lock().unwrap().push((funding_txo, monitor)); assert!(self.simple_monitor.add_monitor(funding_txo, new_monitor).is_ok()); @@ -97,8 +95,6 @@ impl<'a> channelmonitor::ManyChannelMonitor for TestChanne let new_monitor = <(Sha256dHash, channelmonitor::ChannelMonitor)>::read( &mut ::std::io::Cursor::new(&w.0), Arc::new(TestLogger::new())).unwrap().1; assert!(new_monitor == *monitor); - w.0.clear(); - monitor.write_for_watchtower(&mut w).unwrap(); // This at least shouldn't crash... self.added_monitors.lock().unwrap().push((funding_txo, new_monitor)); self.update_ret.lock().unwrap().clone() }