Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Remove CrdsValue::LeaderId #3209

Merged
merged 1 commit into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ mod tests {
use crate::test_tx::test_tx;
use solana_sdk::signature::{Keypair, KeypairUtil};
use std::collections::HashSet;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::net::{IpAddr, Ipv4Addr};
use std::sync::{Arc, RwLock};

#[test]
Expand Down
4 changes: 2 additions & 2 deletions core/src/contact_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ impl Eq for ContactInfo {}
#[macro_export]
macro_rules! socketaddr {
($ip:expr, $port:expr) => {
SocketAddr::from((Ipv4Addr::from($ip), $port))
std::net::SocketAddr::from((Ipv4Addr::from($ip), $port))
};
($str:expr) => {{
let a: SocketAddr = $str.parse().unwrap();
let a: std::net::SocketAddr = $str.parse().unwrap();
a
}};
}
Expand Down
69 changes: 35 additions & 34 deletions core/src/crds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,12 @@ impl Crds {
mod test {
use super::*;
use crate::contact_info::ContactInfo;
use crate::crds_value::LeaderId;
use solana_sdk::signature::{Keypair, KeypairUtil};

#[test]
fn test_insert() {
let mut crds = Crds::default();
let val = CrdsValue::LeaderId(LeaderId::default());
let val = CrdsValue::ContactInfo(ContactInfo::default());
assert_eq!(crds.insert(val.clone(), 0).ok(), Some(None));
assert_eq!(crds.table.len(), 1);
assert!(crds.table.contains_key(&val.label()));
Expand All @@ -180,27 +179,27 @@ mod test {
#[test]
fn test_update_old() {
let mut crds = Crds::default();
let val = CrdsValue::LeaderId(LeaderId::default());
let val = CrdsValue::ContactInfo(ContactInfo::default());
assert_eq!(crds.insert(val.clone(), 0), Ok(None));
assert_eq!(crds.insert(val.clone(), 1), Err(CrdsError::InsertFailed));
assert_eq!(crds.table[&val.label()].local_timestamp, 0);
}
#[test]
fn test_update_new() {
let mut crds = Crds::default();
let original = CrdsValue::LeaderId(LeaderId::default());
let original = CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 0));
assert_matches!(crds.insert(original.clone(), 0), Ok(_));
let val = CrdsValue::LeaderId(LeaderId::new(Pubkey::default(), Pubkey::default(), 1));
let val = CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 1));
assert_eq!(
crds.insert(val.clone(), 1).unwrap().unwrap().value,
original
);
assert_eq!(crds.table[&val.label()].local_timestamp, 1);
}
#[test]
fn test_update_timestsamp() {
fn test_update_timestamp() {
let mut crds = Crds::default();
let val = CrdsValue::LeaderId(LeaderId::default());
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);
Expand All @@ -209,7 +208,7 @@ mod test {

let val2 = CrdsValue::ContactInfo(ContactInfo::default());
assert_eq!(val2.label().pubkey(), val.label().pubkey());
assert_matches!(crds.insert(val2.clone(), 0), Ok(None));
assert_matches!(crds.insert(val2.clone(), 0), Ok(Some(_)));

crds.update_record_timestamp(val.label().pubkey(), 2);
assert_eq!(crds.table[&val.label()].local_timestamp, 2);
Expand All @@ -231,7 +230,7 @@ mod test {
#[test]
fn test_find_old_records() {
let mut crds = Crds::default();
let val = CrdsValue::LeaderId(LeaderId::default());
let val = CrdsValue::ContactInfo(ContactInfo::default());
assert_eq!(crds.insert(val.clone(), 1), Ok(None));

assert!(crds.find_old_labels(0).is_empty());
Expand All @@ -241,7 +240,7 @@ mod test {
#[test]
fn test_remove() {
let mut crds = Crds::default();
let val = CrdsValue::LeaderId(LeaderId::default());
let val = CrdsValue::ContactInfo(ContactInfo::default());
assert_matches!(crds.insert(val.clone(), 1), Ok(_));

assert_eq!(crds.find_old_labels(1), vec![val.label()]);
Expand All @@ -250,48 +249,50 @@ mod test {
}
#[test]
fn test_equal() {
let key = Keypair::new();
let v1 = VersionedCrdsValue::new(
1,
CrdsValue::LeaderId(LeaderId::new(key.pubkey(), Pubkey::default(), 0)),
);
let v2 = VersionedCrdsValue::new(
1,
CrdsValue::LeaderId(LeaderId::new(key.pubkey(), Pubkey::default(), 0)),
);
let val = CrdsValue::ContactInfo(ContactInfo::default());
let v1 = VersionedCrdsValue::new(1, val.clone());
let v2 = VersionedCrdsValue::new(1, val);
assert_eq!(v1, v2);
assert!(!(v1 != v2));
assert!(v1 == v2);
}
#[test]
fn test_hash_order() {
let key = Keypair::new();
let v1 = VersionedCrdsValue::new(
1,
CrdsValue::LeaderId(LeaderId::new(key.pubkey(), Pubkey::default(), 0)),
);
let v2 = VersionedCrdsValue::new(
1,
CrdsValue::LeaderId(LeaderId::new(key.pubkey(), key.pubkey(), 0)),
CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 0)),
);
let v2 = VersionedCrdsValue::new(1, {
let mut contact_info = ContactInfo::new_localhost(Pubkey::default(), 0);
contact_info.rpc = socketaddr!("0.0.0.0:0");
CrdsValue::ContactInfo(contact_info)
});

assert_eq!(v1.value.label(), v2.value.label());
assert_eq!(v1.value.wallclock(), v2.value.wallclock());
assert_ne!(v1.value_hash, v2.value_hash);
assert!(v1 != v2);
assert!(!(v1 == v2));
if v1 > v2 {
assert!(v2 < v1)
assert!(v1 > v2);
assert!(v2 < v1);
} else if v2 > v1 {
assert!(v1 < v2);
assert!(v2 > v1);
} else {
assert!(v2 > v1)
panic!("bad PartialOrd implementation?");
}
}
#[test]
fn test_wallclock_order() {
let key = Keypair::new();
let v1 = VersionedCrdsValue::new(
1,
CrdsValue::LeaderId(LeaderId::new(key.pubkey(), Pubkey::default(), 1)),
CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 1)),
);
let v2 = VersionedCrdsValue::new(
1,
CrdsValue::LeaderId(LeaderId::new(key.pubkey(), Pubkey::default(), 0)),
CrdsValue::ContactInfo(ContactInfo::new_localhost(Pubkey::default(), 0)),
);
assert_eq!(v1.value.label(), v2.value.label());
assert!(v1 > v2);
assert!(!(v1 < v2));
assert!(v1 != v2);
Expand All @@ -301,13 +302,13 @@ mod test {
fn test_label_order() {
let v1 = VersionedCrdsValue::new(
1,
CrdsValue::LeaderId(LeaderId::new(Keypair::new().pubkey(), Pubkey::default(), 0)),
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)),
);
let v2 = VersionedCrdsValue::new(
1,
CrdsValue::LeaderId(LeaderId::new(Keypair::new().pubkey(), Pubkey::default(), 0)),
CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0)),
);
assert!(v1 != v2);
assert_ne!(v1, v2);
assert!(!(v1 == v2));
assert!(!(v1 < v2));
assert!(!(v1 > v2));
Expand Down
10 changes: 6 additions & 4 deletions core/src/crds_gossip_pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ impl CrdsGossipPull {
mod test {
use super::*;
use crate::contact_info::ContactInfo;
use crate::crds_value::LeaderId;
use solana_sdk::signature::{Keypair, KeypairUtil};

#[test]
Expand Down Expand Up @@ -325,17 +324,20 @@ mod test {
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));
node_crds.insert(new.clone(), 0).unwrap();

let mut dest = CrdsGossipPull::default();
let mut dest_crds = Crds::default();
let new = CrdsValue::ContactInfo(ContactInfo::new_localhost(Keypair::new().pubkey(), 0));
let new_id = Keypair::new().pubkey();
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 dest_id = new.label().pubkey();
let same_key = CrdsValue::LeaderId(LeaderId::new(dest_id, dest_id, 1));
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();
assert_eq!(
node_crds
Expand Down
Loading