cleanup old unused code (#3355)

This commit is contained in:
Antioch Peverell 2020-06-15 15:05:47 +01:00 committed by GitHub
parent dd88d28a7a
commit 55a929e214
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 4 additions and 102 deletions

View file

@ -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<File, Error> {
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.

View file

@ -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<File, Error> {
let file = self
.pmmr
.backend()
.data_as_temp_file()
.map_err(|_| ErrorKind::FileReadErr("Data file woes".into()))?;
Ok(file)
}
}

View file

@ -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<T: PMMRable> {
/// 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<File, String>;
/// Release underlying datafiles and locks
fn release_files(&mut self);

View file

@ -14,7 +14,6 @@
use std::collections::HashSet;
use std::convert::TryFrom;
use std::fs::File;
use croaring::Bitmap;
@ -75,10 +74,6 @@ impl<T: PMMRable> Backend<T> for VecBackend<T> {
}
}
fn data_as_temp_file(&self) -> Result<File, String> {
unimplemented!()
}
/// Number of leaves in the MMR
fn n_unpruned_leaves(&self) -> u64 {
unimplemented!()

View file

@ -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<File, chain::Error> {
self.adapter.kernel_data_read()
}
fn kernel_data_write(&self, reader: &mut dyn Read) -> Result<bool, chain::Error> {
self.adapter.kernel_data_write(reader)
}
fn txhashset_read(&self, h: Hash) -> Option<TxHashSetRead> {
self.adapter.txhashset_read(h)
}

View file

@ -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<File, chain::Error> {
self.adapter.kernel_data_read()
}
fn kernel_data_write(&self, reader: &mut dyn Read) -> Result<bool, chain::Error> {
self.adapter.kernel_data_write(reader)
}
fn txhashset_read(&self, h: Hash) -> Option<TxHashSetRead> {
self.adapter.txhashset_read(h)
}

View file

@ -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<core::Block> {
None
}
fn kernel_data_read(&self) -> Result<File, chain::Error> {
unimplemented!()
}
fn kernel_data_write(&self, _reader: &mut dyn Read) -> Result<bool, chain::Error> {
unimplemented!()
}
fn txhashset_read(&self, _h: Hash) -> Option<TxHashSetRead> {
unimplemented!()
}

View file

@ -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<core::Block>;
fn kernel_data_read(&self) -> Result<File, chain::Error>;
fn kernel_data_write(&self, reader: &mut dyn Read) -> Result<bool, chain::Error>;
/// 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.

View file

@ -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<File, chain::Error> {
self.chain().kernel_data_read()
}
fn kernel_data_write(&self, reader: &mut dyn Read) -> Result<bool, chain::Error> {
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.

View file

@ -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<T: PMMRable> Backend<T> for PMMRBackend<T> {
}
}
fn data_as_temp_file(&self) -> Result<File, String> {
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.

View file

@ -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<File> {
self.file.as_temp_file()
}
/// Drop underlying file handles
pub fn release(&mut self) {
self.file.release();