Purging .derefs, fixing clippy warnings. (#1890)

* Fixing clippy warnings

* Purging derefs

* Simplifying engine derefs

* Simplifying more engine derefs
This commit is contained in:
Tomasz Drwięga
2016-08-10 16:29:40 +02:00
committed by Arkadiy Paronyan
parent 8018b69440
commit a427208f79
42 changed files with 160 additions and 182 deletions

View File

@@ -64,9 +64,9 @@ impl From<::std::io::Error> for Error {
}
}
impl From<Box<TrieError>> for Error {
fn from(err: Box<TrieError>) -> Self {
Error::Trie(*err)
impl From<TrieError> for Error {
fn from(err: TrieError) -> Self {
Error::Trie(err)
}
}
@@ -74,4 +74,10 @@ impl From<DecoderError> for Error {
fn from(err: DecoderError) -> Self {
Error::Decoder(err)
}
}
}
impl<E> From<Box<E>> for Error where Error: From<E> {
fn from(err: Box<E>) -> Self {
Error::from(*err)
}
}

View File

@@ -61,7 +61,7 @@ const PREFERRED_CHUNK_SIZE: usize = 4 * 1024 * 1024;
const SNAPSHOT_BLOCKS: u64 = 30000;
/// A progress indicator for snapshots.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Progress {
accounts: AtomicUsize,
blocks: AtomicUsize,
@@ -70,16 +70,6 @@ pub struct Progress {
}
impl Progress {
/// Create a new progress indicator.
pub fn new() -> Self {
Progress {
accounts: AtomicUsize::new(0),
blocks: AtomicUsize::new(0),
size: AtomicUsize::new(0),
done: AtomicBool::new(false),
}
}
/// Get the number of accounts snapshotted thus far.
pub fn accounts(&self) -> usize { self.accounts.load(Ordering::Relaxed) }
@@ -510,12 +500,12 @@ fn rebuild_account_trie(db: &mut HashDB, account_chunk: &[&[u8]], out_chunk: &mu
Ok(())
}
/// Proportion of blocks which we will verify PoW for.
/// Proportion of blocks which we will verify `PoW` for.
const POW_VERIFY_RATE: f32 = 0.02;
/// Rebuilds the blockchain from chunks.
///
/// Does basic verification for all blocks, but PoW verification for some.
/// Does basic verification for all blocks, but `PoW` verification for some.
/// Blocks must be fed in-order.
///
/// The first block in every chunk is disconnected from the last block in the

View File

@@ -101,7 +101,7 @@ impl Restoration {
fn new(manifest: &ManifestData, pruning: Algorithm, path: &Path, gb: &[u8]) -> Result<Self, Error> {
let cfg = DatabaseConfig::with_columns(::client::DB_NO_OF_COLUMNS);
let raw_db = Arc::new(try!(Database::open(&cfg, &*path.to_string_lossy())
.map_err(|s| UtilError::SimpleString(s))));
.map_err(UtilError::SimpleString)));
let chain = BlockChain::new(Default::default(), gb, raw_db.clone());
let blocks = try!(BlockRebuilder::new(chain, manifest.block_number));
@@ -207,23 +207,17 @@ impl Service {
};
// create the snapshot dir if it doesn't exist.
match fs::create_dir_all(service.snapshot_dir()) {
Err(e) => {
if e.kind() != ErrorKind::AlreadyExists {
return Err(e.into())
}
if let Err(e) = fs::create_dir_all(service.snapshot_dir()) {
if e.kind() != ErrorKind::AlreadyExists {
return Err(e.into())
}
_ => {}
}
// delete the temporary restoration dir if it does exist.
match fs::remove_dir_all(service.restoration_dir()) {
Err(e) => {
if e.kind() != ErrorKind::NotFound {
return Err(e.into())
}
if let Err(e) = fs::remove_dir_all(service.restoration_dir()) {
if e.kind() != ErrorKind::NotFound {
return Err(e.into())
}
_ => {}
}
Ok(service)
@@ -434,4 +428,4 @@ impl SnapshotService for Service {
self.io_channel.send(ClientIoMessage::FeedBlockChunk(hash, chunk))
.expect("snapshot service and io service are kept alive by client service; qed");
}
}
}

View File

@@ -55,7 +55,7 @@ fn chunk_and_restore(amount: u64) {
// snapshot it.
let writer = Mutex::new(PackedWriter::new(&snapshot_path).unwrap());
let block_hashes = chunk_blocks(&bc, (amount, best_hash), &writer, &Progress::new()).unwrap();
let block_hashes = chunk_blocks(&bc, (amount, best_hash), &writer, &Progress::default()).unwrap();
writer.into_inner().finish(::snapshot::ManifestData {
state_hashes: Vec::new(),
block_hashes: block_hashes,
@@ -88,4 +88,4 @@ fn chunk_and_restore(amount: u64) {
fn chunk_and_restore_500() { chunk_and_restore(500) }
#[test]
fn chunk_and_restore_40k() { chunk_and_restore(40000) }
fn chunk_and_restore_40k() { chunk_and_restore(40000) }

View File

@@ -116,7 +116,7 @@ pub fn fill_storage(mut db: AccountDBMut, root: &mut H256, seed: &mut H256) {
pub fn compare_dbs(one: &HashDB, two: &HashDB) {
let keys = one.keys();
for (key, _) in keys {
for key in keys.keys() {
assert_eq!(one.get(&key).unwrap(), two.get(&key).unwrap());
}
}
}

View File

@@ -48,7 +48,7 @@ fn snap_and_restore() {
let state_root = producer.state_root();
let writer = Mutex::new(PackedWriter::new(&snap_file).unwrap());
let state_hashes = chunk_state(&old_db, &state_root, &writer, &Progress::new()).unwrap();
let state_hashes = chunk_state(&old_db, &state_root, &writer, &Progress::default()).unwrap();
writer.into_inner().finish(::snapshot::ManifestData {
state_hashes: state_hashes,
@@ -79,4 +79,4 @@ fn snap_and_restore() {
let new_db = journaldb::new(db, Algorithm::Archive, ::client::DB_COL_STATE);
compare_dbs(&old_db, new_db.as_hashdb());
}
}