From aaaa6d72e9d5fca7b292f905a02eccb3bc55d776 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Fri, 13 Jul 2018 13:32:20 -0600 Subject: [PATCH] Don't clone before borrowing Clippy told us to change function parameters to references, but wasn't able to then tell us that the clone() before borrowing was superfluous. This patch removes those by hand. No expectation of a performance improvement here, since we were just cloning reference counts. Just removes a bunch of noise. --- benches/bank.rs | 2 +- src/banking_stage.rs | 2 +- src/bin/client-demo.rs | 4 ++-- src/fullnode.rs | 16 ++++++++-------- src/ncp.rs | 2 +- src/sigverify_stage.rs | 2 +- src/tpu.rs | 2 +- src/tvu.rs | 19 ++++++++++++------- tests/multinode.rs | 2 +- 9 files changed, 28 insertions(+), 23 deletions(-) diff --git a/benches/bank.rs b/benches/bank.rs index f68e45a80a5600..16c2771ca00dee 100644 --- a/benches/bank.rs +++ b/benches/bank.rs @@ -32,7 +32,7 @@ fn bench_process_transaction(bencher: &mut Bencher) { let rando1 = KeyPair::new(); let tx = Transaction::new(&rando0, rando1.pubkey(), 1, last_id); - assert!(bank.process_transaction(&tx.clone()).is_ok()); + assert!(bank.process_transaction(&tx).is_ok()); // Finally, return the transaction to the benchmark. tx diff --git a/src/banking_stage.rs b/src/banking_stage.rs index c8b7f6de357834..533896a40df2f1 100644 --- a/src/banking_stage.rs +++ b/src/banking_stage.rs @@ -40,7 +40,7 @@ impl BankingStage { .name("solana-banking-stage".to_string()) .spawn(move || loop { if let Err(e) = Self::process_packets( - &bank.clone(), + &bank, &verified_receiver, &signal_sender, &packet_recycler, diff --git a/src/bin/client-demo.rs b/src/bin/client-demo.rs index 62e1f4d8a2a15d..54980bed8f1c3c 100644 --- a/src/bin/client-demo.rs +++ b/src/bin/client-demo.rs @@ -224,7 +224,7 @@ fn main() { let signal = Arc::new(AtomicBool::new(false)); let mut c_threads = vec![]; - let validators = converge(&leader, &signal.clone(), num_nodes, &mut c_threads); + let validators = converge(&leader, &signal, num_nodes, &mut c_threads); assert_eq!(validators.len(), num_nodes); let mut client = mk_client(&leader); @@ -393,7 +393,7 @@ fn converge( let window = default_window(); let gossip_send_socket = udp_random_bind(8000, 10000, 5).unwrap(); let ncp = Ncp::new( - &spy_ref.clone(), + &spy_ref, window.clone(), spy_gossip, gossip_send_socket, diff --git a/src/fullnode.rs b/src/fullnode.rs index 0d3e2340a89e15..af3c365db375eb 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -195,7 +195,7 @@ impl FullNode { let bank = Arc::new(bank); let mut thread_hdls = vec![]; let rpu = Rpu::new( - &bank.clone(), + &bank, node.sockets.requests, node.sockets.respond, exit.clone(), @@ -205,18 +205,18 @@ impl FullNode { let blob_recycler = BlobRecycler::default(); let crdt = Arc::new(RwLock::new(Crdt::new(node.data))); let (tpu, blob_receiver) = Tpu::new( - &bank.clone(), - &crdt.clone(), + &bank, + &crdt, tick_duration, node.sockets.transaction, - &blob_recycler.clone(), + &blob_recycler, exit.clone(), writer, ); thread_hdls.extend(tpu.thread_hdls()); let window = FullNode::new_window(ledger_tail, entry_height, &crdt, &blob_recycler); let ncp = Ncp::new( - &crdt.clone(), + &crdt, window.clone(), node.sockets.gossip, node.sockets.gossip_send, @@ -278,7 +278,7 @@ impl FullNode { let bank = Arc::new(bank); let mut thread_hdls = vec![]; let rpu = Rpu::new( - &bank.clone(), + &bank, node.sockets.requests, node.sockets.respond, exit.clone(), @@ -295,7 +295,7 @@ impl FullNode { let window = FullNode::new_window(ledger_tail, entry_height, &crdt, &blob_recycler); let ncp = Ncp::new( - &crdt.clone(), + &crdt, window.clone(), node.sockets.gossip, node.sockets.gossip_send, @@ -304,7 +304,7 @@ impl FullNode { let tvu = Tvu::new( keypair, - bank.clone(), + &bank, entry_height, crdt.clone(), window.clone(), diff --git a/src/ncp.rs b/src/ncp.rs index e03b7b5df1d714..4ee05dc776ecba 100644 --- a/src/ncp.rs +++ b/src/ncp.rs @@ -93,7 +93,7 @@ mod tests { let c = Arc::new(RwLock::new(crdt)); let w = Arc::new(RwLock::new(vec![])); let d = Ncp::new( - &c.clone(), + &c, w, tn.sockets.gossip, tn.sockets.gossip_send, diff --git a/src/sigverify_stage.rs b/src/sigverify_stage.rs index 57ffa020e76a9a..415452f1084671 100644 --- a/src/sigverify_stage.rs +++ b/src/sigverify_stage.rs @@ -77,7 +77,7 @@ impl SigVerifyStage { verified_sender: Arc>>, ) -> JoinHandle<()> { spawn(move || loop { - if let Err(e) = Self::verifier(&packet_receiver.clone(), &verified_sender.clone()) { + if let Err(e) = Self::verifier(&packet_receiver, &verified_sender) { match e { Error::RecvTimeoutError(RecvTimeoutError::Disconnected) => break, Error::RecvTimeoutError(RecvTimeoutError::Timeout) => (), diff --git a/src/tpu.rs b/src/tpu.rs index 10a21c0b22db9e..d9b4eec2949e7a 100644 --- a/src/tpu.rs +++ b/src/tpu.rs @@ -63,7 +63,7 @@ impl Tpu { let packet_recycler = PacketRecycler::default(); let (fetch_stage, packet_receiver) = - FetchStage::new(transactions_socket, exit, &packet_recycler.clone()); + FetchStage::new(transactions_socket, exit, &packet_recycler); let (sigverify_stage, verified_receiver) = SigVerifyStage::new(packet_receiver); diff --git a/src/tvu.rs b/src/tvu.rs index cf1d79ce011da8..d6e8c99d063439 100644 --- a/src/tvu.rs +++ b/src/tvu.rs @@ -70,7 +70,7 @@ impl Tvu { /// * `exit` - The exit signal. pub fn new( keypair: KeyPair, - bank: Arc, + bank: &Arc, entry_height: u64, crdt: Arc>, window: Window, @@ -83,22 +83,27 @@ impl Tvu { let (fetch_stage, blob_fetch_receiver) = BlobFetchStage::new_multi_socket( vec![replicate_socket, repair_socket], exit, - &blob_recycler.clone(), + &blob_recycler, ); //TODO //the packets coming out of blob_receiver need to be sent to the GPU and verified //then sent to the window, which does the erasure coding reconstruction let (window_stage, blob_window_receiver) = WindowStage::new( - &crdt.clone(), + &crdt, window, entry_height, retransmit_socket, - &blob_recycler.clone(), + &blob_recycler, blob_fetch_receiver, ); - let replicate_stage = - ReplicateStage::new(keypair, bank, crdt, blob_recycler, blob_window_receiver); + let replicate_stage = ReplicateStage::new( + keypair, + bank.clone(), + crdt, + blob_recycler, + blob_window_receiver, + ); Tvu { replicate_stage, @@ -225,7 +230,7 @@ pub mod tests { let tvu = Tvu::new( target1_kp, - bank.clone(), + &bank, 0, cref1, dr_1.1, diff --git a/tests/multinode.rs b/tests/multinode.rs index 46790d8d81c25e..27bb8a8af46fe0 100644 --- a/tests/multinode.rs +++ b/tests/multinode.rs @@ -35,7 +35,7 @@ fn converge(leader: &NodeInfo, num_nodes: usize) -> Vec { let spy_ref = Arc::new(RwLock::new(spy_crdt)); let spy_window = default_window(); let ncp = Ncp::new( - &spy_ref.clone(), + &spy_ref, spy_window, spy.sockets.gossip, spy.sockets.gossip_send,