Skip to content

Commit

Permalink
removes CrdsValue::new_unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadnouri committed Nov 7, 2024
1 parent 72a4ab0 commit 3bb154c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
9 changes: 5 additions & 4 deletions gossip/src/crds_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,18 @@ 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,
}
}

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.
Expand Down
16 changes: 8 additions & 8 deletions gossip/tests/crds_gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
)
Expand Down
3 changes: 2 additions & 1 deletion turbine/src/cluster_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,12 @@ pub fn make_test_cluster<R: Rng>(
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(())
Expand Down

0 comments on commit 3bb154c

Please sign in to comment.