reduce pub

This commit is contained in:
Michael Vines
2019-03-11 14:42:24 -07:00
parent f8e07ef5a3
commit 3073ebb20d

View File

@ -168,6 +168,7 @@ impl ClusterInfo {
pub fn new_with_invalid_keypair(contact_info: ContactInfo) -> Self { pub fn new_with_invalid_keypair(contact_info: ContactInfo) -> Self {
Self::new(contact_info, Arc::new(Keypair::new())) Self::new(contact_info, Arc::new(Keypair::new()))
} }
pub fn new(contact_info: ContactInfo, keypair: Arc<Keypair>) -> Self { pub fn new(contact_info: ContactInfo, keypair: Arc<Keypair>) -> Self {
let mut me = Self { let mut me = Self {
gossip: CrdsGossip::default(), gossip: CrdsGossip::default(),
@ -181,6 +182,7 @@ impl ClusterInfo {
me.push_self(&HashMap::new()); me.push_self(&HashMap::new());
me me
} }
pub fn insert_self(&mut self, contact_info: ContactInfo) { pub fn insert_self(&mut self, contact_info: ContactInfo) {
if self.id() == contact_info.id { if self.id() == contact_info.id {
let mut value = CrdsValue::ContactInfo(contact_info.clone()); let mut value = CrdsValue::ContactInfo(contact_info.clone());
@ -188,7 +190,8 @@ impl ClusterInfo {
let _ = self.gossip.crds.insert(value, timestamp()); let _ = self.gossip.crds.insert(value, timestamp());
} }
} }
pub fn push_self(&mut self, stakes: &HashMap<Pubkey, u64>) {
fn push_self(&mut self, stakes: &HashMap<Pubkey, u64>) {
let mut my_data = self.my_data(); let mut my_data = self.my_data();
let now = timestamp(); let now = timestamp();
my_data.wallclock = now; my_data.wallclock = now;
@ -197,18 +200,22 @@ impl ClusterInfo {
self.gossip.refresh_push_active_set(stakes); self.gossip.refresh_push_active_set(stakes);
self.gossip.process_push_message(&[entry], now); self.gossip.process_push_message(&[entry], now);
} }
// TODO kill insert_info, only used by tests // TODO kill insert_info, only used by tests
pub fn insert_info(&mut self, contact_info: ContactInfo) { pub fn insert_info(&mut self, contact_info: ContactInfo) {
let mut value = CrdsValue::ContactInfo(contact_info); let mut value = CrdsValue::ContactInfo(contact_info);
value.sign(&self.keypair); value.sign(&self.keypair);
let _ = self.gossip.crds.insert(value, timestamp()); let _ = self.gossip.crds.insert(value, timestamp());
} }
pub fn set_entrypoint(&mut self, entrypoint: ContactInfo) { pub fn set_entrypoint(&mut self, entrypoint: ContactInfo) {
self.entrypoint = Some(entrypoint) self.entrypoint = Some(entrypoint)
} }
pub fn id(&self) -> Pubkey { pub fn id(&self) -> Pubkey {
self.gossip.id self.gossip.id
} }
pub fn lookup(&self, id: &Pubkey) -> Option<&ContactInfo> { pub fn lookup(&self, id: &Pubkey) -> Option<&ContactInfo> {
let entry = CrdsValueLabel::ContactInfo(*id); let entry = CrdsValueLabel::ContactInfo(*id);
self.gossip self.gossip
@ -216,22 +223,22 @@ impl ClusterInfo {
.lookup(&entry) .lookup(&entry)
.and_then(|x| x.contact_info()) .and_then(|x| x.contact_info())
} }
pub fn my_data(&self) -> ContactInfo { 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
}
// Deprecated: don't use leader_data(). // Deprecated: don't use leader_data().
pub fn leader_data(&self) -> Option<&ContactInfo> { pub fn leader_data(&self) -> Option<&ContactInfo> {
let leader_id = self.leader_id(); let leader_id = self.gossip_leader_id;
if leader_id == Pubkey::default() { if leader_id == Pubkey::default() {
return None; return None;
} }
self.lookup(&leader_id) self.lookup(&leader_id)
} }
pub fn contact_info_trace(&self) -> String { pub fn contact_info_trace(&self) -> String {
let leader_id = self.leader_id(); let leader_id = self.gossip_leader_id;
let nodes: Vec<_> = self let nodes: Vec<_> = self
.rpc_peers() .rpc_peers()
.into_iter() .into_iter()
@ -264,12 +271,11 @@ impl ClusterInfo {
) )
} }
/// Record the id of the current leader for use by `leader_tpu_via_blobs()`
pub fn set_leader(&mut self, leader_id: &Pubkey) { pub fn set_leader(&mut self, leader_id: &Pubkey) {
warn!( warn!(
"{}: LEADER_UPDATE TO {} from {}", "{}: LEADER_UPDATE TO {} from {}",
self.gossip.id, self.gossip.id, leader_id, self.gossip_leader_id,
leader_id,
self.leader_id()
); );
self.gossip_leader_id = *leader_id; self.gossip_leader_id = *leader_id;
} }
@ -364,7 +370,7 @@ impl ClusterInfo {
} }
/// all tvu peers with valid gossip addrs /// all tvu peers with valid gossip addrs
pub fn repair_peers(&self) -> Vec<ContactInfo> { fn repair_peers(&self) -> Vec<ContactInfo> {
let me = self.my_data().id; let me = self.my_data().id;
ClusterInfo::tvu_peers(self) ClusterInfo::tvu_peers(self)
.into_iter() .into_iter()
@ -392,7 +398,7 @@ impl ClusterInfo {
peers_with_stakes peers_with_stakes
} }
pub fn sorted_retransmit_peers<S: std::hash::BuildHasher>( fn sorted_retransmit_peers<S: std::hash::BuildHasher>(
&self, &self,
stakes: &HashMap<Pubkey, u64, S>, stakes: &HashMap<Pubkey, u64, S>,
) -> Vec<ContactInfo> { ) -> Vec<ContactInfo> {
@ -544,7 +550,7 @@ impl ClusterInfo {
/// Given a array of layer indices and another index, returns (as a `Locality`) the layer, /// Given a array of layer indices and another index, returns (as a `Locality`) the layer,
/// layer-bounds and neighborhood-bounds in which the index resides /// layer-bounds and neighborhood-bounds in which the index resides
pub fn localize(layer_indices: &[usize], hood_size: usize, select_index: usize) -> Locality { fn localize(layer_indices: &[usize], hood_size: usize, select_index: usize) -> Locality {
(0..layer_indices.len()) (0..layer_indices.len())
.find_map(|i| ClusterInfo::localize_item(layer_indices, hood_size, select_index, i)) .find_map(|i| ClusterInfo::localize_item(layer_indices, hood_size, select_index, i))
.or_else(|| Some(Locality::default())) .or_else(|| Some(Locality::default()))
@ -734,11 +740,7 @@ impl ClusterInfo {
Ok(out) Ok(out)
} }
pub fn window_highest_index_request_bytes( fn window_highest_index_request_bytes(&self, slot: u64, blob_index: u64) -> Result<Vec<u8>> {
&self,
slot: u64,
blob_index: u64,
) -> Result<Vec<u8>> {
let req = Protocol::RequestHighestWindowIndex(self.my_data().clone(), slot, blob_index); let req = Protocol::RequestHighestWindowIndex(self.my_data().clone(), slot, blob_index);
let out = serialize(&req)?; let out = serialize(&req)?;
Ok(out) Ok(out)