diff --git a/.travis.yml b/.travis.yml index 6ed5b0e8c1..ebbea5aee9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,12 +2,12 @@ language: rust rust: - stable install: - - rustup toolchain install nightly-2018-05-07 - - rustup component add rustfmt-preview --toolchain nightly-2018-05-07 + - rustup toolchain install nightly-2018-07-17 + - rustup component add rustfmt-preview --toolchain nightly-2018-07-17 before_script: - cargo fetch --verbose script: - - cargo +nightly-2018-05-07 fmt -- --write-mode=diff + - cargo +nightly-2018-07-17 fmt -- --check - RUST_BACKTRACE=1 cargo test --verbose --all matrix: allow_failures: diff --git a/codechain/main.rs b/codechain/main.rs index 06c64b73e6..79f62a9ce9 100644 --- a/codechain/main.rs +++ b/codechain/main.rs @@ -249,10 +249,12 @@ fn run_node(matches: ArgMatches) -> Result<(), String> { let config = load_config(&matches)?; let spec = config.operating.chain.spec()?; - let instance_id = config.operating.instance_id.unwrap_or(SystemTime::now() - .duration_since(UNIX_EPOCH) - .expect("Current time should be later than unix epoch") - .subsec_nanos() as usize); + let instance_id = config.operating.instance_id.unwrap_or( + SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("Current time should be later than unix epoch") + .subsec_nanos() as usize, + ); clogger::init(&LoggerConfig::new(instance_id)).expect("Logger must be successfully initialized"); // FIXME: Handle IO error. diff --git a/core/src/blockchain/extras.rs b/core/src/blockchain/extras.rs index d364cff24b..adb2c6e31b 100644 --- a/core/src/blockchain/extras.rs +++ b/core/src/blockchain/extras.rs @@ -264,7 +264,8 @@ impl BlockInvoices { impl Decodable for BlockInvoices { fn decode(rlp: &UntrustedRlp) -> Result { - let invoices = rlp.as_list::>()? + let invoices = rlp + .as_list::>()? .iter() .map(|parcel_invoice| UntrustedRlp::new(&parcel_invoice).as_val::()) .collect::, _>>()?; diff --git a/core/src/consensus/mod.rs b/core/src/consensus/mod.rs index 36bdbea601..abffd1b159 100644 --- a/core/src/consensus/mod.rs +++ b/core/src/consensus/mod.rs @@ -325,8 +325,4 @@ pub trait CodeChainEngine: ConsensusEngine { } // convenience wrappers for existing functions. -impl CodeChainEngine for T -where - T: ConsensusEngine, -{ -} +impl CodeChainEngine for T where T: ConsensusEngine {} diff --git a/core/src/consensus/tendermint/mod.rs b/core/src/consensus/tendermint/mod.rs index 6386ee5b93..cfff6e1768 100644 --- a/core/src/consensus/tendermint/mod.rs +++ b/core/src/consensus/tendermint/mod.rs @@ -239,7 +239,8 @@ impl Tendermint { /// Broadcast all messages since last issued block to get the peers up to speed. fn broadcast_old_messages(&self) { - for m in self.votes + for m in self + .votes .get_up_to(&VoteStep::new( self.height.load(AtomicOrdering::SeqCst), self.view.load(AtomicOrdering::SeqCst), @@ -359,7 +360,9 @@ impl Tendermint { Some(lock) => vote_step > &lock.vote_step, None => true, }; - let lock_change = is_newer_than_lock && vote_step.step == Step::Prevote && message.block_hash.is_some() + let lock_change = is_newer_than_lock + && vote_step.step == Step::Prevote + && message.block_hash.is_some() && self.has_enough_aligned_votes(message); if lock_change { ctrace!(ENGINE, "handle_valid_message: Lock change."); diff --git a/core/src/miner/local_parcels.rs b/core/src/miner/local_parcels.rs index c86603bd19..65f2aac6db 100644 --- a/core/src/miner/local_parcels.rs +++ b/core/src/miner/local_parcels.rs @@ -150,7 +150,8 @@ impl LocalParcelsList { return } - let to_remove = self.parcels + let to_remove = self + .parcels .iter() .filter(|&(_, status)| !status.is_current()) .map(|(hash, _)| *hash) diff --git a/core/src/miner/mem_pool.rs b/core/src/miner/mem_pool.rs index f92f16ade4..33e42e0660 100644 --- a/core/src/miner/mem_pool.rs +++ b/core/src/miner/mem_pool.rs @@ -263,7 +263,8 @@ impl ParcelSet { }; Some(to_drop.into_iter().fold(HashMap::new(), |mut removed, (sender, nonce)| { - let order = self.drop(&sender, &nonce) + let order = self + .drop(&sender, &nonce) .expect("Parcel has just been found in `by_priority`; so it is in `by_address` also."); ctrace!(MEM_POOL, "Dropped out of limit parcel: {:?}", order.hash); @@ -469,7 +470,8 @@ impl MemPool { pub fn remove_old(&mut self, fetch_account: &F, current_time: PoolingInstant) where F: Fn(&Address) -> AccountDetails, { - let senders = self.current + let senders = self + .current .by_address .keys() .chain(self.future.by_address.keys()) @@ -483,7 +485,8 @@ impl MemPool { let max_time = self.max_time_in_pool; let balance_check = max_time >> 3; // Clear parcels occupying the pool too long - let invalid = self.by_hash + let invalid = self + .by_hash .iter() .filter(|&(_, ref parcel)| !parcel.origin.is_local()) .map(|(hash, parcel)| (hash, parcel, current_time.saturating_sub(parcel.insertion_time))) @@ -931,7 +934,8 @@ impl MemPool { fn mark_parcels_local(&mut self, sender: &Address) { fn mark_local(sender: &Address, set: &mut ParcelSet, mut mark: F) { // Mark all parcels from this sender as local - let nonces_from_sender = set.by_address + let nonces_from_sender = set + .by_address .row(sender) .map(|row_map| { row_map diff --git a/core/src/miner/miner.rs b/core/src/miner/miner.rs index 44e263f8f7..70e3710c8d 100644 --- a/core/src/miner/miner.rs +++ b/core/src/miner/miner.rs @@ -161,7 +161,8 @@ impl Miner { if sealing_work.enabled { ctrace!(MINER, "requires_reseal: sealing enabled"); let last_request = *self.sealing_block_last_request.lock(); - let should_disable_sealing = !self.options.force_sealing && !has_local_parcels + let should_disable_sealing = !self.options.force_sealing + && !has_local_parcels && self.engine.seals_internally().is_none() && best_block > last_request && best_block - last_request > SEALING_TIMEOUT_IN_BLOCKS; @@ -209,7 +210,8 @@ impl Miner { cdebug!(MINER, "Rejected parcel {:?}: already in the blockchain", hash); return Err(Error::Parcel(ParcelError::AlreadyImported)) } - match self.engine + match self + .engine .verify_parcel_basic(&parcel, &best_block_header) .and_then(|_| self.engine.verify_parcel_unordered(parcel, &best_block_header)) { @@ -221,7 +223,8 @@ impl Miner { // This check goes here because verify_parcel takes SignedParcel parameter self.engine.machine().verify_parcel(&parcel, &best_block_header, client)?; - let origin = self.accounts + let origin = self + .accounts .as_ref() .and_then(|accounts| match accounts.has_account(parcel.sender()) { Ok(true) => Some(ParcelOrigin::Local), @@ -419,7 +422,8 @@ impl Miner { fn seal_and_import_block_internally(&self, chain: &C, block: ClosedBlock) -> bool where C: BlockChain + ImportSealedBlock, { - if block.parcels().is_empty() && !self.options.force_sealing + if block.parcels().is_empty() + && !self.options.force_sealing && Instant::now() <= *self.next_mandatory_reseal.read() { return false @@ -701,7 +705,8 @@ impl MinerService for Miner { // Be sure to release the lock before we call prepare_work_sealing let mut mem_pool = self.mem_pool.write(); // We need to re-validate parcels - let import = self.add_parcels_to_pool(chain, vec![parcel.into()], ParcelOrigin::Local, &mut mem_pool) + let import = self + .add_parcels_to_pool(chain, vec![parcel.into()], ParcelOrigin::Local, &mut mem_pool) .pop() .expect("one result returned per added parcel; one added => one result; qed"); diff --git a/core/src/miner/work_notify.rs b/core/src/miner/work_notify.rs index c87f12855c..66d426b330 100644 --- a/core/src/miner/work_notify.rs +++ b/core/src/miner/work_notify.rs @@ -42,7 +42,8 @@ pub struct WorkPoster { impl WorkPoster { /// Create new `WorkPoster`. pub fn new(urls: &[String]) -> Self { - let urls = urls.into_iter() + let urls = urls + .into_iter() .filter_map(|u| match Url::parse(u) { Ok(url) => Some(url), Err(e) => { diff --git a/core/src/service.rs b/core/src/service.rs index d16bf5c714..cde35b613e 100644 --- a/core/src/service.rs +++ b/core/src/service.rs @@ -48,10 +48,10 @@ impl ClientService { db_config.compaction = config.db_compaction.compaction_profile(client_path); db_config.wal = config.db_wal; - let db = Arc::new(Database::open( - &db_config, - &client_path.to_str().expect("DB path could not be converted to string."), - ).map_err(::client::Error::Database)?); + let db = Arc::new( + Database::open(&db_config, &client_path.to_str().expect("DB path could not be converted to string.")) + .map_err(::client::Error::Database)?, + ); let client = Client::new(config, &spec, db, miner, io_service.channel())?; diff --git a/core/src/state/shard_level.rs b/core/src/state/shard_level.rs index 50157d9cc3..ebcc2ec68f 100644 --- a/core/src/state/shard_level.rs +++ b/core/src/state/shard_level.rs @@ -334,7 +334,8 @@ impl ShardStateInternal for ShardLevelState { let asset_type = input.prev_out.asset_type.clone(); let asset_scheme_address = AssetSchemeAddress::from_hash(asset_type) .ok_or(TransactionError::AssetSchemeNotFound(asset_type.into()))?; - let _asset_scheme = self.asset_scheme((&asset_scheme_address).into())? + let _asset_scheme = self + .asset_scheme((&asset_scheme_address).into())? .ok_or(TransactionError::AssetSchemeNotFound(asset_scheme_address.into()))?; match self.asset(&address)? { diff --git a/core/src/state_db.rs b/core/src/state_db.rs index b819bb6af6..06d72e55d5 100644 --- a/core/src/state_db.rs +++ b/core/src/state_db.rs @@ -131,7 +131,10 @@ impl StateDB { pub fn new(db: Box, cache_size: usize) -> StateDB { assert_eq!( 100, - ACCOUNT_CACHE_RATIO + METADATA_CACHE_RATIO + SHARD_CACHE_RATIO + ASSET_SCHEME_CACHE_RATIO + ACCOUNT_CACHE_RATIO + + METADATA_CACHE_RATIO + + SHARD_CACHE_RATIO + + ASSET_SCHEME_CACHE_RATIO + ASSET_CACHE_RATIO ); @@ -411,7 +414,8 @@ impl StateDB { /// Heap size used. pub fn mem_used(&self) -> usize { // TODO: account for LRU-cache overhead; this is a close approximation. - self.db.mem_used() + Self::mem_used_impl(&self.account_cache.lock()) + self.db.mem_used() + + Self::mem_used_impl(&self.account_cache.lock()) + Self::mem_used_impl(&self.shard_cache.lock()) + Self::mem_used_impl(&self.asset_scheme_cache.lock()) + Self::mem_used_impl(&self.asset_cache.lock()) diff --git a/keystore/src/accounts_dir/disk.rs b/keystore/src/accounts_dir/disk.rs index e393020f97..3b6678d1a1 100644 --- a/keystore/src/accounts_dir/disk.rs +++ b/keystore/src/accounts_dir/disk.rs @@ -231,7 +231,8 @@ where fn remove(&self, account: &SafeAccount) -> Result<(), Error> { // enumerate all entries in keystore // and find entry with given address - let to_remove = self.files_content()? + let to_remove = self + .files_content()? .into_iter() .find(|&(_, ref acc)| acc.id == account.id && acc.address == account.address); diff --git a/network/src/p2p/handler.rs b/network/src/p2p/handler.rs index cb7835d9d8..b5e64f4034 100644 --- a/network/src/p2p/handler.rs +++ b/network/src/p2p/handler.rs @@ -136,7 +136,8 @@ impl Manager { let local_node_id = self.routing_table.local_node_id(&remote_node_id).ok_or(Error::General("Not handshaked"))?; - let session = self.routing_table + let session = self + .routing_table .unestablished_session(&socket_address) .ok_or(Error::General("Session doesn't exist"))?; @@ -210,7 +211,8 @@ impl Manager { node_id, .. }) => { - let remote_addr = self.connections + let remote_addr = self + .connections .remote_addr_of_waiting_sync(stream) .ok_or(Error::General("Cannot find remote address"))?; let remote_node_id = convert_to_node_id(remote_addr.ip(), port); @@ -223,7 +225,8 @@ impl Manager { } let remote_addr = SocketAddr::new(remote_addr.ip(), port); - let session = self.routing_table + let session = self + .routing_table .unestablished_session(&remote_addr) .ok_or(Error::General("Cannot find session"))?; if !signed_message.is_valid(&session) { diff --git a/network/src/session_initiator/handler.rs b/network/src/session_initiator/handler.rs index 959f41e2a7..a6fb9a0110 100644 --- a/network/src/session_initiator/handler.rs +++ b/network/src/session_initiator/handler.rs @@ -267,7 +267,8 @@ impl SessionInitiator { let message = message::Message::nonce_request(seq as u64, encrypted_nonce); self.server.enqueue(message, from.clone())?; } else { - let requester_pub_key = self.routing_table + let requester_pub_key = self + .routing_table .register_key_pair_for_secret(from) .ok_or(Error::General("Cannot register key pair"))?; @@ -303,7 +304,8 @@ impl SessionInitiator { return Ok(()) } - let _secret = self.routing_table + let _secret = self + .routing_table .share_secret(from, responder_pub_key) .ok_or(Error::General("Cannot share secret"))?; let encrypted_nonce = diff --git a/rpc/src/v1/impls/account.rs b/rpc/src/v1/impls/account.rs index eeb2728fb3..7b717a6a35 100644 --- a/rpc/src/v1/impls/account.rs +++ b/rpc/src/v1/impls/account.rs @@ -42,7 +42,8 @@ impl Account for AccountClient { } fn create_account(&self, passphrase: Option) -> Result
{ - let (address, _) = self.account_provider + let (address, _) = self + .account_provider .new_account_and_public(passphrase.unwrap_or_default().as_ref()) .map_err(account_provider)?; Ok(address) diff --git a/rustfmt.toml b/rustfmt.toml index 2e0502c057..bd67bb390a 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,5 +1,5 @@ indent_style = "Block" -use_small_heuristics = false # true +use_small_heuristics = "Off" # "Default" binop_separator = "Front" # combine_control_expr = true comment_width = 120 # 80 @@ -18,12 +18,14 @@ format_strings = false hard_tabs = false imports_indent = "Block" # "Visual" imports_layout = "Mixed" +merge_imports = false match_block_trailing_comma = false max_width = 120 # 100 merge_derives = true # force_multiline_blocks = false newline_style = "Unix" normalize_comments = false +remove_nested_parens = true reorder_imports = true reorder_modules = true # reorder_impl_items = false @@ -34,7 +36,6 @@ space_after_colon = true space_before_colon = false struct_field_align_threshold = 0 spaces_around_ranges = false -spaces_within_parens_and_brackets = false ## struct_lit_single_line = true tab_spaces = 4 trailing_comma = "Vertical" @@ -44,10 +45,8 @@ use_field_init_shorthand = true # false use_try_shorthand = true # false wrap_comments = false match_arm_blocks = true -write_mode = "Overwrite" blank_lines_upper_bound = 2 # 1 blank_lines_lower_bound = 0 -remove_blank_lines_at_start_or_end_of_block = true hide_parse_errors = false color = "Always" # "Auto" unstable_features = false diff --git a/types/src/transaction/transaction.rs b/types/src/transaction/transaction.rs index cb9d0edb83..86cab88f2f 100644 --- a/types/src/transaction/transaction.rs +++ b/types/src/transaction/transaction.rs @@ -177,7 +177,8 @@ impl Encodable for Transaction { }, registrar, nonce, - } => s.begin_list(8) + } => s + .begin_list(8) .append(&ASSET_MINT_ID) .append(network_id) .append(metadata) @@ -192,7 +193,8 @@ impl Encodable for Transaction { inputs, outputs, nonce, - } => s.begin_list(6) + } => s + .begin_list(6) .append(&ASSET_TRANSFER_ID) .append(network_id) .append_list(burns) diff --git a/util/io/src/service.rs b/util/io/src/service.rs index 73e9d63670..35dfbfe9cc 100644 --- a/util/io/src/service.rs +++ b/util/io/src/service.rs @@ -306,7 +306,8 @@ where IoMessage::AddHandler { handler, } => { - let handler_id = self.handlers + let handler_id = self + .handlers .write() .insert(handler.clone()) .unwrap_or_else(|_| panic!("Too many handlers registered")); diff --git a/util/kvdb-rocksdb/src/lib.rs b/util/kvdb-rocksdb/src/lib.rs index d3123c0601..2028b96c3d 100644 --- a/util/kvdb-rocksdb/src/lib.rs +++ b/util/kvdb-rocksdb/src/lib.rs @@ -526,10 +526,8 @@ impl Database { col, key, value, - } => col.map_or_else( - || batch.put(&key, &value), - |c| batch.put_cf(cfs[c as usize], &key, &value), - )?, + } => col + .map_or_else(|| batch.put(&key, &value), |c| batch.put_cf(cfs[c as usize], &key, &value))?, DBOp::InsertCompressed { col, key, @@ -574,13 +572,15 @@ impl Database { Ok(Some(value.clone())) } Some(&KeyState::Delete) => Ok(None), - None => col.map_or_else( - || db.get_opt(key, &self.read_opts).map(|r| r.map(|v| DBValue::from_slice(&v))), - |c| { - db.get_cf_opt(cfs[c as usize], key, &self.read_opts) - .map(|r| r.map(|v| DBValue::from_slice(&v))) - }, - ).map_err(Into::into), + None => { + col.map_or_else( + || db.get_opt(key, &self.read_opts).map(|r| r.map(|v| DBValue::from_slice(&v))), + |c| { + db.get_cf_opt(cfs[c as usize], key, &self.read_opts) + .map(|r| r.map(|v| DBValue::from_slice(&v))) + }, + ).map_err(Into::into) + } } } } diff --git a/util/patricia_trie/src/triedb.rs b/util/patricia_trie/src/triedb.rs index 50c7742017..bfa0a3c3d6 100644 --- a/util/patricia_trie/src/triedb.rs +++ b/util/patricia_trie/src/triedb.rs @@ -367,7 +367,8 @@ impl<'a> Iterator for TrieDBIterator<'a> { match i { 0 => self.key_nibbles.push(0), i => { - *self.key_nibbles + *self + .key_nibbles .last_mut() .expect("pushed as 0; moves sequentially; removed afterwards; qed") = i as u8 } diff --git a/util/patricia_trie/src/triedbmut.rs b/util/patricia_trie/src/triedbmut.rs index 33485e71c8..1fe2c34796 100644 --- a/util/patricia_trie/src/triedbmut.rs +++ b/util/patricia_trie/src/triedbmut.rs @@ -453,9 +453,10 @@ impl<'a> TrieDBMut<'a> { NodeHandle::Hash(h) => self.cache(h)?, }; let stored = self.storage.destroy(h); - let (new_stored, changed) = self.inspect(stored, move |trie, stored| { - trie.insert_inspector(stored, partial, value, old_val).map(|a| a.into_action()) - })? + let (new_stored, changed) = self + .inspect(stored, move |trie, stored| { + trie.insert_inspector(stored, partial, value, old_val).map(|a| a.into_action()) + })? .expect("Insertion never deletes."); Ok((self.storage.alloc(new_stored), changed))