From 55a929e214bd02aa564c694665148c223d6435f5 Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Mon, 15 Jun 2020 15:05:47 +0100 Subject: [PATCH] cleanup old unused code (#3355) --- chain/src/chain.rs | 25 +------------------ chain/src/txhashset/rewindable_kernel_view.rs | 12 --------- core/src/core/pmmr/backend.rs | 7 ------ core/src/core/pmmr/vec_backend.rs | 5 ---- p2p/src/peer.rs | 9 ------- p2p/src/peers.rs | 9 ------- p2p/src/serv.rs | 8 +----- p2p/src/types.rs | 6 +---- servers/src/common/adapters.rs | 10 -------- store/src/pmmr.rs | 8 +----- store/src/types.rs | 7 ------ 11 files changed, 4 insertions(+), 102 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 35a97571e8..ec94c1bcf4 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -24,7 +24,7 @@ use crate::core::core::{ }; use crate::core::global; use crate::core::pow; -use crate::core::ser::{ProtocolVersion, Readable, StreamingReader}; +use crate::core::ser::ProtocolVersion; use crate::error::{Error, ErrorKind}; use crate::pipe; use crate::store; @@ -38,7 +38,6 @@ use crate::util::RwLock; use grin_store::Error::NotFoundErr; use std::collections::HashMap; use std::fs::{self, File}; -use std::io::Read; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; @@ -673,28 +672,6 @@ impl Chain { txhashset.merkle_proof(commit) } - /// Provides a reading view into the current kernel state. - pub fn kernel_data_read(&self) -> Result { - let txhashset = self.txhashset.read(); - txhashset::rewindable_kernel_view(&txhashset, |view, _| view.kernel_data_read()) - } - - /// Writes kernels provided to us (via a kernel data download). - /// Currently does not write these to disk and simply deserializes - /// the provided data. - /// TODO - Write this data to disk and validate the rebuilt kernel MMR. - pub fn kernel_data_write(&self, reader: &mut dyn Read) -> Result<(), Error> { - let mut count = 0; - let mut stream = StreamingReader::new(reader, ProtocolVersion::local()); - while let Ok(_kernel) = TxKernel::read(&mut stream) { - count += 1; - } - - debug!("kernel_data_write: read {} kernels", count); - - Ok(()) - } - /// Provides a reading view into the current txhashset state as well as /// the required indexes for a consumer to rewind to a consistent state /// at the provided block hash. diff --git a/chain/src/txhashset/rewindable_kernel_view.rs b/chain/src/txhashset/rewindable_kernel_view.rs index 7bfca6a9bc..96b83db7ca 100644 --- a/chain/src/txhashset/rewindable_kernel_view.rs +++ b/chain/src/txhashset/rewindable_kernel_view.rs @@ -14,8 +14,6 @@ //! Lightweight readonly view into kernel MMR for convenience. -use std::fs::File; - use crate::core::core::pmmr::RewindablePMMR; use crate::core::core::{BlockHeader, TxKernel}; use crate::error::{Error, ErrorKind}; @@ -66,14 +64,4 @@ impl<'a> RewindableKernelView<'a> { } Ok(()) } - - /// Read the "raw" kernel backend data file (via temp file for consistent view on data). - pub fn kernel_data_read(&self) -> Result { - let file = self - .pmmr - .backend() - .data_as_temp_file() - .map_err(|_| ErrorKind::FileReadErr("Data file woes".into()))?; - Ok(file) - } } diff --git a/core/src/core/pmmr/backend.rs b/core/src/core/pmmr/backend.rs index 89c56d5674..5159c42775 100644 --- a/core/src/core/pmmr/backend.rs +++ b/core/src/core/pmmr/backend.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::fs::File; - use croaring::Bitmap; use crate::core::hash::Hash; @@ -68,11 +66,6 @@ pub trait Backend { /// triggered removal). fn remove(&mut self, position: u64) -> Result<(), String>; - /// Creates a temp file containing the contents of the underlying data file - /// from the backend storage. This allows a caller to see a consistent view - /// of the data without needing to lock the backend storage. - fn data_as_temp_file(&self) -> Result; - /// Release underlying datafiles and locks fn release_files(&mut self); diff --git a/core/src/core/pmmr/vec_backend.rs b/core/src/core/pmmr/vec_backend.rs index c3dd55c94d..fea1dbe633 100644 --- a/core/src/core/pmmr/vec_backend.rs +++ b/core/src/core/pmmr/vec_backend.rs @@ -14,7 +14,6 @@ use std::collections::HashSet; use std::convert::TryFrom; -use std::fs::File; use croaring::Bitmap; @@ -75,10 +74,6 @@ impl Backend for VecBackend { } } - fn data_as_temp_file(&self) -> Result { - unimplemented!() - } - /// Number of leaves in the MMR fn n_unpruned_leaves(&self) -> u64 { unimplemented!() diff --git a/p2p/src/peer.rs b/p2p/src/peer.rs index 416a44108d..d77da384ad 100644 --- a/p2p/src/peer.rs +++ b/p2p/src/peer.rs @@ -15,7 +15,6 @@ use crate::util::{Mutex, RwLock}; use std::fmt; use std::fs::File; -use std::io::Read; use std::net::{Shutdown, TcpStream}; use std::path::PathBuf; use std::sync::atomic::{AtomicBool, Ordering}; @@ -545,14 +544,6 @@ impl ChainAdapter for TrackingAdapter { self.adapter.get_block(h) } - fn kernel_data_read(&self) -> Result { - self.adapter.kernel_data_read() - } - - fn kernel_data_write(&self, reader: &mut dyn Read) -> Result { - self.adapter.kernel_data_write(reader) - } - fn txhashset_read(&self, h: Hash) -> Option { self.adapter.txhashset_read(h) } diff --git a/p2p/src/peers.rs b/p2p/src/peers.rs index a3727a66fe..afa0c9d08f 100644 --- a/p2p/src/peers.rs +++ b/p2p/src/peers.rs @@ -15,7 +15,6 @@ use crate::util::RwLock; use std::collections::HashMap; use std::fs::File; -use std::io::Read; use std::path::PathBuf; use std::sync::Arc; @@ -672,14 +671,6 @@ impl ChainAdapter for Peers { self.adapter.get_block(h) } - fn kernel_data_read(&self) -> Result { - self.adapter.kernel_data_read() - } - - fn kernel_data_write(&self, reader: &mut dyn Read) -> Result { - self.adapter.kernel_data_write(reader) - } - fn txhashset_read(&self, h: Hash) -> Option { self.adapter.txhashset_read(h) } diff --git a/p2p/src/serv.rs b/p2p/src/serv.rs index 8590f8a101..aab5b35692 100644 --- a/p2p/src/serv.rs +++ b/p2p/src/serv.rs @@ -13,7 +13,7 @@ // limitations under the License. use std::fs::File; -use std::io::{self, Read}; +use std::io; use std::net::{IpAddr, Shutdown, SocketAddr, SocketAddrV4, TcpListener, TcpStream}; use std::path::PathBuf; use std::sync::Arc; @@ -338,12 +338,6 @@ impl ChainAdapter for DummyAdapter { fn get_block(&self, _: Hash) -> Option { None } - fn kernel_data_read(&self) -> Result { - unimplemented!() - } - fn kernel_data_write(&self, _reader: &mut dyn Read) -> Result { - unimplemented!() - } fn txhashset_read(&self, _h: Hash) -> Option { unimplemented!() } diff --git a/p2p/src/types.rs b/p2p/src/types.rs index 24066f6d3d..c4b8cbd0fc 100644 --- a/p2p/src/types.rs +++ b/p2p/src/types.rs @@ -15,7 +15,7 @@ use std::convert::From; use std::fmt; use std::fs::File; -use std::io::{self, Read}; +use std::io; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs}; use std::path::PathBuf; use std::str::FromStr; @@ -601,10 +601,6 @@ pub trait ChainAdapter: Sync + Send { /// Gets a full block by its hash. fn get_block(&self, h: Hash) -> Option; - fn kernel_data_read(&self) -> Result; - - fn kernel_data_write(&self, reader: &mut dyn Read) -> Result; - /// Provides a reading view into the current txhashset state as well as /// the required indexes for a consumer to rewind to a consistant state /// at the provided block hash. diff --git a/servers/src/common/adapters.rs b/servers/src/common/adapters.rs index a5d0c81839..a0ec9b6d7d 100644 --- a/servers/src/common/adapters.rs +++ b/servers/src/common/adapters.rs @@ -17,7 +17,6 @@ use crate::util::RwLock; use std::fs::File; -use std::io::Read; use std::path::PathBuf; use std::sync::{Arc, Weak}; use std::thread; @@ -364,15 +363,6 @@ where } } - fn kernel_data_read(&self) -> Result { - self.chain().kernel_data_read() - } - - fn kernel_data_write(&self, reader: &mut dyn Read) -> Result { - self.chain().kernel_data_write(reader)?; - Ok(true) - } - /// Provides a reading view into the current txhashset state as well as /// the required indexes for a consumer to rewind to a consistent state /// at the provided block hash. diff --git a/store/src/pmmr.rs b/store/src/pmmr.rs index b1748fc037..84ce07b5a5 100644 --- a/store/src/pmmr.rs +++ b/store/src/pmmr.rs @@ -13,7 +13,7 @@ //! Implementation of the persistent Backend for the prunable MMR tree. -use std::fs::{self, File}; +use std::fs; use std::{io, time}; use crate::core::core::hash::{Hash, Hashed}; @@ -171,12 +171,6 @@ impl Backend for PMMRBackend { } } - fn data_as_temp_file(&self) -> Result { - self.data_file - .as_temp_file() - .map_err(|_| "Failed to build temp data file".to_string()) - } - /// Rewind the PMMR backend to the given position. fn rewind(&mut self, position: u64, rewind_rm_pos: &Bitmap) -> Result<(), String> { // First rewind the leaf_set with the necessary added and removed positions. diff --git a/store/src/types.rs b/store/src/types.rs index 0b2c7a633d..7dddff1e02 100644 --- a/store/src/types.rs +++ b/store/src/types.rs @@ -140,13 +140,6 @@ where self.file.path() } - /// Create a new tempfile containing the contents of this data file. - /// This allows callers to see a consistent view of the data without - /// locking the data file. - pub fn as_temp_file(&self) -> io::Result { - self.file.as_temp_file() - } - /// Drop underlying file handles pub fn release(&mut self) { self.file.release();