diff --git a/gossip/src/crds_value.rs b/gossip/src/crds_value.rs index db5d610ce75fb0..908b73f3b44124 100644 --- a/gossip/src/crds_value.rs +++ b/gossip/src/crds_value.rs @@ -95,7 +95,8 @@ impl CrdsValueLabel { } impl CrdsValue { - pub fn new_unsigned(data: CrdsData) -> Self { + #[cfg(test)] + pub(crate) fn new_unsigned(data: CrdsData) -> Self { Self { signature: Signature::default(), data, @@ -103,9 +104,9 @@ impl CrdsValue { } pub fn new(data: CrdsData, keypair: &Keypair) -> Self { - let mut value = Self::new_unsigned(data); - value.sign(keypair); - value + let bincode_serialized_data = bincode::serialize(&data).unwrap(); + let signature = keypair.sign_message(&bincode_serialized_data); + Self { signature, data } } /// New random CrdsValue for tests and benchmarks. diff --git a/gossip/tests/crds_gossip.rs b/gossip/tests/crds_gossip.rs index 72b51313b0b007..22a93e22dee496 100644 --- a/gossip/tests/crds_gossip.rs +++ b/gossip/tests/crds_gossip.rs @@ -100,7 +100,7 @@ fn star_network_create(num: usize) -> Network { let gossip_port_offset = 9000; let node_keypair = Arc::new(Keypair::new()); let contact_info = ContactInfo::new_localhost(&node_keypair.pubkey(), 0); - let entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(contact_info.clone())); + let entry = CrdsValue::new(CrdsData::ContactInfo(contact_info.clone()), &node_keypair); let mut network: HashMap<_, _> = (1..num) .map(|k| { let node_keypair = Arc::new(Keypair::new()); @@ -111,7 +111,7 @@ fn star_network_create(num: usize) -> Network { contact_info .set_gossip((Ipv4Addr::LOCALHOST, gossip_port)) .unwrap(); - let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(contact_info.clone())); + let new = CrdsValue::new(CrdsData::ContactInfo(contact_info.clone()), &node_keypair); let node = CrdsGossip::default(); { let mut node_crds = node.crds.write().unwrap(); @@ -141,7 +141,7 @@ fn star_network_create(num: usize) -> Network { fn rstar_network_create(num: usize) -> Network { let node_keypair = Arc::new(Keypair::new()); let contact_info = ContactInfo::new_localhost(&node_keypair.pubkey(), 0); - let entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(contact_info.clone())); + let entry = CrdsValue::new(CrdsData::ContactInfo(contact_info.clone()), &node_keypair); let origin = CrdsGossip::default(); let id = entry.label().pubkey(); origin @@ -154,7 +154,7 @@ fn rstar_network_create(num: usize) -> Network { .map(|_| { let node_keypair = Arc::new(Keypair::new()); let contact_info = ContactInfo::new_localhost(&node_keypair.pubkey(), 0); - let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(contact_info.clone())); + let new = CrdsValue::new(CrdsData::ContactInfo(contact_info.clone()), &node_keypair); let node = CrdsGossip::default(); node.crds .write() @@ -181,7 +181,7 @@ fn ring_network_create(num: usize) -> Network { .map(|_| { let node_keypair = Arc::new(Keypair::new()); let contact_info = ContactInfo::new_localhost(&node_keypair.pubkey(), 0); - let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(contact_info.clone())); + let new = CrdsValue::new(CrdsData::ContactInfo(contact_info.clone()), &node_keypair); let node = CrdsGossip::default(); node.crds .write() @@ -216,7 +216,7 @@ fn connected_staked_network_create(stakes: &[u64]) -> Network { .map(|n| { let node_keypair = Arc::new(Keypair::new()); let contact_info = ContactInfo::new_localhost(&node_keypair.pubkey(), 0); - let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(contact_info.clone())); + let new = CrdsValue::new(CrdsData::ContactInfo(contact_info.clone()), &node_keypair); let node = CrdsGossip::default(); node.crds .write() @@ -318,7 +318,7 @@ fn network_simulator(thread_pool: &ThreadPool, network: &mut Network, max_conver node.gossip.process_push_message( vec![( Pubkey::default(), - vec![CrdsValue::new_unsigned(CrdsData::ContactInfo(m))], + vec![CrdsValue::new(CrdsData::ContactInfo(m), &Keypair::new())], )], now, ); @@ -761,7 +761,7 @@ fn test_prune_errors() { .write() .unwrap() .insert( - CrdsValue::new_unsigned(CrdsData::ContactInfo(ci.clone())), + CrdsValue::new(CrdsData::ContactInfo(ci.clone()), &Keypair::new()), 0, GossipRoute::LocalMessage, ) diff --git a/turbine/src/cluster_nodes.rs b/turbine/src/cluster_nodes.rs index d7dabbab4f4594..6f8aa6a1522aa5 100644 --- a/turbine/src/cluster_nodes.rs +++ b/turbine/src/cluster_nodes.rs @@ -554,11 +554,12 @@ pub fn make_test_cluster( let cluster_info = ClusterInfo::new(this_node, keypair, SocketAddrSpace::Unspecified); { let now = timestamp(); + let keypair = Keypair::new(); let mut gossip_crds = cluster_info.gossip.crds.write().unwrap(); // First node is pushed to crds table by ClusterInfo constructor. for node in nodes.iter().skip(1) { let node = CrdsData::ContactInfo(node.clone()); - let node = CrdsValue::new_unsigned(node); + let node = CrdsValue::new(node, &keypair); assert_eq!( gossip_crds.insert(node, now, GossipRoute::LocalMessage), Ok(())