diff --git a/ci/test-stable.sh b/ci/test-stable.sh index e9165a6b30..05a6138724 100755 --- a/ci/test-stable.sh +++ b/ci/test-stable.sh @@ -12,7 +12,7 @@ _() { } _ rustup component add rustfmt-preview -_ cargo fmt -- --write-mode=check +_ cargo fmt -- --check _ cargo build --verbose _ cargo test --verbose _ cargo bench --verbose diff --git a/src/bank.rs b/src/bank.rs index acd5d59eca..65c166229a 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -150,7 +150,8 @@ impl Bank { /// Forget the given `signature` with `last_id` because the transaction was rejected. fn forget_signature_with_last_id(&self, signature: &Signature, last_id: &Hash) { - if let Some(entry) = self.last_ids_sigs + if let Some(entry) = self + .last_ids_sigs .write() .expect("'last_ids' read lock in forget_signature_with_last_id") .get_mut(last_id) @@ -167,7 +168,8 @@ impl Bank { } fn reserve_signature_with_last_id(&self, signature: &Signature, last_id: &Hash) -> Result<()> { - if let Some(entry) = self.last_ids_sigs + if let Some(entry) = self + .last_ids_sigs .write() .expect("'last_ids' read lock in reserve_signature_with_last_id") .get_mut(last_id) @@ -198,10 +200,12 @@ impl Bank { /// the oldest ones once its internal cache is full. Once boot, the /// bank will reject transactions using that `last_id`. pub fn register_entry_id(&self, last_id: &Hash) { - let mut last_ids = self.last_ids + let mut last_ids = self + .last_ids .write() .expect("'last_ids' write lock in register_entry_id"); - let mut last_ids_sigs = self.last_ids_sigs + let mut last_ids_sigs = self + .last_ids_sigs .write() .expect("last_ids_sigs write lock"); if last_ids.len() >= MAX_ENTRY_IDS { @@ -262,7 +266,8 @@ impl Bank { if let Some(payment) = plan.final_payment() { self.apply_payment(&payment, balances); } else { - let mut pending = self.pending + let mut pending = self + .pending .write() .expect("'pending' write lock in apply_credits"); pending.insert(tx.sig, plan); @@ -298,7 +303,8 @@ impl Bank { debug!("processing Transactions {}", txs.len()); let txs_len = txs.len(); let now = Instant::now(); - let results: Vec<_> = txs.into_iter() + let results: Vec<_> = txs + .into_iter() .map(|tx| self.apply_debits(&tx, bals).map(|_| tx)) .collect(); // Calling collect() here forces all debits to complete before moving on. @@ -460,7 +466,8 @@ impl Bank { /// Process a Witness Signature. Any payment plans waiting on this signature /// will progress one step. fn apply_signature(&self, from: PublicKey, tx_sig: Signature) -> Result<()> { - if let Occupied(mut e) = self.pending + if let Occupied(mut e) = self + .pending .write() .expect("write() in apply_signature") .entry(tx_sig) @@ -483,7 +490,8 @@ impl Bank { // Hold 'pending' write lock until the end of this function. Otherwise another thread can // double-spend if it enters before the modified plan is removed from 'pending'. - let mut pending = self.pending + let mut pending = self + .pending .write() .expect("'pending' write lock in apply_timestamp"); for (key, plan) in pending.iter_mut() { @@ -532,7 +540,8 @@ impl Bank { } pub fn get_balance(&self, pubkey: &PublicKey) -> i64 { - let bals = self.balances + let bals = self + .balances .read() .expect("'balances' read lock in get_balance"); bals.get(pubkey).cloned().unwrap_or(0) @@ -543,7 +552,8 @@ impl Bank { } pub fn has_signature(&self, signature: &Signature) -> bool { - let last_ids_sigs = self.last_ids_sigs + let last_ids_sigs = self + .last_ids_sigs .read() .expect("'last_ids_sigs' read lock"); for (_hash, signatures) in last_ids_sigs.iter() { @@ -674,7 +684,8 @@ mod tests { let bank = Bank::new(&mint); let pubkey = KeyPair::new().pubkey(); let dt = Utc::now(); - let sig = bank.transfer_on_date(1, &mint.keypair(), pubkey, dt, mint.last_id()) + let sig = bank + .transfer_on_date(1, &mint.keypair(), pubkey, dt, mint.last_id()) .unwrap(); // Assert the debit counts as a transaction. diff --git a/src/crdt.rs b/src/crdt.rs index 7b2e918bc4..cbd6257055 100644 --- a/src/crdt.rs +++ b/src/crdt.rs @@ -473,7 +473,8 @@ impl Crdt { } let leader_id = self.leader_data().unwrap().id; let limit = GOSSIP_PURGE_MILLIS; - let dead_ids: Vec = self.alive + let dead_ids: Vec = self + .alive .iter() .filter_map(|(&k, v)| { if k != self.me && (now - v) > limit { @@ -521,7 +522,8 @@ impl Crdt { let live: Vec<_> = self.alive.iter().collect(); //thread_rng().shuffle(&mut live); let me = &self.table[&self.me]; - let cloned_table: Vec = live.iter() + let cloned_table: Vec = live + .iter() .map(|x| &self.table[x.0]) .filter(|v| { if me.id == v.id { @@ -733,7 +735,8 @@ impl Crdt { fn get_updates_since(&self, v: u64) -> (PublicKey, u64, Vec) { //trace!("get updates since {}", v); - let data = self.table + let data = self + .table .values() .filter(|x| x.id != PublicKey::default() && self.local[&x.id] > v) .cloned() @@ -744,7 +747,8 @@ impl Crdt { } pub fn window_index_request(&self, ix: u64) -> Result<(SocketAddr, Vec)> { - let valid: Vec<_> = self.table + let valid: Vec<_> = self + .table .values() .filter(|r| r.id != self.me && Self::is_valid_address(r.contact_info.tvu_window)) .collect(); @@ -764,7 +768,8 @@ impl Crdt { /// * A - Address to send to /// * B - RequestUpdates protocol message fn gossip_request(&self) -> Result<(SocketAddr, Protocol)> { - let options: Vec<_> = self.table + let options: Vec<_> = self + .table .values() .filter(|v| { v.id != self.me @@ -826,7 +831,8 @@ impl Crdt { // Lock the object only to do this operation and not for any longer // especially not when doing the `sock.send_to` - let (remote_gossip_addr, req) = obj.read() + let (remote_gossip_addr, req) = obj + .read() .expect("'obj' read lock in fn run_gossip") .gossip_request()?; @@ -902,7 +908,8 @@ impl Crdt { continue; } - let liveness_entry = self.external_liveness + let liveness_entry = self + .external_liveness .entry(*pk) .or_insert_with(HashMap::new); let peer_index = *liveness_entry.entry(from).or_insert(*external_remote_index); @@ -1135,7 +1142,8 @@ impl Crdt { while let Ok(mut more) = requests_receiver.try_recv() { reqs.append(&mut more); } - let resp: VecDeque<_> = reqs.iter() + let resp: VecDeque<_> = reqs + .iter() .filter_map(|b| Self::handle_blob(obj, window, blob_recycler, &b.read().unwrap())) .collect(); response_sender.send(resp)?; diff --git a/src/packet.rs b/src/packet.rs index 36741acc46..6687693d48 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -168,7 +168,8 @@ impl Clone for Recycler { impl Recycler { pub fn allocate(&self) -> Arc> { let mut gc = self.gc.lock().expect("recycler lock in pb fn allocate"); - let x = gc.pop() + let x = gc + .pop() .unwrap_or_else(|| Arc::new(RwLock::new(Default::default()))); // Only return the item if this recycler is the last reference to it. diff --git a/src/streamer.rs b/src/streamer.rs index 095a965188..c95990f649 100755 --- a/src/streamer.rs +++ b/src/streamer.rs @@ -53,7 +53,8 @@ fn recv_loop( loop { let msgs = re.allocate(); loop { - let result = msgs.write() + let result = msgs + .write() .expect("write lock in fn recv_loop") .recv_from(sock); match result { @@ -351,7 +352,8 @@ fn process_blob( let w = (pix % WINDOW_SIZE) as usize; let is_coding = { - let blob_r = blob.read() + let blob_r = blob + .read() .expect("blob read lock for flogs streamer::window"); blob_r.is_coding() }; @@ -448,7 +450,8 @@ fn recv_window( ) -> Result<()> { let timer = Duration::from_millis(200); let mut dq = r.recv_timeout(timer)?; - let maybe_leader: Option = crdt.read() + let maybe_leader: Option = crdt + .read() .expect("'crdt' read lock in fn recv_window") .leader_data() .cloned(); diff --git a/src/vote_stage.rs b/src/vote_stage.rs index 9c0d03d9e9..b7bd24b53a 100644 --- a/src/vote_stage.rs +++ b/src/vote_stage.rs @@ -100,7 +100,8 @@ pub fn send_leader_vote( ) -> Result<()> { let now = timing::timestamp(); if now - *last_vote > VOTE_TIMEOUT_MS { - let ids: Vec<_> = crdt.read() + let ids: Vec<_> = crdt + .read() .unwrap() .table .values() diff --git a/tests/data_replicator.rs b/tests/data_replicator.rs index 85c1c8931a..78de62b53c 100644 --- a/tests/data_replicator.rs +++ b/tests/data_replicator.rs @@ -263,7 +263,8 @@ fn test_external_liveness_table() { c4.write().unwrap().insert(&c1_data); c4.write().unwrap().set_leader(c1_data.id); for _ in 0..30 { - done = c1.read() + done = c1 + .read() .unwrap() .get_external_liveness_entry(&c4_id) .is_none(); diff --git a/tests/multinode.rs b/tests/multinode.rs index ea5d792ff8..b66f5faa35 100755 --- a/tests/multinode.rs +++ b/tests/multinode.rs @@ -393,14 +393,16 @@ fn test_multi_node_dynamic_network() { logger::setup(); let key = "SOLANA_DYNAMIC_NODES"; let num_nodes: usize = match env::var(key) { - Ok(val) => val.parse() + Ok(val) => val + .parse() .expect(&format!("env var {} is not parse-able as usize", key)), Err(_) => 60, }; let purge_key = "SOLANA_DYNAMIC_NODES_PURGE_LAG"; let purge_lag: usize = match env::var(purge_key) { - Ok(val) => val.parse() + Ok(val) => val + .parse() .expect(&format!("env var {} is not parse-able as usize", purge_key)), Err(_) => std::usize::MAX, };