pass Pubkeys as refs, copy only where values needed (#3213)

* pass Pubkeys as refs, copy only where values needed

* Pubkey is pervasive

* fixup
This commit is contained in:
Rob Walker
2019-03-09 19:28:43 -08:00
committed by GitHub
parent ac226c3e14
commit 195a880576
89 changed files with 864 additions and 828 deletions

View File

@ -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]);
}

View File

@ -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,

View File

@ -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);

View File

@ -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);

View File

@ -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,

View File

@ -281,7 +281,7 @@ mod test {
}
fn setup_dummy_broadcast_service(
leader_pubkey: Pubkey,
leader_pubkey: &Pubkey,
ledger_path: &str,
entry_receiver: Receiver<WorkingBankEntries>,
) -> 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,
);

View File

@ -126,7 +126,7 @@ mod tests {
&mut num_hashes,
vec![SystemTransaction::new_account(
&keypair,
keypair.pubkey(),
&keypair.pubkey(),
1,
one,
0,

View File

@ -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<RwLock<Self>>, from: Pubkey, data: Vec<CrdsValue>) {
fn handle_pull_response(me: &Arc<RwLock<Self>>, from: &Pubkey, data: Vec<CrdsValue>) {
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<RwLock<Self>>,
from: Pubkey,
from: &Pubkey,
data: &[CrdsValue],
) -> Vec<SharedBlob> {
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()

View File

@ -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,

View File

@ -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());

View File

@ -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));

View File

@ -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<Pubkey> {
@ -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<Pubkey, u64>,
) -> Result<(Pubkey, Bloom<Hash>, 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<CrdsValue>,
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));
}
}

View File

@ -53,7 +53,7 @@ impl CrdsGossipPull {
pub fn new_pull_request(
&self,
crds: &Crds,
self_id: Pubkey,
self_id: &Pubkey,
now: u64,
stakes: &HashMap<Pubkey, u64>,
) -> Result<(Pubkey, Bloom<Hash>, 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<CrdsValue>,
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);

View File

@ -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<Pubkey, u64>,
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();

View File

@ -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);

View File

@ -400,8 +400,8 @@ pub fn make_tiny_test_entries_from_hash(start: &Hash, num: usize) -> Vec<Entry>
&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<Entry> {
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;

View File

@ -81,7 +81,7 @@ impl Fullnode {
mut node: Node,
keypair: &Arc<Keypair>,
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<Fullnode> = (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(),

View File

@ -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);

View File

@ -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;

View File

@ -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,
);

View File

@ -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);

View File

@ -53,8 +53,8 @@ pub struct ReplayStage {
impl ReplayStage {
#[allow(clippy::new_ret_no_self, clippy::too_many_arguments)]
pub fn new<T>(
my_id: Pubkey,
vote_account: Pubkey,
my_id: &Pubkey,
vote_account: &Pubkey,
voting_keypair: Option<Arc<T>>,
blocktree: Arc<Blocktree>,
bank_forks: &Arc<RwLock<BankForks>>,
@ -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<RwLock<BankForks>>,
poh_recorder: &Arc<Mutex<PohRecorder>>,
cluster_info: &Arc<RwLock<ClusterInfo>>,
@ -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");

View File

@ -70,13 +70,13 @@ impl JsonRpcRequestProcessor {
}
}
pub fn get_account_info(&self, pubkey: Pubkey) -> Result<Account> {
pub fn get_account_info(&self, pubkey: &Pubkey) -> Result<Account> {
self.bank()?
.get_account(&pubkey)
.ok_or_else(Error::invalid_request)
}
pub fn get_balance(&self, pubkey: Pubkey) -> Result<u64> {
pub fn get_balance(&self, pubkey: &Pubkey) -> Result<u64> {
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<u64> {
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<String> {
@ -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>, Meta, Hash, Keypair) {
fn start_rpc_handler_with_tx(pubkey: &Pubkey) -> (MetaIoHandler<Meta>, 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,

View File

@ -28,7 +28,7 @@ impl MockRpcClient {
pub fn retry_get_balance(
&self,
id: u64,
pubkey: Pubkey,
pubkey: &Pubkey,
retries: usize,
) -> Result<Option<u64>, Box<dyn error::Error>> {
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)
}

View File

@ -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();

View File

@ -39,7 +39,7 @@ impl RpcClient {
pub fn retry_get_balance(
&self,
id: u64,
pubkey: Pubkey,
pubkey: &Pubkey,
retries: usize,
) -> Result<Option<u64>, Box<dyn error::Error>> {
let params = json!([format!("{}", pubkey)]);

View File

@ -123,7 +123,7 @@ mod tests {
.request_processor
.read()
.unwrap()
.get_balance(alice.pubkey())
.get_balance(&alice.pubkey())
.unwrap()
);
exit.store(true, Ordering::Relaxed);

View File

@ -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();

View File

@ -146,7 +146,7 @@ mod tests {
use std::sync::Arc;
fn new_from_parent(parent: &Arc<Bank>, 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);

View File

@ -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<RwLock<ClusterInfo>> {
fn test_cluster_info(id: &Pubkey) -> Arc<RwLock<ClusterInfo>> {
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();

View File

@ -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)
}

View File

@ -119,7 +119,7 @@ impl ThinClient {
&self,
lamports: u64,
keypair: &Keypair,
to: Pubkey,
to: &Pubkey,
blockhash: &Hash,
) -> io::Result<Signature> {
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();

View File

@ -27,7 +27,7 @@ pub struct Tpu {
impl Tpu {
pub fn new(
id: Pubkey,
id: &Pubkey,
cluster_info: &Arc<RwLock<ClusterInfo>>,
poh_recorder: &Arc<Mutex<PohRecorder>>,
entry_receiver: Receiver<WorkingBankEntries>,

View File

@ -55,7 +55,7 @@ impl Tvu {
/// * `blocktree` - the ledger itself
#[allow(clippy::new_ret_no_self, clippy::too_many_arguments)]
pub fn new<T>(
vote_account: Pubkey,
vote_account: &Pubkey,
voting_keypair: Option<Arc<T>>,
bank_forks: &Arc<RwLock<BankForks>>,
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,

View File

@ -23,7 +23,7 @@ impl RemoteVoteSigner {
impl VoteSigner for RemoteVoteSigner {
fn register(
&self,
pubkey: Pubkey,
pubkey: &Pubkey,
sig: &Signature,
msg: &[u8],
) -> jsonrpc_core::Result<Pubkey> {
@ -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<Signature> {
fn sign(
&self,
pubkey: &Pubkey,
sig: &Signature,
msg: &[u8],
) -> jsonrpc_core::Result<Signature> {
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<T: KeypairUtil>(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();
}