From a427208f795203fb14c6cce79ef09406cdb892ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 10 Aug 2016 16:29:40 +0200 Subject: [PATCH] Purging .derefs, fixing clippy warnings. (#1890) * Fixing clippy warnings * Purging derefs * Simplifying engine derefs * Simplifying more engine derefs --- ethcore/src/block.rs | 21 ++++++++-------- ethcore/src/client/test_client.rs | 8 +++--- ethcore/src/engines/basic_authority.rs | 6 ++--- ethcore/src/engines/instant_seal.rs | 6 ++--- ethcore/src/ethereum/ethash.rs | 8 +++--- ethcore/src/json_tests/state.rs | 2 +- ethcore/src/lib.rs | 2 ++ ethcore/src/miner/transaction_queue.rs | 6 ++--- ethcore/src/snapshot/error.rs | 14 ++++++++--- ethcore/src/snapshot/mod.rs | 16 +++--------- ethcore/src/snapshot/service.rs | 22 ++++++---------- ethcore/src/snapshot/tests/blocks.rs | 4 +-- ethcore/src/snapshot/tests/helpers.rs | 4 +-- ethcore/src/snapshot/tests/state.rs | 4 +-- ethcore/src/state.rs | 22 ++++++++-------- ethcore/src/tests/helpers.rs | 6 ++--- ethcore/src/trace/db.rs | 8 +++--- ethcore/src/verification/verification.rs | 32 ++++++++++++------------ ethkey/src/signature.rs | 2 +- ethstore/src/account/safe_account.rs | 5 ++-- ethstore/src/bin/ethstore.rs | 2 +- parity/informant.rs | 9 +++---- parity/snapshot.rs | 8 +++--- rpc/src/v1/impls/eth.rs | 17 ++++++------- rpc/src/v1/impls/eth_filter.rs | 5 ++-- rpc/src/v1/impls/ethcore.rs | 3 +-- sync/src/api.rs | 17 ++++++------- sync/src/chain.rs | 10 ++++---- sync/src/tests/chain.rs | 15 +++++------ util/bigint/src/hash.rs | 4 +-- util/io/src/panics.rs | 3 +-- util/network/src/host.rs | 2 +- util/network/src/tests.rs | 2 +- util/src/journaldb/archivedb.rs | 2 +- util/src/journaldb/earlymergedb.rs | 2 +- util/src/journaldb/overlayrecentdb.rs | 8 +++--- util/src/journaldb/refcounteddb.rs | 2 +- util/src/kvdb.rs | 13 +++++----- util/src/overlaydb.rs | 7 +++--- util/src/rlp/rlpstream.rs | 6 ++--- util/src/rlp/rlptraits.rs | 5 ++-- util/src/trie/triedb.rs | 2 +- 42 files changed, 160 insertions(+), 182 deletions(-) diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index d2477b489..e87e5e450 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -582,23 +582,22 @@ mod tests { fn open_block() { use spec::*; let spec = Spec::new_test(); - let engine = &spec.engine; let genesis_header = spec.genesis_header(); let mut db_result = get_temp_journal_db(); let mut db = db_result.take(); spec.ensure_db_good(db.as_hashdb_mut()).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let vm_factory = Default::default(); - let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); + let b = OpenBlock::new(&*spec.engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let b = b.close_and_lock(); - let _ = b.seal(engine.deref(), vec![]); + let _ = b.seal(&*spec.engine, vec![]); } #[test] fn enact_block() { use spec::*; let spec = Spec::new_test(); - let engine = &spec.engine; + let engine = &*spec.engine; let genesis_header = spec.genesis_header(); let mut db_result = get_temp_journal_db(); @@ -606,15 +605,15 @@ mod tests { spec.ensure_db_good(db.as_hashdb_mut()).unwrap(); let vm_factory = Default::default(); let last_hashes = Arc::new(vec![genesis_header.hash()]); - let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes.clone(), Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap() - .close_and_lock().seal(engine.deref(), vec![]).unwrap(); + let b = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes.clone(), Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap() + .close_and_lock().seal(engine, vec![]).unwrap(); let orig_bytes = b.rlp_bytes(); let orig_db = b.drain(); let mut db_result = get_temp_journal_db(); let mut db = db_result.take(); spec.ensure_db_good(db.as_hashdb_mut()).unwrap(); - let e = enact_and_seal(&orig_bytes, engine.deref(), false, db, &genesis_header, last_hashes, &Default::default(), Default::default()).unwrap(); + let e = enact_and_seal(&orig_bytes, engine, false, db, &genesis_header, last_hashes, &Default::default(), Default::default()).unwrap(); assert_eq!(e.rlp_bytes(), orig_bytes); @@ -627,7 +626,7 @@ mod tests { fn enact_block_with_uncle() { use spec::*; let spec = Spec::new_test(); - let engine = &spec.engine; + let engine = &*spec.engine; let genesis_header = spec.genesis_header(); let mut db_result = get_temp_journal_db(); @@ -635,14 +634,14 @@ mod tests { spec.ensure_db_good(db.as_hashdb_mut()).unwrap(); let vm_factory = Default::default(); let last_hashes = Arc::new(vec![genesis_header.hash()]); - let mut open_block = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes.clone(), Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); + let mut open_block = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes.clone(), Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let mut uncle1_header = Header::new(); uncle1_header.extra_data = b"uncle1".to_vec(); let mut uncle2_header = Header::new(); uncle2_header.extra_data = b"uncle2".to_vec(); open_block.push_uncle(uncle1_header).unwrap(); open_block.push_uncle(uncle2_header).unwrap(); - let b = open_block.close_and_lock().seal(engine.deref(), vec![]).unwrap(); + let b = open_block.close_and_lock().seal(engine, vec![]).unwrap(); let orig_bytes = b.rlp_bytes(); let orig_db = b.drain(); @@ -650,7 +649,7 @@ mod tests { let mut db_result = get_temp_journal_db(); let mut db = db_result.take(); spec.ensure_db_good(db.as_hashdb_mut()).unwrap(); - let e = enact_and_seal(&orig_bytes, engine.deref(), false, db, &genesis_header, last_hashes, &Default::default(), Default::default()).unwrap(); + let e = enact_and_seal(&orig_bytes, engine, false, db, &genesis_header, last_hashes, &Default::default(), Default::default()).unwrap(); let bytes = e.rlp_bytes(); assert_eq!(bytes, orig_bytes); diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index eedbe4a5b..b4e0d8a90 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -258,7 +258,7 @@ pub fn get_temp_journal_db() -> GuardedTempResult> { impl MiningBlockChainClient for TestBlockChainClient { fn prepare_open_block(&self, author: Address, gas_range_target: (U256, U256), extra_data: Bytes) -> OpenBlock { - let engine = &self.spec.engine; + let engine = &*self.spec.engine; let genesis_header = self.spec.genesis_header(); let mut db_result = get_temp_journal_db(); let mut db = db_result.take(); @@ -266,7 +266,7 @@ impl MiningBlockChainClient for TestBlockChainClient { let last_hashes = vec![genesis_header.hash()]; let mut open_block = OpenBlock::new( - engine.deref(), + engine, self.vm_factory(), Default::default(), false, @@ -482,9 +482,9 @@ impl BlockChainClient for TestBlockChainClient { if number == len { { let mut difficulty = self.difficulty.write(); - *difficulty.deref_mut() = *difficulty.deref() + header.difficulty; + *difficulty = *difficulty + header.difficulty; } - mem::replace(self.last_hash.write().deref_mut(), h.clone()); + mem::replace(&mut *self.last_hash.write(), h.clone()); self.blocks.write().insert(h.clone(), b); self.numbers.write().insert(number, h.clone()); let mut parent_hash = header.parent_hash; diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index 2545340f1..6bdacd22d 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -246,16 +246,16 @@ mod tests { tap.unlock_account_permanently(addr, "".into()).unwrap(); let spec = new_test_authority(); - let engine = &spec.engine; + let engine = &*spec.engine; let genesis_header = spec.genesis_header(); let mut db_result = get_temp_journal_db(); let mut db = db_result.take(); spec.ensure_db_good(db.as_hashdb_mut()).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let vm_factory = Default::default(); - let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, addr, (3141562.into(), 31415620.into()), vec![]).unwrap(); + let b = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, addr, (3141562.into(), 31415620.into()), vec![]).unwrap(); let b = b.close_and_lock(); let seal = engine.generate_seal(b.block(), Some(&tap)).unwrap(); - assert!(b.try_seal(engine.deref(), seal).is_ok()); + assert!(b.try_seal(engine, seal).is_ok()); } } diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index 85d699241..c924257bb 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -80,18 +80,18 @@ mod tests { let addr = tap.insert_account("".sha3(), "").unwrap(); let spec = new_test_instant(); - let engine = &spec.engine; + let engine = &*spec.engine; let genesis_header = spec.genesis_header(); let mut db_result = get_temp_journal_db(); let mut db = db_result.take(); spec.ensure_db_good(db.as_hashdb_mut()).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let vm_factory = Default::default(); - let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, addr, (3141562.into(), 31415620.into()), vec![]).unwrap(); + let b = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, addr, (3141562.into(), 31415620.into()), vec![]).unwrap(); let b = b.close_and_lock(); // Seal with empty AccountProvider. let seal = engine.generate_seal(b.block(), Some(&tap)).unwrap(); - assert!(b.try_seal(engine.deref(), seal).is_ok()); + assert!(b.try_seal(engine, seal).is_ok()); } #[test] diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 764a74bfe..07f330cb7 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -350,14 +350,14 @@ mod tests { #[test] fn on_close_block() { let spec = new_morden(); - let engine = &spec.engine; + let engine = &*spec.engine; let genesis_header = spec.genesis_header(); let mut db_result = get_temp_journal_db(); let mut db = db_result.take(); spec.ensure_db_good(db.as_hashdb_mut()).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let vm_factory = Default::default(); - let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); + let b = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let b = b.close(); assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap()); } @@ -365,14 +365,14 @@ mod tests { #[test] fn on_close_block_with_uncle() { let spec = new_morden(); - let engine = &spec.engine; + let engine = &*spec.engine; let genesis_header = spec.genesis_header(); let mut db_result = get_temp_journal_db(); let mut db = db_result.take(); spec.ensure_db_good(db.as_hashdb_mut()).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let vm_factory = Default::default(); - let mut b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); + let mut b = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let mut uncle = Header::new(); let uncle_author: Address = "ef2d6d194084c2de36e0dabfce45d046b37d1106".into(); uncle.author = uncle_author.clone(); diff --git a/ethcore/src/json_tests/state.rs b/ethcore/src/json_tests/state.rs index 4252c9f30..97f9f70f0 100644 --- a/ethcore/src/json_tests/state.rs +++ b/ethcore/src/json_tests/state.rs @@ -65,7 +65,7 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec { state.commit() .expect(&format!("State test {} failed due to internal error.", name)); let vm_factory = Default::default(); - let res = state.apply(&env, engine.deref(), &vm_factory, &transaction, false); + let res = state.apply(&env, &*engine, &vm_factory, &transaction, false); if fail_unless(state.root() == &post_state_root) { println!("!!! {}: State mismatch (got: {}, expect: {}):", name, state.root(), post_state_root); diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 875abb804..6879ff551 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -26,6 +26,8 @@ #![cfg_attr(feature="dev", allow(match_bool))] // Keeps consistency (all lines with `.clone()`). #![cfg_attr(feature="dev", allow(clone_on_copy))] +// Complains on Box when implementing From> +#![cfg_attr(feature="dev", allow(boxed_local))] // TODO [todr] a lot of warnings to be fixed #![cfg_attr(feature="dev", allow(assign_op_pattern))] diff --git a/ethcore/src/miner/transaction_queue.rs b/ethcore/src/miner/transaction_queue.rs index 6a88b4388..9d3a85995 100644 --- a/ethcore/src/miner/transaction_queue.rs +++ b/ethcore/src/miner/transaction_queue.rs @@ -1464,7 +1464,7 @@ mod test { let keypair = KeyPair::create().unwrap(); let tx = new_unsigned_tx(U256::from(123)).sign(keypair.secret()); let tx2 = { - let mut tx2 = tx.deref().clone(); + let mut tx2 = (*tx).clone(); tx2.gas_price = U256::from(200); tx2.sign(keypair.secret()) }; @@ -1487,12 +1487,12 @@ mod test { let keypair = KeyPair::create().unwrap(); let tx0 = new_unsigned_tx(U256::from(123)).sign(keypair.secret()); let tx1 = { - let mut tx1 = tx0.deref().clone(); + let mut tx1 = (*tx0).clone(); tx1.nonce = U256::from(124); tx1.sign(keypair.secret()) }; let tx2 = { - let mut tx2 = tx1.deref().clone(); + let mut tx2 = (*tx1).clone(); tx2.gas_price = U256::from(200); tx2.sign(keypair.secret()) }; diff --git a/ethcore/src/snapshot/error.rs b/ethcore/src/snapshot/error.rs index be4ed39d2..d41d7cd2f 100644 --- a/ethcore/src/snapshot/error.rs +++ b/ethcore/src/snapshot/error.rs @@ -64,9 +64,9 @@ impl From<::std::io::Error> for Error { } } -impl From> for Error { - fn from(err: Box) -> Self { - Error::Trie(*err) +impl From for Error { + fn from(err: TrieError) -> Self { + Error::Trie(err) } } @@ -74,4 +74,10 @@ impl From for Error { fn from(err: DecoderError) -> Self { Error::Decoder(err) } -} \ No newline at end of file +} + +impl From> for Error where Error: From { + fn from(err: Box) -> Self { + Error::from(*err) + } +} diff --git a/ethcore/src/snapshot/mod.rs b/ethcore/src/snapshot/mod.rs index 9dbbf1d9a..3be35d8d8 100644 --- a/ethcore/src/snapshot/mod.rs +++ b/ethcore/src/snapshot/mod.rs @@ -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 diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index dafce75cf..c3aa57faa 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -101,7 +101,7 @@ impl Restoration { fn new(manifest: &ManifestData, pruning: Algorithm, path: &Path, gb: &[u8]) -> Result { 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"); } -} \ No newline at end of file +} diff --git a/ethcore/src/snapshot/tests/blocks.rs b/ethcore/src/snapshot/tests/blocks.rs index 97fa08e54..7c88d9e83 100644 --- a/ethcore/src/snapshot/tests/blocks.rs +++ b/ethcore/src/snapshot/tests/blocks.rs @@ -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) } \ No newline at end of file +fn chunk_and_restore_40k() { chunk_and_restore(40000) } diff --git a/ethcore/src/snapshot/tests/helpers.rs b/ethcore/src/snapshot/tests/helpers.rs index 20fd4ae03..aa0fc3ae5 100644 --- a/ethcore/src/snapshot/tests/helpers.rs +++ b/ethcore/src/snapshot/tests/helpers.rs @@ -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()); } -} \ No newline at end of file +} diff --git a/ethcore/src/snapshot/tests/state.rs b/ethcore/src/snapshot/tests/state.rs index 9d87899db..c5d60cb03 100644 --- a/ethcore/src/snapshot/tests/state.rs +++ b/ethcore/src/snapshot/tests/state.rs @@ -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()); -} \ No newline at end of file +} diff --git a/ethcore/src/state.rs b/ethcore/src/state.rs index 60acbabc4..589e80c13 100644 --- a/ethcore/src/state.rs +++ b/ethcore/src/state.rs @@ -347,7 +347,7 @@ impl State { let have_key = self.cache.borrow().contains_key(a); if !have_key { let db = self.trie_factory.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR); - let maybe_acc = match db.get(&a) { + let maybe_acc = match db.get(a) { Ok(acc) => acc.map(Account::from_rlp), Err(e) => panic!("Potential DB corruption encountered: {}", e), }; @@ -375,7 +375,7 @@ impl State { let contains_key = self.cache.borrow().contains_key(a); if !contains_key { let db = self.trie_factory.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR); - let maybe_acc = match db.get(&a) { + let maybe_acc = match db.get(a) { Ok(acc) => acc.map(Account::from_rlp), Err(e) => panic!("Potential DB corruption encountered: {}", e), }; @@ -630,7 +630,7 @@ fn should_trace_call_transaction_to_builtin() { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); - let engine = Spec::new_test().engine; + let engine = &*Spec::new_test().engine; let t = Transaction { nonce: 0.into(), @@ -642,7 +642,7 @@ fn should_trace_call_transaction_to_builtin() { }.sign(&"".sha3()); let vm_factory = Default::default(); - let result = state.apply(&info, engine.deref(), &vm_factory, &t, true).unwrap(); + let result = state.apply(&info, engine, &vm_factory, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), @@ -673,7 +673,7 @@ fn should_not_trace_subcall_transaction_to_builtin() { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); - let engine = Spec::new_test().engine; + let engine = &*Spec::new_test().engine; let t = Transaction { nonce: 0.into(), @@ -686,7 +686,7 @@ fn should_not_trace_subcall_transaction_to_builtin() { state.init_code(&0xa.into(), FromHex::from_hex("600060006000600060006001610be0f1").unwrap()); let vm_factory = Default::default(); - let result = state.apply(&info, engine.deref(), &vm_factory, &t, true).unwrap(); + let result = state.apply(&info, engine, &vm_factory, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), @@ -717,7 +717,7 @@ fn should_not_trace_callcode() { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); - let engine = Spec::new_test().engine; + let engine = &*Spec::new_test().engine; let t = Transaction { nonce: 0.into(), @@ -731,7 +731,7 @@ fn should_not_trace_callcode() { state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b611000f2").unwrap()); state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap()); let vm_factory = Default::default(); - let result = state.apply(&info, engine.deref(), &vm_factory, &t, true).unwrap(); + let result = state.apply(&info, engine, &vm_factory, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), @@ -778,7 +778,7 @@ fn should_not_trace_delegatecall() { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); info.number = 0x789b0; - let engine = Spec::new_test().engine; + let engine = &*Spec::new_test().engine; println!("schedule.have_delegate_call: {:?}", engine.schedule(&info).have_delegate_call); @@ -794,7 +794,7 @@ fn should_not_trace_delegatecall() { state.init_code(&0xa.into(), FromHex::from_hex("6000600060006000600b618000f4").unwrap()); state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap()); let vm_factory = Default::default(); - let result = state.apply(&info, engine.deref(), &vm_factory, &t, true).unwrap(); + let result = state.apply(&info, engine, &vm_factory, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), @@ -1489,4 +1489,4 @@ fn create_empty() { assert_eq!(state.root().hex(), "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); } -} \ No newline at end of file +} diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index 4dc4f953d..87250d2af 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -134,7 +134,7 @@ pub fn generate_dummy_client_with_spec_and_data(get_test_spec: F, block_numbe let test_spec = get_test_spec(); let client = Client::new(ClientConfig::default(), &test_spec, dir.as_path(), Arc::new(Miner::with_spec(&test_spec)), IoChannel::disconnected()).unwrap(); - let test_engine = &test_spec.engine; + let test_engine = &*test_spec.engine; let mut db_result = get_temp_journal_db(); let mut db = db_result.take(); @@ -155,7 +155,7 @@ pub fn generate_dummy_client_with_spec_and_data(get_test_spec: F, block_numbe // forge block. let mut b = OpenBlock::new( - test_engine.deref(), + test_engine, &vm_factory, Default::default(), false, @@ -183,7 +183,7 @@ pub fn generate_dummy_client_with_spec_and_data(get_test_spec: F, block_numbe n += 1; } - let b = b.close_and_lock().seal(test_engine.deref(), vec![]).unwrap(); + let b = b.close_and_lock().seal(test_engine, vec![]).unwrap(); if let Err(e) = client.import_block(b.rlp_bytes()) { panic!("error importing block which is valid by definition: {:?}", e); diff --git a/ethcore/src/trace/db.rs b/ethcore/src/trace/db.rs index 3eb3ea125..cd34e73c2 100644 --- a/ethcore/src/trace/db.rs +++ b/ethcore/src/trace/db.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . //! Trace database. -use std::ops::{Deref, DerefMut}; +use std::ops::Deref; use std::collections::HashMap; use std::sync::Arc; use bloomchain::{Number, Config as BloomConfig}; @@ -273,8 +273,7 @@ impl TraceDatabase for TraceDB where T: DatabaseExtras { let mut traces = self.traces.write(); // it's important to use overwrite here, // cause this value might be queried by hash later - batch.write_with_cache(DB_COL_TRACE, traces.deref_mut(), request.block_hash, request.traces, CacheUpdatePolicy::Overwrite); - + batch.write_with_cache(DB_COL_TRACE, &mut *traces, request.block_hash, request.traces, CacheUpdatePolicy::Overwrite); // note_used must be called after locking traces to avoid cache/traces deadlock on garbage collection self.note_used(CacheID::Trace(request.block_hash.clone())); } @@ -303,8 +302,7 @@ impl TraceDatabase for TraceDB where T: DatabaseExtras { let blooms_keys: Vec<_> = blooms_to_insert.keys().cloned().collect(); let mut blooms = self.blooms.write(); - batch.extend_with_cache(DB_COL_TRACE, blooms.deref_mut(), blooms_to_insert, CacheUpdatePolicy::Remove); - + batch.extend_with_cache(DB_COL_TRACE, &mut *blooms, blooms_to_insert, CacheUpdatePolicy::Remove); // note_used must be called after locking blooms to avoid cache/traces deadlock on garbage collection for key in blooms_keys.into_iter() { self.note_used(CacheID::Bloom(key)); diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index 851a702a9..078bb72ae 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -344,7 +344,7 @@ mod tests { // Test against morden let mut good = Header::new(); let spec = Spec::new_test(); - let engine = &spec.engine; + let engine = &*spec.engine; let min_gas_limit = engine.params().min_gas_limit; good.gas_limit = min_gas_limit; @@ -425,69 +425,69 @@ mod tests { bc.insert(create_test_block(&parent7)); bc.insert(create_test_block(&parent8)); - check_ok(basic_test(&create_test_block(&good), engine.deref())); + check_ok(basic_test(&create_test_block(&good), engine)); let mut header = good.clone(); header.transactions_root = good_transactions_root.clone(); header.uncles_hash = good_uncles_hash.clone(); - check_ok(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref())); + check_ok(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine)); header.gas_limit = min_gas_limit - From::from(1); - check_fail(basic_test(&create_test_block(&header), engine.deref()), + check_fail(basic_test(&create_test_block(&header), engine), InvalidGasLimit(OutOfBounds { min: Some(min_gas_limit), max: None, found: header.gas_limit })); header = good.clone(); header.number = BlockNumber::max_value(); - check_fail(basic_test(&create_test_block(&header), engine.deref()), + check_fail(basic_test(&create_test_block(&header), engine), RidiculousNumber(OutOfBounds { max: Some(BlockNumber::max_value()), min: None, found: header.number })); header = good.clone(); header.gas_used = header.gas_limit + From::from(1); - check_fail(basic_test(&create_test_block(&header), engine.deref()), + check_fail(basic_test(&create_test_block(&header), engine), TooMuchGasUsed(OutOfBounds { max: Some(header.gas_limit), min: None, found: header.gas_used })); header = good.clone(); header.extra_data.resize(engine.maximum_extra_data_size() + 1, 0u8); - check_fail(basic_test(&create_test_block(&header), engine.deref()), + check_fail(basic_test(&create_test_block(&header), engine), ExtraDataOutOfBounds(OutOfBounds { max: Some(engine.maximum_extra_data_size()), min: None, found: header.extra_data.len() })); header = good.clone(); header.extra_data.resize(engine.maximum_extra_data_size() + 1, 0u8); - check_fail(basic_test(&create_test_block(&header), engine.deref()), + check_fail(basic_test(&create_test_block(&header), engine), ExtraDataOutOfBounds(OutOfBounds { max: Some(engine.maximum_extra_data_size()), min: None, found: header.extra_data.len() })); header = good.clone(); header.uncles_hash = good_uncles_hash.clone(); - check_fail(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref()), + check_fail(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine), InvalidTransactionsRoot(Mismatch { expected: good_transactions_root.clone(), found: header.transactions_root })); header = good.clone(); header.transactions_root = good_transactions_root.clone(); - check_fail(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref()), + check_fail(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine), InvalidUnclesHash(Mismatch { expected: good_uncles_hash.clone(), found: header.uncles_hash })); - check_ok(family_test(&create_test_block(&good), engine.deref(), &bc)); - check_ok(family_test(&create_test_block_with_data(&good, &good_transactions, &good_uncles), engine.deref(), &bc)); + check_ok(family_test(&create_test_block(&good), engine, &bc)); + check_ok(family_test(&create_test_block_with_data(&good, &good_transactions, &good_uncles), engine, &bc)); header = good.clone(); header.parent_hash = H256::random(); - check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref(), &bc), + check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine, &bc), UnknownParent(header.parent_hash)); header = good.clone(); header.timestamp = 10; - check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref(), &bc), + check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine, &bc), InvalidTimestamp(OutOfBounds { max: None, min: Some(parent.timestamp + 1), found: header.timestamp })); header = good.clone(); header.number = 9; - check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref(), &bc), + check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine, &bc), InvalidNumber(Mismatch { expected: parent.number + 1, found: header.number })); header = good.clone(); let mut bad_uncles = good_uncles.clone(); bad_uncles.push(good_uncle1.clone()); - check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &bad_uncles), engine.deref(), &bc), + check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &bad_uncles), engine, &bc), TooManyUncles(OutOfBounds { max: Some(engine.maximum_uncle_count()), min: None, found: bad_uncles.len() })); // TODO: some additional uncle checks diff --git a/ethkey/src/signature.rs b/ethkey/src/signature.rs index 616db7bc9..407903a84 100644 --- a/ethkey/src/signature.rs +++ b/ethkey/src/signature.rs @@ -136,7 +136,7 @@ pub fn verify_public(public: &Public, signature: &Signature, message: &Message) let pdata: [u8; 65] = { let mut temp = [4u8; 65]; - temp[1..65].copy_from_slice(public.deref()); + temp[1..65].copy_from_slice(&**public); temp }; diff --git a/ethstore/src/account/safe_account.rs b/ethstore/src/account/safe_account.rs index ec80c9537..3b3dcf2ee 100644 --- a/ethstore/src/account/safe_account.rs +++ b/ethstore/src/account/safe_account.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::ops::{Deref, DerefMut}; use ethkey::{KeyPair, sign, Address, Secret, Signature, Message}; use {json, Error, crypto}; use crypto::Keccak256; @@ -87,7 +86,7 @@ impl Crypto { let mut ciphertext = [0u8; 32]; // aes-128-ctr with initial vector of iv - crypto::aes::encrypt(&derived_left_bits, &iv, secret.deref(), &mut ciphertext); + crypto::aes::encrypt(&derived_left_bits, &iv, &**secret, &mut ciphertext); // KECCAK(DK[16..31] ++ ), where DK[16..31] - derived_right_bits let mac = crypto::derive_mac(&derived_right_bits, &ciphertext).keccak256(); @@ -123,7 +122,7 @@ impl Crypto { match self.cipher { Cipher::Aes128Ctr(ref params) => { - crypto::aes::decrypt(&derived_left_bits, ¶ms.iv, &self.ciphertext, secret.deref_mut()) + crypto::aes::decrypt(&derived_left_bits, ¶ms.iv, &self.ciphertext, &mut *secret) }, } diff --git a/ethstore/src/bin/ethstore.rs b/ethstore/src/bin/ethstore.rs index 748480069..d3e18c0e5 100644 --- a/ethstore/src/bin/ethstore.rs +++ b/ethstore/src/bin/ethstore.rs @@ -143,7 +143,7 @@ fn execute(command: I) -> Result where I: IntoIterator8}", format!("#{}", chain_info.best_block_number))), paint(White.bold(), format!("{}", chain_info.best_block_hash)), { - let last_report = match write_report.deref() { &Some(ref last_report) => last_report.clone(), _ => ClientReport::default() }; + let last_report = match *write_report { Some(ref last_report) => last_report.clone(), _ => ClientReport::default() }; format!("{} blk/s {} tx/s {} Mgas/s", paint(Yellow.bold(), format!("{:4}", ((report.blocks_imported - last_report.blocks_imported) * 1000) as u64 / elapsed.as_milliseconds())), paint(Yellow.bold(), format!("{:4}", ((report.transactions_applied - last_report.transactions_applied) * 1000) as u64 / elapsed.as_milliseconds())), @@ -147,9 +146,9 @@ impl Informant { ) ); - *self.chain_info.write().deref_mut() = Some(chain_info); - *self.cache_info.write().deref_mut() = Some(cache_info); - *write_report.deref_mut() = Some(report); + *self.chain_info.write() = Some(chain_info); + *self.cache_info.write() = Some(cache_info); + *write_report = Some(report); } } diff --git a/parity/snapshot.rs b/parity/snapshot.rs index 70abf8fc1..2a3c12567 100644 --- a/parity/snapshot.rs +++ b/parity/snapshot.rs @@ -109,7 +109,7 @@ impl SnapshotCommand { warn!("Snapshot restoration is experimental and the format may be subject to change."); let snapshot = service.snapshot_service(); - let reader = PackedReader::new(&Path::new(&file)) + let reader = PackedReader::new(Path::new(&file)) .map_err(|e| format!("Couldn't open snapshot file: {}", e)) .and_then(|x| x.ok_or("Snapshot file has invalid format.".into())); @@ -172,7 +172,7 @@ impl SnapshotCommand { pub fn take_snapshot(self) -> Result<(), String> { let file_path = try!(self.file_path.clone().ok_or("No file path provided.".to_owned())); let file_path: PathBuf = file_path.into(); - let block_at = self.block_at.clone(); + let block_at = self.block_at; let (service, _panic_handler) = try!(self.start_service()); warn!("Snapshots are currently experimental. File formats may be subject to change."); @@ -180,7 +180,7 @@ impl SnapshotCommand { let writer = try!(PackedWriter::new(&file_path) .map_err(|e| format!("Failed to open snapshot writer: {}", e))); - let progress = Arc::new(Progress::new()); + let progress = Arc::new(Progress::default()); let p = progress.clone(); let informant_handle = ::std::thread::spawn(move || { ::std::thread::sleep(Duration::from_secs(5)); @@ -221,4 +221,4 @@ pub fn execute(cmd: SnapshotCommand) -> Result { } Ok(String::new()) -} \ No newline at end of file +} diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 734588247..7003a2c30 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -23,7 +23,6 @@ use std::process::{Command, Stdio}; use std::thread; use std::time::{Instant, Duration}; use std::sync::{Arc, Weak}; -use std::ops::Deref; use ethsync::{SyncProvider, SyncState}; use ethcore::miner::{MinerService, ExternalMinerService}; use jsonrpc_core::*; @@ -324,7 +323,7 @@ impl Eth for EthClient where .and_then(|(address, block_number,)| { let address: Address = RpcH160::into(address); match block_number { - BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).balance(take_weak!(self.client).deref(), &address))), + BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).balance(&*take_weak!(self.client), &address))), id => match take_weak!(self.client).balance(&address, id.into()) { Some(balance) => to_value(&RpcU256::from(balance)), None => Err(errors::state_pruned()), @@ -356,7 +355,7 @@ impl Eth for EthClient where .and_then(|(address, block_number,)| { let address: Address = RpcH160::into(address); match block_number { - BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).nonce(take_weak!(self.client).deref(), &address))), + BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).nonce(&*take_weak!(self.client), &address))), id => match take_weak!(self.client).nonce(&address, id.into()) { Some(nonce) => to_value(&RpcU256::from(nonce)), None => Err(errors::state_pruned()), @@ -409,7 +408,7 @@ impl Eth for EthClient where .and_then(|(address, block_number,)| { let address: Address = RpcH160::into(address); match block_number { - BlockNumber::Pending => to_value(&take_weak!(self.miner).code(take_weak!(self.client).deref(), &address).map_or_else(Bytes::default, Bytes::new)), + BlockNumber::Pending => to_value(&take_weak!(self.miner).code(&*take_weak!(self.client), &address).map_or_else(Bytes::default, Bytes::new)), _ => match take_weak!(self.client).code(&address, block_number.into()) { Some(code) => to_value(&code.map_or_else(Bytes::default, Bytes::new)), None => Err(errors::state_pruned()), @@ -507,7 +506,7 @@ impl Eth for EthClient where .collect::>(); if include_pending { - let pending = pending_logs(take_weak!(self.miner).deref(), &filter); + let pending = pending_logs(&*take_weak!(self.miner), &filter); logs.extend(pending); } @@ -541,7 +540,7 @@ impl Eth for EthClient where warn!(target: "miner", "Cannot give work package - no author is configured. Use --author to configure!"); return Err(errors::no_author()) } - miner.map_sealing_work(client.deref(), |b| { + miner.map_sealing_work(&*client, |b| { let pow_hash = b.hash(); let target = Ethash::difficulty_to_boundary(b.block().header().difficulty()); let seed_hash = self.seed_compute.lock().get_seedhash(b.block().header().number()); @@ -565,7 +564,7 @@ impl Eth for EthClient where let miner = take_weak!(self.miner); let client = take_weak!(self.client); let seal = vec![encode(&mix_hash).to_vec(), encode(&nonce).to_vec()]; - let r = miner.submit_seal(client.deref(), pow_hash, seal); + let r = miner.submit_seal(&*client, pow_hash, seal); to_value(&r.is_ok()) }) } @@ -597,7 +596,7 @@ impl Eth for EthClient where let request = CallRequest::into(request); let signed = try!(self.sign_call(request)); let r = match block_number { - BlockNumber::Pending => take_weak!(self.miner).call(take_weak!(self.client).deref(), &signed, Default::default()), + BlockNumber::Pending => take_weak!(self.miner).call(&*take_weak!(self.client), &signed, Default::default()), block_number => take_weak!(self.client).call(&signed, block_number.into(), Default::default()), }; to_value(&r.map(|e| Bytes(e.output)).unwrap_or(Bytes::new(vec![]))) @@ -611,7 +610,7 @@ impl Eth for EthClient where let request = CallRequest::into(request); let signed = try!(self.sign_call(request)); let r = match block_number { - BlockNumber::Pending => take_weak!(self.miner).call(take_weak!(self.client).deref(), &signed, Default::default()), + BlockNumber::Pending => take_weak!(self.miner).call(&*take_weak!(self.client), &signed, Default::default()), block => take_weak!(self.client).call(&signed, block.into(), Default::default()), }; to_value(&RpcU256::from(r.map(|res| res.gas_used + res.refunded).unwrap_or(From::from(0)))) diff --git a/rpc/src/v1/impls/eth_filter.rs b/rpc/src/v1/impls/eth_filter.rs index 84e3e7bee..973e23e0b 100644 --- a/rpc/src/v1/impls/eth_filter.rs +++ b/rpc/src/v1/impls/eth_filter.rs @@ -16,7 +16,6 @@ //! Eth Filter RPC implementation -use std::ops::Deref; use std::sync::{Arc, Weak}; use std::collections::HashSet; use jsonrpc_core::*; @@ -160,7 +159,7 @@ impl EthFilter for EthFilterClient where // additionally retrieve pending logs if include_pending { - let pending_logs = pending_logs(take_weak!(self.miner).deref(), &filter); + let pending_logs = pending_logs(&*take_weak!(self.miner), &filter); // remove logs about which client was already notified about let new_pending_logs: Vec<_> = pending_logs.iter() @@ -201,7 +200,7 @@ impl EthFilter for EthFilterClient where .collect::>(); if include_pending { - logs.extend(pending_logs(take_weak!(self.miner).deref(), &filter)); + logs.extend(pending_logs(&*take_weak!(self.miner), &filter)); } to_value(&logs) diff --git a/rpc/src/v1/impls/ethcore.rs b/rpc/src/v1/impls/ethcore.rs index 963869083..f5045e53c 100644 --- a/rpc/src/v1/impls/ethcore.rs +++ b/rpc/src/v1/impls/ethcore.rs @@ -18,7 +18,6 @@ use util::{RotatingLogger}; use util::misc::version_data; use std::sync::{Arc, Weak}; -use std::ops::Deref; use std::collections::{BTreeMap}; use ethcore::client::{MiningBlockChainClient}; use jsonrpc_core::*; @@ -95,7 +94,7 @@ impl Ethcore for EthcoreClient where M: MinerService + 'static, C: M try!(self.active()); try!(expect_no_params(params)); let logs = self.logger.logs(); - to_value(&logs.deref().as_slice()) + to_value(&logs.as_slice()) } fn dev_logs_levels(&self, params: Params) -> Result { diff --git a/sync/src/api.rs b/sync/src/api.rs index c3dc3bf4a..4603ac52e 100644 --- a/sync/src/api.rs +++ b/sync/src/api.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::ops::*; use std::sync::Arc; use network::{NetworkProtocolHandler, NetworkService, NetworkContext, PeerId, NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, NetworkError}; @@ -75,7 +74,7 @@ pub struct EthSync { impl EthSync { /// Creates and register protocol with the network service pub fn new(config: SyncConfig, chain: Arc, network_config: NetworkConfiguration) -> Result, NetworkError> { - let chain_sync = ChainSync::new(config, chain.deref()); + let chain_sync = ChainSync::new(config, &*chain); let service = try!(NetworkService::new(try!(network_config.into_basic()))); let sync = Arc::new(EthSync{ network: service, @@ -108,20 +107,20 @@ impl NetworkProtocolHandler for SyncProtocolHandler { } fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) { - ChainSync::dispatch_packet(&self.sync, &mut NetSyncIo::new(io, self.chain.deref()), *peer, packet_id, data); + ChainSync::dispatch_packet(&self.sync, &mut NetSyncIo::new(io, &*self.chain), *peer, packet_id, data); } fn connected(&self, io: &NetworkContext, peer: &PeerId) { - self.sync.write().on_peer_connected(&mut NetSyncIo::new(io, self.chain.deref()), *peer); + self.sync.write().on_peer_connected(&mut NetSyncIo::new(io, &*self.chain), *peer); } fn disconnected(&self, io: &NetworkContext, peer: &PeerId) { - self.sync.write().on_peer_aborting(&mut NetSyncIo::new(io, self.chain.deref()), *peer); + self.sync.write().on_peer_aborting(&mut NetSyncIo::new(io, &*self.chain), *peer); } fn timeout(&self, io: &NetworkContext, _timer: TimerToken) { - self.sync.write().maintain_peers(&mut NetSyncIo::new(io, self.chain.deref())); - self.sync.write().maintain_sync(&mut NetSyncIo::new(io, self.chain.deref())); + self.sync.write().maintain_peers(&mut NetSyncIo::new(io, &*self.chain)); + self.sync.write().maintain_sync(&mut NetSyncIo::new(io, &*self.chain)); } } @@ -135,7 +134,7 @@ impl ChainNotify for EthSync { _duration: u64) { self.network.with_context(ETH_PROTOCOL, |context| { - let mut sync_io = NetSyncIo::new(context, self.handler.chain.deref()); + let mut sync_io = NetSyncIo::new(context, &*self.handler.chain); self.handler.sync.write().chain_new_blocks( &mut sync_io, &imported, @@ -204,7 +203,7 @@ impl ManageNetwork for EthSync { fn stop_network(&self) { self.network.with_context(ETH_PROTOCOL, |context| { - let mut sync_io = NetSyncIo::new(context, self.handler.chain.deref()); + let mut sync_io = NetSyncIo::new(context, &*self.handler.chain); self.handler.sync.write().abort(&mut sync_io); }); self.stop(); diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 71d27127b..c5571cefd 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -1760,7 +1760,7 @@ mod tests { let chain_info = client.chain_info(); let mut io = TestIo::new(&mut client, &mut queue, None); - let peers = sync.get_lagging_peers(&chain_info, &mut io); + let peers = sync.get_lagging_peers(&chain_info, &io); let peer_count = sync.propagate_new_hashes(&chain_info, &mut io, &peers); // 1 message should be send @@ -1779,7 +1779,7 @@ mod tests { let mut sync = dummy_sync_with_peer(client.block_hash_delta_minus(5), &client); let chain_info = client.chain_info(); let mut io = TestIo::new(&mut client, &mut queue, None); - let peers = sync.get_lagging_peers(&chain_info, &mut io); + let peers = sync.get_lagging_peers(&chain_info, &io); let peer_count = sync.propagate_blocks(&chain_info, &mut io, &[], &peers); // 1 message should be send @@ -1799,7 +1799,7 @@ mod tests { let mut sync = dummy_sync_with_peer(client.block_hash_delta_minus(5), &client); let chain_info = client.chain_info(); let mut io = TestIo::new(&mut client, &mut queue, None); - let peers = sync.get_lagging_peers(&chain_info, &mut io); + let peers = sync.get_lagging_peers(&chain_info, &io); let peer_count = sync.propagate_blocks(&chain_info, &mut io, &[hash.clone()], &peers); // 1 message should be send @@ -1906,7 +1906,7 @@ mod tests { let chain_info = client.chain_info(); let mut io = TestIo::new(&mut client, &mut queue, None); - let peers = sync.get_lagging_peers(&chain_info, &mut io); + let peers = sync.get_lagging_peers(&chain_info, &io); sync.propagate_new_hashes(&chain_info, &mut io, &peers); let data = &io.queue[0].data.clone(); @@ -1925,7 +1925,7 @@ mod tests { let chain_info = client.chain_info(); let mut io = TestIo::new(&mut client, &mut queue, None); - let peers = sync.get_lagging_peers(&chain_info, &mut io); + let peers = sync.get_lagging_peers(&chain_info, &io); sync.propagate_blocks(&chain_info, &mut io, &[], &peers); let data = &io.queue[0].data.clone(); diff --git a/sync/src/tests/chain.rs b/sync/src/tests/chain.rs index 94dcc2a9d..d8d3d0711 100644 --- a/sync/src/tests/chain.rs +++ b/sync/src/tests/chain.rs @@ -27,7 +27,7 @@ fn two_peers() { net.peer_mut(2).chain.add_blocks(1000, EachBlockWith::Uncle); net.sync(); assert!(net.peer(0).chain.block(BlockID::Number(1000)).is_some()); - assert_eq!(net.peer(0).chain.blocks.read().deref(), net.peer(1).chain.blocks.read().deref()); + assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read()); } #[test] @@ -37,7 +37,7 @@ fn long_chain() { net.peer_mut(1).chain.add_blocks(50000, EachBlockWith::Nothing); net.sync(); assert!(net.peer(0).chain.block(BlockID::Number(50000)).is_some()); - assert_eq!(net.peer(0).chain.blocks.read().deref(), net.peer(1).chain.blocks.read().deref()); + assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read()); } #[test] @@ -71,7 +71,7 @@ fn empty_blocks() { } net.sync(); assert!(net.peer(0).chain.block(BlockID::Number(1000)).is_some()); - assert_eq!(net.peer(0).chain.blocks.read().deref(), net.peer(1).chain.blocks.read().deref()); + assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read()); } #[test] @@ -89,10 +89,10 @@ fn forked() { // peer 1 has the best chain of 601 blocks let peer1_chain = net.peer(1).chain.numbers.read().clone(); net.sync(); - assert_eq!(net.peer(0).chain.difficulty.read().deref(), net.peer(1).chain.difficulty.read().deref()); - assert_eq!(net.peer(0).chain.numbers.read().deref(), &peer1_chain); - assert_eq!(net.peer(1).chain.numbers.read().deref(), &peer1_chain); - assert_eq!(net.peer(2).chain.numbers.read().deref(), &peer1_chain); + assert_eq!(*net.peer(0).chain.difficulty.read(), *net.peer(1).chain.difficulty.read()); + assert_eq!(&*net.peer(0).chain.numbers.read(), &peer1_chain); + assert_eq!(&*net.peer(1).chain.numbers.read(), &peer1_chain); + assert_eq!(&*net.peer(2).chain.numbers.read(), &peer1_chain); } #[test] @@ -222,3 +222,4 @@ fn high_td_attach() { assert_eq!(net.peer(0).chain.chain_info().best_block_number, 5); } + diff --git a/util/bigint/src/hash.rs b/util/bigint/src/hash.rs index d2a450e0c..e86a53695 100644 --- a/util/bigint/src/hash.rs +++ b/util/bigint/src/hash.rs @@ -490,9 +490,9 @@ impl Hasher for PlainHasher { } } -/// Specialized version of HashMap with H256 keys and fast hashing function. +/// Specialized version of `HashMap` with H256 keys and fast hashing function. pub type H256FastMap = HashMap>; -/// Specialized version of HashSet with H256 keys and fast hashing function. +/// Specialized version of `HashSet` with H256 keys and fast hashing function. pub type H256FastSet = HashSet>; #[cfg(test)] diff --git a/util/io/src/panics.rs b/util/io/src/panics.rs index 8db875bdf..f67e925a7 100644 --- a/util/io/src/panics.rs +++ b/util/io/src/panics.rs @@ -17,7 +17,6 @@ //! Panic utilities use std::thread; -use std::ops::DerefMut; use std::sync::Arc; use std::default::Default; @@ -91,7 +90,7 @@ impl PanicHandler { /// You should use `catch_panic` instead of calling this method explicitly. pub fn notify_all(&self, r: String) { let mut listeners = self.listeners.lock(); - for listener in listeners.deref_mut() { + for mut listener in &mut **listeners { listener.call(&r); } } diff --git a/util/network/src/host.rs b/util/network/src/host.rs index baf99a0b0..5951288f0 100644 --- a/util/network/src/host.rs +++ b/util/network/src/host.rs @@ -787,7 +787,7 @@ impl Host { let entry = NodeEntry { id: s.id().unwrap().clone(), endpoint: NodeEndpoint { address: address, udp_port: address.port() } }; self.nodes.write().add_node(Node::new(entry.id.clone(), entry.endpoint.clone())); let mut discovery = self.discovery.lock(); - if let Some(ref mut discovery) = *discovery.deref_mut() { + if let Some(ref mut discovery) = *discovery { discovery.add_node(entry); } } diff --git a/util/network/src/tests.rs b/util/network/src/tests.rs index 9c3753813..3a19cbbab 100644 --- a/util/network/src/tests.rs +++ b/util/network/src/tests.rs @@ -46,7 +46,7 @@ impl TestProtocol { } pub fn got_packet(&self) -> bool { - self.packet.lock().deref()[..] == b"hello"[..] + self.packet.lock()[..] == b"hello"[..] } pub fn got_timeout(&self) -> bool { diff --git a/util/src/journaldb/archivedb.rs b/util/src/journaldb/archivedb.rs index 17c3b82fa..1ec46233c 100644 --- a/util/src/journaldb/archivedb.rs +++ b/util/src/journaldb/archivedb.rs @@ -74,7 +74,7 @@ impl HashDB for ArchiveDB { fn keys(&self) -> HashMap { let mut ret: HashMap = HashMap::new(); for (key, _) in self.backing.iter(self.column) { - let h = H256::from_slice(key.deref()); + let h = H256::from_slice(&*key); ret.insert(h, 1); } diff --git a/util/src/journaldb/earlymergedb.rs b/util/src/journaldb/earlymergedb.rs index a5cbfc83f..8e890b2a1 100644 --- a/util/src/journaldb/earlymergedb.rs +++ b/util/src/journaldb/earlymergedb.rs @@ -263,7 +263,7 @@ impl HashDB for EarlyMergeDB { fn keys(&self) -> HashMap { let mut ret: HashMap = HashMap::new(); for (key, _) in self.backing.iter(self.column) { - let h = H256::from_slice(key.deref()); + let h = H256::from_slice(&*key); ret.insert(h, 1); } diff --git a/util/src/journaldb/overlayrecentdb.rs b/util/src/journaldb/overlayrecentdb.rs index 97fa5959a..9de2799ee 100644 --- a/util/src/journaldb/overlayrecentdb.rs +++ b/util/src/journaldb/overlayrecentdb.rs @@ -329,7 +329,7 @@ impl HashDB for OverlayRecentDB { fn keys(&self) -> HashMap { let mut ret: HashMap = HashMap::new(); for (key, _) in self.backing.iter(self.column) { - let h = H256::from_slice(key.deref()); + let h = H256::from_slice(&*key); ret.insert(h, 1); } @@ -348,11 +348,11 @@ impl HashDB for OverlayRecentDB { let v = self.journal_overlay.read().backing_overlay.get(&to_short_key(key)).map(|v| v.to_vec()); match v { Some(x) => { - Some(&self.transaction_overlay.denote(key, x).0) + Some(self.transaction_overlay.denote(key, x).0) } _ => { if let Some(x) = self.payload(key) { - Some(&self.transaction_overlay.denote(key, x).0) + Some(self.transaction_overlay.denote(key, x).0) } else { None @@ -920,4 +920,4 @@ mod tests { assert!(jdb.get(&key).is_none()); } -} \ No newline at end of file +} diff --git a/util/src/journaldb/refcounteddb.rs b/util/src/journaldb/refcounteddb.rs index b29a45212..9b837d68d 100644 --- a/util/src/journaldb/refcounteddb.rs +++ b/util/src/journaldb/refcounteddb.rs @@ -190,7 +190,7 @@ impl JournalDB for RefCountedDB { for remove in self.removes.drain(..) { self.forward.remove(&remove); } - self.forward.commit_to_batch(&batch) + self.forward.commit_to_batch(batch) } } diff --git a/util/src/kvdb.rs b/util/src/kvdb.rs index f88e74034..5e7c0930e 100644 --- a/util/src/kvdb.rs +++ b/util/src/kvdb.rs @@ -421,7 +421,6 @@ mod tests { use super::*; use devtools::*; use std::str::FromStr; - use std::ops::Deref; fn test_db(config: &DatabaseConfig) { let path = RandomTempPath::create_dir(); @@ -435,13 +434,13 @@ mod tests { batch.put(None, &key2, b"dog").unwrap(); db.write(batch).unwrap(); - assert_eq!(db.get(None, &key1).unwrap().unwrap().deref(), b"cat"); + assert_eq!(&*db.get(None, &key1).unwrap().unwrap(), b"cat"); let contents: Vec<_> = db.iter(None).collect(); assert_eq!(contents.len(), 2); - assert_eq!(&*contents[0].0, key1.deref()); + assert_eq!(&*contents[0].0, &*key1); assert_eq!(&*contents[0].1, b"cat"); - assert_eq!(&*contents[1].0, key2.deref()); + assert_eq!(&*contents[1].0, &*key2); assert_eq!(&*contents[1].1, b"dog"); let batch = db.transaction(); @@ -459,10 +458,10 @@ mod tests { transaction.delete(None, &key1).unwrap(); db.write(transaction).unwrap(); assert!(db.get(None, &key1).unwrap().is_none()); - assert_eq!(db.get(None, &key3).unwrap().unwrap().deref(), b"elephant"); + assert_eq!(&*db.get(None, &key3).unwrap().unwrap(), b"elephant"); - assert_eq!(db.get_by_prefix(None, &key3).unwrap().deref(), b"elephant"); - assert_eq!(db.get_by_prefix(None, &key2).unwrap().deref(), b"dog"); + assert_eq!(&*db.get_by_prefix(None, &key3).unwrap(), b"elephant"); + assert_eq!(&*db.get_by_prefix(None, &key2).unwrap(), b"dog"); } #[test] diff --git a/util/src/overlaydb.rs b/util/src/overlaydb.rs index 7310ef536..bce0a83e8 100644 --- a/util/src/overlaydb.rs +++ b/util/src/overlaydb.rs @@ -22,7 +22,6 @@ use bytes::*; use rlp::*; use hashdb::*; use memorydb::*; -use std::ops::*; use std::sync::*; use std::collections::HashMap; use kvdb::{Database, DBTransaction}; @@ -130,7 +129,7 @@ impl HashDB for OverlayDB { fn keys(&self) -> HashMap { let mut ret: HashMap = HashMap::new(); for (key, _) in self.backing.iter(self.column) { - let h = H256::from_slice(key.deref()); + let h = H256::from_slice(&*key); let r = self.payload(&h).unwrap().1; ret.insert(h, r as i32); } @@ -305,7 +304,7 @@ fn playpen() { batch.put(None, b"test", b"test2").unwrap(); db.write(batch).unwrap(); match db.get(None, b"test") { - Ok(Some(value)) => println!("Got value {:?}", value.deref()), + Ok(Some(value)) => println!("Got value {:?}", &*value), Ok(None) => println!("No value for that key"), Err(..) => println!("Gah"), } @@ -314,4 +313,4 @@ fn playpen() { db.write(batch).unwrap(); } fs::remove_dir_all("/tmp/test").unwrap(); -} \ No newline at end of file +} diff --git a/util/src/rlp/rlpstream.rs b/util/src/rlp/rlpstream.rs index 5da3a3822..eb70a7c13 100644 --- a/util/src/rlp/rlpstream.rs +++ b/util/src/rlp/rlpstream.rs @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::ops::Deref; -use std::default::Default; use elastic_array::*; use rlp::bytes::{ToBytes, VecLike}; use rlp::{Stream, Encoder, Encodable}; @@ -293,7 +291,7 @@ impl<'a> Encodable for &'a[u8] { impl Encodable for Vec { fn rlp_append(&self, s: &mut RlpStream) { - s.append_value(&U8Slice(self.deref())) + s.append_value(&U8Slice(self)) } } @@ -334,7 +332,7 @@ impl<'a, T> Encodable for &'a[T] where T: Encodable { impl Encodable for Vec where T: Encodable { fn rlp_append(&self, s: &mut RlpStream) { - Encodable::rlp_append(&self.deref(), s); + Encodable::rlp_append(&self.as_slice(), s); } } diff --git a/util/src/rlp/rlptraits.rs b/util/src/rlp/rlptraits.rs index 1e6ef5917..5eca7ca03 100644 --- a/util/src/rlp/rlptraits.rs +++ b/util/src/rlp/rlptraits.rs @@ -15,7 +15,6 @@ // along with Parity. If not, see . //! Common RLP traits -use std::ops::Deref; use rlp::bytes::VecLike; use rlp::{DecoderError, UntrustedRlp}; use rlp::rlpstream::RlpStream; @@ -244,7 +243,7 @@ pub trait ByteEncodable { fn bytes_len(&self) -> usize; } -/// Structure encodable to RLP. Implement this trait for +/// Structure encodable to RLP. Implement this trait for pub trait Encodable { /// Append a value to the stream fn rlp_append(&self, s: &mut RlpStream); @@ -257,7 +256,7 @@ pub trait Encodable { } /// Get the hash or RLP encoded representation - fn rlp_sha3(&self) -> H256 { self.rlp_bytes().deref().sha3() } + fn rlp_sha3(&self) -> H256 { (&*self.rlp_bytes()).sha3() } } /// Encodable wrapper trait required to handle special case of encoding a &[u8] as string and not as list diff --git a/util/src/trie/triedb.rs b/util/src/trie/triedb.rs index f7704c387..ec0d9a59f 100644 --- a/util/src/trie/triedb.rs +++ b/util/src/trie/triedb.rs @@ -192,7 +192,7 @@ impl<'db> TrieDB<'db> { where 'db: 'key { let root_rlp = try!(self.root_data()); - self.get_from_node(&root_rlp, key) + self.get_from_node(root_rlp, key) } /// Recursible function to retrieve the value given a `node` and a partial `key`. `None` if no