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

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

View File

@@ -17,42 +17,42 @@ use std::sync::{Arc, Mutex};
type Node = Arc<Mutex<CrdsGossip>>;
type Network = HashMap<Pubkey, Node>;
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));
}

View File

@@ -18,7 +18,7 @@ use std::time::Duration;
fn test_node(exit: &Arc<AtomicBool>) -> (Arc<RwLock<ClusterInfo>>, 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) {

View File

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

View File

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

View File

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