Skip to content

Commit

Permalink
cleanup old unused code (#3355)
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp authored Jun 15, 2020
1 parent dd88d28 commit 55a929e
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 102 deletions.
25 changes: 1 addition & 24 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 0 additions & 12 deletions chain/src/txhashset/rewindable_kernel_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
}
}
7 changes: 0 additions & 7 deletions core/src/core/pmmr/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 0 additions & 5 deletions core/src/core/pmmr/vec_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use std::collections::HashSet;
use std::convert::TryFrom;
use std::fs::File;

use croaring::Bitmap;

Expand Down Expand Up @@ -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!()
Expand Down
9 changes: 0 additions & 9 deletions p2p/src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 0 additions & 9 deletions p2p/src/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 1 addition & 7 deletions p2p/src/serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!()
}
Expand Down
6 changes: 1 addition & 5 deletions p2p/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 0 additions & 10 deletions servers/src/common/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 1 addition & 7 deletions store/src/pmmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 0 additions & 7 deletions store/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 55a929e

Please sign in to comment.