From 195a880576ccc27b799a2ad72ff3ed633105e1f0 Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Sat, 9 Mar 2019 19:28:43 -0800 Subject: [PATCH] pass Pubkeys as refs, copy only where values needed (#3213) * pass Pubkeys as refs, copy only where values needed * Pubkey is pervasive * fixup --- bench-tps/src/bench.rs | 4 +- benches/append_vec.rs | 4 +- benches/banking_stage.rs | 8 +- benches/ledger.rs | 2 +- core/src/bank_forks.rs | 6 +- core/src/banking_stage.rs | 18 +-- core/src/blockstream.rs | 12 +- core/src/blockstream_service.rs | 6 +- core/src/blocktree_processor.rs | 42 +++---- core/src/broadcast_stage.rs | 6 +- core/src/chacha.rs | 2 +- core/src/cluster_info.rs | 80 ++++++------ core/src/cluster_tests.rs | 4 +- core/src/contact_info.rs | 16 +-- core/src/crds.rs | 24 ++-- core/src/crds_gossip.rs | 31 ++--- core/src/crds_gossip_pull.rs | 66 +++++----- core/src/crds_gossip_push.rs | 52 ++++---- core/src/crds_value.rs | 11 +- core/src/entry.rs | 36 +++--- core/src/fullnode.rs | 26 ++-- core/src/leader_confirmation_service.rs | 6 +- core/src/leader_schedule_utils.rs | 4 +- core/src/local_cluster.rs | 16 +-- core/src/packet.rs | 2 +- core/src/replay_stage.rs | 28 +++-- core/src/rpc.rs | 34 +++--- core/src/rpc_mock.rs | 4 +- core/src/rpc_pubsub.rs | 20 +-- core/src/rpc_request.rs | 2 +- core/src/rpc_service.rs | 2 +- core/src/rpc_subscriptions.rs | 10 +- core/src/staking_utils.rs | 10 +- core/src/storage_stage.rs | 10 +- core/src/test_tx.rs | 2 +- core/src/thin_client.rs | 22 ++-- core/src/tpu.rs | 2 +- core/src/tvu.rs | 8 +- core/src/voting_keypair.rs | 21 ++-- drone/src/drone.rs | 4 +- drone/tests/local-drone.rs | 2 +- fullnode/src/main.rs | 4 +- genesis/src/main.rs | 2 +- ledger-tool/tests/basic.rs | 2 +- programs/bpf/tests/programs.rs | 16 +-- programs/budget/src/budget_program.rs | 64 +++++----- programs/budget/tests/budget.rs | 4 +- programs/budget_api/src/budget_expr.rs | 77 ++++++------ programs/budget_api/src/budget_instruction.rs | 24 ++-- programs/budget_api/src/budget_state.rs | 4 +- programs/budget_api/src/budget_transaction.rs | 60 ++++----- programs/failure/tests/failure.rs | 4 +- programs/noop/tests/noop.rs | 4 +- programs/rewards/src/lib.rs | 2 +- programs/rewards/tests/rewards.rs | 18 +-- .../rewards_api/src/rewards_instruction.rs | 4 +- .../rewards_api/src/rewards_transaction.rs | 10 +- programs/storage/tests/storage.rs | 20 +-- programs/storage_api/src/lib.rs | 8 +- programs/system/src/lib.rs | 50 ++++---- programs/system/tests/system.rs | 4 +- programs/vote/src/lib.rs | 4 +- programs/vote/tests/vote.rs | 16 +-- programs/vote_api/src/vote_instruction.rs | 27 +++-- programs/vote_api/src/vote_state.rs | 26 ++-- programs/vote_api/src/vote_transaction.rs | 30 ++--- replicator/src/main.rs | 2 +- runtime/src/accounts.rs | 75 ++++++------ runtime/src/bank.rs | 86 ++++++------- runtime/src/loader_utils.rs | 4 +- runtime/src/runtime.rs | 18 +-- sdk/src/account.rs | 4 +- sdk/src/genesis_block.rs | 12 +- sdk/src/loader_transaction.rs | 4 +- sdk/src/system_instruction.rs | 14 +-- sdk/src/system_transaction.rs | 28 +++-- sdk/src/transaction.rs | 14 +-- sdk/src/transaction_builder.rs | 12 +- tests/cluster_info.rs | 6 +- tests/crds_gossip.rs | 36 +++--- tests/gossip.rs | 10 +- tests/replicator.rs | 32 ++--- tests/rpc.rs | 2 +- tests/tvu.rs | 6 +- vote-signer/src/rpc.rs | 20 +-- wallet/src/main.rs | 2 +- wallet/src/wallet.rs | 114 +++++++++--------- wallet/tests/pay.rs | 40 +++--- wallet/tests/request_airdrop.rs | 2 +- 89 files changed, 864 insertions(+), 828 deletions(-) diff --git a/bench-tps/src/bench.rs b/bench-tps/src/bench.rs index 3b4a05eeed..2970614b99 100644 --- a/bench-tps/src/bench.rs +++ b/bench-tps/src/bench.rs @@ -120,7 +120,7 @@ pub fn send_barrier_transaction( *blockhash = barrier_client.get_recent_blockhash(); let signature = barrier_client - .transfer(0, &source_keypair, *dest_id, blockhash) + .transfer(0, &source_keypair, dest_id, blockhash) .expect("Unable to send barrier transaction"); let confirmatiom = barrier_client.poll_for_signature(&signature); @@ -196,7 +196,7 @@ pub fn generate_txs( .par_iter() .map(|(id, keypair)| { ( - SystemTransaction::new_account(id, keypair.pubkey(), 1, blockhash, 0), + SystemTransaction::new_account(id, &keypair.pubkey(), 1, blockhash, 0), timestamp(), ) }) diff --git a/benches/append_vec.rs b/benches/append_vec.rs index d1f1c50771..be05218aba 100644 --- a/benches/append_vec.rs +++ b/benches/append_vec.rs @@ -200,7 +200,7 @@ fn append_vec_concurrent_get_append(bencher: &mut Bencher) { #[bench] fn bench_account_serialize(bencher: &mut Bencher) { let num: usize = 1000; - let account = Account::new(2, 100, Keypair::new().pubkey()); + let account = Account::new(2, 100, &Keypair::new().pubkey()); let len = get_serialized_size(&account); let ser_len = align_up!(len + std::mem::size_of::(), std::mem::size_of::()); let mut memory = vec![0; num * ser_len]; @@ -225,7 +225,7 @@ fn bench_account_serialize(bencher: &mut Bencher) { #[bench] fn bench_account_serialize_bincode(bencher: &mut Bencher) { let num: usize = 1000; - let account = Account::new(2, 100, Keypair::new().pubkey()); + let account = Account::new(2, 100, &Keypair::new().pubkey()); let len = serialized_size(&account).unwrap() as usize; let mut memory = vec![0u8; num * len]; bencher.iter(|| { diff --git a/benches/banking_stage.rs b/benches/banking_stage.rs index 7add8a47be..817c675b8b 100644 --- a/benches/banking_stage.rs +++ b/benches/banking_stage.rs @@ -55,7 +55,7 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) { let bank = Arc::new(Bank::new(&genesis_block)); let dummy = SystemTransaction::new_move( &mint_keypair, - mint_keypair.pubkey(), + &mint_keypair.pubkey(), 1, genesis_block.hash(), 0, @@ -77,7 +77,7 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) { transactions.iter().for_each(|tx| { let fund = SystemTransaction::new_move( &mint_keypair, - tx.account_keys[0], + &tx.account_keys[0], mint_total / txes as u64, genesis_block.hash(), 0, @@ -147,7 +147,7 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) { let bank = Arc::new(Bank::new(&genesis_block)); let dummy = SystemTransaction::new_move( &mint_keypair, - mint_keypair.pubkey(), + &mint_keypair.pubkey(), 1, genesis_block.hash(), 0, @@ -185,7 +185,7 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) { transactions.iter().for_each(|tx| { let fund = SystemTransaction::new_move( &mint_keypair, - tx.account_keys[0], + &tx.account_keys[0], mint_total / txes as u64, genesis_block.hash(), 0, diff --git a/benches/ledger.rs b/benches/ledger.rs index aebf010223..ab246a3b09 100644 --- a/benches/ledger.rs +++ b/benches/ledger.rs @@ -13,7 +13,7 @@ fn bench_block_to_blobs_to_block(bencher: &mut Bencher) { let zero = Hash::default(); let one = hash(&zero.as_ref()); let keypair = Keypair::new(); - let tx0 = SystemTransaction::new_move(&keypair, keypair.pubkey(), 1, one, 0); + let tx0 = SystemTransaction::new_move(&keypair, &keypair.pubkey(), 1, one, 0); let transactions = vec![tx0; 10]; let entries = next_entries(&zero, 1, transactions); diff --git a/core/src/bank_forks.rs b/core/src/bank_forks.rs index 60d4e81217..b251e3a580 100644 --- a/core/src/bank_forks.rs +++ b/core/src/bank_forks.rs @@ -101,7 +101,7 @@ mod tests { let (genesis_block, _) = GenesisBlock::new(10_000); let bank = Bank::new(&genesis_block); let mut bank_forks = BankForks::new(0, bank); - let child_bank = Bank::new_from_parent(&bank_forks[0u64], Pubkey::default(), 1); + let child_bank = Bank::new_from_parent(&bank_forks[0u64], &Pubkey::default(), 1); child_bank.register_tick(&Hash::default()); bank_forks.insert(1, child_bank); assert_eq!(bank_forks[1u64].tick_height(), 1); @@ -113,7 +113,7 @@ mod tests { let (genesis_block, _) = GenesisBlock::new(10_000); let bank = Bank::new(&genesis_block); let mut bank_forks = BankForks::new(0, bank); - let child_bank = Bank::new_from_parent(&bank_forks[0u64], Pubkey::default(), 1); + let child_bank = Bank::new_from_parent(&bank_forks[0u64], &Pubkey::default(), 1); bank_forks.insert(1, child_bank); assert!(bank_forks.frozen_banks().get(&0).is_some()); assert!(bank_forks.frozen_banks().get(&1).is_none()); @@ -124,7 +124,7 @@ mod tests { let (genesis_block, _) = GenesisBlock::new(10_000); let bank = Bank::new(&genesis_block); let mut bank_forks = BankForks::new(0, bank); - let child_bank = Bank::new_from_parent(&bank_forks[0u64], Pubkey::default(), 1); + let child_bank = Bank::new_from_parent(&bank_forks[0u64], &Pubkey::default(), 1); bank_forks.insert(1, child_bank); assert_eq!(bank_forks.active_banks(), vec![1]); } diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index 2878778bd5..d87370b979 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -440,15 +440,15 @@ mod tests { // good tx let keypair = mint_keypair; - let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, start_hash, 0); + let tx = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, start_hash, 0); // good tx, but no verify let tx_no_ver = - SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, start_hash, 0); + SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, start_hash, 0); // bad tx, AccountNotFound let keypair = Keypair::new(); - let tx_anf = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, start_hash, 0); + let tx_anf = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, start_hash, 0); // send 'em over let packets = to_packets(&[tx, tx_no_ver, tx_anf]); @@ -500,7 +500,7 @@ mod tests { let alice = Keypair::new(); let tx = SystemTransaction::new_account( &mint_keypair, - alice.pubkey(), + &alice.pubkey(), 2, genesis_block.hash(), 0, @@ -514,7 +514,7 @@ mod tests { // Process a second batch that spends one of those lamports. let tx = SystemTransaction::new_account( &alice, - mint_keypair.pubkey(), + &mint_keypair.pubkey(), 1, genesis_block.hash(), 0, @@ -567,8 +567,8 @@ mod tests { let pubkey = Keypair::new().pubkey(); let transactions = vec![ - SystemTransaction::new_move(&mint_keypair, pubkey, 1, genesis_block.hash(), 0), - SystemTransaction::new_move(&mint_keypair, pubkey, 1, genesis_block.hash(), 0), + SystemTransaction::new_move(&mint_keypair, &pubkey, 1, genesis_block.hash(), 0), + SystemTransaction::new_move(&mint_keypair, &pubkey, 1, genesis_block.hash(), 0), ]; let mut results = vec![Ok(()), Ok(())]; @@ -601,7 +601,7 @@ mod tests { let transactions = vec![SystemTransaction::new_move( &mint_keypair, - pubkey, + &pubkey, 1, genesis_block.hash(), 0, @@ -642,7 +642,7 @@ mod tests { let transactions = vec![SystemTransaction::new_move( &mint_keypair, - pubkey, + &pubkey, 2, genesis_block.hash(), 0, diff --git a/core/src/blockstream.rs b/core/src/blockstream.rs index e78ebcb8a1..27cfa8da4b 100644 --- a/core/src/blockstream.rs +++ b/core/src/blockstream.rs @@ -63,14 +63,14 @@ pub trait BlockstreamEvents { &self, slot: u64, tick_height: u64, - leader_id: Pubkey, + leader_id: &Pubkey, entries: &Entry, ) -> Result<()>; fn emit_block_event( &self, slot: u64, tick_height: u64, - leader_id: Pubkey, + leader_id: &Pubkey, blockhash: Hash, ) -> Result<()>; } @@ -88,7 +88,7 @@ where &self, slot: u64, tick_height: u64, - leader_id: Pubkey, + leader_id: &Pubkey, entry: &Entry, ) -> Result<()> { let json_entry = serde_json::to_string(&entry)?; @@ -108,7 +108,7 @@ where &self, slot: u64, tick_height: u64, - leader_id: Pubkey, + leader_id: &Pubkey, blockhash: Hash, ) -> Result<()> { let payload = format!( @@ -175,14 +175,14 @@ mod test { for tick_height in tick_height_initial..=tick_height_final { if tick_height == 5 { blockstream - .emit_block_event(curr_slot, tick_height - 1, leader_id, blockhash) + .emit_block_event(curr_slot, tick_height - 1, &leader_id, blockhash) .unwrap(); curr_slot += 1; } let entry = Entry::new(&mut blockhash, 1, vec![]); // just ticks blockhash = entry.hash; blockstream - .emit_entry_event(curr_slot, tick_height, leader_id, &entry) + .emit_entry_event(curr_slot, tick_height, &leader_id, &entry) .unwrap(); expected_entries.push(entry.clone()); entries.push(entry); diff --git a/core/src/blockstream_service.rs b/core/src/blockstream_service.rs index 2295b75354..51dff3b930 100644 --- a/core/src/blockstream_service.rs +++ b/core/src/blockstream_service.rs @@ -80,13 +80,13 @@ impl BlockstreamService { tick_height += 1; } blockstream - .emit_entry_event(slot, tick_height, slot_leader, &entry) + .emit_entry_event(slot, tick_height, &slot_leader, &entry) .unwrap_or_else(|e| { debug!("Blockstream error: {:?}, {:?}", e, blockstream.output); }); if i == entries.len() - 1 { blockstream - .emit_block_event(slot, tick_height, slot_leader, entry.hash) + .emit_block_event(slot, tick_height, &slot_leader, entry.hash) .unwrap_or_else(|e| { debug!("Blockstream error: {:?}, {:?}", e, blockstream.output); }); @@ -140,7 +140,7 @@ mod test { let keypair = Keypair::new(); let mut blockhash = entries[3].hash; - let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, Hash::default(), 0); + let tx = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, Hash::default(), 0); let entry = Entry::new(&mut blockhash, 1, vec![tx]); blockhash = entry.hash; entries.push(entry); diff --git a/core/src/blocktree_processor.rs b/core/src/blocktree_processor.rs index a8410d137a..fda9f7ba1e 100644 --- a/core/src/blocktree_processor.rs +++ b/core/src/blocktree_processor.rs @@ -194,7 +194,7 @@ pub fn process_blocktree( if next_meta.is_full() { let next_bank = Arc::new(Bank::new_from_parent( &bank, - leader_schedule_utils::slot_leader_at(next_slot, &bank).unwrap(), + &leader_schedule_utils::slot_leader_at(next_slot, &bank).unwrap(), next_slot, )); trace!("Add child bank for slot={}", next_slot); @@ -429,7 +429,7 @@ mod tests { let slot_entries = create_ticks(genesis_block.ticks_per_slot - 1, genesis_block.hash()); let tx = SystemTransaction::new_account( &mint_keypair, - keypair.pubkey(), + &keypair.pubkey(), 1, slot_entries.last().unwrap().hash, 0, @@ -450,7 +450,7 @@ mod tests { fn test_process_ledger_simple() { solana_logger::setup(); let leader_pubkey = Keypair::new().pubkey(); - let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, leader_pubkey, 50); + let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, &leader_pubkey, 50); let (ledger_path, mut last_entry_hash) = create_new_tmp_ledger!(&genesis_block); debug!("ledger_path: {:?}", ledger_path); @@ -460,7 +460,7 @@ mod tests { // Transfer one token from the mint to a random account let keypair = Keypair::new(); let tx = - SystemTransaction::new_account(&mint_keypair, keypair.pubkey(), 1, blockhash, 0); + SystemTransaction::new_account(&mint_keypair, &keypair.pubkey(), 1, blockhash, 0); let entry = Entry::new(&last_entry_hash, 1, vec![tx]); last_entry_hash = entry.hash; entries.push(entry); @@ -468,7 +468,7 @@ mod tests { // Add a second Transaction that will produce a // ProgramError<0, ResultWithNegativeLamports> error when processed let keypair2 = Keypair::new(); - let tx = SystemTransaction::new_account(&keypair, keypair2.pubkey(), 42, blockhash, 0); + let tx = SystemTransaction::new_account(&keypair, &keypair2.pubkey(), 42, blockhash, 0); let entry = Entry::new(&last_entry_hash, 1, vec![tx]); last_entry_hash = entry.hash; entries.push(entry); @@ -545,7 +545,7 @@ mod tests { // ensure bank can process 2 entries that have a common account and no tick is registered let tx = SystemTransaction::new_account( &mint_keypair, - keypair1.pubkey(), + &keypair1.pubkey(), 2, bank.last_blockhash(), 0, @@ -553,7 +553,7 @@ mod tests { let entry_1 = next_entry(&blockhash, 1, vec![tx]); let tx = SystemTransaction::new_account( &mint_keypair, - keypair2.pubkey(), + &keypair2.pubkey(), 2, bank.last_blockhash(), 0, @@ -575,11 +575,11 @@ mod tests { // fund: put 4 in each of 1 and 2 assert_matches!( - bank.transfer(4, &mint_keypair, keypair1.pubkey(), bank.last_blockhash()), + bank.transfer(4, &mint_keypair, &keypair1.pubkey(), bank.last_blockhash()), Ok(_) ); assert_matches!( - bank.transfer(4, &mint_keypair, keypair2.pubkey(), bank.last_blockhash()), + bank.transfer(4, &mint_keypair, &keypair2.pubkey(), bank.last_blockhash()), Ok(_) ); @@ -589,7 +589,7 @@ mod tests { 1, vec![SystemTransaction::new_account( &keypair1, - mint_keypair.pubkey(), + &mint_keypair.pubkey(), 1, bank.last_blockhash(), 0, @@ -602,14 +602,14 @@ mod tests { vec![ SystemTransaction::new_account( &keypair2, - keypair3.pubkey(), + &keypair3.pubkey(), 2, bank.last_blockhash(), 0, ), // should be fine SystemTransaction::new_account( &keypair1, - mint_keypair.pubkey(), + &mint_keypair.pubkey(), 2, bank.last_blockhash(), 0, @@ -639,7 +639,7 @@ mod tests { //load accounts let tx = SystemTransaction::new_account( &mint_keypair, - keypair1.pubkey(), + &keypair1.pubkey(), 1, bank.last_blockhash(), 0, @@ -647,7 +647,7 @@ mod tests { assert_eq!(bank.process_transaction(&tx), Ok(())); let tx = SystemTransaction::new_account( &mint_keypair, - keypair2.pubkey(), + &keypair2.pubkey(), 1, bank.last_blockhash(), 0, @@ -658,7 +658,7 @@ mod tests { let blockhash = bank.last_blockhash(); let tx = SystemTransaction::new_account( &keypair1, - keypair3.pubkey(), + &keypair3.pubkey(), 1, bank.last_blockhash(), 0, @@ -666,7 +666,7 @@ mod tests { let entry_1 = next_entry(&blockhash, 1, vec![tx]); let tx = SystemTransaction::new_account( &keypair2, - keypair4.pubkey(), + &keypair4.pubkey(), 1, bank.last_blockhash(), 0, @@ -690,7 +690,7 @@ mod tests { //load accounts let tx = SystemTransaction::new_account( &mint_keypair, - keypair1.pubkey(), + &keypair1.pubkey(), 1, bank.last_blockhash(), 0, @@ -698,7 +698,7 @@ mod tests { assert_eq!(bank.process_transaction(&tx), Ok(())); let tx = SystemTransaction::new_account( &mint_keypair, - keypair2.pubkey(), + &keypair2.pubkey(), 1, bank.last_blockhash(), 0, @@ -711,12 +711,12 @@ mod tests { } // ensure bank can process 2 entries that do not have a common account and tick is registered - let tx = SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 1, blockhash, 0); + let tx = SystemTransaction::new_account(&keypair2, &keypair3.pubkey(), 1, blockhash, 0); let entry_1 = next_entry(&blockhash, 1, vec![tx]); let tick = next_entry(&entry_1.hash, 1, vec![]); let tx = SystemTransaction::new_account( &keypair1, - keypair4.pubkey(), + &keypair4.pubkey(), 1, bank.last_blockhash(), 0, @@ -732,7 +732,7 @@ mod tests { // ensure that an error is returned for an empty account (keypair2) let tx = SystemTransaction::new_account( &keypair2, - keypair3.pubkey(), + &keypair3.pubkey(), 1, bank.last_blockhash(), 0, diff --git a/core/src/broadcast_stage.rs b/core/src/broadcast_stage.rs index 6463123921..89ca33318e 100644 --- a/core/src/broadcast_stage.rs +++ b/core/src/broadcast_stage.rs @@ -281,7 +281,7 @@ mod test { } fn setup_dummy_broadcast_service( - leader_pubkey: Pubkey, + leader_pubkey: &Pubkey, ledger_path: &str, entry_receiver: Receiver, ) -> MockBroadcastStage { @@ -293,7 +293,7 @@ mod test { // Make a node to broadcast to let buddy_keypair = Keypair::new(); - let broadcast_buddy = Node::new_localhost_with_pubkey(buddy_keypair.pubkey()); + let broadcast_buddy = Node::new_localhost_with_pubkey(&buddy_keypair.pubkey()); // Fill the cluster_info with the buddy's info let mut cluster_info = ClusterInfo::new_with_invalid_keypair(leader_info.info.clone()); @@ -332,7 +332,7 @@ mod test { let (entry_sender, entry_receiver) = channel(); let broadcast_service = setup_dummy_broadcast_service( - leader_keypair.pubkey(), + &leader_keypair.pubkey(), &ledger_path, entry_receiver, ); diff --git a/core/src/chacha.rs b/core/src/chacha.rs index 90d4983caf..fabe5bfbb4 100644 --- a/core/src/chacha.rs +++ b/core/src/chacha.rs @@ -126,7 +126,7 @@ mod tests { &mut num_hashes, vec![SystemTransaction::new_account( &keypair, - keypair.pubkey(), + &keypair.pubkey(), 1, one, 0, diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index 8624c651c8..d1d4e0893e 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -176,7 +176,7 @@ impl ClusterInfo { entrypoint: None, }; let id = contact_info.id; - me.gossip.set_self(id); + me.gossip.set_self(&id); me.insert_self(contact_info); me.push_self(&HashMap::new()); me @@ -209,15 +209,15 @@ impl ClusterInfo { pub fn id(&self) -> Pubkey { self.gossip.id } - pub fn lookup(&self, id: Pubkey) -> Option<&ContactInfo> { - let entry = CrdsValueLabel::ContactInfo(id); + pub fn lookup(&self, id: &Pubkey) -> Option<&ContactInfo> { + let entry = CrdsValueLabel::ContactInfo(*id); self.gossip .crds .lookup(&entry) .and_then(|x| x.contact_info()) } pub fn my_data(&self) -> ContactInfo { - self.lookup(self.id()).cloned().unwrap() + self.lookup(&self.id()).cloned().unwrap() } fn leader_id(&self) -> Pubkey { self.gossip_leader_id @@ -228,7 +228,7 @@ impl ClusterInfo { if leader_id == Pubkey::default() { return None; } - self.lookup(leader_id) + self.lookup(&leader_id) } pub fn contact_info_trace(&self) -> String { let leader_id = self.leader_id(); @@ -264,14 +264,14 @@ impl ClusterInfo { ) } - pub fn set_leader(&mut self, leader_id: Pubkey) { + pub fn set_leader(&mut self, leader_id: &Pubkey) { warn!( "{}: LEADER_UPDATE TO {} from {}", self.gossip.id, leader_id, self.leader_id() ); - self.gossip_leader_id = leader_id; + self.gossip_leader_id = *leader_id; } pub fn push_vote(&mut self, vote: Transaction) { @@ -822,7 +822,7 @@ impl ClusterInfo { } pr.into_iter() .map(|(peer, filter, gossip, self_info)| { - self.gossip.mark_pull_request_creation_time(peer, now); + self.gossip.mark_pull_request_creation_time(&peer, now); (gossip, Protocol::PullRequest(filter, self_info)) }) .collect() @@ -1022,7 +1022,7 @@ impl ClusterInfo { to_shared_blob(rsp, from.gossip).ok().into_iter().collect() } } - fn handle_pull_response(me: &Arc>, from: Pubkey, data: Vec) { + fn handle_pull_response(me: &Arc>, from: &Pubkey, data: Vec) { let len = data.len(); let now = Instant::now(); let self_id = me.read().unwrap().gossip.id; @@ -1038,7 +1038,7 @@ impl ClusterInfo { } fn handle_push_message( me: &Arc>, - from: Pubkey, + from: &Pubkey, data: &[CrdsValue], ) -> Vec { let self_id = me.read().unwrap().gossip.id; @@ -1059,7 +1059,7 @@ impl ClusterInfo { pubkey: self_id, prunes, signature: Signature::default(), - destination: from, + destination: *from, wallclock: timestamp(), }; prune_msg.sign(&me.read().unwrap().keypair); @@ -1109,7 +1109,7 @@ impl ClusterInfo { .unwrap() .gossip .crds - .update_record_timestamp(from.id, timestamp()); + .update_record_timestamp(&from.id, timestamp()); let my_info = me.read().unwrap().my_data().clone(); inc_new_counter_info!("cluster_info-window-request-recv", 1); trace!( @@ -1158,7 +1158,7 @@ impl ClusterInfo { } ret }); - Self::handle_pull_response(me, from, data); + Self::handle_pull_response(me, &from, data); vec![] } Protocol::PushMessage(from, mut data) => { @@ -1169,15 +1169,15 @@ impl ClusterInfo { } ret }); - Self::handle_push_message(me, from, &data) + Self::handle_push_message(me, &from, &data) } Protocol::PruneMessage(from, data) => { if data.verify() { inc_new_counter_info!("cluster_info-prune_message", 1); inc_new_counter_info!("cluster_info-prune_message-size", data.prunes.len()); match me.write().unwrap().gossip.process_prune_msg( - from, - data.destination, + &from, + &data.destination, &data.prunes, data.wallclock, timestamp(), @@ -1272,7 +1272,7 @@ impl ClusterInfo { let (_, gossip_socket) = bind_in_range(FULLNODE_PORT_RANGE).unwrap(); let daddr = socketaddr_any!(); - let node = ContactInfo::new(*id, daddr, daddr, daddr, daddr, daddr, daddr, timestamp()); + let node = ContactInfo::new(id, daddr, daddr, daddr, daddr, daddr, daddr, timestamp()); (node, gossip_socket) } } @@ -1345,9 +1345,9 @@ pub struct Node { impl Node { pub fn new_localhost() -> Self { let pubkey = Keypair::new().pubkey(); - Self::new_localhost_with_pubkey(pubkey) + Self::new_localhost_with_pubkey(&pubkey) } - pub fn new_localhost_with_pubkey(pubkey: Pubkey) -> Self { + pub fn new_localhost_with_pubkey(pubkey: &Pubkey) -> Self { let tpu = UdpSocket::bind("127.0.0.1:0").unwrap(); let gossip = UdpSocket::bind("127.0.0.1:0").unwrap(); let tvu = UdpSocket::bind("127.0.0.1:0").unwrap(); @@ -1383,7 +1383,7 @@ impl Node { }, } } - pub fn new_with_external_ip(pubkey: Pubkey, gossip_addr: &SocketAddr) -> Node { + pub fn new_with_external_ip(pubkey: &Pubkey, gossip_addr: &SocketAddr) -> Node { fn bind() -> (u16, UdpSocket) { bind_in_range(FULLNODE_PORT_RANGE).expect("Failed to bind") }; @@ -1485,43 +1485,43 @@ mod tests { #[test] fn test_cluster_info_new() { - let d = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp()); + let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp()); let cluster_info = ClusterInfo::new_with_invalid_keypair(d.clone()); assert_eq!(d.id, cluster_info.my_data().id); } #[test] fn insert_info_test() { - let d = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp()); + let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp()); let mut cluster_info = ClusterInfo::new_with_invalid_keypair(d); - let d = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp()); + let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp()); let label = CrdsValueLabel::ContactInfo(d.id); cluster_info.insert_info(d); assert!(cluster_info.gossip.crds.lookup(&label).is_some()); } #[test] fn test_insert_self() { - let d = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp()); + let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp()); let mut cluster_info = ClusterInfo::new_with_invalid_keypair(d.clone()); let entry_label = CrdsValueLabel::ContactInfo(cluster_info.id()); assert!(cluster_info.gossip.crds.lookup(&entry_label).is_some()); // inserting something else shouldn't work - let d = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp()); + let d = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp()); cluster_info.insert_self(d.clone()); let label = CrdsValueLabel::ContactInfo(d.id); assert!(cluster_info.gossip.crds.lookup(&label).is_none()); } #[test] fn window_index_request() { - let me = ContactInfo::new_localhost(Keypair::new().pubkey(), timestamp()); + let me = ContactInfo::new_localhost(&Keypair::new().pubkey(), timestamp()); let mut cluster_info = ClusterInfo::new_with_invalid_keypair(me); let rv = cluster_info.window_index_request(0, 0, false); assert_matches!(rv, Err(Error::ClusterInfoError(ClusterInfoError::NoPeers))); let gossip_addr = socketaddr!([127, 0, 0, 1], 1234); let nxt = ContactInfo::new( - Keypair::new().pubkey(), + &Keypair::new().pubkey(), gossip_addr, socketaddr!([127, 0, 0, 1], 1235), socketaddr!([127, 0, 0, 1], 1236), @@ -1537,7 +1537,7 @@ mod tests { let gossip_addr2 = socketaddr!([127, 0, 0, 2], 1234); let nxt = ContactInfo::new( - Keypair::new().pubkey(), + &Keypair::new().pubkey(), gossip_addr2, socketaddr!([127, 0, 0, 1], 1235), socketaddr!([127, 0, 0, 1], 1236), @@ -1570,7 +1570,7 @@ mod tests { { let blocktree = Arc::new(Blocktree::open(&ledger_path).unwrap()); let me = ContactInfo::new( - Keypair::new().pubkey(), + &Keypair::new().pubkey(), socketaddr!("127.0.0.1:1234"), socketaddr!("127.0.0.1:1235"), socketaddr!("127.0.0.1:1236"), @@ -1671,7 +1671,7 @@ mod tests { #[test] fn test_default_leader() { solana_logger::setup(); - let contact_info = ContactInfo::new_localhost(Keypair::new().pubkey(), 0); + let contact_info = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0); let mut cluster_info = ClusterInfo::new_with_invalid_keypair(contact_info); let network_entry_point = ContactInfo::new_gossip_entry_point(&socketaddr!("127.0.0.1:1239")); @@ -1682,7 +1682,7 @@ mod tests { #[test] fn new_with_external_ip_test_random() { let ip = Ipv4Addr::from(0); - let node = Node::new_with_external_ip(Keypair::new().pubkey(), &socketaddr!(ip, 0)); + let node = Node::new_with_external_ip(&Keypair::new().pubkey(), &socketaddr!(ip, 0)); assert_eq!(node.sockets.gossip.local_addr().unwrap().ip(), ip); assert!(node.sockets.tvu.len() > 1); for tx_socket in node.sockets.tvu.iter() { @@ -1715,7 +1715,7 @@ mod tests { #[test] fn new_with_external_ip_test_gossip() { let ip = IpAddr::V4(Ipv4Addr::from(0)); - let node = Node::new_with_external_ip(Keypair::new().pubkey(), &socketaddr!(0, 8050)); + let node = Node::new_with_external_ip(&Keypair::new().pubkey(), &socketaddr!(0, 8050)); assert_eq!(node.sockets.gossip.local_addr().unwrap().ip(), ip); assert!(node.sockets.tvu.len() > 1); for tx_socket in node.sockets.tvu.iter() { @@ -1752,11 +1752,11 @@ mod tests { let keypair = Keypair::new(); let peer_keypair = Keypair::new(); let leader_keypair = Keypair::new(); - let contact_info = ContactInfo::new_localhost(keypair.pubkey(), 0); - let leader = ContactInfo::new_localhost(leader_keypair.pubkey(), 0); - let peer = ContactInfo::new_localhost(peer_keypair.pubkey(), 0); + let contact_info = ContactInfo::new_localhost(&keypair.pubkey(), 0); + let leader = ContactInfo::new_localhost(&leader_keypair.pubkey(), 0); + let peer = ContactInfo::new_localhost(&peer_keypair.pubkey(), 0); let mut cluster_info = ClusterInfo::new(contact_info.clone(), Arc::new(keypair)); - cluster_info.set_leader(leader.id); + cluster_info.set_leader(&leader.id); cluster_info.insert_info(peer.clone()); //check that all types of gossip messages are signed correctly let (_, _, vals) = cluster_info.gossip.new_push_messages(timestamp()); @@ -1926,7 +1926,7 @@ mod tests { fn test_push_vote() { let keys = Keypair::new(); let now = timestamp(); - let contact_info = ContactInfo::new_localhost(keys.pubkey(), 0); + let contact_info = ContactInfo::new_localhost(&keys.pubkey(), 0); let mut cluster_info = ClusterInfo::new_with_invalid_keypair(contact_info); // make sure empty crds is handled correctly @@ -1953,11 +1953,11 @@ mod tests { fn test_add_entrypoint() { let node_keypair = Arc::new(Keypair::new()); let mut cluster_info = ClusterInfo::new( - ContactInfo::new_localhost(node_keypair.pubkey(), timestamp()), + ContactInfo::new_localhost(&node_keypair.pubkey(), timestamp()), node_keypair, ); let entrypoint_id = Keypair::new().pubkey(); - let entrypoint = ContactInfo::new_localhost(entrypoint_id, timestamp()); + let entrypoint = ContactInfo::new_localhost(&entrypoint_id, timestamp()); cluster_info.set_entrypoint(entrypoint.clone()); let pulls = cluster_info.new_pull_requests(&HashMap::new()); assert_eq!(1, pulls.len()); @@ -1978,7 +1978,7 @@ fn test_add_entrypoint() { // now add this message back to the table and make sure after the next pull, the entrypoint is unset let entrypoint_crdsvalue = CrdsValue::ContactInfo(entrypoint.clone()); let cluster_info = Arc::new(RwLock::new(cluster_info)); - ClusterInfo::handle_pull_response(&cluster_info, entrypoint_id, vec![entrypoint_crdsvalue]); + ClusterInfo::handle_pull_response(&cluster_info, &entrypoint_id, vec![entrypoint_crdsvalue]); let pulls = cluster_info .write() .unwrap() diff --git a/core/src/cluster_tests.rs b/core/src/cluster_tests.rs index 4f81d08c79..81cefe970b 100644 --- a/core/src/cluster_tests.rs +++ b/core/src/cluster_tests.rs @@ -33,7 +33,7 @@ pub fn spend_and_verify_all_nodes( assert!(bal > 0); let mut transaction = SystemTransaction::new_move( &funding_keypair, - random_keypair.pubkey(), + &random_keypair.pubkey(), 1, client.get_recent_blockhash(), 0, @@ -124,7 +124,7 @@ pub fn kill_entry_and_spend_and_verify_rest( assert!(bal > 0); let mut transaction = SystemTransaction::new_move( &funding_keypair, - random_keypair.pubkey(), + &random_keypair.pubkey(), 1, client.get_recent_blockhash(), 0, diff --git a/core/src/contact_info.rs b/core/src/contact_info.rs index 62b19302d3..6fc2f4e2f0 100644 --- a/core/src/contact_info.rs +++ b/core/src/contact_info.rs @@ -83,7 +83,7 @@ impl Default for ContactInfo { impl ContactInfo { pub fn new( - id: Pubkey, + id: &Pubkey, gossip: SocketAddr, tvu: SocketAddr, tpu: SocketAddr, @@ -93,7 +93,7 @@ impl ContactInfo { now: u64, ) -> Self { Self { - id, + id: *id, signature: Signature::default(), gossip, tvu, @@ -105,7 +105,7 @@ impl ContactInfo { } } - pub fn new_localhost(id: Pubkey, now: u64) -> Self { + pub fn new_localhost(id: &Pubkey, now: u64) -> Self { Self::new( id, socketaddr!("127.0.0.1:1234"), @@ -124,7 +124,7 @@ impl ContactInfo { let addr = socketaddr!("224.0.1.255:1000"); assert!(addr.ip().is_multicast()); Self::new( - Keypair::new().pubkey(), + &Keypair::new().pubkey(), addr, addr, addr, @@ -139,7 +139,7 @@ impl ContactInfo { nxt_addr.set_port(addr.port() + nxt); nxt_addr } - fn new_with_pubkey_socketaddr(pubkey: Pubkey, bind_addr: &SocketAddr) -> Self { + fn new_with_pubkey_socketaddr(pubkey: &Pubkey, bind_addr: &SocketAddr) -> Self { let tpu_addr = *bind_addr; let gossip_addr = Self::next_port(&bind_addr, 1); let tvu_addr = Self::next_port(&bind_addr, 2); @@ -158,14 +158,14 @@ impl ContactInfo { } pub fn new_with_socketaddr(bind_addr: &SocketAddr) -> Self { let keypair = Keypair::new(); - Self::new_with_pubkey_socketaddr(keypair.pubkey(), bind_addr) + Self::new_with_pubkey_socketaddr(&keypair.pubkey(), bind_addr) } // Construct a ContactInfo that's only usable for gossip pub fn new_gossip_entry_point(gossip_addr: &SocketAddr) -> Self { let daddr: SocketAddr = socketaddr!("0.0.0.0:0"); Self::new( - Pubkey::default(), + &Pubkey::default(), *gossip_addr, daddr, daddr, @@ -292,7 +292,7 @@ mod tests { fn replayed_data_new_with_socketaddr_with_pubkey() { let keypair = Keypair::new(); let d1 = ContactInfo::new_with_pubkey_socketaddr( - keypair.pubkey().clone(), + &keypair.pubkey(), &socketaddr!("127.0.0.1:1234"), ); assert_eq!(d1.id, keypair.pubkey()); diff --git a/core/src/crds.rs b/core/src/crds.rs index 9dc35393bd..00b07cff4b 100644 --- a/core/src/crds.rs +++ b/core/src/crds.rs @@ -135,7 +135,7 @@ impl Crds { } /// Update the timestamp's of all the labels that are assosciated with Pubkey - pub fn update_record_timestamp(&mut self, pubkey: Pubkey, now: u64) { + pub fn update_record_timestamp(&mut self, pubkey: &Pubkey, now: u64) { for label in &CrdsValue::record_labels(pubkey) { self.update_label_timestamp(label, now); } @@ -187,9 +187,9 @@ mod test { #[test] fn test_update_new() { let mut crds = Crds::default(); - let original = CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 0)); + let original = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 0)); assert_matches!(crds.insert(original.clone(), 0), Ok(_)); - let val = CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 1)); + let val = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 1)); assert_eq!( crds.insert(val.clone(), 1).unwrap().unwrap().value, original @@ -199,7 +199,7 @@ mod test { #[test] fn test_update_timestamp() { let mut crds = Crds::default(); - let val = CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 0)); + let val = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 0)); assert_eq!(crds.insert(val.clone(), 0), Ok(None)); crds.update_label_timestamp(&val.label(), 1); @@ -210,13 +210,13 @@ mod test { assert_eq!(val2.label().pubkey(), val.label().pubkey()); assert_matches!(crds.insert(val2.clone(), 0), Ok(Some(_))); - crds.update_record_timestamp(val.label().pubkey(), 2); + crds.update_record_timestamp(&val.label().pubkey(), 2); assert_eq!(crds.table[&val.label()].local_timestamp, 2); assert_eq!(crds.table[&val.label()].insert_timestamp, 0); assert_eq!(crds.table[&val2.label()].local_timestamp, 2); assert_eq!(crds.table[&val2.label()].insert_timestamp, 0); - crds.update_record_timestamp(val.label().pubkey(), 1); + crds.update_record_timestamp(&val.label().pubkey(), 1); assert_eq!(crds.table[&val.label()].local_timestamp, 2); assert_eq!(crds.table[&val.label()].insert_timestamp, 0); @@ -259,10 +259,10 @@ mod test { fn test_hash_order() { let v1 = VersionedCrdsValue::new( 1, - CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 0)), + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 0)), ); let v2 = VersionedCrdsValue::new(1, { - let mut contact_info = ContactInfo::new_localhost(Pubkey::default(), 0); + let mut contact_info = ContactInfo::new_localhost(&Pubkey::default(), 0); contact_info.rpc = socketaddr!("0.0.0.0:0"); CrdsValue::ContactInfo(contact_info) }); @@ -286,11 +286,11 @@ mod test { fn test_wallclock_order() { let v1 = VersionedCrdsValue::new( 1, - CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 1)), + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 1)), ); let v2 = VersionedCrdsValue::new( 1, - CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 0)), + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Pubkey::default(), 0)), ); assert_eq!(v1.value.label(), v2.value.label()); assert!(v1 > v2); @@ -302,11 +302,11 @@ mod test { fn test_label_order() { let v1 = VersionedCrdsValue::new( 1, - CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)), + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)), ); let v2 = VersionedCrdsValue::new( 1, - CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)), + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)), ); assert_ne!(v1, v2); assert!(!(v1 == v2)); diff --git a/core/src/crds_gossip.rs b/core/src/crds_gossip.rs index 04e1e07d60..966900fdef 100644 --- a/core/src/crds_gossip.rs +++ b/core/src/crds_gossip.rs @@ -36,8 +36,8 @@ impl Default for CrdsGossip { } impl CrdsGossip { - pub fn set_self(&mut self, id: Pubkey) { - self.id = id; + pub fn set_self(&mut self, id: &Pubkey) { + self.id = *id; } /// process a push message to the network pub fn process_push_message(&mut self, values: &[CrdsValue], now: u64) -> Vec { @@ -73,8 +73,8 @@ impl CrdsGossip { /// add the `from` to the peer's filter of nodes pub fn process_prune_msg( &mut self, - peer: Pubkey, - destination: Pubkey, + peer: &Pubkey, + destination: &Pubkey, origin: &[Pubkey], wallclock: u64, now: u64, @@ -83,7 +83,7 @@ impl CrdsGossip { if expired { return Err(CrdsGossipError::PruneMessageTimeout); } - if self.id == destination { + if self.id == *destination { self.push.process_prune_msg(peer, origin); Ok(()) } else { @@ -97,7 +97,7 @@ impl CrdsGossip { self.push.refresh_push_active_set( &self.crds, stakes, - self.id, + &self.id, self.pull.pull_request_time.len(), CRDS_GOSSIP_NUM_ACTIVE, ) @@ -109,14 +109,15 @@ impl CrdsGossip { now: u64, stakes: &HashMap, ) -> Result<(Pubkey, Bloom, CrdsValue), CrdsGossipError> { - self.pull.new_pull_request(&self.crds, self.id, now, stakes) + self.pull + .new_pull_request(&self.crds, &self.id, now, stakes) } /// time when a request to `from` was initiated /// This is used for weighted random selection during `new_pull_request` /// It's important to use the local nodes request creation time as the weight /// instead of the response received time otherwise failed nodes will increase their weight. - pub fn mark_pull_request_creation_time(&mut self, from: Pubkey, now: u64) { + pub fn mark_pull_request_creation_time(&mut self, from: &Pubkey, now: u64) { self.pull.mark_pull_request_creation_time(from, now) } /// process a pull request and create a response @@ -132,7 +133,7 @@ impl CrdsGossip { /// process a pull response pub fn process_pull_response( &mut self, - from: Pubkey, + from: &Pubkey, response: Vec, now: u64, ) -> usize { @@ -150,7 +151,7 @@ impl CrdsGossip { } if now > self.pull.crds_timeout { let min = now - self.pull.crds_timeout; - self.pull.purge_active(&mut self.crds, self.id, min); + self.pull.purge_active(&mut self.crds, &self.id, min); } if now > 5 * self.pull.crds_timeout { let min = now - 5 * self.pull.crds_timeout; @@ -188,7 +189,7 @@ mod test { let mut crds_gossip = CrdsGossip::default(); crds_gossip.id = Pubkey::new(&[0; 32]); let id = crds_gossip.id; - let ci = ContactInfo::new_localhost(Pubkey::new(&[1; 32]), 0); + let ci = ContactInfo::new_localhost(&Pubkey::new(&[1; 32]), 0); let prune_pubkey = Pubkey::new(&[2; 32]); crds_gossip .crds @@ -198,19 +199,19 @@ mod test { let now = timestamp(); //incorrect dest let mut res = crds_gossip.process_prune_msg( - ci.id, - Pubkey::new(hash(&[1; 32]).as_ref()), + &ci.id, + &Pubkey::new(hash(&[1; 32]).as_ref()), &[prune_pubkey], now, now, ); assert_eq!(res.err(), Some(CrdsGossipError::BadPruneDestination)); //correct dest - res = crds_gossip.process_prune_msg(ci.id, id, &[prune_pubkey], now, now); + res = crds_gossip.process_prune_msg(&ci.id, &id, &[prune_pubkey], now, now); res.unwrap(); //test timeout let timeout = now + crds_gossip.push.prune_timeout * 2; - res = crds_gossip.process_prune_msg(ci.id, id, &[prune_pubkey], now, timeout); + res = crds_gossip.process_prune_msg(&ci.id, &id, &[prune_pubkey], now, timeout); assert_eq!(res.err(), Some(CrdsGossipError::PruneMessageTimeout)); } } diff --git a/core/src/crds_gossip_pull.rs b/core/src/crds_gossip_pull.rs index 8a8cb9fb35..69fc266de7 100644 --- a/core/src/crds_gossip_pull.rs +++ b/core/src/crds_gossip_pull.rs @@ -53,7 +53,7 @@ impl CrdsGossipPull { pub fn new_pull_request( &self, crds: &Crds, - self_id: Pubkey, + self_id: &Pubkey, now: u64, stakes: &HashMap, ) -> Result<(Pubkey, Bloom, CrdsValue), CrdsGossipError> { @@ -65,7 +65,7 @@ impl CrdsGossipPull { let index = WeightedIndex::new(options.iter().map(|weighted| weighted.0)).unwrap(); let random = index.sample(&mut rand::thread_rng()); let self_info = crds - .lookup(&CrdsValueLabel::ContactInfo(self_id)) + .lookup(&CrdsValueLabel::ContactInfo(*self_id)) .unwrap_or_else(|| panic!("self_id invalid {}", self_id)); Ok((options[random].1.id, filter, self_info.clone())) } @@ -96,8 +96,8 @@ impl CrdsGossipPull { /// This is used for weighted random selection during `new_pull_request` /// It's important to use the local nodes request creation time as the weight /// instead of the response received time otherwise failed nodes will increase their weight. - pub fn mark_pull_request_creation_time(&mut self, from: Pubkey, now: u64) { - self.pull_request_time.insert(from, now); + pub fn mark_pull_request_creation_time(&mut self, from: &Pubkey, now: u64) { + self.pull_request_time.insert(*from, now); } /// Store an old hash in the purged values set @@ -120,14 +120,14 @@ impl CrdsGossipPull { self.purged_values .push_back((val.value_hash, val.local_timestamp)) } - crds.update_record_timestamp(key, now); + crds.update_record_timestamp(&key, now); rv } /// process a pull response pub fn process_pull_response( &mut self, crds: &mut Crds, - from: Pubkey, + from: &Pubkey, response: Vec, now: u64, ) -> usize { @@ -137,7 +137,7 @@ impl CrdsGossipPull { let old = crds.insert(r, now); failed += old.is_err() as usize; old.ok().map(|opt| { - crds.update_record_timestamp(owner, now); + crds.update_record_timestamp(&owner, now); opt.map(|val| { self.purged_values .push_back((val.value_hash, val.local_timestamp)) @@ -180,11 +180,11 @@ impl CrdsGossipPull { } /// Purge values from the crds that are older then `active_timeout` /// The value_hash of an active item is put into self.purged_values queue - pub fn purge_active(&mut self, crds: &mut Crds, self_id: Pubkey, min_ts: u64) { + pub fn purge_active(&mut self, crds: &mut Crds, self_id: &Pubkey, min_ts: u64) { let old = crds.find_old_labels(min_ts); let mut purged: VecDeque<_> = old .iter() - .filter(|label| label.pubkey() != self_id) + .filter(|label| label.pubkey() != *self_id) .filter_map(|label| { let rv = crds .lookup_versioned(label) @@ -216,11 +216,11 @@ mod test { let mut crds = Crds::default(); let mut stakes = HashMap::new(); let node = CrdsGossipPull::default(); - let me = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let me = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); crds.insert(me.clone(), 0).unwrap(); for i in 1..=30 { let entry = - CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let id = entry.label().pubkey(); crds.insert(entry.clone(), 0).unwrap(); stakes.insert(id, i * 100); @@ -239,23 +239,23 @@ mod test { #[test] fn test_new_pull_request() { let mut crds = Crds::default(); - let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let id = entry.label().pubkey(); let node = CrdsGossipPull::default(); assert_eq!( - node.new_pull_request(&crds, id, 0, &HashMap::new()), + node.new_pull_request(&crds, &id, 0, &HashMap::new()), Err(CrdsGossipError::NoPeers) ); crds.insert(entry.clone(), 0).unwrap(); assert_eq!( - node.new_pull_request(&crds, id, 0, &HashMap::new()), + node.new_pull_request(&crds, &id, 0, &HashMap::new()), Err(CrdsGossipError::NoPeers) ); - let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); crds.insert(new.clone(), 0).unwrap(); - let req = node.new_pull_request(&crds, id, 0, &HashMap::new()); + let req = node.new_pull_request(&crds, &id, 0, &HashMap::new()); let (to, _, self_info) = req.unwrap(); assert_eq!(to, new.label().pubkey()); assert_eq!(self_info, entry); @@ -264,21 +264,21 @@ mod test { #[test] fn test_new_mark_creation_time() { let mut crds = Crds::default(); - let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let node_id = entry.label().pubkey(); let mut node = CrdsGossipPull::default(); crds.insert(entry.clone(), 0).unwrap(); - let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); crds.insert(old.clone(), 0).unwrap(); - let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); crds.insert(new.clone(), 0).unwrap(); // set request creation time to max_value - node.mark_pull_request_creation_time(new.label().pubkey(), u64::max_value()); + node.mark_pull_request_creation_time(&new.label().pubkey(), u64::max_value()); // odds of getting the other request should be 1 in u64::max_value() for _ in 0..10 { - let req = node.new_pull_request(&crds, node_id, u64::max_value(), &HashMap::new()); + let req = node.new_pull_request(&crds, &node_id, u64::max_value(), &HashMap::new()); let (to, _, self_info) = req.unwrap(); assert_eq!(to, old.label().pubkey()); assert_eq!(self_info, entry); @@ -288,13 +288,13 @@ mod test { #[test] fn test_process_pull_request() { let mut node_crds = Crds::default(); - let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let node_id = entry.label().pubkey(); let node = CrdsGossipPull::default(); node_crds.insert(entry.clone(), 0).unwrap(); - let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); node_crds.insert(new.clone(), 0).unwrap(); - let req = node.new_pull_request(&node_crds, node_id, 0, &HashMap::new()); + let req = node.new_pull_request(&node_crds, &node_id, 0, &HashMap::new()); let mut dest_crds = Crds::default(); let mut dest = CrdsGossipPull::default(); @@ -320,22 +320,22 @@ mod test { #[test] fn test_process_pull_request_response() { let mut node_crds = Crds::default(); - let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let node_id = entry.label().pubkey(); let mut node = CrdsGossipPull::default(); node_crds.insert(entry.clone(), 0).unwrap(); - let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); node_crds.insert(new.clone(), 0).unwrap(); let mut dest = CrdsGossipPull::default(); let mut dest_crds = Crds::default(); let new_id = Keypair::new().pubkey(); - let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(new_id, 1)); + let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(&new_id, 1)); dest_crds.insert(new.clone(), 0).unwrap(); // node contains a key from the dest node, but at an older local timestamp - let same_key = CrdsValue::ContactInfo(ContactInfo::new_localhost(new_id, 0)); + let same_key = CrdsValue::ContactInfo(ContactInfo::new_localhost(&new_id, 0)); assert_eq!(same_key.label(), new.label()); assert!(same_key.wallclock() < new.wallclock()); node_crds.insert(same_key.clone(), 0).unwrap(); @@ -349,7 +349,7 @@ mod test { let mut done = false; for _ in 0..30 { // there is a chance of a false positive with bloom filters - let req = node.new_pull_request(&node_crds, node_id, 0, &HashMap::new()); + let req = node.new_pull_request(&node_crds, &node_id, 0, &HashMap::new()); let (_, filter, caller) = req.unwrap(); let rsp = dest.process_pull_request(&mut dest_crds, caller, filter, 0); // if there is a false positive this is empty @@ -359,7 +359,7 @@ mod test { } assert_eq!(rsp.len(), 1); - let failed = node.process_pull_response(&mut node_crds, node_id, rsp, 1); + let failed = node.process_pull_response(&mut node_crds, &node_id, rsp, 1); assert_eq!(failed, 0); assert_eq!( node_crds @@ -384,12 +384,12 @@ mod test { #[test] fn test_gossip_purge() { let mut node_crds = Crds::default(); - let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let node_label = entry.label(); let node_id = node_label.pubkey(); let mut node = CrdsGossipPull::default(); node_crds.insert(entry.clone(), 0).unwrap(); - let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let old = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); node_crds.insert(old.clone(), 0).unwrap(); let value_hash = node_crds.lookup_versioned(&old.label()).unwrap().value_hash; @@ -397,7 +397,7 @@ mod test { assert_eq!(node_crds.lookup(&node_label).unwrap().label(), node_label); // purge - node.purge_active(&mut node_crds, node_id, 1); + node.purge_active(&mut node_crds, &node_id, 1); //verify self is still valid after purge assert_eq!(node_crds.lookup(&node_label).unwrap().label(), node_label); diff --git a/core/src/crds_gossip_push.rs b/core/src/crds_gossip_push.rs index 4fbee3f275..b0d29b7b7f 100644 --- a/core/src/crds_gossip_push.rs +++ b/core/src/crds_gossip_push.rs @@ -144,9 +144,9 @@ impl CrdsGossipPush { } /// add the `from` to the peer's filter of nodes - pub fn process_prune_msg(&mut self, peer: Pubkey, origins: &[Pubkey]) { + pub fn process_prune_msg(&mut self, peer: &Pubkey, origins: &[Pubkey]) { for origin in origins { - if let Some(p) = self.active_set.get_mut(&peer) { + if let Some(p) = self.active_set.get_mut(peer) { p.add(origin) } } @@ -163,7 +163,7 @@ impl CrdsGossipPush { &mut self, crds: &Crds, stakes: &HashMap, - self_id: Pubkey, + self_id: &Pubkey, network_size: usize, ratio: usize, ) { @@ -272,7 +272,7 @@ mod test { fn test_process_push() { let mut crds = Crds::default(); let mut push = CrdsGossipPush::default(); - let value = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let value = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let label = value.label(); // push a new message assert_eq!( @@ -291,7 +291,7 @@ mod test { fn test_process_push_old_version() { let mut crds = Crds::default(); let mut push = CrdsGossipPush::default(); - let mut ci = ContactInfo::new_localhost(Keypair::new().pubkey(), 0); + let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0); ci.wallclock = 1; let value = CrdsValue::ContactInfo(ci.clone()); @@ -311,7 +311,7 @@ mod test { let mut crds = Crds::default(); let mut push = CrdsGossipPush::default(); let timeout = push.msg_timeout; - let mut ci = ContactInfo::new_localhost(Keypair::new().pubkey(), 0); + let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0); // push a version to far in the future ci.wallclock = timeout + 1; @@ -333,7 +333,7 @@ mod test { fn test_process_push_update() { let mut crds = Crds::default(); let mut push = CrdsGossipPush::default(); - let mut ci = ContactInfo::new_localhost(Keypair::new().pubkey(), 0); + let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0); ci.wallclock = 0; let value_old = CrdsValue::ContactInfo(ci.clone()); @@ -366,17 +366,19 @@ mod test { solana_logger::setup(); let mut crds = Crds::default(); let mut push = CrdsGossipPush::default(); - let value1 = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let value1 = + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); assert_eq!(crds.insert(value1.clone(), 0), Ok(None)); - push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1); + push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1); assert!(push.active_set.get(&value1.label().pubkey()).is_some()); - let value2 = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let value2 = + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); assert!(push.active_set.get(&value2.label().pubkey()).is_none()); assert_eq!(crds.insert(value2.clone(), 0), Ok(None)); for _ in 0..30 { - push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1); + push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1); if push.active_set.get(&value2.label().pubkey()).is_some() { break; } @@ -385,10 +387,10 @@ mod test { for _ in 0..push.num_active { let value2 = - CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); assert_eq!(crds.insert(value2.clone(), 0), Ok(None)); } - push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1); + push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1); assert_eq!(push.active_set.len(), push.num_active); } #[test] @@ -399,7 +401,7 @@ mod test { let mut stakes = HashMap::new(); for i in 1..=100 { let peer = - CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), time)); + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), time)); let id = peer.label().pubkey(); crds.insert(peer.clone(), time).unwrap(); stakes.insert(id, i * 100); @@ -417,12 +419,12 @@ mod test { fn test_new_push_messages() { let mut crds = Crds::default(); let mut push = CrdsGossipPush::default(); - let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); assert_eq!(crds.insert(peer.clone(), 0), Ok(None)); - push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1); + push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1); let new_msg = - CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); assert_eq!( push.process_push_message(&mut crds, new_msg.clone(), 0), Ok(None) @@ -437,17 +439,17 @@ mod test { fn test_process_prune() { let mut crds = Crds::default(); let mut push = CrdsGossipPush::default(); - let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); assert_eq!(crds.insert(peer.clone(), 0), Ok(None)); - push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1); + push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1); let new_msg = - CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); assert_eq!( push.process_push_message(&mut crds, new_msg.clone(), 0), Ok(None) ); - push.process_prune_msg(peer.label().pubkey(), &[new_msg.label().pubkey()]); + push.process_prune_msg(&peer.label().pubkey(), &[new_msg.label().pubkey()]); assert_eq!( push.new_push_messages(&crds, 0), (vec![peer.label().pubkey()], vec![]) @@ -457,11 +459,11 @@ mod test { fn test_purge_old_pending_push_messages() { let mut crds = Crds::default(); let mut push = CrdsGossipPush::default(); - let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let peer = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); assert_eq!(crds.insert(peer.clone(), 0), Ok(None)); - push.refresh_push_active_set(&crds, &HashMap::new(), Pubkey::default(), 1, 1); + push.refresh_push_active_set(&crds, &HashMap::new(), &Pubkey::default(), 1, 1); - let mut ci = ContactInfo::new_localhost(Keypair::new().pubkey(), 0); + let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0); ci.wallclock = 1; let new_msg = CrdsValue::ContactInfo(ci.clone()); assert_eq!( @@ -479,7 +481,7 @@ mod test { fn test_purge_old_pushed_once_messages() { let mut crds = Crds::default(); let mut push = CrdsGossipPush::default(); - let mut ci = ContactInfo::new_localhost(Keypair::new().pubkey(), 0); + let mut ci = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0); ci.wallclock = 0; let value = CrdsValue::ContactInfo(ci.clone()); let label = value.label(); diff --git a/core/src/crds_value.rs b/core/src/crds_value.rs index 073dfa2284..cac72eea07 100644 --- a/core/src/crds_value.rs +++ b/core/src/crds_value.rs @@ -108,8 +108,11 @@ impl CrdsValue { } } /// Return all the possible labels for a record identified by Pubkey. - pub fn record_labels(key: Pubkey) -> [CrdsValueLabel; 2] { - [CrdsValueLabel::ContactInfo(key), CrdsValueLabel::Vote(key)] + pub fn record_labels(key: &Pubkey) -> [CrdsValueLabel; 2] { + [ + CrdsValueLabel::ContactInfo(*key), + CrdsValueLabel::Vote(*key), + ] } } @@ -159,7 +162,7 @@ mod test { fn test_labels() { let mut hits = [false; 2]; // this method should cover all the possible labels - for v in &CrdsValue::record_labels(Pubkey::default()) { + for v in &CrdsValue::record_labels(&Pubkey::default()) { match v { CrdsValueLabel::ContactInfo(_) => hits[0] = true, CrdsValueLabel::Vote(_) => hits[1] = true, @@ -184,7 +187,7 @@ mod test { let keypair = Keypair::new(); let fake_keypair = Keypair::new(); let mut v = - CrdsValue::ContactInfo(ContactInfo::new_localhost(keypair.pubkey(), timestamp())); + CrdsValue::ContactInfo(ContactInfo::new_localhost(&keypair.pubkey(), timestamp())); v.sign(&keypair); assert!(v.verify()); v.sign(&fake_keypair); diff --git a/core/src/entry.rs b/core/src/entry.rs index a7f8d044f8..eb22467cdb 100644 --- a/core/src/entry.rs +++ b/core/src/entry.rs @@ -400,8 +400,8 @@ pub fn make_tiny_test_entries_from_hash(start: &Hash, num: usize) -> Vec &mut num_hashes, vec![BudgetTransaction::new_timestamp( &keypair, - keypair.pubkey(), - keypair.pubkey(), + &keypair.pubkey(), + &keypair.pubkey(), Utc::now(), *start, )], @@ -423,8 +423,8 @@ pub fn make_large_test_entries(num_entries: usize) -> Vec { let tx = BudgetTransaction::new_timestamp( &keypair, - keypair.pubkey(), - keypair.pubkey(), + &keypair.pubkey(), + &keypair.pubkey(), Utc::now(), one, ); @@ -496,8 +496,8 @@ mod tests { // First, verify entries let keypair = Keypair::new(); - let tx0 = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, zero, 0); - let tx1 = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, zero, 0); + let tx0 = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 0, zero, 0); + let tx1 = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, zero, 0); let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()]); assert!(e0.verify(&zero)); @@ -515,13 +515,13 @@ mod tests { let keypair = Keypair::new(); let tx0 = BudgetTransaction::new_timestamp( &keypair, - keypair.pubkey(), - keypair.pubkey(), + &keypair.pubkey(), + &keypair.pubkey(), Utc::now(), zero, ); let tx1 = - BudgetTransaction::new_signature(&keypair, keypair.pubkey(), keypair.pubkey(), zero); + BudgetTransaction::new_signature(&keypair, &keypair.pubkey(), &keypair.pubkey(), zero); let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()]); assert!(e0.verify(&zero)); @@ -545,8 +545,8 @@ mod tests { let keypair = Keypair::new(); let tx0 = BudgetTransaction::new_timestamp( &keypair, - keypair.pubkey(), - keypair.pubkey(), + &keypair.pubkey(), + &keypair.pubkey(), Utc::now(), zero, ); @@ -560,7 +560,7 @@ mod tests { fn test_next_entry_panic() { let zero = Hash::default(); let keypair = Keypair::new(); - let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, zero, 0); + let tx = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 0, zero, 0); next_entry(&zero, 0, vec![tx]); } @@ -568,7 +568,7 @@ mod tests { fn test_serialized_size() { let zero = Hash::default(); let keypair = Keypair::new(); - let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, zero, 0); + let tx = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 0, zero, 0); let entry = next_entry(&zero, 1, vec![tx.clone()]); assert_eq!( Entry::serialized_size(&[tx]), @@ -596,11 +596,11 @@ mod tests { let one = hash(&zero.as_ref()); let keypair = Keypair::new(); let vote_account = Keypair::new(); - let tx0 = VoteTransaction::new_vote(vote_account.pubkey(), &vote_account, 1, one, 1); + let tx0 = VoteTransaction::new_vote(&vote_account.pubkey(), &vote_account, 1, one, 1); let tx1 = BudgetTransaction::new_timestamp( &keypair, - keypair.pubkey(), - keypair.pubkey(), + &keypair.pubkey(), + &keypair.pubkey(), Utc::now(), one, ); @@ -645,8 +645,8 @@ mod tests { let keypair = Keypair::new(); let vote_account = Keypair::new(); let tx_small = - VoteTransaction::new_vote(vote_account.pubkey(), &vote_account, 1, next_hash, 2); - let tx_large = BudgetTransaction::new_payment(&keypair, keypair.pubkey(), 1, next_hash, 0); + VoteTransaction::new_vote(&vote_account.pubkey(), &vote_account, 1, next_hash, 2); + let tx_large = BudgetTransaction::new_payment(&keypair, &keypair.pubkey(), 1, next_hash, 0); let tx_small_size = tx_small.serialized_size().unwrap() as usize; let tx_large_size = tx_large.serialized_size().unwrap() as usize; diff --git a/core/src/fullnode.rs b/core/src/fullnode.rs index 183eeb8c58..96ff4e6905 100644 --- a/core/src/fullnode.rs +++ b/core/src/fullnode.rs @@ -81,7 +81,7 @@ impl Fullnode { mut node: Node, keypair: &Arc, ledger_path: &str, - vote_account: Pubkey, + vote_account: &Pubkey, voting_keypair: T, entrypoint_info_option: Option<&ContactInfo>, config: &FullnodeConfig, @@ -208,7 +208,7 @@ impl Fullnode { &exit, ); let tpu = Tpu::new( - id, + &id, &cluster_info, &poh_recorder, entry_receiver, @@ -325,7 +325,7 @@ pub fn make_active_set_entries( // 1) Assume the active_keypair node has no lamports staked let transfer_tx = SystemTransaction::new_account( &lamport_source, - active_keypair.pubkey(), + &active_keypair.pubkey(), stake, *blockhash, 0, @@ -339,7 +339,7 @@ pub fn make_active_set_entries( let new_vote_account_tx = VoteTransaction::new_account( active_keypair, - vote_account_id, + &vote_account_id, *blockhash, stake.saturating_sub(2), 1, @@ -348,7 +348,7 @@ pub fn make_active_set_entries( // 3) Create vote entry let vote_tx = VoteTransaction::new_vote( - voting_keypair.pubkey(), + &voting_keypair.pubkey(), &voting_keypair, slot_to_vote_on, *blockhash, @@ -373,12 +373,12 @@ mod tests { #[test] fn validator_exit() { let leader_keypair = Keypair::new(); - let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey()); + let leader_node = Node::new_localhost_with_pubkey(&leader_keypair.pubkey()); let validator_keypair = Keypair::new(); - let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey()); + let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey()); let (genesis_block, _mint_keypair) = - GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000); + GenesisBlock::new_with_leader(10_000, &leader_keypair.pubkey(), 1000); let (validator_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block); let voting_keypair = Keypair::new(); @@ -386,7 +386,7 @@ mod tests { validator_node, &Arc::new(validator_keypair), &validator_ledger_path, - voting_keypair.pubkey(), + &voting_keypair.pubkey(), voting_keypair, Some(&leader_node.info), &FullnodeConfig::default(), @@ -398,15 +398,15 @@ mod tests { #[test] fn validator_parallel_exit() { let leader_keypair = Keypair::new(); - let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey()); + let leader_node = Node::new_localhost_with_pubkey(&leader_keypair.pubkey()); let mut ledger_paths = vec![]; let validators: Vec = (0..2) .map(|_| { let validator_keypair = Keypair::new(); - let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey()); + let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey()); let (genesis_block, _mint_keypair) = - GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000); + GenesisBlock::new_with_leader(10_000, &leader_keypair.pubkey(), 1000); let (validator_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block); ledger_paths.push(validator_ledger_path.clone()); let voting_keypair = Keypair::new(); @@ -414,7 +414,7 @@ mod tests { validator_node, &Arc::new(validator_keypair), &validator_ledger_path, - voting_keypair.pubkey(), + &voting_keypair.pubkey(), voting_keypair, Some(&leader_node.info), &FullnodeConfig::default(), diff --git a/core/src/leader_confirmation_service.rs b/core/src/leader_confirmation_service.rs index 9aaea59ac5..5ee700150b 100644 --- a/core/src/leader_confirmation_service.rs +++ b/core/src/leader_confirmation_service.rs @@ -139,7 +139,7 @@ mod tests { bank.register_tick(&tick_hash); } - bank = Arc::new(Bank::new_from_parent(&bank, Pubkey::default(), slot)); + bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), slot)); } let blockhash = bank.last_blockhash(); @@ -154,7 +154,7 @@ mod tests { let voting_pubkey = voting_keypair.pubkey(); // Give the validator some lamports - bank.transfer(2, &mint_keypair, validator_keypair.pubkey(), blockhash) + bank.transfer(2, &mint_keypair, &validator_keypair.pubkey(), blockhash) .unwrap(); new_vote_account(&validator_keypair, &voting_pubkey, &bank, 1); @@ -173,7 +173,7 @@ mod tests { // Get another validator to vote, so we now have 2/3 consensus let voting_keypair = &vote_accounts[7].0; let vote_tx = - VoteTransaction::new_vote(voting_keypair.pubkey(), voting_keypair, 7, blockhash, 0); + VoteTransaction::new_vote(&voting_keypair.pubkey(), voting_keypair, 7, blockhash, 0); bank.process_transaction(&vote_tx).unwrap(); LeaderConfirmationService::compute_confirmation(&bank, &mut last_confirmation_time); diff --git a/core/src/leader_schedule_utils.rs b/core/src/leader_schedule_utils.rs index acbb670357..63c17525cd 100644 --- a/core/src/leader_schedule_utils.rs +++ b/core/src/leader_schedule_utils.rs @@ -59,7 +59,7 @@ mod tests { let pubkey = Keypair::new().pubkey(); let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader( BOOTSTRAP_LEADER_LAMPORTS, - pubkey, + &pubkey, BOOTSTRAP_LEADER_LAMPORTS, ); let bank = Bank::new(&genesis_block); @@ -79,7 +79,7 @@ mod tests { let pubkey = Keypair::new().pubkey(); let genesis_block = GenesisBlock::new_with_leader( BOOTSTRAP_LEADER_LAMPORTS, - pubkey, + &pubkey, BOOTSTRAP_LEADER_LAMPORTS, ) .0; diff --git a/core/src/local_cluster.rs b/core/src/local_cluster.rs index 289f962744..d99c2e3d3d 100644 --- a/core/src/local_cluster.rs +++ b/core/src/local_cluster.rs @@ -39,9 +39,9 @@ impl LocalCluster { ) -> Self { let leader_keypair = Arc::new(Keypair::new()); let leader_pubkey = leader_keypair.pubkey(); - let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey()); + let leader_node = Node::new_localhost_with_pubkey(&leader_keypair.pubkey()); let (genesis_block, mint_keypair) = - GenesisBlock::new_with_leader(cluster_lamports, leader_pubkey, node_stakes[0]); + GenesisBlock::new_with_leader(cluster_lamports, &leader_pubkey, node_stakes[0]); let (genesis_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block); let leader_ledger_path = tmp_copy_blocktree!(&genesis_ledger_path); let mut ledger_paths = vec![]; @@ -53,7 +53,7 @@ impl LocalCluster { leader_node, &leader_keypair, &leader_ledger_path, - voting_keypair.pubkey(), + &voting_keypair.pubkey(), voting_keypair, None, fullnode_config, @@ -66,7 +66,7 @@ impl LocalCluster { let validator_keypair = Arc::new(Keypair::new()); let voting_keypair = Keypair::new(); let validator_pubkey = validator_keypair.pubkey(); - let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey()); + let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey()); let ledger_path = tmp_copy_blocktree!(&genesis_ledger_path); ledger_paths.push(ledger_path.clone()); @@ -89,7 +89,7 @@ impl LocalCluster { validator_node, &validator_keypair, &ledger_path, - voting_keypair.pubkey(), + &voting_keypair.pubkey(), voting_keypair, Some(&leader_contact_info), fullnode_config, @@ -134,7 +134,7 @@ impl LocalCluster { trace!("getting leader blockhash"); let blockhash = client.get_recent_blockhash(); let mut tx = - SystemTransaction::new_account(&source_keypair, *dest_pubkey, lamports, blockhash, 0); + SystemTransaction::new_account(&source_keypair, dest_pubkey, lamports, blockhash, 0); info!( "executing transfer of {} from {} to {}", lamports, @@ -160,7 +160,7 @@ impl LocalCluster { // 1) Create vote account let mut transaction = VoteTransaction::new_account( from_account, - vote_account_pubkey, + &vote_account_pubkey, client.get_recent_blockhash(), amount, 1, @@ -175,7 +175,7 @@ impl LocalCluster { let mut transaction = VoteTransaction::delegate_vote_account( vote_account, client.get_recent_blockhash(), - delegate_id, + &delegate_id, 0, ); diff --git a/core/src/packet.rs b/core/src/packet.rs index f7b79a75e6..eb88f756c9 100644 --- a/core/src/packet.rs +++ b/core/src/packet.rs @@ -524,7 +524,7 @@ mod tests { fn test_to_packets() { let keypair = Keypair::new(); let hash = Hash::new(&[1; 32]); - let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, hash, 0); + let tx = SystemTransaction::new_account(&keypair, &keypair.pubkey(), 1, hash, 0); let rv = to_packets(&vec![tx.clone(); 1]); assert_eq!(rv.len(), 1); assert_eq!(rv[0].read().unwrap().packets.len(), 1); diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index bddfefedfe..ad8bad10c3 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -53,8 +53,8 @@ pub struct ReplayStage { impl ReplayStage { #[allow(clippy::new_ret_no_self, clippy::too_many_arguments)] pub fn new( - my_id: Pubkey, - vote_account: Pubkey, + my_id: &Pubkey, + vote_account: &Pubkey, voting_keypair: Option>, blocktree: Arc, bank_forks: &Arc>, @@ -74,6 +74,8 @@ impl ReplayStage { let subscriptions = subscriptions.clone(); let bank_forks = bank_forks.clone(); let poh_recorder = poh_recorder.clone(); + let my_id = *my_id; + let vote_account = *vote_account; // Start the replay stage loop let t_replay = Builder::new() @@ -132,7 +134,7 @@ impl ReplayStage { if let Some(ref voting_keypair) = voting_keypair { let keypair = voting_keypair.as_ref(); let vote = VoteTransaction::new_vote( - vote_account, + &vote_account, keypair, *latest_slot_vote, parent.last_blockhash(), @@ -148,7 +150,7 @@ impl ReplayStage { } if !is_tpu_bank_active { - Self::start_leader(my_id, &bank_forks, &poh_recorder, &cluster_info); + Self::start_leader(&my_id, &bank_forks, &poh_recorder, &cluster_info); } inc_new_counter_info!( @@ -173,7 +175,7 @@ impl ReplayStage { ) } pub fn start_leader( - my_id: Pubkey, + my_id: &Pubkey, bank_forks: &Arc>, poh_recorder: &Arc>, cluster_info: &Arc>, @@ -195,8 +197,8 @@ impl ReplayStage { "me: {} leader {} at poh slot {}", my_id, next_leader, poh_slot ); - cluster_info.write().unwrap().set_leader(next_leader); - if next_leader == my_id { + cluster_info.write().unwrap().set_leader(&next_leader); + if next_leader == *my_id { debug!("starting tpu for slot {}", poh_slot); let tpu_bank = Bank::new_from_parent(parent, my_id, poh_slot); bank_forks.write().unwrap().insert(poh_slot, tpu_bank); @@ -325,7 +327,7 @@ impl ReplayStage { info!("new fork:{} parent:{}", child_id, parent_id); forks.insert( child_id, - Bank::new_from_parent(&parent_bank, leader, child_id), + Bank::new_from_parent(&parent_bank, &leader, child_id), ); } } @@ -364,12 +366,12 @@ mod test { // Set up dummy node to host a ReplayStage let my_keypair = Keypair::new(); let my_id = my_keypair.pubkey(); - let my_node = Node::new_localhost_with_pubkey(my_id); + let my_node = Node::new_localhost_with_pubkey(&my_id); // Create keypair for the leader let leader_id = Keypair::new().pubkey(); - let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10_000, leader_id, 500); + let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10_000, &leader_id, 500); let (my_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block); @@ -388,8 +390,8 @@ mod test { let blocktree = Arc::new(blocktree); let (exit, poh_recorder, poh_service, _entry_receiver) = create_test_recorder(&bank); let (replay_stage, _slot_full_receiver, ledger_writer_recv) = ReplayStage::new( - my_keypair.pubkey(), - voting_keypair.pubkey(), + &my_keypair.pubkey(), + &voting_keypair.pubkey(), Some(voting_keypair.clone()), blocktree.clone(), &Arc::new(RwLock::new(bank_forks)), @@ -402,7 +404,7 @@ mod test { let keypair = voting_keypair.as_ref(); let vote = - VoteTransaction::new_vote(keypair.pubkey(), keypair, 0, bank.last_blockhash(), 0); + VoteTransaction::new_vote(&keypair.pubkey(), keypair, 0, bank.last_blockhash(), 0); cluster_info_me.write().unwrap().push_vote(vote); info!("Send ReplayStage an entry, should see it on the ledger writer receiver"); diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 72a521a201..88844b24ee 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -70,13 +70,13 @@ impl JsonRpcRequestProcessor { } } - pub fn get_account_info(&self, pubkey: Pubkey) -> Result { + pub fn get_account_info(&self, pubkey: &Pubkey) -> Result { self.bank()? .get_account(&pubkey) .ok_or_else(Error::invalid_request) } - pub fn get_balance(&self, pubkey: Pubkey) -> Result { + pub fn get_balance(&self, pubkey: &Pubkey) -> Result { let val = self.bank()?.get_balance(&pubkey); Ok(val) } @@ -229,13 +229,13 @@ impl RpcSol for RpcSolImpl { meta.request_processor .read() .unwrap() - .get_account_info(pubkey) + .get_account_info(&pubkey) } fn get_balance(&self, meta: Self::Metadata, id: String) -> Result { info!("get_balance rpc request received: {:?}", id); let pubkey = verify_pubkey(id)?; - meta.request_processor.read().unwrap().get_balance(pubkey) + meta.request_processor.read().unwrap().get_balance(&pubkey) } fn get_recent_blockhash(&self, meta: Self::Metadata) -> Result { @@ -414,7 +414,7 @@ mod tests { use solana_sdk::system_transaction::SystemTransaction; use std::thread; - fn start_rpc_handler_with_tx(pubkey: Pubkey) -> (MetaIoHandler, Meta, Hash, Keypair) { + fn start_rpc_handler_with_tx(pubkey: &Pubkey) -> (MetaIoHandler, Meta, Hash, Keypair) { let (genesis_block, alice) = GenesisBlock::new(10_000); let bank = Arc::new(Bank::new(&genesis_block)); let exit = Arc::new(AtomicBool::new(false)); @@ -457,7 +457,7 @@ mod tests { request_processor.set_bank(&bank); thread::spawn(move || { let blockhash = bank.last_blockhash(); - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0); + let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0); bank.process_transaction(&tx).expect("process transaction"); }) .join() @@ -468,7 +468,7 @@ mod tests { #[test] fn test_rpc_get_balance() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(bob_pubkey); + let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["{}"]}}"#, @@ -486,7 +486,7 @@ mod tests { #[test] fn test_rpc_get_tx_count() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(bob_pubkey); + let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey); let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getTransactionCount"}}"#); let res = io.handle_request_sync(&req, meta); @@ -501,7 +501,7 @@ mod tests { #[test] fn test_rpc_get_account_info() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(bob_pubkey); + let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}"]}}"#, @@ -528,8 +528,8 @@ mod tests { #[test] fn test_rpc_confirm_tx() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(bob_pubkey); - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0); + let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(&bob_pubkey); + let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"confirmTransaction","params":["{}"]}}"#, @@ -547,8 +547,8 @@ mod tests { #[test] fn test_rpc_get_signature_status() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(bob_pubkey); - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0); + let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(&bob_pubkey); + let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#, @@ -563,7 +563,7 @@ mod tests { assert_eq!(expected, result); // Test getSignatureStatus request on unprocessed tx - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 10, blockhash, 0); + let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 10, blockhash, 0); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#, tx.signatures[0] @@ -580,7 +580,7 @@ mod tests { #[test] fn test_rpc_get_recent_blockhash() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, blockhash, _alice) = start_rpc_handler_with_tx(bob_pubkey); + let (io, meta, blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey); let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getRecentBlockhash"}}"#); let res = io.handle_request_sync(&req, meta); @@ -595,7 +595,7 @@ mod tests { #[test] fn test_rpc_fail_request_airdrop() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(bob_pubkey); + let (io, meta, _blockhash, _alice) = start_rpc_handler_with_tx(&bob_pubkey); // Expect internal error because no drone is available let req = format!( @@ -674,7 +674,7 @@ mod tests { fn test_rpc_verify_signature() { let tx = SystemTransaction::new_move( &Keypair::new(), - Keypair::new().pubkey(), + &Keypair::new().pubkey(), 20, hash(&[0]), 0, diff --git a/core/src/rpc_mock.rs b/core/src/rpc_mock.rs index 2fde6bcab0..eafd792ec5 100644 --- a/core/src/rpc_mock.rs +++ b/core/src/rpc_mock.rs @@ -28,7 +28,7 @@ impl MockRpcClient { pub fn retry_get_balance( &self, id: u64, - pubkey: Pubkey, + pubkey: &Pubkey, retries: usize, ) -> Result, Box> { let params = json!([format!("{}", pubkey)]); @@ -106,6 +106,6 @@ pub fn request_airdrop_transaction( let key = Keypair::new(); let to = Keypair::new().pubkey(); let blockhash = Hash::default(); - let tx = SystemTransaction::new_account(&key, to, lamports, blockhash, 0); + let tx = SystemTransaction::new_account(&key, &to, lamports, blockhash, 0); Ok(tx) } diff --git a/core/src/rpc_pubsub.rs b/core/src/rpc_pubsub.rs index 7b913fcd55..2776fb33a7 100644 --- a/core/src/rpc_pubsub.rs +++ b/core/src/rpc_pubsub.rs @@ -249,7 +249,7 @@ mod tests { // Simulate a block boundary Ok(Arc::new(Bank::new_from_parent( &bank, - Pubkey::default(), + &Pubkey::default(), bank.slot() + 1, ))) } @@ -270,7 +270,7 @@ mod tests { let rpc = RpcSolPubSubImpl::default(); // Test signature subscriptions - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0); + let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0); let session = create_session(); let (subscriber, _id_receiver, mut receiver) = @@ -302,7 +302,7 @@ mod tests { let rpc = RpcSolPubSubImpl::default(); io.extend_with(rpc.to_delegate()); - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0); + let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#, tx.signatures[0].to_string() @@ -348,14 +348,14 @@ mod tests { let (subscriber, _id_receiver, mut receiver) = Subscriber::new_test("accountNotification"); rpc.account_subscribe(session, subscriber, contract_state.pubkey().to_string()); - let tx = SystemTransaction::new_account(&alice, contract_funds.pubkey(), 51, blockhash, 0); + let tx = SystemTransaction::new_account(&alice, &contract_funds.pubkey(), 51, blockhash, 0); let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap(); let tx = BudgetTransaction::new_when_signed( &contract_funds, - bob_pubkey, - contract_state.pubkey(), - witness.pubkey(), + &bob_pubkey, + &contract_state.pubkey(), + &witness.pubkey(), None, 51, blockhash, @@ -387,13 +387,13 @@ mod tests { assert_eq!(serde_json::to_string(&expected).unwrap(), response); } - let tx = SystemTransaction::new_account(&alice, witness.pubkey(), 1, blockhash, 0); + let tx = SystemTransaction::new_account(&alice, &witness.pubkey(), 1, blockhash, 0); let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap(); sleep(Duration::from_millis(200)); let tx = BudgetTransaction::new_signature( &witness, - contract_state.pubkey(), - bob_pubkey, + &contract_state.pubkey(), + &bob_pubkey, blockhash, ); let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap(); diff --git a/core/src/rpc_request.rs b/core/src/rpc_request.rs index 32607e37bf..82af7181a0 100644 --- a/core/src/rpc_request.rs +++ b/core/src/rpc_request.rs @@ -39,7 +39,7 @@ impl RpcClient { pub fn retry_get_balance( &self, id: u64, - pubkey: Pubkey, + pubkey: &Pubkey, retries: usize, ) -> Result, Box> { let params = json!([format!("{}", pubkey)]); diff --git a/core/src/rpc_service.rs b/core/src/rpc_service.rs index c4fd4bb783..519295ab4d 100644 --- a/core/src/rpc_service.rs +++ b/core/src/rpc_service.rs @@ -123,7 +123,7 @@ mod tests { .request_processor .read() .unwrap() - .get_balance(alice.pubkey()) + .get_balance(&alice.pubkey()) .unwrap() ); exit.store(true, Ordering::Relaxed); diff --git a/core/src/rpc_subscriptions.rs b/core/src/rpc_subscriptions.rs index dba527a229..4bf54db8f3 100644 --- a/core/src/rpc_subscriptions.rs +++ b/core/src/rpc_subscriptions.rs @@ -210,11 +210,11 @@ mod tests { let blockhash = bank.last_blockhash(); let tx = SystemTransaction::new_program_account( &mint_keypair, - alice.pubkey(), + &alice.pubkey(), blockhash, 1, 16, - solana_budget_api::id(), + &solana_budget_api::id(), 0, ); bank.process_transaction(&tx).unwrap(); @@ -256,11 +256,11 @@ mod tests { let blockhash = bank.last_blockhash(); let tx = SystemTransaction::new_program_account( &mint_keypair, - alice.pubkey(), + &alice.pubkey(), blockhash, 1, 16, - solana_budget_api::id(), + &solana_budget_api::id(), 0, ); bank.process_transaction(&tx).unwrap(); @@ -299,7 +299,7 @@ mod tests { let bank = Bank::new(&genesis_block); let alice = Keypair::new(); let blockhash = bank.last_blockhash(); - let tx = SystemTransaction::new_move(&mint_keypair, alice.pubkey(), 20, blockhash, 0); + let tx = SystemTransaction::new_move(&mint_keypair, &alice.pubkey(), 20, blockhash, 0); let signature = tx.signatures[0]; bank.process_transaction(&tx).unwrap(); diff --git a/core/src/staking_utils.rs b/core/src/staking_utils.rs index 92d10547e2..4e8959de8f 100644 --- a/core/src/staking_utils.rs +++ b/core/src/staking_utils.rs @@ -146,7 +146,7 @@ mod tests { use std::sync::Arc; fn new_from_parent(parent: &Arc, slot: u64) -> Bank { - Bank::new_from_parent(parent, Pubkey::default(), slot) + Bank::new_from_parent(parent, &Pubkey::default(), slot) } #[test] @@ -154,7 +154,7 @@ mod tests { let pubkey = Keypair::new().pubkey(); let bootstrap_lamports = 3; let (genesis_block, _) = - GenesisBlock::new_with_leader(bootstrap_lamports, pubkey, bootstrap_lamports); + GenesisBlock::new_with_leader(bootstrap_lamports, &pubkey, bootstrap_lamports); let bank = Bank::new(&genesis_block); // Epoch doesn't exist @@ -184,7 +184,7 @@ mod tests { // Give the validator some stake but don't setup a staking account // Validator has no lamports staked, so they get filtered out. Only the bootstrap leader // created by the genesis block will get included - bank.transfer(1, &mint_keypair, validator.pubkey(), genesis_block.hash()) + bank.transfer(1, &mint_keypair, &validator.pubkey(), genesis_block.hash()) .unwrap(); // Make a mint vote account. Because the mint has nonzero stake, this @@ -266,11 +266,11 @@ mod tests { // Delegate 1 has stake of 3 for i in 0..3 { - stakes.push((i, VoteState::new(delegate1))); + stakes.push((i, VoteState::new(&delegate1))); } // Delegate 1 has stake of 5 - stakes.push((5, VoteState::new(delegate2))); + stakes.push((5, VoteState::new(&delegate2))); let result = to_delegated_stakes(stakes.into_iter()); assert_eq!(result.len(), 2); diff --git a/core/src/storage_stage.rs b/core/src/storage_stage.rs index 432e6abfaf..44694ea326 100644 --- a/core/src/storage_stage.rs +++ b/core/src/storage_stage.rs @@ -474,7 +474,7 @@ mod tests { let keypair = Arc::new(Keypair::new()); let exit = Arc::new(AtomicBool::new(false)); - let cluster_info = test_cluster_info(keypair.pubkey()); + let cluster_info = test_cluster_info(&keypair.pubkey()); let (_storage_entry_sender, storage_entry_receiver) = channel(); let storage_state = StorageState::new(); @@ -492,7 +492,7 @@ mod tests { storage_stage.join().unwrap(); } - fn test_cluster_info(id: Pubkey) -> Arc> { + fn test_cluster_info(id: &Pubkey) -> Arc> { let contact_info = ContactInfo::new_localhost(id, 0); let cluster_info = ClusterInfo::new_with_invalid_keypair(contact_info); Arc::new(RwLock::new(cluster_info)) @@ -512,7 +512,7 @@ mod tests { let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap(); blocktree.write_entries(1, 0, 0, &entries).unwrap(); - let cluster_info = test_cluster_info(keypair.pubkey()); + let cluster_info = test_cluster_info(&keypair.pubkey()); let (storage_entry_sender, storage_entry_receiver) = channel(); let storage_state = StorageState::new(); @@ -574,7 +574,7 @@ mod tests { let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap(); blocktree.write_entries(1, 0, 0, &entries).unwrap(); - let cluster_info = test_cluster_info(keypair.pubkey()); + let cluster_info = test_cluster_info(&keypair.pubkey()); let (storage_entry_sender, storage_entry_receiver) = channel(); let storage_state = StorageState::new(); @@ -599,7 +599,7 @@ mod tests { let mut vote_txs: Vec<_> = Vec::new(); let keypair = Keypair::new(); let vote_tx = - VoteTransaction::new_vote(keypair.pubkey(), &keypair, 123456, Hash::default(), 1); + VoteTransaction::new_vote(&keypair.pubkey(), &keypair, 123456, Hash::default(), 1); vote_txs.push(vote_tx); let vote_entries = vec![Entry::new(&Hash::default(), 1, vote_txs)]; storage_entry_sender.send(vote_entries).unwrap(); diff --git a/core/src/test_tx.rs b/core/src/test_tx.rs index 789a298187..4afebaf410 100644 --- a/core/src/test_tx.rs +++ b/core/src/test_tx.rs @@ -7,5 +7,5 @@ pub fn test_tx() -> Transaction { let keypair1 = Keypair::new(); let pubkey1 = keypair1.pubkey(); let zero = Hash::default(); - SystemTransaction::new_account(&keypair1, pubkey1, 42, zero, 0) + SystemTransaction::new_account(&keypair1, &pubkey1, 42, zero, 0) } diff --git a/core/src/thin_client.rs b/core/src/thin_client.rs index 744d52ba8f..3ca882b0a5 100644 --- a/core/src/thin_client.rs +++ b/core/src/thin_client.rs @@ -119,7 +119,7 @@ impl ThinClient { &self, lamports: u64, keypair: &Keypair, - to: Pubkey, + to: &Pubkey, blockhash: &Hash, ) -> io::Result { debug!( @@ -420,10 +420,10 @@ pub fn new_fullnode() -> (Fullnode, ContactInfo, Keypair, String) { use solana_sdk::signature::KeypairUtil; let node_keypair = Arc::new(Keypair::new()); - let node = Node::new_localhost_with_pubkey(node_keypair.pubkey()); + let node = Node::new_localhost_with_pubkey(&node_keypair.pubkey()); let contact_info = node.info.clone(); - let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(10_000, contact_info.id, 42); + let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(10_000, &contact_info.id, 42); let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block); let voting_keypair = Keypair::new(); @@ -431,7 +431,7 @@ pub fn new_fullnode() -> (Fullnode, ContactInfo, Keypair, String) { node, &node_keypair, &ledger_path, - voting_keypair.pubkey(), + &voting_keypair.pubkey(), voting_keypair, None, &FullnodeConfig::default(), @@ -467,7 +467,7 @@ mod tests { info!("test_thin_client blockhash: {:?}", blockhash); let signature = client - .transfer(500, &alice, bob_pubkey, &blockhash) + .transfer(500, &alice, &bob_pubkey, &blockhash) .unwrap(); info!("test_thin_client signature: {:?}", signature); client.poll_for_signature(&signature).unwrap(); @@ -493,13 +493,13 @@ mod tests { let blockhash = client.get_recent_blockhash(); - let tx = SystemTransaction::new_account(&alice, bob_pubkey, 500, blockhash, 0); + let tx = SystemTransaction::new_account(&alice, &bob_pubkey, 500, blockhash, 0); let _sig = client.transfer_signed(&tx).unwrap(); let blockhash = client.get_recent_blockhash(); - let mut tr2 = SystemTransaction::new_account(&alice, bob_pubkey, 501, blockhash, 0); + let mut tr2 = SystemTransaction::new_account(&alice, &bob_pubkey, 501, blockhash, 0); let mut instruction2 = deserialize(tr2.userdata(0)).unwrap(); if let SystemInstruction::Move { ref mut lamports } = instruction2 { *lamports = 502; @@ -526,7 +526,7 @@ mod tests { let validator_keypair = Keypair::new(); let blockhash = client.get_recent_blockhash(); let signature = client - .transfer(500, &alice, validator_keypair.pubkey(), &blockhash) + .transfer(500, &alice, &validator_keypair.pubkey(), &blockhash) .unwrap(); client.poll_for_signature(&signature).unwrap(); @@ -537,7 +537,7 @@ mod tests { let blockhash = client.get_recent_blockhash(); let transaction = - VoteTransaction::new_account(&validator_keypair, vote_account_id, blockhash, 1, 1); + VoteTransaction::new_account(&validator_keypair, &vote_account_id, blockhash, 1, 1); let signature = client.transfer_signed(&transaction).unwrap(); client.poll_for_signature(&signature).unwrap(); @@ -595,7 +595,7 @@ mod tests { info!("Give Bob 500 lamports"); let signature = client - .transfer(500, &alice, bob_keypair.pubkey(), &blockhash) + .transfer(500, &alice, &bob_keypair.pubkey(), &blockhash) .unwrap(); client.poll_for_signature(&signature).unwrap(); @@ -604,7 +604,7 @@ mod tests { info!("Take Bob's 500 lamports away"); let signature = client - .transfer(500, &bob_keypair, alice.pubkey(), &blockhash) + .transfer(500, &bob_keypair, &alice.pubkey(), &blockhash) .unwrap(); client.poll_for_signature(&signature).unwrap(); let alice_balance = client.poll_get_balance(&alice.pubkey()).unwrap(); diff --git a/core/src/tpu.rs b/core/src/tpu.rs index 08a2f77e77..781dbe2a5a 100644 --- a/core/src/tpu.rs +++ b/core/src/tpu.rs @@ -27,7 +27,7 @@ pub struct Tpu { impl Tpu { pub fn new( - id: Pubkey, + id: &Pubkey, cluster_info: &Arc>, poh_recorder: &Arc>, entry_receiver: Receiver, diff --git a/core/src/tvu.rs b/core/src/tvu.rs index 9d704e5f0a..f95143a324 100644 --- a/core/src/tvu.rs +++ b/core/src/tvu.rs @@ -55,7 +55,7 @@ impl Tvu { /// * `blocktree` - the ledger itself #[allow(clippy::new_ret_no_self, clippy::too_many_arguments)] pub fn new( - vote_account: Pubkey, + vote_account: &Pubkey, voting_keypair: Option>, bank_forks: &Arc>, bank_forks_info: &[BankForksInfo], @@ -107,7 +107,7 @@ impl Tvu { ); let (replay_stage, slot_full_receiver, forward_entry_receiver) = ReplayStage::new( - keypair.pubkey(), + &keypair.pubkey(), vote_account, voting_keypair, blocktree.clone(), @@ -183,7 +183,7 @@ pub mod tests { solana_logger::setup(); let leader = Node::new_localhost(); let target1_keypair = Keypair::new(); - let target1 = Node::new_localhost_with_pubkey(target1_keypair.pubkey()); + let target1 = Node::new_localhost_with_pubkey(&target1_keypair.pubkey()); let starting_balance = 10_000; let (genesis_block, _mint_keypair) = GenesisBlock::new(starting_balance); @@ -206,7 +206,7 @@ pub mod tests { let (exit, poh_recorder, poh_service, _entry_receiver) = create_test_recorder(&bank); let voting_keypair = Keypair::new(); let tvu = Tvu::new( - voting_keypair.pubkey(), + &voting_keypair.pubkey(), Some(Arc::new(voting_keypair)), &Arc::new(RwLock::new(bank_forks)), &bank_forks_info, diff --git a/core/src/voting_keypair.rs b/core/src/voting_keypair.rs index d91d7295ac..cd97d596f3 100644 --- a/core/src/voting_keypair.rs +++ b/core/src/voting_keypair.rs @@ -23,7 +23,7 @@ impl RemoteVoteSigner { impl VoteSigner for RemoteVoteSigner { fn register( &self, - pubkey: Pubkey, + pubkey: &Pubkey, sig: &Signature, msg: &[u8], ) -> jsonrpc_core::Result { @@ -35,7 +35,12 @@ impl VoteSigner for RemoteVoteSigner { let vote_account: Pubkey = serde_json::from_value(resp).unwrap(); Ok(vote_account) } - fn sign(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> jsonrpc_core::Result { + fn sign( + &self, + pubkey: &Pubkey, + sig: &Signature, + msg: &[u8], + ) -> jsonrpc_core::Result { let params = json!([pubkey, sig, msg]); let resp = self .rpc_client @@ -44,7 +49,7 @@ impl VoteSigner for RemoteVoteSigner { let vote_signature: Signature = serde_json::from_value(resp).unwrap(); Ok(vote_signature) } - fn deregister(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> jsonrpc_core::Result<()> { + fn deregister(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> jsonrpc_core::Result<()> { let params = json!([pubkey, sig, msg]); let _resp = self .rpc_client @@ -70,7 +75,9 @@ impl KeypairUtil for VotingKeypair { fn sign_message(&self, msg: &[u8]) -> Signature { let sig = self.keypair.sign_message(msg); - self.signer.sign(self.keypair.pubkey(), &sig, &msg).unwrap() + self.signer + .sign(&self.keypair.pubkey(), &sig, &msg) + .unwrap() } } @@ -85,7 +92,7 @@ impl VotingKeypair { let msg = "Registering a new node"; let sig = keypair.sign_message(msg.as_bytes()); let vote_account = signer - .register(keypair.pubkey(), &sig, msg.as_bytes()) + .register(&keypair.pubkey(), &sig, msg.as_bytes()) .unwrap(); Self { keypair: keypair.clone(), @@ -109,14 +116,14 @@ pub mod tests { lamports: u64, ) { let blockhash = bank.last_blockhash(); - let tx = VoteTransaction::new_account(from_keypair, *voting_pubkey, blockhash, lamports, 0); + let tx = VoteTransaction::new_account(from_keypair, voting_pubkey, blockhash, lamports, 0); bank.process_transaction(&tx).unwrap(); } pub fn push_vote(voting_keypair: &T, bank: &Bank, slot: u64) { let blockhash = bank.last_blockhash(); let tx = - VoteTransaction::new_vote(voting_keypair.pubkey(), voting_keypair, slot, blockhash, 0); + VoteTransaction::new_vote(&voting_keypair.pubkey(), voting_keypair, slot, blockhash, 0); bank.process_transaction(&tx).unwrap(); } diff --git a/drone/src/drone.rs b/drone/src/drone.rs index dd5bd0a60a..1dbebab70a 100644 --- a/drone/src/drone.rs +++ b/drone/src/drone.rs @@ -135,7 +135,7 @@ impl Drone { let mut transaction = Transaction::new( &self.mint_keypair, &[to], - system_program::id(), + &system_program::id(), &create_instruction, blockhash, 0, /*fee*/ @@ -411,7 +411,7 @@ mod tests { let mut expected_tx = Transaction::new( &keypair, &[to], - system_program::id(), + &system_program::id(), &expected_instruction, blockhash, 0, diff --git a/drone/tests/local-drone.rs b/drone/tests/local-drone.rs index a30f8a95b2..29588dc0db 100644 --- a/drone/tests/local-drone.rs +++ b/drone/tests/local-drone.rs @@ -20,7 +20,7 @@ fn test_local_drone() { let mut expected_tx = Transaction::new( &keypair, &[to], - system_program::id(), + &system_program::id(), &expected_instruction, blockhash, 0, diff --git a/fullnode/src/main.rs b/fullnode/src/main.rs index 06830630d2..61ef74d84b 100644 --- a/fullnode/src/main.rs +++ b/fullnode/src/main.rs @@ -229,7 +229,7 @@ fn main() { fullnode_config.blockstream = matches.value_of("blockstream").map(|s| s.to_string()); let keypair = Arc::new(keypair); - let mut node = Node::new_with_external_ip(keypair.pubkey(), &gossip_addr); + let mut node = Node::new_with_external_ip(&keypair.pubkey(), &gossip_addr); node.info.rpc.set_port(rpc_port); node.info.rpc_pubsub.set_port(rpc_pubsub_port); @@ -242,7 +242,7 @@ fn main() { node, &keypair, ledger_path, - staking_account, + &staking_account, voting_keypair, cluster_entrypoint.as_ref(), &fullnode_config, diff --git a/genesis/src/main.rs b/genesis/src/main.rs index c46235fd90..9cba96e26e 100644 --- a/genesis/src/main.rs +++ b/genesis/src/main.rs @@ -69,7 +69,7 @@ fn main() -> Result<(), Box> { let bootstrap_leader_vote_account_keypair = Keypair::new(); let (mut genesis_block, _mint_keypair) = GenesisBlock::new_with_leader( lamports, - bootstrap_leader_keypair.pubkey(), + &bootstrap_leader_keypair.pubkey(), BOOTSTRAP_LEADER_LAMPORTS, ); genesis_block.mint_id = mint_keypair.pubkey(); diff --git a/ledger-tool/tests/basic.rs b/ledger-tool/tests/basic.rs index 2f71c3f08c..68f1436803 100644 --- a/ledger-tool/tests/basic.rs +++ b/ledger-tool/tests/basic.rs @@ -35,7 +35,7 @@ fn bad_arguments() { #[test] fn nominal() { let keypair = Arc::new(Keypair::new()); - let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(100, keypair.pubkey(), 50); + let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(100, &keypair.pubkey(), 50); let ticks_per_slot = genesis_block.ticks_per_slot; let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block); diff --git a/programs/bpf/tests/programs.rs b/programs/bpf/tests/programs.rs index 2aa4a3960d..67f307ea4f 100644 --- a/programs/bpf/tests/programs.rs +++ b/programs/bpf/tests/programs.rs @@ -42,11 +42,11 @@ mod bpf { let bank = Bank::new(&genesis_block); // Call user program - let program_id = load_program(&bank, &mint_keypair, bpf_loader::id(), elf); + let program_id = load_program(&bank, &mint_keypair, &bpf_loader::id(), elf); let tx = Transaction::new( &mint_keypair, &[], - program_id, + &program_id, &vec![1u8], bank.last_blockhash(), 0, @@ -80,16 +80,16 @@ mod bpf { let loader_id = load_program( &bank, &mint_keypair, - native_loader::id(), + &native_loader::id(), "solana_bpf_loader".as_bytes().to_vec(), ); // Call user program - let program_id = load_program(&bank, &mint_keypair, loader_id, elf); + let program_id = load_program(&bank, &mint_keypair, &loader_id, elf); let tx = Transaction::new( &mint_keypair, &[], - program_id, + &program_id, &vec![1u8], bank.last_blockhash(), 0, @@ -126,16 +126,16 @@ mod bpf { let loader_id = load_program( &bank, &mint_keypair, - native_loader::id(), + &native_loader::id(), "solana_bpf_loader".as_bytes().to_vec(), ); // Call user program - let program_id = load_program(&bank, &mint_keypair, loader_id, elf); + let program_id = load_program(&bank, &mint_keypair, &loader_id, elf); let tx = Transaction::new( &mint_keypair, &[], - program_id, + &program_id, &vec![1u8], bank.last_blockhash(), 0, diff --git a/programs/budget/src/budget_program.rs b/programs/budget/src/budget_program.rs index cd5abaf92b..bd83ebb07b 100644 --- a/programs/budget/src/budget_program.rs +++ b/programs/budget/src/budget_program.rs @@ -175,14 +175,14 @@ mod test { #[test] fn test_invalid_instruction() { - let mut accounts = vec![Account::new(1, 0, id()), Account::new(0, 512, id())]; + let mut accounts = vec![Account::new(1, 0, &id()), Account::new(0, 512, &id())]; let from = Keypair::new(); let contract = Keypair::new(); let userdata = (1u8, 2u8, 3u8); let tx = Transaction::new( &from, &[contract.pubkey()], - id(), + &id(), &userdata, Hash::default(), 0, @@ -192,7 +192,7 @@ mod test { #[test] fn test_unsigned_witness_key() { - let mut accounts = vec![Account::new(1, 0, system_program::id())]; + let mut accounts = vec![Account::new(1, 0, &system_program::id())]; // Initialize BudgetState let from = Keypair::new(); @@ -201,9 +201,9 @@ mod test { let witness = Keypair::new().pubkey(); let tx = BudgetTransaction::new_when_signed( &from, - to, - contract, - witness, + &to, + &contract, + &witness, None, 1, Hash::default(), @@ -212,7 +212,7 @@ mod test { // Attack! Part 1: Sign a witness transaction with a random key. let rando = Keypair::new(); - let mut tx = BudgetTransaction::new_signature(&rando, contract, to, Hash::default()); + let mut tx = BudgetTransaction::new_signature(&rando, &contract, &to, Hash::default()); // Attack! Part 2: Point the instruction to the expected, but unsigned, key. tx.account_keys.push(from.pubkey()); @@ -227,7 +227,7 @@ mod test { #[test] fn test_unsigned_timestamp() { - let mut accounts = vec![Account::new(1, 0, system_program::id())]; + let mut accounts = vec![Account::new(1, 0, &system_program::id())]; // Initialize BudgetState let from = Keypair::new(); @@ -236,10 +236,10 @@ mod test { let dt = Utc::now(); let tx = BudgetTransaction::new_on_date( &from, - to, - contract, + &to, + &contract, dt, - from.pubkey(), + &from.pubkey(), None, 1, Hash::default(), @@ -248,7 +248,7 @@ mod test { // Attack! Part 1: Sign a timestamp transaction with a random key. let rando = Keypair::new(); - let mut tx = BudgetTransaction::new_timestamp(&rando, contract, to, dt, Hash::default()); + let mut tx = BudgetTransaction::new_timestamp(&rando, &contract, &to, dt, Hash::default()); // Attack! Part 2: Point the instruction to the expected, but unsigned, key. tx.account_keys.push(from.pubkey()); @@ -263,7 +263,7 @@ mod test { #[test] fn test_transfer_on_date() { - let mut accounts = vec![Account::new(1, 0, system_program::id())]; + let mut accounts = vec![Account::new(1, 0, &system_program::id())]; let from_account = 0; let contract_account = 1; let to_account = 2; @@ -274,10 +274,10 @@ mod test { let dt = Utc::now(); let tx = BudgetTransaction::new_on_date( &from, - to.pubkey(), - contract.pubkey(), + &to.pubkey(), + &contract.pubkey(), dt, - from.pubkey(), + &from.pubkey(), None, 1, Hash::default(), @@ -291,8 +291,8 @@ mod test { // Attack! Try to payout to a rando key let tx = BudgetTransaction::new_timestamp( &from, - contract.pubkey(), - rando.pubkey(), + &contract.pubkey(), + &rando.pubkey(), dt, Hash::default(), ); @@ -311,8 +311,8 @@ mod test { // that pubkey's funds are now available. let tx = BudgetTransaction::new_timestamp( &from, - contract.pubkey(), - to.pubkey(), + &contract.pubkey(), + &to.pubkey(), dt, Hash::default(), ); @@ -335,7 +335,7 @@ mod test { } #[test] fn test_cancel_transfer() { - let mut accounts = vec![Account::new(1, 0, system_program::id())]; + let mut accounts = vec![Account::new(1, 0, &system_program::id())]; let from_account = 0; let contract_account = 1; let pay_account = 2; @@ -345,10 +345,10 @@ mod test { let dt = Utc::now(); let tx = BudgetTransaction::new_on_date( &from, - to.pubkey(), - contract.pubkey(), + &to.pubkey(), + &contract.pubkey(), dt, - from.pubkey(), + &from.pubkey(), Some(from.pubkey()), 1, Hash::default(), @@ -360,8 +360,12 @@ mod test { assert!(budget_state.is_pending()); // Attack! try to put the lamports into the wrong account with cancel - let tx = - BudgetTransaction::new_signature(&to, contract.pubkey(), to.pubkey(), Hash::default()); + let tx = BudgetTransaction::new_signature( + &to, + &contract.pubkey(), + &to.pubkey(), + Hash::default(), + ); // unit test hack, the `from account` is passed instead of the `to` account to avoid // creating more account vectors process_transaction(&tx, &mut accounts).unwrap(); @@ -373,8 +377,8 @@ mod test { // Now, cancel the transaction. from gets her funds back let tx = BudgetTransaction::new_signature( &from, - contract.pubkey(), - from.pubkey(), + &contract.pubkey(), + &from.pubkey(), Hash::default(), ); process_transaction(&tx, &mut accounts).unwrap(); @@ -385,8 +389,8 @@ mod test { // try to replay the cancel contract let tx = BudgetTransaction::new_signature( &from, - contract.pubkey(), - from.pubkey(), + &contract.pubkey(), + &from.pubkey(), Hash::default(), ); assert_eq!( diff --git a/programs/budget/tests/budget.rs b/programs/budget/tests/budget.rs index 62c9f1d6fb..45541ccacc 100644 --- a/programs/budget/tests/budget.rs +++ b/programs/budget/tests/budget.rs @@ -14,7 +14,7 @@ impl<'a> BudgetBank<'a> { Self { bank } } - fn pay(&self, from_keypair: &Keypair, to_id: Pubkey, lamports: u64) -> Result<()> { + fn pay(&self, from_keypair: &Keypair, to_id: &Pubkey, lamports: u64) -> Result<()> { let blockhash = self.bank.last_blockhash(); let tx = BudgetTransaction::new_payment(from_keypair, to_id, lamports, blockhash, 0); self.bank.process_transaction(&tx) @@ -27,6 +27,6 @@ fn test_budget_payment_via_bank() { let bank = Bank::new(&genesis_block); let budget_bank = BudgetBank::new(&bank); let to_id = Keypair::new().pubkey(); - budget_bank.pay(&from_keypair, to_id, 100).unwrap(); + budget_bank.pay(&from_keypair, &to_id, 100).unwrap(); assert_eq!(bank.get_balance(&to_id), 100); } diff --git a/programs/budget_api/src/budget_expr.rs b/programs/budget_api/src/budget_expr.rs index d9e371ed3b..ad20de3f8a 100644 --- a/programs/budget_api/src/budget_expr.rs +++ b/programs/budget_api/src/budget_expr.rs @@ -1,4 +1,4 @@ -//! The `budget_expr` module provides a domain-specific language for payment plans. Users create BudgetExpr objects that +//! The `budget_expr` module provides a domain-specific language for pa&yment plans. Users create BudgetExpr objects that //! are given to an interpreter. The interpreter listens for `Witness` transactions, //! which it uses to reduce the payment plan. When the budget is reduced to a //! `Payment`, the payment is executed. @@ -52,36 +52,41 @@ pub enum BudgetExpr { impl BudgetExpr { /// Create the simplest budget - one that pays `lamports` to Pubkey. - pub fn new_payment(lamports: u64, to: Pubkey) -> Self { - BudgetExpr::Pay(Payment { lamports, to }) + pub fn new_payment(lamports: u64, to: &Pubkey) -> Self { + BudgetExpr::Pay(Payment { lamports, to: *to }) } /// Create a budget that pays `lamports` to `to` after being witnessed by `from`. - pub fn new_authorized_payment(from: Pubkey, lamports: u64, to: Pubkey) -> Self { + pub fn new_authorized_payment(from: &Pubkey, lamports: u64, to: &Pubkey) -> Self { BudgetExpr::After( - Condition::Signature(from), + Condition::Signature(*from), Box::new(Self::new_payment(lamports, to)), ) } /// Create a budget that pays lamports` to `to` after being witnessed by 2x `from`s pub fn new_2_2_multisig_payment( - from0: Pubkey, - from1: Pubkey, + from0: &Pubkey, + from1: &Pubkey, lamports: u64, - to: Pubkey, + to: &Pubkey, ) -> Self { BudgetExpr::And( - Condition::Signature(from0), - Condition::Signature(from1), + Condition::Signature(*from0), + Condition::Signature(*from1), Box::new(Self::new_payment(lamports, to)), ) } /// Create a budget that pays `lamports` to `to` after the given DateTime. - pub fn new_future_payment(dt: DateTime, from: Pubkey, lamports: u64, to: Pubkey) -> Self { + pub fn new_future_payment( + dt: DateTime, + from: &Pubkey, + lamports: u64, + to: &Pubkey, + ) -> Self { BudgetExpr::After( - Condition::Timestamp(dt, from), + Condition::Timestamp(dt, *from), Box::new(Self::new_payment(lamports, to)), ) } @@ -90,17 +95,17 @@ impl BudgetExpr { /// unless cancelled by `from`. pub fn new_cancelable_future_payment( dt: DateTime, - from: Pubkey, + from: &Pubkey, lamports: u64, - to: Pubkey, + to: &Pubkey, ) -> Self { BudgetExpr::Or( ( - Condition::Timestamp(dt, from), + Condition::Timestamp(dt, *from), Box::new(Self::new_payment(lamports, to)), ), ( - Condition::Signature(from), + Condition::Signature(*from), Box::new(Self::new_payment(lamports, to)), ), ) @@ -183,10 +188,10 @@ mod tests { let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10); let from = Pubkey::default(); let to = Pubkey::default(); - assert!(BudgetExpr::new_payment(42, to).verify(42)); - assert!(BudgetExpr::new_authorized_payment(from, 42, to).verify(42)); - assert!(BudgetExpr::new_future_payment(dt, from, 42, to).verify(42)); - assert!(BudgetExpr::new_cancelable_future_payment(dt, from, 42, to).verify(42)); + assert!(BudgetExpr::new_payment(42, &to).verify(42)); + assert!(BudgetExpr::new_authorized_payment(&from, 42, &to).verify(42)); + assert!(BudgetExpr::new_future_payment(dt, &from, 42, &to).verify(42)); + assert!(BudgetExpr::new_cancelable_future_payment(dt, &from, 42, &to).verify(42)); } #[test] @@ -194,9 +199,9 @@ mod tests { let from = Pubkey::default(); let to = Pubkey::default(); - let mut expr = BudgetExpr::new_authorized_payment(from, 42, to); + let mut expr = BudgetExpr::new_authorized_payment(&from, 42, &to); expr.apply_witness(&Witness::Signature, &from); - assert_eq!(expr, BudgetExpr::new_payment(42, to)); + assert_eq!(expr, BudgetExpr::new_payment(42, &to)); } #[test] @@ -205,9 +210,9 @@ mod tests { let from = Keypair::new().pubkey(); let to = Keypair::new().pubkey(); - let mut expr = BudgetExpr::new_future_payment(dt, from, 42, to); + let mut expr = BudgetExpr::new_future_payment(dt, &from, 42, &to); expr.apply_witness(&Witness::Timestamp(dt), &from); - assert_eq!(expr, BudgetExpr::new_payment(42, to)); + assert_eq!(expr, BudgetExpr::new_payment(42, &to)); } #[test] @@ -218,7 +223,7 @@ mod tests { let from = Keypair::new().pubkey(); let to = Keypair::new().pubkey(); - let mut expr = BudgetExpr::new_future_payment(dt, from, 42, to); + let mut expr = BudgetExpr::new_future_payment(dt, &from, 42, &to); let orig_expr = expr.clone(); expr.apply_witness(&Witness::Timestamp(dt), &to); // <-- Attack! assert_eq!(expr, orig_expr); @@ -230,13 +235,13 @@ mod tests { let from = Pubkey::default(); let to = Pubkey::default(); - let mut expr = BudgetExpr::new_cancelable_future_payment(dt, from, 42, to); + let mut expr = BudgetExpr::new_cancelable_future_payment(dt, &from, 42, &to); expr.apply_witness(&Witness::Timestamp(dt), &from); - assert_eq!(expr, BudgetExpr::new_payment(42, to)); + assert_eq!(expr, BudgetExpr::new_payment(42, &to)); - let mut expr = BudgetExpr::new_cancelable_future_payment(dt, from, 42, to); + let mut expr = BudgetExpr::new_cancelable_future_payment(dt, &from, 42, &to); expr.apply_witness(&Witness::Signature, &from); - assert_eq!(expr, BudgetExpr::new_payment(42, from)); + assert_eq!(expr, BudgetExpr::new_payment(42, &from)); } #[test] fn test_2_2_multisig_payment() { @@ -244,9 +249,9 @@ mod tests { let from1 = Keypair::new().pubkey(); let to = Pubkey::default(); - let mut expr = BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to); + let mut expr = BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to); expr.apply_witness(&Witness::Signature, &from0); - assert_eq!(expr, BudgetExpr::new_authorized_payment(from1, 42, to)); + assert_eq!(expr, BudgetExpr::new_authorized_payment(&from1, 42, &to)); } #[test] @@ -256,12 +261,12 @@ mod tests { let from2 = Keypair::new().pubkey(); let to = Pubkey::default(); - let expr = BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to); + let expr = BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to); let mut expr = BudgetExpr::After(Condition::Signature(from2), Box::new(expr)); expr.apply_witness(&Witness::Signature, &from2); expr.apply_witness(&Witness::Signature, &from0); - assert_eq!(expr, BudgetExpr::new_authorized_payment(from1, 42, to)); + assert_eq!(expr, BudgetExpr::new_authorized_payment(&from1, 42, &to)); } #[test] @@ -271,16 +276,16 @@ mod tests { let dt = Utc.ymd(2014, 11, 11).and_hms(7, 7, 7); let to = Pubkey::default(); - let expr = BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to); + let expr = BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to); let mut expr = BudgetExpr::After(Condition::Timestamp(dt, from0), Box::new(expr)); expr.apply_witness(&Witness::Timestamp(dt), &from0); assert_eq!( expr, - BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to) + BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to) ); expr.apply_witness(&Witness::Signature, &from0); - assert_eq!(expr, BudgetExpr::new_authorized_payment(from1, 42, to)); + assert_eq!(expr, BudgetExpr::new_authorized_payment(&from1, 42, &to)); } } diff --git a/programs/budget_api/src/budget_instruction.rs b/programs/budget_api/src/budget_instruction.rs index 42a98184ba..31aa92170c 100644 --- a/programs/budget_api/src/budget_instruction.rs +++ b/programs/budget_api/src/budget_instruction.rs @@ -28,32 +28,36 @@ pub enum BudgetInstruction { } impl BudgetInstruction { - pub fn new_initialize_account(contract: Pubkey, expr: BudgetExpr) -> BuilderInstruction { + pub fn new_initialize_account(contract: &Pubkey, expr: BudgetExpr) -> BuilderInstruction { let mut keys = vec![]; if let BudgetExpr::Pay(payment) = &expr { keys.push((payment.to, false)); } - keys.push((contract, false)); + keys.push((*contract, false)); BuilderInstruction::new(id(), &BudgetInstruction::InitializeAccount(expr), keys) } pub fn new_apply_timestamp( - from: Pubkey, - contract: Pubkey, - to: Pubkey, + from: &Pubkey, + contract: &Pubkey, + to: &Pubkey, dt: DateTime, ) -> BuilderInstruction { - let mut keys = vec![(from, true), (contract, false)]; + let mut keys = vec![(*from, true), (*contract, false)]; if from != to { - keys.push((to, false)); + keys.push((*to, false)); } BuilderInstruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), keys) } - pub fn new_apply_signature(from: Pubkey, contract: Pubkey, to: Pubkey) -> BuilderInstruction { - let mut keys = vec![(from, true), (contract, false)]; + pub fn new_apply_signature( + from: &Pubkey, + contract: &Pubkey, + to: &Pubkey, + ) -> BuilderInstruction { + let mut keys = vec![(*from, true), (*contract, false)]; if from != to { - keys.push((to, false)); + keys.push((*to, false)); } BuilderInstruction::new(id(), &BudgetInstruction::ApplySignature, keys) } diff --git a/programs/budget_api/src/budget_state.rs b/programs/budget_api/src/budget_state.rs index b2d590e350..f3c8a76108 100644 --- a/programs/budget_api/src/budget_state.rs +++ b/programs/budget_api/src/budget_state.rs @@ -54,7 +54,7 @@ mod test { #[test] fn test_serializer() { - let mut a = Account::new(0, 512, id()); + let mut a = Account::new(0, 512, &id()); let b = BudgetState::default(); b.serialize(&mut a.userdata).unwrap(); let c = BudgetState::deserialize(&a.userdata).unwrap(); @@ -63,7 +63,7 @@ mod test { #[test] fn test_serializer_userdata_too_small() { - let mut a = Account::new(0, 1, id()); + let mut a = Account::new(0, 1, &id()); let b = BudgetState::default(); assert_eq!( b.serialize(&mut a.userdata), diff --git a/programs/budget_api/src/budget_transaction.rs b/programs/budget_api/src/budget_transaction.rs index e49c1c8a6d..dab6263827 100644 --- a/programs/budget_api/src/budget_transaction.rs +++ b/programs/budget_api/src/budget_transaction.rs @@ -20,7 +20,7 @@ impl BudgetTransaction { #[allow(clippy::new_ret_no_self)] fn new( from_keypair: &Keypair, - contract: Pubkey, + contract: &Pubkey, expr: BudgetExpr, lamports: u64, recent_blockhash: Hash, @@ -30,11 +30,11 @@ impl BudgetTransaction { let space = serialized_size(&BudgetState::new(expr.clone())).unwrap(); TransactionBuilder::new(fee) .push(SystemInstruction::new_program_account( - from, + &from, contract, lamports, space, - id(), + &id(), )) .push(BudgetInstruction::new_initialize_account(contract, expr)) .sign(&[from_keypair], recent_blockhash) @@ -43,7 +43,7 @@ impl BudgetTransaction { /// Create and sign a new Transaction. Used for unit-testing. pub fn new_payment( from_keypair: &Keypair, - to: Pubkey, + to: &Pubkey, lamports: u64, recent_blockhash: Hash, fee: u64, @@ -52,7 +52,7 @@ impl BudgetTransaction { let expr = BudgetExpr::new_payment(lamports, to); Self::new( from_keypair, - contract, + &contract, expr, lamports, recent_blockhash, @@ -63,15 +63,15 @@ impl BudgetTransaction { /// Create and sign a new Witness Timestamp. Used for unit-testing. pub fn new_timestamp( from_keypair: &Keypair, - contract: Pubkey, - to: Pubkey, + contract: &Pubkey, + to: &Pubkey, dt: DateTime, recent_blockhash: Hash, ) -> Transaction { let from = from_keypair.pubkey(); TransactionBuilder::default() .push(BudgetInstruction::new_apply_timestamp( - from, contract, to, dt, + &from, contract, to, dt, )) .sign(&[from_keypair], recent_blockhash) } @@ -79,23 +79,23 @@ impl BudgetTransaction { /// Create and sign a new Witness Signature. Used for unit-testing. pub fn new_signature( from_keypair: &Keypair, - contract: Pubkey, - to: Pubkey, + contract: &Pubkey, + to: &Pubkey, recent_blockhash: Hash, ) -> Transaction { let from = from_keypair.pubkey(); TransactionBuilder::default() - .push(BudgetInstruction::new_apply_signature(from, contract, to)) + .push(BudgetInstruction::new_apply_signature(&from, contract, to)) .sign(&[from_keypair], recent_blockhash) } /// Create and sign a postdated Transaction. Used for unit-testing. pub fn new_on_date( from_keypair: &Keypair, - to: Pubkey, - contract: Pubkey, + to: &Pubkey, + contract: &Pubkey, dt: DateTime, - dt_pubkey: Pubkey, + dt_pubkey: &Pubkey, cancelable: Option, lamports: u64, recent_blockhash: Hash, @@ -103,17 +103,17 @@ impl BudgetTransaction { let expr = if let Some(from) = cancelable { BudgetExpr::Or( ( - Condition::Timestamp(dt, dt_pubkey), + Condition::Timestamp(dt, *dt_pubkey), Box::new(BudgetExpr::new_payment(lamports, to)), ), ( Condition::Signature(from), - Box::new(BudgetExpr::new_payment(lamports, from)), + Box::new(BudgetExpr::new_payment(lamports, &from)), ), ) } else { BudgetExpr::After( - Condition::Timestamp(dt, dt_pubkey), + Condition::Timestamp(dt, *dt_pubkey), Box::new(BudgetExpr::new_payment(lamports, to)), ) }; @@ -123,9 +123,9 @@ impl BudgetTransaction { /// Create and sign a multisig Transaction. pub fn new_when_signed( from_keypair: &Keypair, - to: Pubkey, - contract: Pubkey, - witness: Pubkey, + to: &Pubkey, + contract: &Pubkey, + witness: &Pubkey, cancelable: Option, lamports: u64, recent_blockhash: Hash, @@ -133,17 +133,17 @@ impl BudgetTransaction { let expr = if let Some(from) = cancelable { BudgetExpr::Or( ( - Condition::Signature(witness), + Condition::Signature(*witness), Box::new(BudgetExpr::new_payment(lamports, to)), ), ( Condition::Signature(from), - Box::new(BudgetExpr::new_payment(lamports, from)), + Box::new(BudgetExpr::new_payment(lamports, &from)), ), ) } else { BudgetExpr::After( - Condition::Signature(witness), + Condition::Signature(*witness), Box::new(BudgetExpr::new_payment(lamports, to)), ) }; @@ -184,7 +184,7 @@ mod tests { fn test_claim() { let keypair = Keypair::new(); let zero = Hash::default(); - let tx0 = BudgetTransaction::new_payment(&keypair, keypair.pubkey(), 42, zero, 0); + let tx0 = BudgetTransaction::new_payment(&keypair, &keypair.pubkey(), 42, zero, 0); assert!(BudgetTransaction::verify_plan(&tx0)); } @@ -194,7 +194,7 @@ mod tests { let keypair0 = Keypair::new(); let keypair1 = Keypair::new(); let pubkey1 = keypair1.pubkey(); - let tx0 = BudgetTransaction::new_payment(&keypair0, pubkey1, 42, zero, 0); + let tx0 = BudgetTransaction::new_payment(&keypair0, &pubkey1, 42, zero, 0); assert!(BudgetTransaction::verify_plan(&tx0)); } @@ -203,7 +203,7 @@ mod tests { let zero = Hash::default(); let keypair0 = Keypair::new(); let pubkey1 = Keypair::new().pubkey(); - let tx0 = BudgetTransaction::new_payment(&keypair0, pubkey1, 1, zero, 1); + let tx0 = BudgetTransaction::new_payment(&keypair0, &pubkey1, 1, zero, 1); assert!(BudgetTransaction::verify_plan(&tx0)); } @@ -212,7 +212,7 @@ mod tests { let zero = Hash::default(); let keypair0 = Keypair::new(); let pubkey1 = Keypair::new().pubkey(); - let tx0 = BudgetTransaction::new_payment(&keypair0, pubkey1, 1, zero, 1); + let tx0 = BudgetTransaction::new_payment(&keypair0, &pubkey1, 1, zero, 1); let buf = serialize(&tx0).unwrap(); let tx1: Transaction = deserialize(&buf).unwrap(); assert_eq!(tx1, tx0); @@ -223,7 +223,7 @@ mod tests { let zero = Hash::default(); let keypair = Keypair::new(); let pubkey = keypair.pubkey(); - let mut tx = BudgetTransaction::new_payment(&keypair, pubkey, 42, zero, 0); + let mut tx = BudgetTransaction::new_payment(&keypair, &pubkey, 42, zero, 0); let mut system_instruction = BudgetTransaction::system_instruction(&tx, 0).unwrap(); if let SystemInstruction::CreateAccount { ref mut lamports, .. @@ -250,7 +250,7 @@ mod tests { let thief_keypair = Keypair::new(); let pubkey1 = keypair1.pubkey(); let zero = Hash::default(); - let mut tx = BudgetTransaction::new_payment(&keypair0, pubkey1, 42, zero, 0); + let mut tx = BudgetTransaction::new_payment(&keypair0, &pubkey1, 42, zero, 0); let mut instruction = BudgetTransaction::instruction(&tx, 1); if let Some(BudgetInstruction::InitializeAccount(ref mut expr)) = instruction { if let BudgetExpr::Pay(ref mut payment) = expr { @@ -267,7 +267,7 @@ mod tests { let keypair0 = Keypair::new(); let keypair1 = Keypair::new(); let zero = Hash::default(); - let mut tx = BudgetTransaction::new_payment(&keypair0, keypair1.pubkey(), 1, zero, 0); + let mut tx = BudgetTransaction::new_payment(&keypair0, &keypair1.pubkey(), 1, zero, 0); let mut instruction = BudgetTransaction::instruction(&tx, 1).unwrap(); if let BudgetInstruction::InitializeAccount(ref mut expr) = instruction { if let BudgetExpr::Pay(ref mut payment) = expr { diff --git a/programs/failure/tests/failure.rs b/programs/failure/tests/failure.rs index d2896f9930..6ee24e96d4 100644 --- a/programs/failure/tests/failure.rs +++ b/programs/failure/tests/failure.rs @@ -12,13 +12,13 @@ fn test_program_native_failure() { let bank = Bank::new(&genesis_block); let program = "failure".as_bytes().to_vec(); - let program_id = load_program(&bank, &mint_keypair, native_loader::id(), program); + let program_id = load_program(&bank, &mint_keypair, &native_loader::id(), program); // Call user program let tx = Transaction::new( &mint_keypair, &[], - program_id, + &program_id, &1u8, bank.last_blockhash(), 0, diff --git a/programs/noop/tests/noop.rs b/programs/noop/tests/noop.rs index 733a35cf11..764d4dd810 100644 --- a/programs/noop/tests/noop.rs +++ b/programs/noop/tests/noop.rs @@ -12,13 +12,13 @@ fn test_program_native_noop() { let bank = Bank::new(&genesis_block); let program = "noop".as_bytes().to_vec(); - let program_id = load_program(&bank, &mint_keypair, native_loader::id(), program); + let program_id = load_program(&bank, &mint_keypair, &native_loader::id(), program); // Call user program let tx = Transaction::new( &mint_keypair, &[], - program_id, + &program_id, &1u8, bank.last_blockhash(), 0, diff --git a/programs/rewards/src/lib.rs b/programs/rewards/src/lib.rs index 7d75926397..502140c807 100644 --- a/programs/rewards/src/lib.rs +++ b/programs/rewards/src/lib.rs @@ -92,7 +92,7 @@ mod tests { fn create_rewards_account(lamports: u64) -> Account { let space = RewardsState::max_size(); - Account::new(lamports, space, solana_rewards_api::id()) + Account::new(lamports, space, &solana_rewards_api::id()) } fn redeem_vote_credits_( diff --git a/programs/rewards/tests/rewards.rs b/programs/rewards/tests/rewards.rs index 159df52a09..4ca5c7e0d5 100644 --- a/programs/rewards/tests/rewards.rs +++ b/programs/rewards/tests/rewards.rs @@ -20,7 +20,7 @@ impl<'a> RewardsBank<'a> { fn create_rewards_account( &self, from_keypair: &Keypair, - rewards_id: Pubkey, + rewards_id: &Pubkey, lamports: u64, ) -> Result<()> { let blockhash = self.bank.last_blockhash(); @@ -31,7 +31,7 @@ impl<'a> RewardsBank<'a> { fn create_vote_account( &self, from_keypair: &Keypair, - vote_id: Pubkey, + vote_id: &Pubkey, lamports: u64, ) -> Result<()> { let blockhash = self.bank.last_blockhash(); @@ -41,7 +41,7 @@ impl<'a> RewardsBank<'a> { fn submit_vote( &self, - staking_account: Pubkey, + staking_account: &Pubkey, vote_keypair: &Keypair, tick_height: u64, ) -> Result { @@ -55,7 +55,7 @@ impl<'a> RewardsBank<'a> { Ok(VoteState::deserialize(&vote_account.userdata).unwrap()) } - fn redeem_credits(&self, rewards_id: Pubkey, vote_keypair: &Keypair) -> Result { + fn redeem_credits(&self, rewards_id: &Pubkey, vote_keypair: &Keypair) -> Result { let blockhash = self.bank.last_blockhash(); let tx = RewardsTransaction::new_redeem_credits(&vote_keypair, rewards_id, blockhash, 0); self.bank.process_transaction(&tx)?; @@ -74,26 +74,26 @@ fn test_redeem_vote_credits_via_bank() { let rewards_keypair = Keypair::new(); let rewards_id = rewards_keypair.pubkey(); rewards_bank - .create_rewards_account(&from_keypair, rewards_id, 100) + .create_rewards_account(&from_keypair, &rewards_id, 100) .unwrap(); // A staker create a vote account account and delegates a validator to vote on its behalf. let vote_keypair = Keypair::new(); let vote_id = vote_keypair.pubkey(); rewards_bank - .create_vote_account(&from_keypair, vote_id, 100) + .create_vote_account(&from_keypair, &vote_id, 100) .unwrap(); // The validator submits votes to accumulate credits. for i in 0..vote_state::MAX_LOCKOUT_HISTORY { let vote_state = rewards_bank - .submit_vote(vote_id, &vote_keypair, i as u64) + .submit_vote(&vote_id, &vote_keypair, i as u64) .unwrap(); assert_eq!(vote_state.credits(), 0); } let vote_state = rewards_bank .submit_vote( - vote_id, + &vote_id, &vote_keypair, vote_state::MAX_LOCKOUT_HISTORY as u64 + 1, ) @@ -108,7 +108,7 @@ fn test_redeem_vote_credits_via_bank() { // Periodically, the staker sumbits its vote account to the rewards pool // to exchange its credits for lamports. let vote_state = rewards_bank - .redeem_credits(rewards_id, &vote_keypair) + .redeem_credits(&rewards_id, &vote_keypair) .unwrap(); assert!(bank.get_balance(&to_id) > to_lamports); assert_eq!(vote_state.credits(), 0); diff --git a/programs/rewards_api/src/rewards_instruction.rs b/programs/rewards_api/src/rewards_instruction.rs index 74a232bc68..ab9c4f1de8 100644 --- a/programs/rewards_api/src/rewards_instruction.rs +++ b/programs/rewards_api/src/rewards_instruction.rs @@ -9,11 +9,11 @@ pub enum RewardsInstruction { } impl RewardsInstruction { - pub fn new_redeem_vote_credits(vote_id: Pubkey, rewards_id: Pubkey) -> BuilderInstruction { + pub fn new_redeem_vote_credits(vote_id: &Pubkey, rewards_id: &Pubkey) -> BuilderInstruction { BuilderInstruction::new( id(), &RewardsInstruction::RedeemVoteCredits, - vec![(vote_id, true), (rewards_id, false)], + vec![(*vote_id, true), (*rewards_id, false)], ) } } diff --git a/programs/rewards_api/src/rewards_transaction.rs b/programs/rewards_api/src/rewards_transaction.rs index e81be53b94..d9b6de1fae 100644 --- a/programs/rewards_api/src/rewards_transaction.rs +++ b/programs/rewards_api/src/rewards_transaction.rs @@ -17,7 +17,7 @@ pub struct RewardsTransaction {} impl RewardsTransaction { pub fn new_account( from_keypair: &Keypair, - rewards_id: Pubkey, + rewards_id: &Pubkey, blockhash: Hash, lamports: u64, fee: u64, @@ -28,23 +28,23 @@ impl RewardsTransaction { blockhash, lamports, RewardsState::max_size() as u64, - id(), + &id(), fee, ) } pub fn new_redeem_credits( vote_keypair: &Keypair, - rewards_id: Pubkey, + rewards_id: &Pubkey, blockhash: Hash, fee: u64, ) -> Transaction { let vote_id = vote_keypair.pubkey(); TransactionBuilder::new(fee) .push(RewardsInstruction::new_redeem_vote_credits( - vote_id, rewards_id, + &vote_id, rewards_id, )) - .push(VoteInstruction::new_clear_credits(vote_id)) + .push(VoteInstruction::new_clear_credits(&vote_id)) .sign(&[vote_keypair], blockhash) } } diff --git a/programs/storage/tests/storage.rs b/programs/storage/tests/storage.rs index 3409ba9ad9..69b7b5caa7 100644 --- a/programs/storage/tests/storage.rs +++ b/programs/storage/tests/storage.rs @@ -8,7 +8,7 @@ use solana_sdk::signature::{Keypair, KeypairUtil}; use solana_sdk::system_transaction::SystemTransaction; use solana_storage_api::{StorageTransaction, ENTRIES_PER_SEGMENT}; -fn get_storage_entry_height(bank: &Bank, account: Pubkey) -> u64 { +fn get_storage_entry_height(bank: &Bank, account: &Pubkey) -> u64 { match bank.get_account(&account) { Some(storage_system_account) => { let state = deserialize(&storage_system_account.userdata); @@ -24,7 +24,7 @@ fn get_storage_entry_height(bank: &Bank, account: Pubkey) -> u64 { 0 } -fn get_storage_blockhash(bank: &Bank, account: Pubkey) -> Hash { +fn get_storage_blockhash(bank: &Bank, account: &Pubkey) -> Hash { if let Some(storage_system_account) = bank.get_account(&account) { let state = deserialize(&storage_system_account.userdata); if let Ok(state) = state { @@ -51,18 +51,20 @@ fn test_bank_storage() { bank.register_tick(&blockhash); - bank.transfer(10, &alice, jill.pubkey(), blockhash).unwrap(); + bank.transfer(10, &alice, &jill.pubkey(), blockhash) + .unwrap(); - bank.transfer(10, &alice, bob.pubkey(), blockhash).unwrap(); - bank.transfer(10, &alice, jack.pubkey(), blockhash).unwrap(); + bank.transfer(10, &alice, &bob.pubkey(), blockhash).unwrap(); + bank.transfer(10, &alice, &jack.pubkey(), blockhash) + .unwrap(); let tx = SystemTransaction::new_program_account( &alice, - bob.pubkey(), + &bob.pubkey(), blockhash, 1, 4 * 1024, - solana_storage_api::id(), + &solana_storage_api::id(), 0, ); @@ -90,11 +92,11 @@ fn test_bank_storage() { //let _result = bank.process_transaction(&tx).unwrap(); assert_eq!( - get_storage_entry_height(&bank, bob.pubkey()), + get_storage_entry_height(&bank, &bob.pubkey()), ENTRIES_PER_SEGMENT ); assert_eq!( - get_storage_blockhash(&bank, bob.pubkey()), + get_storage_blockhash(&bank, &bob.pubkey()), storage_blockhash ); } diff --git a/programs/storage_api/src/lib.rs b/programs/storage_api/src/lib.rs index 9cf2cc644b..f1ec6572f9 100644 --- a/programs/storage_api/src/lib.rs +++ b/programs/storage_api/src/lib.rs @@ -90,7 +90,7 @@ impl StorageTransaction { entry_height, signature, }; - Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0) + Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0) } pub fn new_advertise_recent_blockhash( @@ -103,7 +103,7 @@ impl StorageTransaction { hash: storage_hash, entry_height, }; - Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0) + Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0) } pub fn new_proof_validation( @@ -116,7 +116,7 @@ impl StorageTransaction { entry_height, proof_mask, }; - Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0) + Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0) } pub fn new_reward_claim( @@ -125,6 +125,6 @@ impl StorageTransaction { entry_height: u64, ) -> Transaction { let program = StorageProgram::ClaimStorageReward { entry_height }; - Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0) + Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0) } } diff --git a/programs/system/src/lib.rs b/programs/system/src/lib.rs index 30141b52ed..b3fe2798cf 100644 --- a/programs/system/src/lib.rs +++ b/programs/system/src/lib.rs @@ -19,7 +19,7 @@ fn create_system_account( keyed_accounts: &mut [KeyedAccount], lamports: u64, space: u64, - program_id: Pubkey, + program_id: &Pubkey, ) -> Result<(), SystemError> { if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) { info!("CreateAccount: invalid account[from] owner"); @@ -44,7 +44,7 @@ fn create_system_account( } keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports; keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports; - keyed_accounts[TO_ACCOUNT_INDEX].account.owner = program_id; + keyed_accounts[TO_ACCOUNT_INDEX].account.owner = *program_id; keyed_accounts[TO_ACCOUNT_INDEX].account.userdata = vec![0; space as usize]; keyed_accounts[TO_ACCOUNT_INDEX].account.executable = false; Ok(()) @@ -52,12 +52,12 @@ fn create_system_account( fn assign_account_to_program( keyed_accounts: &mut [KeyedAccount], - program_id: Pubkey, + program_id: &Pubkey, ) -> Result<(), ProgramError> { if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) { Err(ProgramError::AssignOfUnownedAccount)?; } - keyed_accounts[FROM_ACCOUNT_INDEX].account.owner = program_id; + keyed_accounts[FROM_ACCOUNT_INDEX].account.owner = *program_id; Ok(()) } fn move_lamports(keyed_accounts: &mut [KeyedAccount], lamports: u64) -> Result<(), ProgramError> { @@ -94,7 +94,7 @@ pub fn entrypoint( lamports, space, program_id, - } => create_system_account(keyed_accounts, lamports, space, program_id).map_err(|e| { + } => create_system_account(keyed_accounts, lamports, space, &program_id).map_err(|e| { match e { SystemError::AccountAlreadyInUse => ProgramError::InvalidArgument, SystemError::ResultWithNegativeLamports => { @@ -104,7 +104,7 @@ pub fn entrypoint( } }), SystemInstruction::Assign { program_id } => { - assign_account_to_program(keyed_accounts, program_id) + assign_account_to_program(keyed_accounts, &program_id) } SystemInstruction::Move { lamports } => move_lamports(keyed_accounts, lamports), } @@ -124,16 +124,16 @@ mod tests { fn test_create_system_account() { let new_program_owner = Pubkey::new(&[9; 32]); let from = Keypair::new().pubkey(); - let mut from_account = Account::new(100, 0, system_program::id()); + let mut from_account = Account::new(100, 0, &system_program::id()); let to = Keypair::new().pubkey(); - let mut to_account = Account::new(0, 0, Pubkey::default()); + let mut to_account = Account::new(0, 0, &Pubkey::default()); let mut keyed_accounts = [ KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&to, false, &mut to_account), ]; - create_system_account(&mut keyed_accounts, 50, 2, new_program_owner).unwrap(); + create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner).unwrap(); let from_lamports = from_account.lamports; let to_lamports = to_account.lamports; let to_owner = to_account.owner; @@ -149,17 +149,17 @@ mod tests { // Attempt to create account with more lamports than remaining in from_account let new_program_owner = Pubkey::new(&[9; 32]); let from = Keypair::new().pubkey(); - let mut from_account = Account::new(100, 0, system_program::id()); + let mut from_account = Account::new(100, 0, &system_program::id()); let to = Keypair::new().pubkey(); - let mut to_account = Account::new(0, 0, Pubkey::default()); + let mut to_account = Account::new(0, 0, &Pubkey::default()); let unchanged_account = to_account.clone(); let mut keyed_accounts = [ KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&to, false, &mut to_account), ]; - let result = create_system_account(&mut keyed_accounts, 150, 2, new_program_owner); + let result = create_system_account(&mut keyed_accounts, 150, 2, &new_program_owner); assert_eq!(result, Err(SystemError::ResultWithNegativeLamports)); let from_lamports = from_account.lamports; assert_eq!(from_lamports, 100); @@ -171,18 +171,18 @@ mod tests { // Attempt to create system account in account already owned by another program let new_program_owner = Pubkey::new(&[9; 32]); let from = Keypair::new().pubkey(); - let mut from_account = Account::new(100, 0, system_program::id()); + let mut from_account = Account::new(100, 0, &system_program::id()); let original_program_owner = Pubkey::new(&[5; 32]); let owned_key = Keypair::new().pubkey(); - let mut owned_account = Account::new(0, 0, original_program_owner); + let mut owned_account = Account::new(0, 0, &original_program_owner); let unchanged_account = owned_account.clone(); let mut keyed_accounts = [ KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&owned_key, false, &mut owned_account), ]; - let result = create_system_account(&mut keyed_accounts, 50, 2, new_program_owner); + let result = create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner); assert_eq!(result, Err(SystemError::AccountAlreadyInUse)); let from_lamports = from_account.lamports; assert_eq!(from_lamports, 100); @@ -194,7 +194,7 @@ mod tests { // Attempt to create system account in account with populated userdata let new_program_owner = Pubkey::new(&[9; 32]); let from = Keypair::new().pubkey(); - let mut from_account = Account::new(100, 0, system_program::id()); + let mut from_account = Account::new(100, 0, &system_program::id()); let populated_key = Keypair::new().pubkey(); let mut populated_account = Account { @@ -209,7 +209,7 @@ mod tests { KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&populated_key, false, &mut populated_account), ]; - let result = create_system_account(&mut keyed_accounts, 50, 2, new_program_owner); + let result = create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner); assert_eq!(result, Err(SystemError::AccountAlreadyInUse)); assert_eq!(from_account.lamports, 100); assert_eq!(populated_account, unchanged_account); @@ -220,14 +220,14 @@ mod tests { let other_program = Pubkey::new(&[9; 32]); let from = Keypair::new().pubkey(); - let mut from_account = Account::new(100, 0, other_program); + let mut from_account = Account::new(100, 0, &other_program); let to = Keypair::new().pubkey(); - let mut to_account = Account::new(0, 0, Pubkey::default()); + let mut to_account = Account::new(0, 0, &Pubkey::default()); let mut keyed_accounts = [ KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&to, false, &mut to_account), ]; - let result = create_system_account(&mut keyed_accounts, 50, 2, other_program); + let result = create_system_account(&mut keyed_accounts, 50, 2, &other_program); assert_eq!(result, Err(SystemError::SourceNotSystemAccount)); } @@ -236,16 +236,16 @@ mod tests { let new_program_owner = Pubkey::new(&[9; 32]); let from = Keypair::new().pubkey(); - let mut from_account = Account::new(100, 0, system_program::id()); + let mut from_account = Account::new(100, 0, &system_program::id()); let mut keyed_accounts = [KeyedAccount::new(&from, true, &mut from_account)]; - assign_account_to_program(&mut keyed_accounts, new_program_owner).unwrap(); + assign_account_to_program(&mut keyed_accounts, &new_program_owner).unwrap(); let from_owner = from_account.owner; assert_eq!(from_owner, new_program_owner); // Attempt to assign account not owned by system program let another_program_owner = Pubkey::new(&[8; 32]); keyed_accounts = [KeyedAccount::new(&from, true, &mut from_account)]; - let result = assign_account_to_program(&mut keyed_accounts, another_program_owner); + let result = assign_account_to_program(&mut keyed_accounts, &another_program_owner); assert_eq!(result, Err(ProgramError::AssignOfUnownedAccount)); assert_eq!(from_account.owner, new_program_owner); } @@ -253,9 +253,9 @@ mod tests { #[test] fn test_move_lamports() { let from = Keypair::new().pubkey(); - let mut from_account = Account::new(100, 0, Pubkey::new(&[2; 32])); // account owner should not matter + let mut from_account = Account::new(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter let to = Keypair::new().pubkey(); - let mut to_account = Account::new(1, 0, Pubkey::new(&[3; 32])); // account owner should not matter + let mut to_account = Account::new(1, 0, &Pubkey::new(&[3; 32])); // account owner should not matter let mut keyed_accounts = [ KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&to, false, &mut to_account), diff --git a/programs/system/tests/system.rs b/programs/system/tests/system.rs index a72cec43bf..b9cebebe0e 100644 --- a/programs/system/tests/system.rs +++ b/programs/system/tests/system.rs @@ -27,8 +27,8 @@ fn test_system_unsigned_transaction() { let blockhash = system_bank.bank.last_blockhash(); let tx = TransactionBuilder::default() .push(SystemInstruction::new_move( - from_keypair.pubkey(), - to_keypair.pubkey(), + &from_keypair.pubkey(), + &to_keypair.pubkey(), 50, )) .sign(&[&from_keypair], blockhash); diff --git a/programs/vote/src/lib.rs b/programs/vote/src/lib.rs index 53eeb31489..702fb5815e 100644 --- a/programs/vote/src/lib.rs +++ b/programs/vote/src/lib.rs @@ -25,10 +25,10 @@ fn entrypoint( match deserialize(data).map_err(|_| ProgramError::InvalidUserdata)? { VoteInstruction::InitializeAccount => vote_state::initialize_account(keyed_accounts), VoteInstruction::DelegateStake(delegate_id) => { - vote_state::delegate_stake(keyed_accounts, delegate_id) + vote_state::delegate_stake(keyed_accounts, &delegate_id) } VoteInstruction::AuthorizeVoter(voter_id) => { - vote_state::authorize_voter(keyed_accounts, voter_id) + vote_state::authorize_voter(keyed_accounts, &voter_id) } VoteInstruction::Vote(vote) => { debug!("{:?} by {}", vote, keyed_accounts[0].signer_key().unwrap()); diff --git a/programs/vote/tests/vote.rs b/programs/vote/tests/vote.rs index d61af067a1..8167269b02 100644 --- a/programs/vote/tests/vote.rs +++ b/programs/vote/tests/vote.rs @@ -24,7 +24,7 @@ impl<'a> VoteBank<'a> { fn create_vote_account( &self, from_keypair: &Keypair, - vote_id: Pubkey, + vote_id: &Pubkey, lamports: u64, ) -> Result<()> { let blockhash = self.bank.last_blockhash(); @@ -36,7 +36,7 @@ impl<'a> VoteBank<'a> { &self, from_keypair: &Keypair, vote_keypair: &Keypair, - delegate_id: Pubkey, + delegate_id: &Pubkey, lamports: u64, ) -> Result<()> { let blockhash = self.bank.last_blockhash(); @@ -53,7 +53,7 @@ impl<'a> VoteBank<'a> { fn submit_vote( &self, - staking_account: Pubkey, + staking_account: &Pubkey, vote_keypair: &Keypair, tick_height: u64, ) -> Result { @@ -77,10 +77,10 @@ fn test_vote_bank_basic() { let vote_keypair = Keypair::new(); let vote_id = vote_keypair.pubkey(); vote_bank - .create_vote_account(&from_keypair, vote_id, 100) + .create_vote_account(&from_keypair, &vote_id, 100) .unwrap(); - let vote_state = vote_bank.submit_vote(vote_id, &vote_keypair, 0).unwrap(); + let vote_state = vote_bank.submit_vote(&vote_id, &vote_keypair, 0).unwrap(); assert_eq!(vote_state.votes.len(), 1); } @@ -93,7 +93,7 @@ fn test_vote_bank_delegate() { let delegate_keypair = Keypair::new(); let delegate_id = delegate_keypair.pubkey(); vote_bank - .create_vote_account_with_delegate(&from_keypair, &vote_keypair, delegate_id, 100) + .create_vote_account_with_delegate(&from_keypair, &vote_keypair, &delegate_id, 100) .unwrap(); } @@ -106,7 +106,7 @@ fn test_vote_via_bank_with_no_signature() { let vote_keypair = Keypair::new(); let vote_id = vote_keypair.pubkey(); vote_bank - .create_vote_account(&mallory_keypair, vote_id, 100) + .create_vote_account(&mallory_keypair, &vote_id, 100) .unwrap(); let mallory_id = mallory_keypair.pubkey(); @@ -121,7 +121,7 @@ fn test_vote_via_bank_with_no_signature() { // the 0th account in the second instruction is not! The program // needs to check that it's signed. let tx = TransactionBuilder::default() - .push(SystemInstruction::new_move(mallory_id, vote_id, 1)) + .push(SystemInstruction::new_move(&mallory_id, &vote_id, 1)) .push(vote_ix) .sign(&[&mallory_keypair], blockhash); diff --git a/programs/vote_api/src/vote_instruction.rs b/programs/vote_api/src/vote_instruction.rs index 18d4cad7fa..ea69c829d7 100644 --- a/programs/vote_api/src/vote_instruction.rs +++ b/programs/vote_api/src/vote_instruction.rs @@ -32,31 +32,34 @@ pub enum VoteInstruction { } impl VoteInstruction { - pub fn new_clear_credits(vote_id: Pubkey) -> BuilderInstruction { - BuilderInstruction::new(id(), &VoteInstruction::ClearCredits, vec![(vote_id, true)]) + pub fn new_clear_credits(vote_id: &Pubkey) -> BuilderInstruction { + BuilderInstruction::new(id(), &VoteInstruction::ClearCredits, vec![(*vote_id, true)]) } - pub fn new_delegate_stake(vote_id: Pubkey, delegate_id: Pubkey) -> BuilderInstruction { + pub fn new_delegate_stake(vote_id: &Pubkey, delegate_id: &Pubkey) -> BuilderInstruction { BuilderInstruction::new( id(), - &VoteInstruction::DelegateStake(delegate_id), - vec![(vote_id, true)], + &VoteInstruction::DelegateStake(*delegate_id), + vec![(*vote_id, true)], ) } - pub fn new_authorize_voter(vote_id: Pubkey, authorized_voter_id: Pubkey) -> BuilderInstruction { + pub fn new_authorize_voter( + vote_id: &Pubkey, + authorized_voter_id: &Pubkey, + ) -> BuilderInstruction { BuilderInstruction::new( id(), - &VoteInstruction::AuthorizeVoter(authorized_voter_id), - vec![(vote_id, true)], + &VoteInstruction::AuthorizeVoter(*authorized_voter_id), + vec![(*vote_id, true)], ) } - pub fn new_initialize_account(vote_id: Pubkey) -> BuilderInstruction { + pub fn new_initialize_account(vote_id: &Pubkey) -> BuilderInstruction { BuilderInstruction::new( id(), &VoteInstruction::InitializeAccount, - vec![(vote_id, false)], + vec![(*vote_id, false)], ) } - pub fn new_vote(vote_id: Pubkey, vote: Vote) -> BuilderInstruction { - BuilderInstruction::new(id(), &VoteInstruction::Vote(vote), vec![(vote_id, true)]) + pub fn new_vote(vote_id: &Pubkey, vote: Vote) -> BuilderInstruction { + BuilderInstruction::new(id(), &VoteInstruction::Vote(vote), vec![(*vote_id, true)]) } } diff --git a/programs/vote_api/src/vote_state.rs b/programs/vote_api/src/vote_state.rs index 8d4d017ac0..56383a3059 100644 --- a/programs/vote_api/src/vote_state.rs +++ b/programs/vote_api/src/vote_state.rs @@ -51,14 +51,14 @@ pub struct VoteState { } impl VoteState { - pub fn new(staker_id: Pubkey) -> Self { + pub fn new(staker_id: &Pubkey) -> Self { let votes = VecDeque::new(); let credits = 0; let root_slot = None; Self { votes, - delegate_id: staker_id, - authorized_voter_id: staker_id, + delegate_id: *staker_id, + authorized_voter_id: *staker_id, credits, root_slot, } @@ -151,7 +151,7 @@ impl VoteState { pub fn delegate_stake( keyed_accounts: &mut [KeyedAccount], - node_id: Pubkey, + node_id: &Pubkey, ) -> Result<(), ProgramError> { if !check_id(&keyed_accounts[0].account.owner) { error!("account[0] is not assigned to the VOTE_PROGRAM"); @@ -165,7 +165,7 @@ pub fn delegate_stake( let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata); if let Ok(mut vote_state) = vote_state { - vote_state.delegate_id = node_id; + vote_state.delegate_id = *node_id; vote_state.serialize(&mut keyed_accounts[0].account.userdata)?; } else { error!("account[0] does not valid userdata"); @@ -180,7 +180,7 @@ pub fn delegate_stake( /// voter. The default voter is the owner of the vote account's pubkey. pub fn authorize_voter( keyed_accounts: &mut [KeyedAccount], - voter_id: Pubkey, + voter_id: &Pubkey, ) -> Result<(), ProgramError> { if !check_id(&keyed_accounts[0].account.owner) { error!("account[0] is not assigned to the VOTE_PROGRAM"); @@ -194,7 +194,7 @@ pub fn authorize_voter( let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata); if let Ok(mut vote_state) = vote_state { - vote_state.authorized_voter_id = voter_id; + vote_state.authorized_voter_id = *voter_id; vote_state.serialize(&mut keyed_accounts[0].account.userdata)?; } else { error!("account[0] does not valid userdata"); @@ -217,7 +217,7 @@ pub fn initialize_account(keyed_accounts: &mut [KeyedAccount]) -> Result<(), Pro let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata); if let Ok(vote_state) = vote_state { if vote_state.delegate_id == Pubkey::default() { - let vote_state = VoteState::new(*staker_id); + let vote_state = VoteState::new(staker_id); vote_state.serialize(&mut keyed_accounts[0].account.userdata)?; } else { error!("account[0] userdata already initialized"); @@ -274,7 +274,7 @@ pub fn clear_credits(keyed_accounts: &mut [KeyedAccount]) -> Result<(), ProgramE pub fn create_vote_account(lamports: u64) -> Account { let space = VoteState::max_size(); - Account::new(lamports, space, id()) + Account::new(lamports, space, &id()) } pub fn initialize_and_deserialize( @@ -309,7 +309,7 @@ mod tests { let mut vote_account = create_vote_account(100); let bogus_account_id = Keypair::new().pubkey(); - let mut bogus_account = Account::new(100, 0, id()); + let mut bogus_account = Account::new(100, 0, &id()); let mut keyed_accounts = [KeyedAccount::new( &bogus_account_id, @@ -385,7 +385,7 @@ mod tests { #[test] fn test_vote_lockout() { let voter_id = Keypair::new().pubkey(); - let mut vote_state = VoteState::new(voter_id); + let mut vote_state = VoteState::new(&voter_id); for i in 0..(MAX_LOCKOUT_HISTORY + 1) { vote_state.process_vote(Vote::new((INITIAL_LOCKOUT as usize * i) as u64)); @@ -415,7 +415,7 @@ mod tests { #[test] fn test_vote_double_lockout_after_expiration() { let voter_id = Keypair::new().pubkey(); - let mut vote_state = VoteState::new(voter_id); + let mut vote_state = VoteState::new(&voter_id); for i in 0..3 { let vote = Vote::new(i as u64); @@ -441,7 +441,7 @@ mod tests { #[test] fn test_vote_credits() { let voter_id = Keypair::new().pubkey(); - let mut vote_state = VoteState::new(voter_id); + let mut vote_state = VoteState::new(&voter_id); for i in 0..MAX_LOCKOUT_HISTORY { vote_state.process_vote(Vote::new(i as u64)); diff --git a/programs/vote_api/src/vote_transaction.rs b/programs/vote_api/src/vote_transaction.rs index 82b2d847f3..db25c3e4a8 100644 --- a/programs/vote_api/src/vote_transaction.rs +++ b/programs/vote_api/src/vote_transaction.rs @@ -15,7 +15,7 @@ pub struct VoteTransaction {} impl VoteTransaction { pub fn new_vote( - staking_account: Pubkey, + staking_account: &Pubkey, authorized_voter_keypair: &T, slot: u64, recent_blockhash: Hash, @@ -30,7 +30,7 @@ impl VoteTransaction { /// Fund or create the staking account with lamports pub fn new_account( from_keypair: &Keypair, - staker_id: Pubkey, + staker_id: &Pubkey, recent_blockhash: Hash, lamports: u64, fee: u64, @@ -39,11 +39,11 @@ impl VoteTransaction { let space = VoteState::max_size() as u64; TransactionBuilder::new(fee) .push(SystemInstruction::new_program_account( - from_id, + &from_id, staker_id, lamports, space, - id(), + &id(), )) .push(VoteInstruction::new_initialize_account(staker_id)) .sign(&[from_keypair], recent_blockhash) @@ -53,7 +53,7 @@ impl VoteTransaction { pub fn new_account_with_delegate( from_keypair: &Keypair, voter_keypair: &Keypair, - delegate_id: Pubkey, + delegate_id: &Pubkey, recent_blockhash: Hash, lamports: u64, fee: u64, @@ -63,14 +63,14 @@ impl VoteTransaction { let space = VoteState::max_size() as u64; TransactionBuilder::new(fee) .push(SystemInstruction::new_program_account( - from_id, - voter_id, + &from_id, + &voter_id, lamports, space, - id(), + &id(), )) - .push(VoteInstruction::new_initialize_account(voter_id)) - .push(VoteInstruction::new_delegate_stake(voter_id, delegate_id)) + .push(VoteInstruction::new_initialize_account(&voter_id)) + .push(VoteInstruction::new_delegate_stake(&voter_id, &delegate_id)) .sign(&[from_keypair, voter_keypair], recent_blockhash) } @@ -78,12 +78,12 @@ impl VoteTransaction { pub fn new_authorize_voter( vote_keypair: &Keypair, recent_blockhash: Hash, - authorized_voter_id: Pubkey, + authorized_voter_id: &Pubkey, fee: u64, ) -> Transaction { TransactionBuilder::new(fee) .push(VoteInstruction::new_authorize_voter( - vote_keypair.pubkey(), + &vote_keypair.pubkey(), authorized_voter_id, )) .sign(&[vote_keypair], recent_blockhash) @@ -93,12 +93,12 @@ impl VoteTransaction { pub fn delegate_vote_account( vote_keypair: &T, recent_blockhash: Hash, - node_id: Pubkey, + node_id: &Pubkey, fee: u64, ) -> Transaction { TransactionBuilder::new(fee) .push(VoteInstruction::new_delegate_stake( - vote_keypair.pubkey(), + &vote_keypair.pubkey(), node_id, )) .sign(&[vote_keypair], recent_blockhash) @@ -133,7 +133,7 @@ mod tests { let slot = 1; let recent_blockhash = Hash::default(); let transaction = - VoteTransaction::new_vote(keypair.pubkey(), &keypair, slot, recent_blockhash, 0); + VoteTransaction::new_vote(&keypair.pubkey(), &keypair, slot, recent_blockhash, 0); assert_eq!( VoteTransaction::get_votes(&transaction), vec![(keypair.pubkey(), Vote::new(slot), recent_blockhash)] diff --git a/replicator/src/main.rs b/replicator/src/main.rs index 467cae5755..da93265b5a 100644 --- a/replicator/src/main.rs +++ b/replicator/src/main.rs @@ -67,7 +67,7 @@ fn main() { } addr }; - let node = Node::new_with_external_ip(keypair.pubkey(), &gossip_addr); + let node = Node::new_with_external_ip(&keypair.pubkey(), &gossip_addr); println!( "replicating the data with keypair={:?} gossip_addr={:?}", diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index ebd2d1e647..dc2245720a 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -635,11 +635,12 @@ impl AccountsDB { fn load_executable_accounts( &self, fork: Fork, - mut program_id: Pubkey, + program_id: &Pubkey, error_counters: &mut ErrorCounters, ) -> Result> { let mut accounts = Vec::new(); let mut depth = 0; + let mut program_id = *program_id; loop { if native_loader::check_id(&program_id) { // at the root of the chain, ready to dispatch @@ -687,7 +688,7 @@ impl AccountsDB { return Err(BankError::AccountNotFound); } let program_id = tx.program_ids[ix.program_ids_index as usize]; - self.load_executable_accounts(fork, program_id, error_counters) + self.load_executable_accounts(fork, &program_id, error_counters) }) .collect() } @@ -1092,10 +1093,10 @@ mod tests { let key0 = keypair.pubkey(); let key1 = Pubkey::new(&[5u8; 32]); - let account = Account::new(1, 1, Pubkey::default()); + let account = Account::new(1, 1, &Pubkey::default()); accounts.push((key0, account)); - let account = Account::new(2, 1, Pubkey::default()); + let account = Account::new(2, 1, &Pubkey::default()); accounts.push((key1, account)); let instructions = vec![Instruction::new(1, &(), vec![0])]; @@ -1123,7 +1124,7 @@ mod tests { let keypair = Keypair::new(); let key0 = keypair.pubkey(); - let account = Account::new(1, 1, Pubkey::default()); + let account = Account::new(1, 1, &Pubkey::default()); accounts.push((key0, account)); let instructions = vec![Instruction::new(1, &(), vec![0])]; @@ -1152,10 +1153,10 @@ mod tests { let key0 = keypair.pubkey(); let key1 = Pubkey::new(&[5u8; 32]); - let account = Account::new(1, 1, Pubkey::default()); + let account = Account::new(1, 1, &Pubkey::default()); accounts.push((key0, account)); - let account = Account::new(2, 1, Pubkey::default()); + let account = Account::new(2, 1, &Pubkey::default()); accounts.push((key1, account)); let instructions = vec![Instruction::new(0, &(), vec![0, 1])]; @@ -1197,35 +1198,35 @@ mod tests { let key5 = Pubkey::new(&[9u8; 32]); let key6 = Pubkey::new(&[10u8; 32]); - let account = Account::new(1, 1, Pubkey::default()); + let account = Account::new(1, 1, &Pubkey::default()); accounts.push((key0, account)); - let mut account = Account::new(40, 1, Pubkey::default()); + let mut account = Account::new(40, 1, &Pubkey::default()); account.executable = true; account.owner = native_loader::id(); accounts.push((key1, account)); - let mut account = Account::new(41, 1, Pubkey::default()); + let mut account = Account::new(41, 1, &Pubkey::default()); account.executable = true; account.owner = key1; accounts.push((key2, account)); - let mut account = Account::new(42, 1, Pubkey::default()); + let mut account = Account::new(42, 1, &Pubkey::default()); account.executable = true; account.owner = key2; accounts.push((key3, account)); - let mut account = Account::new(43, 1, Pubkey::default()); + let mut account = Account::new(43, 1, &Pubkey::default()); account.executable = true; account.owner = key3; accounts.push((key4, account)); - let mut account = Account::new(44, 1, Pubkey::default()); + let mut account = Account::new(44, 1, &Pubkey::default()); account.executable = true; account.owner = key4; accounts.push((key5, account)); - let mut account = Account::new(45, 1, Pubkey::default()); + let mut account = Account::new(45, 1, &Pubkey::default()); account.executable = true; account.owner = key5; accounts.push((key6, account)); @@ -1256,10 +1257,10 @@ mod tests { let key0 = keypair.pubkey(); let key1 = Pubkey::new(&[5u8; 32]); - let account = Account::new(1, 1, Pubkey::default()); + let account = Account::new(1, 1, &Pubkey::default()); accounts.push((key0, account)); - let mut account = Account::new(40, 1, Pubkey::default()); + let mut account = Account::new(40, 1, &Pubkey::default()); account.executable = true; account.owner = Pubkey::default(); accounts.push((key1, account)); @@ -1290,10 +1291,10 @@ mod tests { let key0 = keypair.pubkey(); let key1 = Pubkey::new(&[5u8; 32]); - let account = Account::new(1, 1, Pubkey::default()); + let account = Account::new(1, 1, &Pubkey::default()); accounts.push((key0, account)); - let mut account = Account::new(40, 1, Pubkey::default()); + let mut account = Account::new(40, 1, &Pubkey::default()); account.owner = native_loader::id(); accounts.push((key1, account)); @@ -1325,20 +1326,20 @@ mod tests { let key2 = Pubkey::new(&[6u8; 32]); let key3 = Pubkey::new(&[7u8; 32]); - let account = Account::new(1, 1, Pubkey::default()); + let account = Account::new(1, 1, &Pubkey::default()); accounts.push((key0, account)); - let mut account = Account::new(40, 1, Pubkey::default()); + let mut account = Account::new(40, 1, &Pubkey::default()); account.executable = true; account.owner = native_loader::id(); accounts.push((key1, account)); - let mut account = Account::new(41, 1, Pubkey::default()); + let mut account = Account::new(41, 1, &Pubkey::default()); account.executable = true; account.owner = key1; accounts.push((key2, account)); - let mut account = Account::new(42, 1, Pubkey::default()); + let mut account = Account::new(42, 1, &Pubkey::default()); account.executable = true; account.owner = key2; accounts.push((key3, account)); @@ -1386,7 +1387,7 @@ mod tests { let keypair = Keypair::new(); let pubkey = keypair.pubkey(); - let account = Account::new(10, 1, Pubkey::default()); + let account = Account::new(10, 1, &Pubkey::default()); accounts.push((pubkey, account)); let instructions = vec![Instruction::new(0, &(), vec![0, 1])]; @@ -1448,7 +1449,7 @@ mod tests { let paths = get_tmp_accounts_path!(); let db = AccountsDB::new(0, &paths.paths); let key = Pubkey::default(); - let account0 = Account::new(1, 0, key); + let account0 = Account::new(1, 0, &key); // store value 1 in the "root", i.e. db zero db.store(0, &key, &account0); @@ -1466,7 +1467,7 @@ mod tests { // (via root0) // store value 0 in one child - let account1 = Account::new(0, 0, key); + let account1 = Account::new(0, 0, &key); db.store(1, &key, &account1); // masking accounts is done at the Accounts level, at accountsDB we see @@ -1546,12 +1547,12 @@ mod tests { // 1 token in the "root", i.e. db zero let paths = get_tmp_accounts_path!(); let db0 = AccountsDB::new(0, &paths.paths); - let account0 = Account::new(1, 0, key); + let account0 = Account::new(1, 0, &key); db0.store(0, &key, &account0); db0.add_fork(1, Some(0)); // 0 lamports in the child - let account1 = Account::new(0, 0, key); + let account1 = Account::new(0, 0, &key); db0.store(1, &key, &account1); // masking accounts is done at the Accounts level, at accountsDB we see @@ -1670,7 +1671,7 @@ mod tests { let mut keys = vec![]; for i in 0..9 { let key = Keypair::new().pubkey(); - let account = Account::new(i + 1, size as usize / 4, key); + let account = Account::new(i + 1, size as usize / 4, &key); accounts.store(0, &key, &account); keys.push(key); } @@ -1703,7 +1704,7 @@ mod tests { AccountStorageStatus::StorageFull, ]; let pubkey1 = Keypair::new().pubkey(); - let account1 = Account::new(1, ACCOUNT_DATA_FILE_SIZE as usize / 2, pubkey1); + let account1 = Account::new(1, ACCOUNT_DATA_FILE_SIZE as usize / 2, &pubkey1); accounts.store(0, &pubkey1, &account1); { let stores = accounts.storage.read().unwrap(); @@ -1713,7 +1714,7 @@ mod tests { } let pubkey2 = Keypair::new().pubkey(); - let account2 = Account::new(1, ACCOUNT_DATA_FILE_SIZE as usize / 2, pubkey2); + let account2 = Account::new(1, ACCOUNT_DATA_FILE_SIZE as usize / 2, &pubkey2); accounts.store(0, &pubkey2, &account2); { let stores = accounts.storage.read().unwrap(); @@ -1747,7 +1748,7 @@ mod tests { #[test] fn test_accounts_vote_filter() { let accounts = Accounts::new(0, None); - let mut vote_account = Account::new(1, 0, solana_vote_api::id()); + let mut vote_account = Account::new(1, 0, &solana_vote_api::id()); let key = Keypair::new().pubkey(); accounts.store_slow(0, &key, &vote_account); @@ -1762,7 +1763,7 @@ mod tests { vote_accounts = accounts.get_vote_accounts(1).collect(); assert_eq!(vote_accounts.len(), 0); - let mut vote_account1 = Account::new(2, 0, solana_vote_api::id()); + let mut vote_account1 = Account::new(2, 0, &solana_vote_api::id()); let key1 = Keypair::new().pubkey(); accounts.store_slow(1, &key1, &vote_account1); @@ -1792,7 +1793,7 @@ mod tests { assert_eq!(account.owner, solana_vote_api::id()); }); let lastkey = Keypair::new().pubkey(); - let mut lastaccount = Account::new(1, 0, solana_vote_api::id()); + let mut lastaccount = Account::new(1, 0, &solana_vote_api::id()); accounts_db.store(0, &lastkey, &lastaccount); assert_eq!(accounts_db.get_vote_accounts(0).len(), 2); @@ -1862,7 +1863,7 @@ mod tests { let accounts = AccountsDB::new(0, &paths.paths); let mut error_counters = ErrorCounters::default(); assert_eq!( - accounts.load_executable_accounts(0, Keypair::new().pubkey(), &mut error_counters), + accounts.load_executable_accounts(0, &Keypair::new().pubkey(), &mut error_counters), Err(BankError::AccountNotFound) ); assert_eq!(error_counters.account_not_found, 1); @@ -1894,13 +1895,13 @@ mod tests { // Load accounts owned by various programs into AccountsDB let pubkey0 = Keypair::new().pubkey(); - let account0 = Account::new(1, 0, Pubkey::new(&[2; 32])); + let account0 = Account::new(1, 0, &Pubkey::new(&[2; 32])); accounts_db.store(0, &pubkey0, &account0); let pubkey1 = Keypair::new().pubkey(); - let account1 = Account::new(1, 0, Pubkey::new(&[2; 32])); + let account1 = Account::new(1, 0, &Pubkey::new(&[2; 32])); accounts_db.store(0, &pubkey1, &account1); let pubkey2 = Keypair::new().pubkey(); - let account2 = Account::new(1, 0, Pubkey::new(&[3; 32])); + let account2 = Account::new(1, 0, &Pubkey::new(&[3; 32])); accounts_db.store(0, &pubkey2, &account2); let accounts = accounts_db.load_by_program(0, &Pubkey::new(&[2; 32]), false); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 1e7223c001..fea31c139e 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -224,7 +224,7 @@ impl Bank { } /// Create a new bank that points to an immutable checkpoint of another bank. - pub fn new_from_parent(parent: &Arc, collector_id: Pubkey, slot: u64) -> Self { + pub fn new_from_parent(parent: &Arc, collector_id: &Pubkey, slot: u64) -> Self { parent.freeze(); assert_ne!(slot, parent.slot()); @@ -239,7 +239,7 @@ impl Bank { bank.slot = slot; bank.parent = RwLock::new(Some(parent.clone())); bank.parent_hash = parent.hash(); - bank.collector_id = collector_id; + bank.collector_id = *collector_id; // Accounts needs a unique id static BANK_ACCOUNTS_ID: AtomicUsize = AtomicUsize::new(1); @@ -340,7 +340,7 @@ impl Bank { executable: false, }; - let mut vote_state = VoteState::new(genesis_block.bootstrap_leader_id); + let mut vote_state = VoteState::new(&genesis_block.bootstrap_leader_id); vote_state.votes.push_back(Lockout::new(&Vote::new(0))); vote_state .serialize(&mut bootstrap_leader_vote_account.userdata) @@ -731,7 +731,7 @@ impl Bank { &self, n: u64, keypair: &Keypair, - to: Pubkey, + to: &Pubkey, blockhash: Hash, ) -> Result { let tx = SystemTransaction::new_account(keypair, to, n, blockhash, 0); @@ -909,7 +909,7 @@ mod tests { let dummy_leader_id = Keypair::new().pubkey(); let dummy_leader_lamports = BOOTSTRAP_LEADER_LAMPORTS; let (genesis_block, _) = - GenesisBlock::new_with_leader(10_000, dummy_leader_id, dummy_leader_lamports); + GenesisBlock::new_with_leader(10_000, &dummy_leader_id, dummy_leader_lamports); assert_eq!( genesis_block.bootstrap_leader_lamports, dummy_leader_lamports @@ -932,11 +932,11 @@ mod tests { let bank = Bank::new(&genesis_block); assert_eq!(bank.last_blockhash(), genesis_block.hash()); - bank.transfer(1_000, &mint_keypair, pubkey, genesis_block.hash()) + bank.transfer(1_000, &mint_keypair, &pubkey, genesis_block.hash()) .unwrap(); assert_eq!(bank.get_balance(&pubkey), 1_000); - bank.transfer(500, &mint_keypair, pubkey, genesis_block.hash()) + bank.transfer(500, &mint_keypair, &pubkey, genesis_block.hash()) .unwrap(); assert_eq!(bank.get_balance(&pubkey), 1_500); assert_eq!(bank.transaction_count(), 2); @@ -950,8 +950,8 @@ mod tests { let bank = Bank::new(&genesis_block); assert_eq!(bank.last_blockhash(), genesis_block.hash()); - let t1 = SystemTransaction::new_move(&mint_keypair, key1, 1, genesis_block.hash(), 0); - let t2 = SystemTransaction::new_move(&mint_keypair, key2, 1, genesis_block.hash(), 0); + let t1 = SystemTransaction::new_move(&mint_keypair, &key1, 1, genesis_block.hash(), 0); + let t2 = SystemTransaction::new_move(&mint_keypair, &key2, 1, genesis_block.hash(), 0); let res = bank.process_transactions(&vec![t1.clone(), t2.clone()]); assert_eq!(res.len(), 2); assert_eq!(res[0], Ok(())); @@ -1040,7 +1040,7 @@ mod tests { // source with 0 program context let tx = SystemTransaction::new_account( &mint_keypair, - dest.pubkey(), + &dest.pubkey(), 2, genesis_block.hash(), 1, @@ -1069,7 +1069,7 @@ mod tests { let bank = Bank::new(&genesis_block); let keypair = Keypair::new(); assert_eq!( - bank.transfer(1, &keypair, mint_keypair.pubkey(), genesis_block.hash()), + bank.transfer(1, &keypair, &mint_keypair.pubkey(), genesis_block.hash()), Err(BankError::AccountNotFound) ); assert_eq!(bank.transaction_count(), 0); @@ -1080,12 +1080,12 @@ mod tests { let (genesis_block, mint_keypair) = GenesisBlock::new(11_000); let bank = Bank::new(&genesis_block); let pubkey = Keypair::new().pubkey(); - bank.transfer(1_000, &mint_keypair, pubkey, genesis_block.hash()) + bank.transfer(1_000, &mint_keypair, &pubkey, genesis_block.hash()) .unwrap(); assert_eq!(bank.transaction_count(), 1); assert_eq!(bank.get_balance(&pubkey), 1_000); assert_eq!( - bank.transfer(10_001, &mint_keypair, pubkey, genesis_block.hash()), + bank.transfer(10_001, &mint_keypair, &pubkey, genesis_block.hash()), Err(BankError::ProgramError( 0, ProgramError::ResultWithNegativeLamports @@ -1103,7 +1103,7 @@ mod tests { let (genesis_block, mint_keypair) = GenesisBlock::new(10_000); let bank = Bank::new(&genesis_block); let pubkey = Keypair::new().pubkey(); - bank.transfer(500, &mint_keypair, pubkey, genesis_block.hash()) + bank.transfer(500, &mint_keypair, &pubkey, genesis_block.hash()) .unwrap(); assert_eq!(bank.get_balance(&pubkey), 500); } @@ -1152,20 +1152,20 @@ mod tests { #[test] fn test_bank_tx_fee() { let leader = Keypair::new().pubkey(); - let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, leader, 3); + let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, &leader, 3); let bank = Bank::new(&genesis_block); let key1 = Keypair::new(); let key2 = Keypair::new(); let tx = - SystemTransaction::new_move(&mint_keypair, key1.pubkey(), 2, genesis_block.hash(), 3); + SystemTransaction::new_move(&mint_keypair, &key1.pubkey(), 2, genesis_block.hash(), 3); let initial_balance = bank.get_balance(&leader); assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.get_balance(&leader), initial_balance + 3); assert_eq!(bank.get_balance(&key1.pubkey()), 2); assert_eq!(bank.get_balance(&mint_keypair.pubkey()), 100 - 5 - 3); - let tx = SystemTransaction::new_move(&key1, key2.pubkey(), 1, genesis_block.hash(), 1); + let tx = SystemTransaction::new_move(&key1, &key2.pubkey(), 1, genesis_block.hash(), 1); assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.get_balance(&leader), initial_balance + 4); assert_eq!(bank.get_balance(&key1.pubkey()), 0); @@ -1176,14 +1176,14 @@ mod tests { #[test] fn test_filter_program_errors_and_collect_fee() { let leader = Keypair::new().pubkey(); - let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, leader, 3); + let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, &leader, 3); let bank = Bank::new(&genesis_block); let key = Keypair::new(); let tx1 = - SystemTransaction::new_move(&mint_keypair, key.pubkey(), 2, genesis_block.hash(), 3); + SystemTransaction::new_move(&mint_keypair, &key.pubkey(), 2, genesis_block.hash(), 3); let tx2 = - SystemTransaction::new_move(&mint_keypair, key.pubkey(), 5, genesis_block.hash(), 1); + SystemTransaction::new_move(&mint_keypair, &key.pubkey(), 5, genesis_block.hash(), 1); let results = vec![ Ok(()), @@ -1207,14 +1207,14 @@ mod tests { let keypair = Keypair::new(); let tx0 = SystemTransaction::new_account( &mint_keypair, - keypair.pubkey(), + &keypair.pubkey(), 2, genesis_block.hash(), 0, ); let tx1 = SystemTransaction::new_account( &keypair, - mint_keypair.pubkey(), + &mint_keypair.pubkey(), 1, genesis_block.hash(), 0, @@ -1232,7 +1232,7 @@ mod tests { let dummy_leader_id = Keypair::new().pubkey(); let dummy_leader_lamports = 3; let (genesis_block, _) = - GenesisBlock::new_with_leader(5, dummy_leader_id, dummy_leader_lamports); + GenesisBlock::new_with_leader(5, &dummy_leader_id, dummy_leader_lamports); let bank = Bank::new(&genesis_block); assert_eq!(bank.get_balance(&genesis_block.mint_id), 2); assert_eq!(bank.get_balance(&dummy_leader_id), 2); @@ -1247,7 +1247,7 @@ mod tests { let tx1 = SystemTransaction::new_account( &mint_keypair, - alice.pubkey(), + &alice.pubkey(), 1, genesis_block.hash(), 0, @@ -1264,20 +1264,20 @@ mod tests { // try executing an interleaved transfer twice assert_eq!( - bank.transfer(1, &mint_keypair, bob.pubkey(), genesis_block.hash()), + bank.transfer(1, &mint_keypair, &bob.pubkey(), genesis_block.hash()), Err(BankError::AccountInUse) ); // the second time should fail as well // this verifies that `unlock_accounts` doesn't unlock `AccountInUse` accounts assert_eq!( - bank.transfer(1, &mint_keypair, bob.pubkey(), genesis_block.hash()), + bank.transfer(1, &mint_keypair, &bob.pubkey(), genesis_block.hash()), Err(BankError::AccountInUse) ); bank.unlock_accounts(&pay_alice, &results_alice); assert!(bank - .transfer(2, &mint_keypair, bob.pubkey(), genesis_block.hash()) + .transfer(2, &mint_keypair, &bob.pubkey(), genesis_block.hash()) .is_ok()); } @@ -1342,10 +1342,10 @@ mod tests { let key1 = Keypair::new(); let bank = Bank::new(&genesis_block); - bank.transfer(1, &mint_keypair, key1.pubkey(), genesis_block.hash()) + bank.transfer(1, &mint_keypair, &key1.pubkey(), genesis_block.hash()) .unwrap(); assert_eq!(bank.get_balance(&key1.pubkey()), 1); - let tx = SystemTransaction::new_move(&key1, key1.pubkey(), 1, genesis_block.hash(), 0); + let tx = SystemTransaction::new_move(&key1, &key1.pubkey(), 1, genesis_block.hash(), 0); let res = bank.process_transactions(&vec![tx.clone()]); assert_eq!(res.len(), 1); assert_eq!(bank.get_balance(&key1.pubkey()), 1); @@ -1353,7 +1353,7 @@ mod tests { } fn new_from_parent(parent: &Arc) -> Bank { - Bank::new_from_parent(parent, Pubkey::default(), parent.slot() + 1) + Bank::new_from_parent(parent, &Pubkey::default(), parent.slot() + 1) } /// Verify that the parent's vector is computed correctly @@ -1374,7 +1374,7 @@ mod tests { let parent = Arc::new(Bank::new(&genesis_block)); let tx = - SystemTransaction::new_move(&mint_keypair, key1.pubkey(), 1, genesis_block.hash(), 0); + SystemTransaction::new_move(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0); assert_eq!(parent.process_transaction(&tx), Ok(())); let bank = new_from_parent(&parent); assert_eq!( @@ -1392,10 +1392,10 @@ mod tests { let parent = Arc::new(Bank::new(&genesis_block)); let tx = - SystemTransaction::new_move(&mint_keypair, key1.pubkey(), 1, genesis_block.hash(), 0); + SystemTransaction::new_move(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0); assert_eq!(parent.process_transaction(&tx), Ok(())); let bank = new_from_parent(&parent); - let tx = SystemTransaction::new_move(&key1, key2.pubkey(), 1, genesis_block.hash(), 0); + let tx = SystemTransaction::new_move(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0); assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(parent.get_signature_status(&tx.signatures[0]), None); } @@ -1410,11 +1410,11 @@ mod tests { let pubkey = Keypair::new().pubkey(); bank0 - .transfer(1_000, &mint_keypair, pubkey, bank0.last_blockhash()) + .transfer(1_000, &mint_keypair, &pubkey, bank0.last_blockhash()) .unwrap(); assert_ne!(bank0.hash_internal_state(), initial_state); bank1 - .transfer(1_000, &mint_keypair, pubkey, bank1.last_blockhash()) + .transfer(1_000, &mint_keypair, &pubkey, bank1.last_blockhash()) .unwrap(); assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state()); @@ -1434,7 +1434,7 @@ mod tests { fn test_bank_hash_internal_state_squash() { let collector_id = Pubkey::default(); let bank0 = Arc::new(Bank::new(&GenesisBlock::new(10).0)); - let bank1 = Bank::new_from_parent(&bank0, collector_id, 1); + let bank1 = Bank::new_from_parent(&bank0, &collector_id, 1); // no delta in bank1, hashes match assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state()); @@ -1456,14 +1456,14 @@ mod tests { let parent = Arc::new(Bank::new(&genesis_block)); let tx_move_mint_to_1 = - SystemTransaction::new_move(&mint_keypair, key1.pubkey(), 1, genesis_block.hash(), 0); + SystemTransaction::new_move(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0); assert_eq!(parent.process_transaction(&tx_move_mint_to_1), Ok(())); assert_eq!(parent.transaction_count(), 1); let bank = new_from_parent(&parent); assert_eq!(bank.transaction_count(), parent.transaction_count()); let tx_move_1_to_2 = - SystemTransaction::new_move(&key1, key2.pubkey(), 1, genesis_block.hash(), 0); + SystemTransaction::new_move(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0); assert_eq!(bank.process_transaction(&tx_move_1_to_2), Ok(())); assert_eq!(bank.transaction_count(), 2); assert_eq!(parent.transaction_count(), 1); @@ -1502,7 +1502,7 @@ mod tests { let key1 = Keypair::new(); parent - .transfer(1, &mint_keypair, key1.pubkey(), genesis_block.hash()) + .transfer(1, &mint_keypair, &key1.pubkey(), genesis_block.hash()) .unwrap(); assert_eq!(parent.get_balance(&key1.pubkey()), 1); let bank = new_from_parent(&parent); @@ -1514,7 +1514,7 @@ mod tests { fn test_bank_epoch_vote_accounts() { let leader_id = Keypair::new().pubkey(); let leader_lamports = 3; - let (mut genesis_block, _) = GenesisBlock::new_with_leader(5, leader_id, leader_lamports); + let (mut genesis_block, _) = GenesisBlock::new_with_leader(5, &leader_id, leader_lamports); // set this up weird, forces future generation, odd mod(), etc. // this says: "stakes for slot X should be generated at slot index 3 in slot X-2... @@ -1557,7 +1557,7 @@ mod tests { // child crosses epoch boundary and is the first slot in the epoch let child = Bank::new_from_parent( &parent, - leader_id, + &leader_id, SLOTS_PER_EPOCH - (STAKERS_SLOT_OFFSET % SLOTS_PER_EPOCH), ); @@ -1566,7 +1566,7 @@ mod tests { // child crosses epoch boundary but isn't the first slot in the epoch let child = Bank::new_from_parent( &parent, - leader_id, + &leader_id, SLOTS_PER_EPOCH - (STAKERS_SLOT_OFFSET % SLOTS_PER_EPOCH) + 1, ); assert!(child.epoch_vote_accounts(i).is_some()); @@ -1584,7 +1584,7 @@ mod tests { let mut tx = Transaction::new_unsigned( &mint_keypair.pubkey(), &[key.pubkey()], - system_program::id(), + &system_program::id(), &move_lamports, bank.last_blockhash(), 2, diff --git a/runtime/src/loader_utils.rs b/runtime/src/loader_utils.rs index 71c21cbc9a..b60488fe2d 100644 --- a/runtime/src/loader_utils.rs +++ b/runtime/src/loader_utils.rs @@ -4,12 +4,12 @@ use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; use solana_sdk::system_transaction::SystemTransaction; -pub fn load_program(bank: &Bank, from: &Keypair, loader_id: Pubkey, program: Vec) -> Pubkey { +pub fn load_program(bank: &Bank, from: &Keypair, loader_id: &Pubkey, program: Vec) -> Pubkey { let program_account = Keypair::new(); let tx = SystemTransaction::new_program_account( from, - program_account.pubkey(), + &program_account.pubkey(), bank.last_blockhash(), 1, program.len() as u64, diff --git a/runtime/src/runtime.rs b/runtime/src/runtime.rs index fc9deecad3..e8b3f7bb35 100644 --- a/runtime/src/runtime.rs +++ b/runtime/src/runtime.rs @@ -8,7 +8,7 @@ use solana_sdk::transaction::Transaction; /// Reasons the runtime might have rejected a transaction. #[derive(Debug, PartialEq, Eq, Clone)] pub enum RuntimeError { - /// Executing the instruction at the given index produced an error. + /// Executing the instruction at the give&n index produced an error. ProgramError(u8, ProgramError), } @@ -199,7 +199,7 @@ where F: Fn(&Pubkey, &mut [KeyedAccount], &[u8]) -> Result<(), E>, { for _ in tx_accounts.len()..tx.account_keys.len() { - tx_accounts.push(Account::new(0, 0, system_program::id())); + tx_accounts.push(Account::new(0, 0, &system_program::id())); } for (i, ix) in tx.instructions.iter().enumerate() { let mut ix_accounts = get_subset_unchecked_mut(tx_accounts, &ix.accounts); @@ -262,7 +262,7 @@ mod tests { #[test] fn test_verify_instruction_change_program_id() { - fn change_program_id(ix: Pubkey, pre: Pubkey, post: Pubkey) -> Result<(), ProgramError> { + fn change_program_id(ix: &Pubkey, pre: &Pubkey, post: &Pubkey) -> Result<(), ProgramError> { verify_instruction(&ix, &pre, 0, &[], &Account::new(0, 0, post)) } @@ -271,12 +271,12 @@ mod tests { let mallory_program_id = Keypair::new().pubkey(); assert_eq!( - change_program_id(system_program_id, system_program_id, alice_program_id), + change_program_id(&system_program_id, &system_program_id, &alice_program_id), Ok(()), "system program should be able to change the account owner" ); assert_eq!( - change_program_id(mallory_program_id, system_program_id, alice_program_id), + change_program_id(&mallory_program_id, &system_program_id, &alice_program_id), Err(ProgramError::ModifiedProgramId), "malicious Mallory should not be able to change the account owner" ); @@ -284,9 +284,9 @@ mod tests { #[test] fn test_verify_instruction_change_userdata() { - fn change_userdata(program_id: Pubkey) -> Result<(), ProgramError> { + fn change_userdata(program_id: &Pubkey) -> Result<(), ProgramError> { let alice_program_id = Keypair::new().pubkey(); - let account = Account::new(0, 0, alice_program_id); + let account = Account::new(0, 0, &alice_program_id); verify_instruction(&program_id, &alice_program_id, 0, &[42], &account) } @@ -294,12 +294,12 @@ mod tests { let mallory_program_id = Keypair::new().pubkey(); assert_eq!( - change_userdata(system_program_id), + change_userdata(&system_program_id), Ok(()), "system program should be able to change the userdata" ); assert_eq!( - change_userdata(mallory_program_id), + change_userdata(&mallory_program_id), Err(ProgramError::ExternalAccountUserdataModified), "malicious Mallory should not be able to change the account userdata" ); diff --git a/sdk/src/account.rs b/sdk/src/account.rs index 5c20a1aea4..674922bd07 100644 --- a/sdk/src/account.rs +++ b/sdk/src/account.rs @@ -40,11 +40,11 @@ impl fmt::Debug for Account { impl Account { // TODO do we want to add executable and leader_owner even though they should always be false/default? - pub fn new(lamports: u64, space: usize, owner: Pubkey) -> Account { + pub fn new(lamports: u64, space: usize, owner: &Pubkey) -> Account { Account { lamports, userdata: vec![0u8; space], - owner, + owner: *owner, executable: false, } } diff --git a/sdk/src/genesis_block.rs b/sdk/src/genesis_block.rs index 54594bb3f4..4dde4e3b27 100644 --- a/sdk/src/genesis_block.rs +++ b/sdk/src/genesis_block.rs @@ -32,19 +32,23 @@ impl GenesisBlock { let lamports = lamports .checked_add(BOOTSTRAP_LEADER_LAMPORTS) .unwrap_or(lamports); - Self::new_with_leader(lamports, Keypair::new().pubkey(), BOOTSTRAP_LEADER_LAMPORTS) + Self::new_with_leader( + lamports, + &Keypair::new().pubkey(), + BOOTSTRAP_LEADER_LAMPORTS, + ) } pub fn new_with_leader( lamports: u64, - bootstrap_leader_id: Pubkey, + bootstrap_leader_id: &Pubkey, bootstrap_leader_lamports: u64, ) -> (Self, Keypair) { let mint_keypair = Keypair::new(); let bootstrap_leader_vote_account_keypair = Keypair::new(); ( Self { - bootstrap_leader_id, + bootstrap_leader_id: *bootstrap_leader_id, bootstrap_leader_lamports, bootstrap_leader_vote_account_id: bootstrap_leader_vote_account_keypair.pubkey(), mint_id: mint_keypair.pubkey(), @@ -97,7 +101,7 @@ mod tests { fn test_genesis_block_new_with_leader() { let leader_keypair = Keypair::new(); let (genesis_block, mint) = - GenesisBlock::new_with_leader(20_000, leader_keypair.pubkey(), 123); + GenesisBlock::new_with_leader(20_000, &leader_keypair.pubkey(), 123); assert_eq!(genesis_block.lamports, 20_000); assert_eq!(genesis_block.mint_id, mint.pubkey()); diff --git a/sdk/src/loader_transaction.rs b/sdk/src/loader_transaction.rs index fe9f2d2f2c..7ca8f9e9f8 100644 --- a/sdk/src/loader_transaction.rs +++ b/sdk/src/loader_transaction.rs @@ -11,7 +11,7 @@ pub struct LoaderTransaction {} impl LoaderTransaction { pub fn new_write( from_keypair: &Keypair, - loader: Pubkey, + loader: &Pubkey, offset: u32, bytes: Vec, recent_blockhash: Hash, @@ -30,7 +30,7 @@ impl LoaderTransaction { pub fn new_finalize( from_keypair: &Keypair, - loader: Pubkey, + loader: &Pubkey, recent_blockhash: Hash, fee: u64, ) -> Transaction { diff --git a/sdk/src/system_instruction.rs b/sdk/src/system_instruction.rs index 25676cc08a..47aa686578 100644 --- a/sdk/src/system_instruction.rs +++ b/sdk/src/system_instruction.rs @@ -26,28 +26,28 @@ pub enum SystemInstruction { impl SystemInstruction { pub fn new_program_account( - from_id: Pubkey, - to_id: Pubkey, + from_id: &Pubkey, + to_id: &Pubkey, lamports: u64, space: u64, - program_id: Pubkey, + program_id: &Pubkey, ) -> BuilderInstruction { BuilderInstruction::new( system_program::id(), &SystemInstruction::CreateAccount { lamports, space, - program_id, + program_id: *program_id, }, - vec![(from_id, true), (to_id, false)], + vec![(*from_id, true), (*to_id, false)], ) } - pub fn new_move(from_id: Pubkey, to_id: Pubkey, lamports: u64) -> BuilderInstruction { + pub fn new_move(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> BuilderInstruction { BuilderInstruction::new( system_program::id(), &SystemInstruction::Move { lamports }, - vec![(from_id, true), (to_id, false)], + vec![(*from_id, true), (*to_id, false)], ) } } diff --git a/sdk/src/system_transaction.rs b/sdk/src/system_transaction.rs index d9d488a3c4..3d71298a28 100644 --- a/sdk/src/system_transaction.rs +++ b/sdk/src/system_transaction.rs @@ -13,22 +13,22 @@ impl SystemTransaction { /// Create and sign new SystemInstruction::CreateAccount transaction pub fn new_program_account( from_keypair: &Keypair, - to: Pubkey, + to: &Pubkey, recent_blockhash: Hash, lamports: u64, space: u64, - program_id: Pubkey, + program_id: &Pubkey, fee: u64, ) -> Transaction { let create = SystemInstruction::CreateAccount { lamports, //TODO, the lamports to allocate might need to be higher then 0 in the future space, - program_id, + program_id: *program_id, }; Transaction::new( from_keypair, - &[to], - system_program::id(), + &[*to], + &system_program::id(), &create, recent_blockhash, fee, @@ -38,7 +38,7 @@ impl SystemTransaction { /// Create and sign a transaction to create a system account pub fn new_account( from_keypair: &Keypair, - to: Pubkey, + to: &Pubkey, lamports: u64, recent_blockhash: Hash, fee: u64, @@ -50,7 +50,7 @@ impl SystemTransaction { recent_blockhash, lamports, 0, - program_id, + &program_id, fee, ) } @@ -58,14 +58,16 @@ impl SystemTransaction { pub fn new_assign( from_keypair: &Keypair, recent_blockhash: Hash, - program_id: Pubkey, + program_id: &Pubkey, fee: u64, ) -> Transaction { - let assign = SystemInstruction::Assign { program_id }; + let assign = SystemInstruction::Assign { + program_id: *program_id, + }; Transaction::new( from_keypair, &[], - system_program::id(), + &system_program::id(), &assign, recent_blockhash, fee, @@ -74,7 +76,7 @@ impl SystemTransaction { /// Create and sign new SystemInstruction::Move transaction pub fn new_move( from_keypair: &Keypair, - to: Pubkey, + to: &Pubkey, lamports: u64, recent_blockhash: Hash, fee: u64, @@ -82,8 +84,8 @@ impl SystemTransaction { let move_lamports = SystemInstruction::Move { lamports }; Transaction::new( from_keypair, - &[to], - system_program::id(), + &[*to], + &system_program::id(), &move_lamports, recent_blockhash, fee, diff --git a/sdk/src/transaction.rs b/sdk/src/transaction.rs index 2bcb45226b..7391b773c5 100644 --- a/sdk/src/transaction.rs +++ b/sdk/src/transaction.rs @@ -99,12 +99,12 @@ impl Transaction { pub fn new( from_keypair: &T, transaction_keys: &[Pubkey], - program_id: Pubkey, + program_id: &Pubkey, userdata: &S, recent_blockhash: Hash, fee: u64, ) -> Self { - let program_ids = vec![program_id]; + let program_ids = vec![*program_id]; let accounts = (0..=transaction_keys.len() as u8).collect(); let instructions = vec![Instruction::new(0, userdata, accounts)]; Self::new_with_instructions( @@ -119,12 +119,12 @@ impl Transaction { pub fn new_unsigned( from_pubkey: &Pubkey, transaction_keys: &[Pubkey], - program_id: Pubkey, + program_id: &Pubkey, userdata: &T, recent_blockhash: Hash, fee: u64, ) -> Self { - let program_ids = vec![program_id]; + let program_ids = vec![*program_id]; let accounts = (0..=transaction_keys.len() as u8).collect(); let instructions = vec![Instruction::new(0, userdata, accounts)]; let mut keys = vec![*from_pubkey]; @@ -492,7 +492,7 @@ mod tests { let tx = Transaction::new( &keypair, &[keypair.pubkey(), to], - program_id, + &program_id, &(1u8, 2u8, 3u8), Hash::default(), 99, @@ -511,7 +511,7 @@ mod tests { let tx = Transaction::new( &keypair, &[keypair.pubkey(), to], - program_id, + &program_id, &(1u8, 2u8, 3u8), Hash::default(), 99, @@ -557,7 +557,7 @@ mod tests { let tx = Transaction::new( &keypair, &[keypair.pubkey(), to], - program_id, + &program_id, &(1u8, 2u8, 3u8), Hash::default(), 99, diff --git a/sdk/src/transaction_builder.rs b/sdk/src/transaction_builder.rs index d345051711..d0273a52c9 100644 --- a/sdk/src/transaction_builder.rs +++ b/sdk/src/transaction_builder.rs @@ -8,8 +8,8 @@ use itertools::Itertools; pub type BuilderInstruction = Instruction; -fn position(keys: &[Pubkey], key: Pubkey) -> u8 { - keys.iter().position(|&k| k == key).unwrap() as u8 +fn position(keys: &[Pubkey], key: &Pubkey) -> u8 { + keys.iter().position(|k| k == key).unwrap() as u8 } fn compile_instruction( @@ -17,13 +17,9 @@ fn compile_instruction( keys: &[Pubkey], program_ids: &[Pubkey], ) -> Instruction { - let accounts: Vec<_> = ix - .accounts - .iter() - .map(|&(k, _)| position(keys, k)) - .collect(); + let accounts: Vec<_> = ix.accounts.iter().map(|(k, _)| position(keys, k)).collect(); Instruction { - program_ids_index: position(program_ids, ix.program_ids_index), + program_ids_index: position(program_ids, &ix.program_ids_index), userdata: ix.userdata.clone(), accounts, } diff --git a/tests/cluster_info.rs b/tests/cluster_info.rs index 4d8e7ffee3..d0ade249a7 100644 --- a/tests/cluster_info.rs +++ b/tests/cluster_info.rs @@ -36,7 +36,7 @@ fn run_simulation(num_nodes: u64, fanout: usize, hood_size: usize) { let timeout = 60 * 5; // describe the leader - let leader_info = ContactInfo::new_localhost(Keypair::new().pubkey(), 0); + let leader_info = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0); let mut cluster_info = ClusterInfo::new_with_invalid_keypair(leader_info.clone()); // setup stakes @@ -59,7 +59,7 @@ fn run_simulation(num_nodes: u64, fanout: usize, hood_size: usize) { chunk.into_iter().for_each(|i| { //distribute neighbors across threads to maximize parallel compute let batch_ix = *i as usize % batches.len(); - let node = ContactInfo::new_localhost(Keypair::new().pubkey(), 0); + let node = ContactInfo::new_localhost(&Keypair::new().pubkey(), 0); stakes.insert(node.id, *i); cluster_info.insert_info(node.clone()); let (s, r) = channel(); @@ -103,7 +103,7 @@ fn run_simulation(num_nodes: u64, fanout: usize, hood_size: usize) { while remaining > 0 { for (id, (recv, r)) in batch.iter_mut() { assert!(now.elapsed().as_secs() < timeout, "Timed out"); - cluster.gossip.set_self(*id); + cluster.gossip.set_self(&*id); if !mapped_peers.contains_key(id) { let (neighbors, children) = compute_retransmit_peers( &stakes, diff --git a/tests/crds_gossip.rs b/tests/crds_gossip.rs index 2071d32737..ba8d495b34 100644 --- a/tests/crds_gossip.rs +++ b/tests/crds_gossip.rs @@ -17,42 +17,42 @@ use std::sync::{Arc, Mutex}; type Node = Arc>; type Network = HashMap; fn star_network_create(num: usize) -> Network { - let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let mut network: HashMap<_, _> = (1..num) .map(|_| { let new = - CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let id = new.label().pubkey(); let mut node = CrdsGossip::default(); node.crds.insert(new.clone(), 0).unwrap(); node.crds.insert(entry.clone(), 0).unwrap(); - node.set_self(id); + node.set_self(&id); (new.label().pubkey(), Arc::new(Mutex::new(node))) }) .collect(); let mut node = CrdsGossip::default(); let id = entry.label().pubkey(); node.crds.insert(entry.clone(), 0).unwrap(); - node.set_self(id); + node.set_self(&id); network.insert(id, Arc::new(Mutex::new(node))); network } fn rstar_network_create(num: usize) -> Network { - let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + let entry = CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let mut origin = CrdsGossip::default(); let id = entry.label().pubkey(); origin.crds.insert(entry.clone(), 0).unwrap(); - origin.set_self(id); + origin.set_self(&id); let mut network: HashMap<_, _> = (1..num) .map(|_| { let new = - CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let id = new.label().pubkey(); let mut node = CrdsGossip::default(); node.crds.insert(new.clone(), 0).unwrap(); origin.crds.insert(new.clone(), 0).unwrap(); - node.set_self(id); + node.set_self(&id); (new.label().pubkey(), Arc::new(Mutex::new(node))) }) .collect(); @@ -64,11 +64,11 @@ fn ring_network_create(num: usize) -> Network { let mut network: HashMap<_, _> = (0..num) .map(|_| { let new = - CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)); + CrdsValue::ContactInfo(ContactInfo::new_localhost(&Keypair::new().pubkey(), 0)); let id = new.label().pubkey(); let mut node = CrdsGossip::default(); node.crds.insert(new.clone(), 0).unwrap(); - node.set_self(id); + node.set_self(&id); (new.label().pubkey(), Arc::new(Mutex::new(node))) }) .collect(); @@ -195,7 +195,7 @@ fn network_run_push(network: &mut Network, start: usize, end: usize) -> (usize, let mut node = node.lock().unwrap(); let destination = node.id; let now = timestamp(); - node.process_prune_msg(*to, destination, &rsps, now, now) + node.process_prune_msg(&*to, &destination, &rsps, now, now) .unwrap() }) .unwrap(); @@ -283,8 +283,8 @@ fn network_run_pull( network.get(&from).map(|node| { node.lock() .unwrap() - .mark_pull_request_creation_time(from, now); - overhead += node.lock().unwrap().process_pull_response(from, rsp, now); + .mark_pull_request_creation_time(&from, now); + overhead += node.lock().unwrap().process_pull_response(&from, rsp, now); }); (bytes, msgs, overhead) }) @@ -374,7 +374,7 @@ fn test_prune_errors() { let mut crds_gossip = CrdsGossip::default(); crds_gossip.id = Pubkey::new(&[0; 32]); let id = crds_gossip.id; - let ci = ContactInfo::new_localhost(Pubkey::new(&[1; 32]), 0); + let ci = ContactInfo::new_localhost(&Pubkey::new(&[1; 32]), 0); let prune_pubkey = Pubkey::new(&[2; 32]); crds_gossip .crds @@ -384,18 +384,18 @@ fn test_prune_errors() { let now = timestamp(); //incorrect dest let mut res = crds_gossip.process_prune_msg( - ci.id, - Pubkey::new(hash(&[1; 32]).as_ref()), + &ci.id, + &Pubkey::new(hash(&[1; 32]).as_ref()), &[prune_pubkey], now, now, ); assert_eq!(res.err(), Some(CrdsGossipError::BadPruneDestination)); //correct dest - res = crds_gossip.process_prune_msg(ci.id, id, &[prune_pubkey], now, now); + res = crds_gossip.process_prune_msg(&ci.id, &id, &[prune_pubkey], now, now); res.unwrap(); //test timeout let timeout = now + crds_gossip.push.prune_timeout * 2; - res = crds_gossip.process_prune_msg(ci.id, id, &[prune_pubkey], now, timeout); + res = crds_gossip.process_prune_msg(&ci.id, &id, &[prune_pubkey], now, timeout); assert_eq!(res.err(), Some(CrdsGossipError::PruneMessageTimeout)); } diff --git a/tests/gossip.rs b/tests/gossip.rs index 156107f2be..59feef39bb 100644 --- a/tests/gossip.rs +++ b/tests/gossip.rs @@ -18,7 +18,7 @@ use std::time::Duration; fn test_node(exit: &Arc) -> (Arc>, GossipService, UdpSocket) { let keypair = Arc::new(Keypair::new()); - let mut test_node = Node::new_localhost_with_pubkey(keypair.pubkey()); + let mut test_node = Node::new_localhost_with_pubkey(&keypair.pubkey()); let cluster_info = Arc::new(RwLock::new(ClusterInfo::new( test_node.info.clone(), keypair, @@ -76,7 +76,7 @@ fn gossip_ring() -> result::Result<()> { let x = (n + 1) % listen.len(); let mut xv = listen[x].0.write().unwrap(); let yv = listen[y].0.read().unwrap(); - let mut d = yv.lookup(yv.id()).unwrap().clone(); + let mut d = yv.lookup(&yv.id()).unwrap().clone(); d.wallclock = timestamp(); xv.insert_info(d); } @@ -97,7 +97,7 @@ fn gossip_ring_large() -> result::Result<()> { let x = (n + 1) % listen.len(); let mut xv = listen[x].0.write().unwrap(); let yv = listen[y].0.read().unwrap(); - let mut d = yv.lookup(yv.id()).unwrap().clone(); + let mut d = yv.lookup(&yv.id()).unwrap().clone(); d.wallclock = timestamp(); xv.insert_info(d); } @@ -116,7 +116,7 @@ fn gossip_star() { let y = (n + 1) % listen.len(); let mut xv = listen[x].0.write().unwrap(); let yv = listen[y].0.read().unwrap(); - let mut yd = yv.lookup(yv.id()).unwrap().clone(); + let mut yd = yv.lookup(&yv.id()).unwrap().clone(); yd.wallclock = timestamp(); xv.insert_info(yd); trace!("star leader {}", &xv.id()); @@ -132,7 +132,7 @@ fn gossip_rstar() { let num = listen.len(); let xd = { let xv = listen[0].0.read().unwrap(); - xv.lookup(xv.id()).unwrap().clone() + xv.lookup(&xv.id()).unwrap().clone() }; trace!("rstar leader {}", xd.id); for n in 0..(num - 1) { diff --git a/tests/replicator.rs b/tests/replicator.rs index 23a133ce30..d9446e6031 100644 --- a/tests/replicator.rs +++ b/tests/replicator.rs @@ -39,11 +39,11 @@ fn test_replicator_startup_basic() { info!("starting leader node"); let leader_keypair = Arc::new(Keypair::new()); - let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey()); + let leader_node = Node::new_localhost_with_pubkey(&leader_keypair.pubkey()); let leader_info = leader_node.info.clone(); let (genesis_block, mint_keypair) = - GenesisBlock::new_with_leader(1_000_000_000, leader_info.id, 42); + GenesisBlock::new_with_leader(1_000_000_000, &leader_info.id, 42); let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block); let validator_ledger_path = tmp_copy_blocktree!(&leader_ledger_path); @@ -57,7 +57,7 @@ fn test_replicator_startup_basic() { leader_node, &leader_keypair, &leader_ledger_path, - voting_keypair.pubkey(), + &voting_keypair.pubkey(), voting_keypair, None, &fullnode_config, @@ -74,10 +74,10 @@ fn test_replicator_startup_basic() { debug!("blockhash: {:?}", blockhash); leader_client - .transfer(10, &mint_keypair, validator_keypair.pubkey(), &blockhash) + .transfer(10, &mint_keypair, &validator_keypair.pubkey(), &blockhash) .unwrap(); - let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey()); + let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey()); #[cfg(feature = "chacha")] let validator_contact_info = validator_node.info.clone(); @@ -85,7 +85,7 @@ fn test_replicator_startup_basic() { validator_node, &validator_keypair, &validator_ledger_path, - voting_keypair.pubkey(), + &voting_keypair.pubkey(), voting_keypair, Some(&leader_info), &fullnode_config, @@ -98,7 +98,7 @@ fn test_replicator_startup_basic() { debug!("transfer {}", i); let blockhash = leader_client.get_recent_blockhash(); let mut transaction = - SystemTransaction::new_account(&mint_keypair, bob.pubkey(), 1, blockhash, 0); + SystemTransaction::new_account(&mint_keypair, &bob.pubkey(), 1, blockhash, 0); leader_client .retry_transfer(&mint_keypair, &mut transaction, 5) .unwrap(); @@ -118,7 +118,7 @@ fn test_replicator_startup_basic() { // Give the replicator some lamports let mut tx = SystemTransaction::new_account( &mint_keypair, - replicator_keypair.pubkey(), + &replicator_keypair.pubkey(), 1, blockhash, 0, @@ -128,7 +128,7 @@ fn test_replicator_startup_basic() { .unwrap(); info!("starting replicator node"); - let replicator_node = Node::new_localhost_with_pubkey(replicator_keypair.pubkey()); + let replicator_node = Node::new_localhost_with_pubkey(&replicator_keypair.pubkey()); let replicator_info = replicator_node.info.clone(); let leader_info = ContactInfo::new_gossip_entry_point(&leader_info.gossip); @@ -242,7 +242,7 @@ fn test_replicator_startup_leader_hang() { let replicator_keypair = Arc::new(Keypair::new()); info!("starting replicator node"); - let replicator_node = Node::new_localhost_with_pubkey(replicator_keypair.pubkey()); + let replicator_node = Node::new_localhost_with_pubkey(&replicator_keypair.pubkey()); let fake_gossip = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0); let leader_info = ContactInfo::new_gossip_entry_point(&fake_gossip); @@ -272,11 +272,11 @@ fn test_replicator_startup_ledger_hang() { let leader_keypair = Arc::new(Keypair::new()); let (genesis_block, _mint_keypair) = - GenesisBlock::new_with_leader(100, leader_keypair.pubkey(), 42); + GenesisBlock::new_with_leader(100, &leader_keypair.pubkey(), 42); let (replicator_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block); info!("starting leader node"); - let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey()); + let leader_node = Node::new_localhost_with_pubkey(&leader_keypair.pubkey()); let leader_info = leader_node.info.clone(); let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block); @@ -290,7 +290,7 @@ fn test_replicator_startup_ledger_hang() { leader_node, &leader_keypair, &leader_ledger_path, - voting_keypair.pubkey(), + &voting_keypair.pubkey(), voting_keypair, None, &fullnode_config, @@ -298,13 +298,13 @@ fn test_replicator_startup_ledger_hang() { let validator_keypair = Arc::new(Keypair::new()); let voting_keypair = Keypair::new(); - let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey()); + let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey()); let _ = Fullnode::new( validator_node, &validator_keypair, &validator_ledger_path, - voting_keypair.pubkey(), + &voting_keypair.pubkey(), voting_keypair, Some(&leader_info), &FullnodeConfig::default(), @@ -312,7 +312,7 @@ fn test_replicator_startup_ledger_hang() { info!("starting replicator node"); let bad_keys = Arc::new(Keypair::new()); - let mut replicator_node = Node::new_localhost_with_pubkey(bad_keys.pubkey()); + let mut replicator_node = Node::new_localhost_with_pubkey(&bad_keys.pubkey()); // Pass bad TVU sockets to prevent successful ledger download replicator_node.sockets.tvu = vec![std::net::UdpSocket::bind("0.0.0.0:0").unwrap()]; diff --git a/tests/rpc.rs b/tests/rpc.rs index c0a0b77259..ac798ceb9e 100644 --- a/tests/rpc.rs +++ b/tests/rpc.rs @@ -41,7 +41,7 @@ fn test_rpc_send_tx() { let blockhash = Hash::new(&blockhash_vec); info!("blockhash: {:?}", blockhash); - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, blockhash, 0); + let tx = SystemTransaction::new_move(&alice, &bob_pubkey, 20, blockhash, 0); let serial_tx = serialize(&tx).unwrap(); let client = reqwest::Client::new(); diff --git a/tests/tvu.rs b/tests/tvu.rs index dd9d721655..2aa8a742e8 100644 --- a/tests/tvu.rs +++ b/tests/tvu.rs @@ -42,7 +42,7 @@ fn test_replay() { solana_logger::setup(); let leader = Node::new_localhost(); let target1_keypair = Keypair::new(); - let target1 = Node::new_localhost_with_pubkey(target1_keypair.pubkey()); + let target1 = Node::new_localhost_with_pubkey(&target1_keypair.pubkey()); let target2 = Node::new_localhost(); let exit = Arc::new(AtomicBool::new(false)); @@ -109,7 +109,7 @@ fn test_replay() { let (poh_service_exit, poh_recorder, poh_service, _entry_receiver) = create_test_recorder(&bank); let tvu = Tvu::new( - voting_keypair.pubkey(), + &voting_keypair.pubkey(), Some(Arc::new(voting_keypair)), &Arc::new(RwLock::new(bank_forks)), &bank_forks_info, @@ -144,7 +144,7 @@ fn test_replay() { let tx0 = SystemTransaction::new_account( &mint_keypair, - bob_keypair.pubkey(), + &bob_keypair.pubkey(), transfer_amount, blockhash, 0, diff --git a/vote-signer/src/rpc.rs b/vote-signer/src/rpc.rs index 5c6bbb4773..4523bc2ca2 100644 --- a/vote-signer/src/rpc.rs +++ b/vote-signer/src/rpc.rs @@ -85,7 +85,7 @@ impl VoteSignerRpc for VoteSignerRpcImpl { signed_msg: Vec, ) -> Result { info!("register rpc request received: {:?}", id); - meta.request_processor.register(id, &sig, &signed_msg) + meta.request_processor.register(&id, &sig, &signed_msg) } fn sign( @@ -96,7 +96,7 @@ impl VoteSignerRpc for VoteSignerRpcImpl { signed_msg: Vec, ) -> Result { info!("sign rpc request received: {:?}", id); - meta.request_processor.sign(id, &sig, &signed_msg) + meta.request_processor.sign(&id, &sig, &signed_msg) } fn deregister( @@ -107,7 +107,7 @@ impl VoteSignerRpc for VoteSignerRpcImpl { signed_msg: Vec, ) -> Result<()> { info!("deregister rpc request received: {:?}", id); - meta.request_processor.deregister(id, &sig, &signed_msg) + meta.request_processor.deregister(&id, &sig, &signed_msg) } } @@ -120,9 +120,9 @@ fn verify_signature(sig: &Signature, pubkey: &Pubkey, msg: &[u8]) -> Result<()> } pub trait VoteSigner { - fn register(&self, pubkey: Pubkey, sig: &Signature, signed_msg: &[u8]) -> Result; - fn sign(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> Result; - fn deregister(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> Result<()>; + fn register(&self, pubkey: &Pubkey, sig: &Signature, signed_msg: &[u8]) -> Result; + fn sign(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> Result; + fn deregister(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> Result<()>; } #[derive(Clone)] @@ -131,7 +131,7 @@ pub struct LocalVoteSigner { } impl VoteSigner for LocalVoteSigner { /// Process JSON-RPC request items sent via JSON-RPC. - fn register(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> Result { + fn register(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> Result { verify_signature(&sig, &pubkey, &msg)?; { if let Some(voting_keypair) = self.nodes.read().unwrap().get(&pubkey) { @@ -140,17 +140,17 @@ impl VoteSigner for LocalVoteSigner { } let voting_keypair = Keypair::new(); let voting_pubkey = voting_keypair.pubkey(); - self.nodes.write().unwrap().insert(pubkey, voting_keypair); + self.nodes.write().unwrap().insert(*pubkey, voting_keypair); Ok(voting_pubkey) } - fn sign(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> Result { + fn sign(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> Result { verify_signature(&sig, &pubkey, &msg)?; match self.nodes.read().unwrap().get(&pubkey) { Some(voting_keypair) => Ok(voting_keypair.sign_message(&msg)), None => Err(Error::invalid_request()), } } - fn deregister(&self, pubkey: Pubkey, sig: &Signature, msg: &[u8]) -> Result<()> { + fn deregister(&self, pubkey: &Pubkey, sig: &Signature, msg: &[u8]) -> Result<()> { verify_signature(&sig, &pubkey, &msg)?; self.nodes.write().unwrap().remove(&pubkey); Ok(()) diff --git a/wallet/src/main.rs b/wallet/src/main.rs index 3aeb0dd6a9..07f278e310 100644 --- a/wallet/src/main.rs +++ b/wallet/src/main.rs @@ -61,7 +61,7 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result, ) -> Result> { let response = match matches.subcommand() { @@ -231,7 +231,7 @@ pub fn parse_command( } Pubkey::new(&pubkey_vec) } else { - pubkey + *pubkey }; let timestamp = if pay_matches.is_present("timestamp") { // Parse input for serde_json @@ -280,7 +280,7 @@ pub fn parse_command( None }; let cancelable = if pay_matches.is_present("cancelable") { - Some(pubkey) + Some(*pubkey) } else { None }; @@ -376,7 +376,7 @@ fn process_airdrop( "Requesting airdrop of {:?} lamports from {}", lamports, drone_addr ); - let previous_balance = match rpc_client.retry_get_balance(1, config.id.pubkey(), 5)? { + let previous_balance = match rpc_client.retry_get_balance(1, &config.id.pubkey(), 5)? { Some(lamports) => lamports, None => Err(WalletError::RpcRequestError( "Received result of an unexpected type".to_string(), @@ -386,7 +386,7 @@ fn process_airdrop( request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, lamports)?; let current_balance = rpc_client - .retry_get_balance(1, config.id.pubkey(), 5)? + .retry_get_balance(1, &config.id.pubkey(), 5)? .unwrap_or(previous_balance); if current_balance < previous_balance { @@ -406,7 +406,7 @@ fn process_airdrop( } fn process_balance(config: &WalletConfig, rpc_client: &RpcClient) -> ProcessResult { - let balance = rpc_client.retry_get_balance(1, config.id.pubkey(), 5)?; + let balance = rpc_client.retry_get_balance(1, &config.id.pubkey(), 5)?; match balance { Some(0) => Ok("No account found! Request an airdrop to get started.".to_string()), Some(lamports) => Ok(format!("Your balance is: {:?}", lamports)), @@ -445,14 +445,14 @@ fn process_configure_staking( let mut tx = TransactionBuilder::new(0); if let Some(delegate_id) = delegate_option { tx.push(VoteInstruction::new_delegate_stake( - config.id.pubkey(), - delegate_id, + &config.id.pubkey(), + &delegate_id, )); } if let Some(authorized_voter_id) = authorized_voter_option { tx.push(VoteInstruction::new_authorize_voter( - config.id.pubkey(), - authorized_voter_id, + &config.id.pubkey(), + &authorized_voter_id, )); } let mut tx = tx.sign(&[&config.id], recent_blockhash); @@ -463,7 +463,7 @@ fn process_configure_staking( fn process_create_staking( rpc_client: &RpcClient, config: &WalletConfig, - voting_account_id: Pubkey, + voting_account_id: &Pubkey, lamports: u64, ) -> ProcessResult { let recent_blockhash = get_recent_blockhash(&rpc_client)?; @@ -478,7 +478,7 @@ fn process_deploy( config: &WalletConfig, program_location: &str, ) -> ProcessResult { - let balance = rpc_client.retry_get_balance(1, config.id.pubkey(), 5)?; + let balance = rpc_client.retry_get_balance(1, &config.id.pubkey(), 5)?; if let Some(lamports) = balance { if lamports < 1 { Err(WalletError::DynamicProgramError( @@ -503,11 +503,11 @@ fn process_deploy( let mut tx = SystemTransaction::new_program_account( &config.id, - program_id.pubkey(), + &program_id.pubkey(), blockhash, 1, program_userdata.len() as u64, - bpf_loader::id(), + &bpf_loader::id(), 0, ); trace!("Creating program account"); @@ -522,7 +522,7 @@ fn process_deploy( .map(|(chunk, i)| { LoaderTransaction::new_write( &program_id, - bpf_loader::id(), + &bpf_loader::id(), (i * USERDATA_CHUNK_SIZE) as u32, chunk.to_vec(), blockhash, @@ -533,7 +533,7 @@ fn process_deploy( send_and_confirm_transactions(&rpc_client, write_transactions, &program_id)?; trace!("Finalizing program account"); - let mut tx = LoaderTransaction::new_finalize(&program_id, bpf_loader::id(), blockhash, 0); + let mut tx = LoaderTransaction::new_finalize(&program_id, &bpf_loader::id(), blockhash, 0); send_and_confirm_transaction(&rpc_client, &mut tx, &program_id).map_err(|_| { WalletError::DynamicProgramError("Program finalize transaction failed".to_string()) })?; @@ -548,7 +548,7 @@ fn process_pay( rpc_client: &RpcClient, config: &WalletConfig, lamports: u64, - to: Pubkey, + to: &Pubkey, timestamp: Option>, timestamp_pubkey: Option, witnesses: &Option>, @@ -573,9 +573,9 @@ fn process_pay( let mut tx = BudgetTransaction::new_on_date( &config.id, to, - contract_state.pubkey(), + &contract_state.pubkey(), dt, - dt_pubkey, + &dt_pubkey, cancelable, lamports, blockhash, @@ -604,8 +604,8 @@ fn process_pay( let mut tx = BudgetTransaction::new_when_signed( &config.id, to, - contract_state.pubkey(), - witness, + &contract_state.pubkey(), + &witness, cancelable, lamports, blockhash, @@ -622,10 +622,10 @@ fn process_pay( } } -fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: Pubkey) -> ProcessResult { +fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: &Pubkey) -> ProcessResult { let blockhash = get_recent_blockhash(&rpc_client)?; let mut tx = - BudgetTransaction::new_signature(&config.id, pubkey, config.id.pubkey(), blockhash); + BudgetTransaction::new_signature(&config.id, pubkey, &config.id.pubkey(), blockhash); let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?; Ok(signature_str.to_string()) } @@ -646,11 +646,11 @@ fn process_time_elapsed( rpc_client: &RpcClient, config: &WalletConfig, drone_addr: SocketAddr, - to: Pubkey, - pubkey: Pubkey, + to: &Pubkey, + pubkey: &Pubkey, dt: DateTime, ) -> ProcessResult { - let balance = rpc_client.retry_get_balance(1, config.id.pubkey(), 5)?; + let balance = rpc_client.retry_get_balance(1, &config.id.pubkey(), 5)?; if let Some(0) = balance { request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?; @@ -668,10 +668,10 @@ fn process_witness( rpc_client: &RpcClient, config: &WalletConfig, drone_addr: SocketAddr, - to: Pubkey, - pubkey: Pubkey, + to: &Pubkey, + pubkey: &Pubkey, ) -> ProcessResult { - let balance = rpc_client.retry_get_balance(1, config.id.pubkey(), 5)?; + let balance = rpc_client.retry_get_balance(1, &config.id.pubkey(), 5)?; if let Some(0) = balance { request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?; @@ -712,7 +712,7 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult { WalletCommand::Balance => process_balance(config, &rpc_client), // Cancel a contract by contract Pubkey - WalletCommand::Cancel(pubkey) => process_cancel(&rpc_client, config, pubkey), + WalletCommand::Cancel(pubkey) => process_cancel(&rpc_client, config, &pubkey), // Confirm the last client transaction by signature WalletCommand::Confirm(signature) => process_confirm(&rpc_client, signature), @@ -729,7 +729,7 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult { // Create staking account WalletCommand::CreateStakingAccount(voting_account_id, lamports) => { - process_create_staking(&rpc_client, config, voting_account_id, lamports) + process_create_staking(&rpc_client, config, &voting_account_id, lamports) } // Deploy a custom program to the chain @@ -751,7 +751,7 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult { &rpc_client, config, lamports, - to, + &to, timestamp, timestamp_pubkey, witnesses, @@ -760,12 +760,12 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult { // Apply time elapsed to contract WalletCommand::TimeElapsed(to, pubkey, dt) => { - process_time_elapsed(&rpc_client, config, drone_addr, to, pubkey, dt) + process_time_elapsed(&rpc_client, config, drone_addr, &to, &pubkey, dt) } // Apply witness signature to contract WalletCommand::Witness(to, pubkey) => { - process_witness(&rpc_client, config, drone_addr, to, pubkey) + process_witness(&rpc_client, config, drone_addr, &to, &pubkey) } } } @@ -1241,13 +1241,13 @@ mod tests { .clone() .get_matches_from(vec!["test", "airdrop", "50"]); assert_eq!( - parse_command(pubkey, &test_airdrop).unwrap(), + parse_command(&pubkey, &test_airdrop).unwrap(), WalletCommand::Airdrop(50) ); let test_bad_airdrop = test_commands .clone() .get_matches_from(vec!["test", "airdrop", "notint"]); - assert!(parse_command(pubkey, &test_bad_airdrop).is_err()); + assert!(parse_command(&pubkey, &test_bad_airdrop).is_err()); // Test Cancel Subcommand let test_cancel = @@ -1255,7 +1255,7 @@ mod tests { .clone() .get_matches_from(vec!["test", "cancel", &pubkey_string]); assert_eq!( - parse_command(pubkey, &test_cancel).unwrap(), + parse_command(&pubkey, &test_cancel).unwrap(), WalletCommand::Cancel(pubkey) ); @@ -1267,13 +1267,13 @@ mod tests { .clone() .get_matches_from(vec!["test", "confirm", &signature_string]); assert_eq!( - parse_command(pubkey, &test_confirm).unwrap(), + parse_command(&pubkey, &test_confirm).unwrap(), WalletCommand::Confirm(signature) ); let test_bad_signature = test_commands .clone() .get_matches_from(vec!["test", "confirm", "deadbeef"]); - assert!(parse_command(pubkey, &test_bad_signature).is_err()); + assert!(parse_command(&pubkey, &test_bad_signature).is_err()); // Test ConfigureStakingAccount Subcommand let second_pubkey = Keypair::new().pubkey(); @@ -1287,7 +1287,7 @@ mod tests { &second_pubkey_string, ]); assert_eq!( - parse_command(pubkey, &test_configure_staking_account).unwrap(), + parse_command(&pubkey, &test_configure_staking_account).unwrap(), WalletCommand::ConfigureStakingAccount(Some(pubkey), Some(second_pubkey)) ); let test_configure_staking_account = test_commands.clone().get_matches_from(vec![ @@ -1297,7 +1297,7 @@ mod tests { &pubkey_string, ]); assert_eq!( - parse_command(pubkey, &test_configure_staking_account).unwrap(), + parse_command(&pubkey, &test_configure_staking_account).unwrap(), WalletCommand::ConfigureStakingAccount(Some(pubkey), None) ); @@ -1309,7 +1309,7 @@ mod tests { "50", ]); assert_eq!( - parse_command(pubkey, &test_create_staking_account).unwrap(), + parse_command(&pubkey, &test_create_staking_account).unwrap(), WalletCommand::CreateStakingAccount(pubkey, 50) ); let test_bad_pubkey = test_commands.clone().get_matches_from(vec![ @@ -1318,7 +1318,7 @@ mod tests { "deadbeef", "50", ]); - assert!(parse_command(pubkey, &test_bad_pubkey).is_err()); + assert!(parse_command(&pubkey, &test_bad_pubkey).is_err()); // Test Deploy Subcommand let test_deploy = @@ -1326,7 +1326,7 @@ mod tests { .clone() .get_matches_from(vec!["test", "deploy", "/Users/test/program.o"]); assert_eq!( - parse_command(pubkey, &test_deploy).unwrap(), + parse_command(&pubkey, &test_deploy).unwrap(), WalletCommand::Deploy("/Users/test/program.o".to_string()) ); @@ -1336,13 +1336,13 @@ mod tests { .clone() .get_matches_from(vec!["test", "pay", &pubkey_string, "50"]); assert_eq!( - parse_command(pubkey, &test_pay).unwrap(), + parse_command(&pubkey, &test_pay).unwrap(), WalletCommand::Pay(50, pubkey, None, None, None, None) ); let test_bad_pubkey = test_commands .clone() .get_matches_from(vec!["test", "pay", "deadbeef", "50"]); - assert!(parse_command(pubkey, &test_bad_pubkey).is_err()); + assert!(parse_command(&pubkey, &test_bad_pubkey).is_err()); // Test Pay Subcommand w/ Witness let test_pay_multiple_witnesses = test_commands.clone().get_matches_from(vec![ @@ -1356,7 +1356,7 @@ mod tests { &witness1_string, ]); assert_eq!( - parse_command(pubkey, &test_pay_multiple_witnesses).unwrap(), + parse_command(&pubkey, &test_pay_multiple_witnesses).unwrap(), WalletCommand::Pay(50, pubkey, None, None, Some(vec![witness0, witness1]), None) ); let test_pay_single_witness = test_commands.clone().get_matches_from(vec![ @@ -1368,7 +1368,7 @@ mod tests { &witness0_string, ]); assert_eq!( - parse_command(pubkey, &test_pay_single_witness).unwrap(), + parse_command(&pubkey, &test_pay_single_witness).unwrap(), WalletCommand::Pay(50, pubkey, None, None, Some(vec![witness0]), None) ); @@ -1384,7 +1384,7 @@ mod tests { &witness0_string, ]); assert_eq!( - parse_command(pubkey, &test_pay_timestamp).unwrap(), + parse_command(&pubkey, &test_pay_timestamp).unwrap(), WalletCommand::Pay(50, pubkey, Some(dt), Some(witness0), None, None) ); @@ -1396,7 +1396,7 @@ mod tests { &pubkey_string, ]); assert_eq!( - parse_command(pubkey, &test_send_signature).unwrap(), + parse_command(&pubkey, &test_send_signature).unwrap(), WalletCommand::Witness(pubkey, pubkey) ); let test_pay_multiple_witnesses = test_commands.clone().get_matches_from(vec![ @@ -1414,7 +1414,7 @@ mod tests { &witness1_string, ]); assert_eq!( - parse_command(pubkey, &test_pay_multiple_witnesses).unwrap(), + parse_command(&pubkey, &test_pay_multiple_witnesses).unwrap(), WalletCommand::Pay( 50, pubkey, @@ -1435,7 +1435,7 @@ mod tests { "2018-09-19T17:30:59", ]); assert_eq!( - parse_command(pubkey, &test_send_timestamp).unwrap(), + parse_command(&pubkey, &test_send_timestamp).unwrap(), WalletCommand::TimeElapsed(pubkey, pubkey, dt) ); let test_bad_timestamp = test_commands.clone().get_matches_from(vec![ @@ -1446,7 +1446,7 @@ mod tests { "--date", "20180919T17:30:59", ]); - assert!(parse_command(pubkey, &test_bad_timestamp).is_err()); + assert!(parse_command(&pubkey, &test_bad_timestamp).is_err()); } #[test] @@ -1688,7 +1688,7 @@ mod tests { let key = Keypair::new(); let to = Keypair::new().pubkey(); let blockhash = Hash::default(); - let tx = SystemTransaction::new_account(&key, to, 50, blockhash, 0); + let tx = SystemTransaction::new_account(&key, &to, 50, blockhash, 0); let signature = send_transaction(&rpc_client, &tx); assert_eq!(signature.unwrap(), SIGNATURE.to_string()); @@ -1724,7 +1724,7 @@ mod tests { let key = Keypair::new(); let to = Keypair::new().pubkey(); let blockhash = Hash::default(); - let mut tx = SystemTransaction::new_account(&key, to, 50, blockhash, 0); + let mut tx = SystemTransaction::new_account(&key, &to, 50, blockhash, 0); let signer = Keypair::new(); @@ -1750,8 +1750,8 @@ mod tests { .into_vec() .unwrap(); let blockhash = Hash::new(&vec); - let prev_tx = SystemTransaction::new_account(&key, to, 50, blockhash, 0); - let mut tx = SystemTransaction::new_account(&key, to, 50, blockhash, 0); + let prev_tx = SystemTransaction::new_account(&key, &to, 50, blockhash, 0); + let mut tx = SystemTransaction::new_account(&key, &to, 50, blockhash, 0); resign_transaction(&rpc_client, &mut tx, &key).unwrap(); diff --git a/wallet/tests/pay.rs b/wallet/tests/pay.rs index 55402dd82e..1f72fb1d2f 100644 --- a/wallet/tests/pay.rs +++ b/wallet/tests/pay.rs @@ -13,7 +13,7 @@ use std::sync::mpsc::channel; #[cfg(test)] use solana::thin_client::new_fullnode; -fn check_balance(expected_balance: u64, client: &RpcClient, pubkey: Pubkey) { +fn check_balance(expected_balance: u64, client: &RpcClient, pubkey: &Pubkey) { let balance = client.retry_get_balance(1, pubkey, 1).unwrap().unwrap(); assert_eq!(balance, expected_balance); } @@ -40,7 +40,7 @@ fn test_wallet_timestamp_tx() { assert_ne!(config_payer.id.pubkey(), config_witness.id.pubkey()); request_and_confirm_airdrop(&rpc_client, &drone_addr, &config_payer.id, 50).unwrap(); - check_balance(50, &rpc_client, config_payer.id.pubkey()); + check_balance(50, &rpc_client, &config_payer.id.pubkey()); // Make transaction (from config_payer to bob_pubkey) requiring timestamp from config_witness let date_string = "\"2018-09-19T17:30:59Z\""; @@ -62,17 +62,17 @@ fn test_wallet_timestamp_tx() { .expect("base58-encoded public key"); let process_id = Pubkey::new(&process_id_vec); - check_balance(40, &rpc_client, config_payer.id.pubkey()); // config_payer balance - check_balance(10, &rpc_client, process_id); // contract balance - check_balance(0, &rpc_client, bob_pubkey); // recipient balance + check_balance(40, &rpc_client, &config_payer.id.pubkey()); // config_payer balance + check_balance(10, &rpc_client, &process_id); // contract balance + check_balance(0, &rpc_client, &bob_pubkey); // recipient balance // Sign transaction by config_witness config_witness.command = WalletCommand::TimeElapsed(bob_pubkey, process_id, dt); process_command(&config_witness).unwrap(); - check_balance(40, &rpc_client, config_payer.id.pubkey()); // config_payer balance - check_balance(0, &rpc_client, process_id); // contract balance - check_balance(10, &rpc_client, bob_pubkey); // recipient balance + check_balance(40, &rpc_client, &config_payer.id.pubkey()); // config_payer balance + check_balance(0, &rpc_client, &process_id); // contract balance + check_balance(10, &rpc_client, &bob_pubkey); // recipient balance server.close().unwrap(); remove_dir_all(ledger_path).unwrap(); @@ -119,17 +119,17 @@ fn test_wallet_witness_tx() { .expect("base58-encoded public key"); let process_id = Pubkey::new(&process_id_vec); - check_balance(40, &rpc_client, config_payer.id.pubkey()); // config_payer balance - check_balance(10, &rpc_client, process_id); // contract balance - check_balance(0, &rpc_client, bob_pubkey); // recipient balance + check_balance(40, &rpc_client, &config_payer.id.pubkey()); // config_payer balance + check_balance(10, &rpc_client, &process_id); // contract balance + check_balance(0, &rpc_client, &bob_pubkey); // recipient balance // Sign transaction by config_witness config_witness.command = WalletCommand::Witness(bob_pubkey, process_id); process_command(&config_witness).unwrap(); - check_balance(40, &rpc_client, config_payer.id.pubkey()); // config_payer balance - check_balance(0, &rpc_client, process_id); // contract balance - check_balance(10, &rpc_client, bob_pubkey); // recipient balance + check_balance(40, &rpc_client, &config_payer.id.pubkey()); // config_payer balance + check_balance(0, &rpc_client, &process_id); // contract balance + check_balance(10, &rpc_client, &bob_pubkey); // recipient balance server.close().unwrap(); remove_dir_all(ledger_path).unwrap(); @@ -176,17 +176,17 @@ fn test_wallet_cancel_tx() { .expect("base58-encoded public key"); let process_id = Pubkey::new(&process_id_vec); - check_balance(40, &rpc_client, config_payer.id.pubkey()); // config_payer balance - check_balance(10, &rpc_client, process_id); // contract balance - check_balance(0, &rpc_client, bob_pubkey); // recipient balance + check_balance(40, &rpc_client, &config_payer.id.pubkey()); // config_payer balance + check_balance(10, &rpc_client, &process_id); // contract balance + check_balance(0, &rpc_client, &bob_pubkey); // recipient balance // Sign transaction by config_witness config_payer.command = WalletCommand::Cancel(process_id); process_command(&config_payer).unwrap(); - check_balance(50, &rpc_client, config_payer.id.pubkey()); // config_payer balance - check_balance(0, &rpc_client, process_id); // contract balance - check_balance(0, &rpc_client, bob_pubkey); // recipient balance + check_balance(50, &rpc_client, &config_payer.id.pubkey()); // config_payer balance + check_balance(0, &rpc_client, &process_id); // contract balance + check_balance(0, &rpc_client, &bob_pubkey); // recipient balance server.close().unwrap(); remove_dir_all(ledger_path).unwrap(); diff --git a/wallet/tests/request_airdrop.rs b/wallet/tests/request_airdrop.rs index 28da6e7939..2c3153a5f1 100644 --- a/wallet/tests/request_airdrop.rs +++ b/wallet/tests/request_airdrop.rs @@ -24,7 +24,7 @@ fn test_wallet_request_airdrop() { let rpc_client = RpcClient::new_from_socket(leader_data.rpc); let balance = rpc_client - .retry_get_balance(1, bob_config.id.pubkey(), 1) + .retry_get_balance(1, &bob_config.id.pubkey(), 1) .unwrap() .unwrap(); assert_eq!(balance, 50);