]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Rename ChannelMonitor::write_for_disk --> serialize_for_disk
authorValentine Wallace <vwallace@protonmail.com>
Mon, 5 Oct 2020 21:39:28 +0000 (17:39 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Fri, 16 Oct 2020 17:41:39 +0000 (13:41 -0400)
This function does not necessarily write to disk, it can serialize to anything
that implements Writer.

fuzz/src/chanmon_consistency.rs
fuzz/src/chanmon_deser.rs
lightning-persister/src/lib.rs
lightning/src/chain/channelmonitor.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/util/test_utils.rs

index 8202ae3cd9be6ff2cfb2041cf2be0d0914741bf8..d88cc71fbf50a4175690d76a62bedfc5f3df808c 100644 (file)
@@ -111,7 +111,7 @@ impl chain::Watch for TestChainMonitor {
 
        fn watch_channel(&self, funding_txo: OutPoint, monitor: channelmonitor::ChannelMonitor<EnforcingChannelKeys>) -> Result<(), channelmonitor::ChannelMonitorUpdateErr> {
                let mut ser = VecWriter(Vec::new());
-               monitor.write_for_disk(&mut ser).unwrap();
+               monitor.serialize_for_disk(&mut ser).unwrap();
                if let Some(_) = self.latest_monitors.lock().unwrap().insert(funding_txo, (monitor.get_latest_update_id(), ser.0)) {
                        panic!("Already had monitor pre-watch_channel");
                }
@@ -130,7 +130,7 @@ impl chain::Watch for TestChainMonitor {
                        read(&mut Cursor::new(&map_entry.get().1)).unwrap().1;
                deserialized_monitor.update_monitor(&update, &&TestBroadcaster {}, &self.logger).unwrap();
                let mut ser = VecWriter(Vec::new());
-               deserialized_monitor.write_for_disk(&mut ser).unwrap();
+               deserialized_monitor.serialize_for_disk(&mut ser).unwrap();
                map_entry.insert((update.update_id, ser.0));
                self.should_update_manager.store(true, atomic::Ordering::Relaxed);
                self.update_ret.lock().unwrap().clone()
index 5a76340ff309447c9cbae3baa0b112353b027210..fd326cc2ec85bdc72670da4cae4f7388366c05af 100644 (file)
@@ -26,7 +26,7 @@ impl Writer for VecWriter {
 pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        if let Ok((latest_block_hash, monitor)) = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(data)) {
                let mut w = VecWriter(Vec::new());
-               monitor.write_for_disk(&mut w).unwrap();
+               monitor.serialize_for_disk(&mut w).unwrap();
                let deserialized_copy = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&w.0)).unwrap();
                assert!(latest_block_hash == deserialized_copy.0);
                assert!(monitor == deserialized_copy.1);
index 2a6f7cf0e0e04fe0c3f85af1a381f8f24427d44c..48d4d0aa810c3b4b0ca8645acd8485646a9722e7 100644 (file)
@@ -45,7 +45,7 @@ trait DiskWriteable {
 
 impl<ChanSigner: ChannelKeys + Writeable> DiskWriteable for ChannelMonitor<ChanSigner> {
        fn write(&self, writer: &mut fs::File) -> Result<(), Error> {
-               self.write_for_disk(writer)
+               self.serialize_for_disk(writer)
        }
 }
 
index 2503a7a76bfbe37632a481eef1dddb82e5bcdeb7..889dfa211ee78d167dbad2229ffcaf7dc82d1d4c 100644 (file)
@@ -746,7 +746,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
        /// the "reorg path" (ie disconnecting blocks until you find a common ancestor from both the
        /// returned block hash and the the current chain and then reconnecting blocks to get to the
        /// best chain) upon deserializing the object!
-       pub fn write_for_disk<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
+       pub fn serialize_for_disk<W: Writer>(&self, writer: &mut W) -> Result<(), 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])?;
@@ -2141,10 +2141,10 @@ pub trait Persist<Keys: ChannelKeys>: Send + Sync {
        /// stored channel data). Note that you **must** persist every new monitor to
        /// disk. See the `Persist` trait documentation for more details.
        ///
-       /// See [`ChannelMonitor::write_for_disk`] for writing out a `ChannelMonitor`,
+       /// See [`ChannelMonitor::serialize_for_disk`] for writing out a `ChannelMonitor`,
        /// and [`ChannelMonitorUpdateErr`] for requirements when returning errors.
        ///
-       /// [`ChannelMonitor::write_for_disk`]: struct.ChannelMonitor.html#method.write_for_disk
+       /// [`ChannelMonitor::serialize_for_disk`]: struct.ChannelMonitor.html#method.serialize_for_disk
        /// [`ChannelMonitorUpdateErr`]: enum.ChannelMonitorUpdateErr.html
        fn persist_new_channel(&self, id: OutPoint, data: &ChannelMonitor<Keys>) -> Result<(), ChannelMonitorUpdateErr>;
 
@@ -2167,12 +2167,12 @@ pub trait Persist<Keys: ChannelKeys>: Send + Sync {
        /// them in batches. The size of each monitor grows `O(number of state updates)`
        /// whereas updates are small and `O(1)`.
        ///
-       /// See [`ChannelMonitor::write_for_disk`] for writing out a `ChannelMonitor`,
+       /// See [`ChannelMonitor::serialize_for_disk`] for writing out a `ChannelMonitor`,
        /// [`ChannelMonitorUpdate::write`] for writing out an update, and
        /// [`ChannelMonitorUpdateErr`] for requirements when returning errors.
        ///
        /// [`ChannelMonitor::update_monitor`]: struct.ChannelMonitor.html#impl-1
-       /// [`ChannelMonitor::write_for_disk`]: struct.ChannelMonitor.html#method.write_for_disk
+       /// [`ChannelMonitor::serialize_for_disk`]: struct.ChannelMonitor.html#method.serialize_for_disk
        /// [`ChannelMonitorUpdate::write`]: struct.ChannelMonitorUpdate.html#method.write
        /// [`ChannelMonitorUpdateErr`]: enum.ChannelMonitorUpdateErr.html
        fn update_persisted_channel(&self, id: OutPoint, update: &ChannelMonitorUpdate, data: &ChannelMonitor<Keys>) -> Result<(), ChannelMonitorUpdateErr>;
index bf2e78996f4afcc0175d83947408a243fe4073c0..2784f93495669dc704cda8caf03a58557dacb920 100644 (file)
@@ -170,7 +170,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
                                let old_monitors = self.chain_monitor.chain_monitor.monitors.lock().unwrap();
                                for (_, old_monitor) in old_monitors.iter() {
                                        let mut w = test_utils::TestVecWriter(Vec::new());
-                                       old_monitor.write_for_disk(&mut w).unwrap();
+                                       old_monitor.serialize_for_disk(&mut w).unwrap();
                                        let (_, deserialized_monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(
                                                &mut ::std::io::Cursor::new(&w.0)).unwrap();
                                        deserialized_monitors.push(deserialized_monitor);
index 276d912f7e84008711b60c81628ad6312c46598d..a2e12504031780718736fd9086f57a656da826b3 100644 (file)
@@ -4319,7 +4319,7 @@ fn test_no_txn_manager_serialize_deserialize() {
 
        let nodes_0_serialized = nodes[0].node.encode();
        let mut chan_0_monitor_serialized = test_utils::TestVecWriter(Vec::new());
-       nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap().iter().next().unwrap().1.write_for_disk(&mut chan_0_monitor_serialized).unwrap();
+       nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap().iter().next().unwrap().1.serialize_for_disk(&mut chan_0_monitor_serialized).unwrap();
 
        logger = test_utils::TestLogger::new();
        fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: 253 };
@@ -4428,7 +4428,7 @@ fn test_manager_serialize_deserialize_events() {
        // Start the de/seriailization process mid-channel creation to check that the channel manager will hold onto events that are serialized
        let nodes_0_serialized = nodes[0].node.encode();
        let mut chan_0_monitor_serialized = test_utils::TestVecWriter(Vec::new());
-       nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap().iter().next().unwrap().1.write_for_disk(&mut chan_0_monitor_serialized).unwrap();
+       nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap().iter().next().unwrap().1.serialize_for_disk(&mut chan_0_monitor_serialized).unwrap();
 
        fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: 253 };
        logger = test_utils::TestLogger::new();
@@ -4520,7 +4520,7 @@ fn test_simple_manager_serialize_deserialize() {
 
        let nodes_0_serialized = nodes[0].node.encode();
        let mut chan_0_monitor_serialized = test_utils::TestVecWriter(Vec::new());
-       nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap().iter().next().unwrap().1.write_for_disk(&mut chan_0_monitor_serialized).unwrap();
+       nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap().iter().next().unwrap().1.serialize_for_disk(&mut chan_0_monitor_serialized).unwrap();
 
        logger = test_utils::TestLogger::new();
        fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: 253 };
@@ -4579,7 +4579,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
        let mut node_0_stale_monitors_serialized = Vec::new();
        for monitor in nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap().iter() {
                let mut writer = test_utils::TestVecWriter(Vec::new());
-               monitor.1.write_for_disk(&mut writer).unwrap();
+               monitor.1.serialize_for_disk(&mut writer).unwrap();
                node_0_stale_monitors_serialized.push(writer.0);
        }
 
@@ -4598,7 +4598,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
        let mut node_0_monitors_serialized = Vec::new();
        for monitor in nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap().iter() {
                let mut writer = test_utils::TestVecWriter(Vec::new());
-               monitor.1.write_for_disk(&mut writer).unwrap();
+               monitor.1.serialize_for_disk(&mut writer).unwrap();
                node_0_monitors_serialized.push(writer.0);
        }
 
@@ -7432,7 +7432,7 @@ fn test_data_loss_protect() {
        // Cache node A state before any channel update
        let previous_node_state = nodes[0].node.encode();
        let mut previous_chain_monitor_state = test_utils::TestVecWriter(Vec::new());
-       nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap().iter().next().unwrap().1.write_for_disk(&mut previous_chain_monitor_state).unwrap();
+       nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap().iter().next().unwrap().1.serialize_for_disk(&mut previous_chain_monitor_state).unwrap();
 
        send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000, 8_000_000);
        send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000, 8_000_000);
@@ -8314,7 +8314,7 @@ fn test_update_err_monitor_lockdown() {
                let monitors = nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap();
                let monitor = monitors.get(&outpoint).unwrap();
                let mut w = test_utils::TestVecWriter(Vec::new());
-               monitor.write_for_disk(&mut w).unwrap();
+               monitor.serialize_for_disk(&mut w).unwrap();
                let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
                                &mut ::std::io::Cursor::new(&w.0)).unwrap().1;
                assert!(new_monitor == *monitor);
@@ -8373,7 +8373,7 @@ fn test_concurrent_monitor_claim() {
                let monitors = nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap();
                let monitor = monitors.get(&outpoint).unwrap();
                let mut w = test_utils::TestVecWriter(Vec::new());
-               monitor.write_for_disk(&mut w).unwrap();
+               monitor.serialize_for_disk(&mut w).unwrap();
                let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
                                &mut ::std::io::Cursor::new(&w.0)).unwrap().1;
                assert!(new_monitor == *monitor);
@@ -8399,7 +8399,7 @@ fn test_concurrent_monitor_claim() {
                let monitors = nodes[0].chain_monitor.chain_monitor.monitors.lock().unwrap();
                let monitor = monitors.get(&outpoint).unwrap();
                let mut w = test_utils::TestVecWriter(Vec::new());
-               monitor.write_for_disk(&mut w).unwrap();
+               monitor.serialize_for_disk(&mut w).unwrap();
                let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
                                &mut ::std::io::Cursor::new(&w.0)).unwrap().1;
                assert!(new_monitor == *monitor);
index 5e6b5fff53c7de5f8282694364f696df293245f3..6c3552d5df0853f1b8b2e79592573373c25f7c99 100644 (file)
@@ -87,7 +87,7 @@ impl<'a> chain::Watch for TestChainMonitor<'a> {
                // At every point where we get a monitor update, we should be able to send a useful monitor
                // to a watchtower and disk...
                let mut w = TestVecWriter(Vec::new());
-               monitor.write_for_disk(&mut w).unwrap();
+               monitor.serialize_for_disk(&mut w).unwrap();
                let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
                        &mut ::std::io::Cursor::new(&w.0)).unwrap().1;
                assert!(new_monitor == monitor);
@@ -120,7 +120,7 @@ impl<'a> chain::Watch for TestChainMonitor<'a> {
                let monitors = self.chain_monitor.monitors.lock().unwrap();
                let monitor = monitors.get(&funding_txo).unwrap();
                w.0.clear();
-               monitor.write_for_disk(&mut w).unwrap();
+               monitor.serialize_for_disk(&mut w).unwrap();
                let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
                        &mut ::std::io::Cursor::new(&w.0)).unwrap().1;
                assert!(new_monitor == *monitor);