From fd3695447754789383a802dfde0d513549408c8f Mon Sep 17 00:00:00 2001 From: Anatoly Yakovenko Date: Fri, 14 Sep 2018 11:40:05 -0700 Subject: [PATCH] clippy --- src/bank.rs | 20 +++++++++++--------- src/bin/bench-tps.rs | 14 ++++++-------- src/fullnode.rs | 2 +- src/recvmmsg.rs | 3 +-- src/tpu.rs | 2 +- src/transaction.rs | 10 +++++----- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/bank.rs b/src/bank.rs index 278742bcc1..5b66bce71e 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -363,7 +363,7 @@ impl Bank { let mut called_accounts: Vec = tx .keys .iter() - .map(|key| accounts.get(key).cloned().unwrap_or(Account::default())) + .map(|key| accounts.get(key).cloned().unwrap_or_default()) .collect(); // There is no way to predict what contract will execute without an error // If a fee can pay for execution then the contract will be scheduled @@ -374,7 +374,7 @@ impl Bank { } fn load_accounts( &self, - txs: &Vec, + txs: &[Transaction], accounts: &HashMap, error_counters: &mut ErrorCounters, ) -> Vec>> { @@ -409,8 +409,8 @@ impl Bank { } pub fn store_accounts( - res: &Vec>, - loaded: &Vec>>, + res: &[Result], + loaded: &[Result>], accounts: &mut HashMap, ) { loaded.iter().zip(res.iter()).for_each(|(racc, rtx)| { @@ -439,7 +439,7 @@ impl Bank { let txs_len = txs.len(); let mut error_counters = ErrorCounters::default(); let now = Instant::now(); - let mut loaded_accounts = self.load_accounts(&txs, &mut accounts, &mut error_counters); + let mut loaded_accounts = self.load_accounts(&txs, &accounts, &mut error_counters); let load_elapsed = now.elapsed(); let now = Instant::now(); @@ -494,7 +494,7 @@ impl Bank { } } let cur_tx_count = self.transaction_count.load(Ordering::Relaxed); - if ((cur_tx_count + tx_count) & !(262144 - 1)) > cur_tx_count & !(262144 - 1) { + if ((cur_tx_count + tx_count) & !(262_144 - 1)) > cur_tx_count & !(262_144 - 1) { info!("accounts.len: {}", accounts.len()); } self.transaction_count @@ -628,7 +628,7 @@ impl Bank { /// will progress one step. fn apply_signature(from: Pubkey, signature: Signature, account: &mut [Account]) { let mut pending: HashMap = - deserialize(&account[1].userdata).unwrap_or(HashMap::new()); + deserialize(&account[1].userdata).unwrap_or_default(); if let Occupied(mut e) = pending.entry(signature) { e.get_mut().apply_witness(&Witness::Signature, &from); if let Some(payment) = e.get().final_payment() { @@ -651,13 +651,15 @@ impl Bank { /// will progress one step. fn apply_timestamp(from: Pubkey, dt: DateTime, account: &mut Account) { let mut pending: HashMap = - deserialize(&account.userdata).unwrap_or(HashMap::new()); + deserialize(&account.userdata).unwrap_or_default(); + //deserialize(&account.userdata).unwrap_or(HashMap::new()); + // Check to see if any timelocked transactions can be completed. let mut completed = vec![]; // 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'. - for (key, plan) in pending.iter_mut() { + for (key, plan) in &mut pending { plan.apply_witness(&Witness::Timestamp(dt), &from); if let Some(_payment) = plan.final_payment() { completed.push(key.clone()); diff --git a/src/bin/bench-tps.rs b/src/bin/bench-tps.rs index 9201569321..2b9327e4db 100644 --- a/src/bin/bench-tps.rs +++ b/src/bin/bench-tps.rs @@ -515,14 +515,12 @@ fn main() { ); exit(1); } - if matches.is_present("reject-extra-nodes") { - if nodes.len() > num_nodes { - println!( - "Error: Extra nodes discovered. Expecting exactly {}", - num_nodes - ); - exit(1); - } + if matches.is_present("reject-extra-nodes") && nodes.len() > num_nodes { + println!( + "Error: Extra nodes discovered. Expecting exactly {}", + num_nodes + ); + exit(1); } if leader.is_none() { diff --git a/src/fullnode.rs b/src/fullnode.rs index 7209185723..bb8088365c 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -293,7 +293,7 @@ impl Fullnode { &crdt, tick_duration, node.sockets.transaction, - blob_recycler.clone(), + &blob_recycler, exit.clone(), ledger_path, sigverify_disabled, diff --git a/src/recvmmsg.rs b/src/recvmmsg.rs index 908713fb85..ce6f89a379 100644 --- a/src/recvmmsg.rs +++ b/src/recvmmsg.rs @@ -12,8 +12,7 @@ pub fn recv_mmsg(socket: &UdpSocket, packets: &mut [Packet]) -> io::Result 0 => { diff --git a/src/tpu.rs b/src/tpu.rs index 7ae5221806..9b9bc7c15f 100644 --- a/src/tpu.rs +++ b/src/tpu.rs @@ -57,7 +57,7 @@ impl Tpu { crdt: &Arc>, tick_duration: Option, transactions_sockets: Vec, - blob_recycler: BlobRecycler, + blob_recycler: &BlobRecycler, exit: Arc, ledger_path: &str, sigverify_disabled: bool, diff --git a/src/transaction.rs b/src/transaction.rs index 8f3d52fe2d..53a6d263b6 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -131,11 +131,11 @@ impl Transaction { fn new_from_instruction( from_keypair: &Keypair, contract: Pubkey, - instruction: Instruction, + instruction: &Instruction, last_id: Hash, fee: i64, ) -> Self { - let userdata = serialize(&instruction).unwrap(); + let userdata = serialize(instruction).unwrap(); Self::new_with_userdata(from_keypair, &[contract], userdata, last_id, fee) } @@ -154,7 +154,7 @@ impl Transaction { let budget = Budget::Pay(payment); let plan = Plan::Budget(budget); let instruction = Instruction::NewContract(Contract { plan, tokens }); - Self::new_from_instruction(from_keypair, contract, instruction, last_id, fee) + Self::new_from_instruction(from_keypair, contract, &instruction, last_id, fee) } /// Create and sign a new Transaction. Used for unit-testing. @@ -170,7 +170,7 @@ impl Transaction { last_id: Hash, ) -> Self { let instruction = Instruction::ApplyTimestamp(dt); - Self::new_from_instruction(from_keypair, contract, instruction, last_id, 0) + Self::new_from_instruction(from_keypair, contract, &instruction, last_id, 0) } /// Create and sign a new Witness Signature. Used for unit-testing. @@ -181,7 +181,7 @@ impl Transaction { last_id: Hash, ) -> Self { let instruction = Instruction::ApplySignature(signature); - Self::new_from_instruction(from_keypair, contract, instruction, last_id, 0) + Self::new_from_instruction(from_keypair, contract, &instruction, last_id, 0) } pub fn new_vote(from_keypair: &Keypair, vote: Vote, last_id: Hash, fee: i64) -> Self {