From a88024e2952dedfe0c815993111f8dee545929e5 Mon Sep 17 00:00:00 2001 From: behzad nouri Date: Sat, 22 Apr 2023 20:18:39 +0000 Subject: [PATCH] removes wallclock from LegacyContactInfo public interface (#31303) --- core/src/cluster_nodes.rs | 4 ++-- core/src/validator.rs | 2 +- gossip/src/cluster_info.rs | 8 ++++---- gossip/src/crds.rs | 6 +++--- gossip/src/crds_gossip_push.rs | 18 +++++++++--------- gossip/src/crds_value.rs | 2 +- gossip/src/legacy_contact_info.rs | 11 ++++++++++- gossip/tests/crds_gossip.rs | 2 +- gossip/tests/gossip.rs | 6 +++--- 9 files changed, 34 insertions(+), 25 deletions(-) diff --git a/core/src/cluster_nodes.rs b/core/src/cluster_nodes.rs index 02e2d7032..99cc031dd 100644 --- a/core/src/cluster_nodes.rs +++ b/core/src/cluster_nodes.rs @@ -119,12 +119,12 @@ impl ClusterNodes { if node.stake != 0u64 { num_nodes_staked += 1; } - match node.contact_info() { + match node.contact_info().map(ContactInfo::wallclock) { None => { num_nodes_dead += 1; stake_dead += node.stake; } - Some(&ContactInfo { wallclock, .. }) => { + Some(wallclock) => { let age = now.saturating_sub(wallclock); if age > CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS { num_nodes_stale += 1; diff --git a/core/src/validator.rs b/core/src/validator.rs index 5d10d0fd6..194ff82b7 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -2100,7 +2100,7 @@ fn get_stake_percent_in_gossip(bank: &Bank, cluster_info: &ClusterInfo, log: boo .all_tvu_peers() .into_iter() .filter(|node| { - let age = now.saturating_sub(node.wallclock); + let age = now.saturating_sub(node.wallclock()); // Contact infos are refreshed twice during this period. age < CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS }) diff --git a/gossip/src/cluster_info.rs b/gossip/src/cluster_info.rs index 1b74532c6..4c27346db 100644 --- a/gossip/src/cluster_info.rs +++ b/gossip/src/cluster_info.rs @@ -1393,10 +1393,10 @@ impl ClusterInfo { }; if !pulls.is_empty() { let now = timestamp(); - if now <= entrypoint.wallclock.saturating_add(THROTTLE_DELAY) { + if now <= entrypoint.wallclock().saturating_add(THROTTLE_DELAY) { return; } - entrypoint.wallclock = now; + entrypoint.set_wallclock(now); if let Ok(entrypoint_gossip) = entrypoint.gossip() { if self .time_gossip_read_lock("entrypoint", &self.stats.entrypoint) @@ -4329,7 +4329,7 @@ RPC Enabled Nodes: 1"#; // Pull request 2: pretend it's been a while since we've pulled from `entrypoint`. There should // now be two pull requests - cluster_info.entrypoints.write().unwrap()[0].wallclock = 0; + cluster_info.entrypoints.write().unwrap()[0].set_wallclock(0); let (pings, pulls) = cluster_info.new_pull_requests(&thread_pool, None, &stakes); assert!(pings.is_empty()); assert_eq!(pulls.len(), 2 * MIN_NUM_BLOOM_FILTERS); @@ -4766,7 +4766,7 @@ RPC Enabled Nodes: 1"#; peers.push(keypair.pubkey()); let mut rand_ci = LegacyContactInfo::new_rand(&mut rng, Some(keypair.pubkey())); rand_ci.shred_version = shred_version; - rand_ci.wallclock = timestamp(); + rand_ci.set_wallclock(timestamp()); CrdsValue::new_signed(CrdsData::LegacyContactInfo(rand_ci), &keypair) }) .take(NO_ENTRIES) diff --git a/gossip/src/crds.rs b/gossip/src/crds.rs index 7e370e65e..bc76a90fb 100644 --- a/gossip/src/crds.rs +++ b/gossip/src/crds.rs @@ -1284,7 +1284,7 @@ mod tests { assert_eq!(crds.get_shred_version(&pubkey), None); // Initial insertion of a node with shred version: let mut node = ContactInfo::new_rand(&mut rng, Some(pubkey)); - let wallclock = node.wallclock; + let wallclock = node.wallclock(); node.shred_version = 42; let node = CrdsData::LegacyContactInfo(node); let node = CrdsValue::new_unsigned(node); @@ -1295,7 +1295,7 @@ mod tests { assert_eq!(crds.get_shred_version(&pubkey), Some(42)); // An outdated value should not update shred-version: let mut node = ContactInfo::new_rand(&mut rng, Some(pubkey)); - node.wallclock = wallclock - 1; // outdated. + node.set_wallclock(wallclock - 1); // outdated. node.shred_version = 8; let node = CrdsData::LegacyContactInfo(node); let node = CrdsValue::new_unsigned(node); @@ -1306,7 +1306,7 @@ mod tests { assert_eq!(crds.get_shred_version(&pubkey), Some(42)); // Update shred version: let mut node = ContactInfo::new_rand(&mut rng, Some(pubkey)); - node.wallclock = wallclock + 1; // so that it overrides the prev one. + node.set_wallclock(wallclock + 1); // so that it overrides the prev one. node.shred_version = 8; let node = CrdsData::LegacyContactInfo(node); let node = CrdsValue::new_unsigned(node); diff --git a/gossip/src/crds_gossip_push.rs b/gossip/src/crds_gossip_push.rs index cd772d576..692518c83 100644 --- a/gossip/src/crds_gossip_push.rs +++ b/gossip/src/crds_gossip_push.rs @@ -330,7 +330,7 @@ mod tests { let crds = RwLock::::default(); let push = CrdsGossipPush::default(); let mut ci = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0); - ci.wallclock = 1; + ci.set_wallclock(1); let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci.clone())); // push a new message @@ -340,7 +340,7 @@ mod tests { ); // push an old version - ci.wallclock = 0; + ci.set_wallclock(0); let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci)); assert!(push .process_push_message(&crds, vec![(Pubkey::default(), vec![value])], 0) @@ -354,14 +354,14 @@ mod tests { let mut ci = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0); // push a version to far in the future - ci.wallclock = timeout + 1; + ci.set_wallclock(timeout + 1); let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci.clone())); assert!(push .process_push_message(&crds, vec![(Pubkey::default(), vec![value])], 0) .is_empty()); // push a version to far in the past - ci.wallclock = 0; + ci.set_wallclock(0); let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci)); assert!(push .process_push_message(&crds, vec![(Pubkey::default(), vec![value])], timeout + 1) @@ -373,7 +373,7 @@ mod tests { let push = CrdsGossipPush::default(); let mut ci = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0); let origin = ci.id; - ci.wallclock = 0; + ci.set_wallclock(0); let value_old = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci.clone())); // push a new message @@ -383,7 +383,7 @@ mod tests { ); // push an old version - ci.wallclock = 1; + ci.set_wallclock(1); let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci)); assert_eq!( push.process_push_message(&crds, vec![(Pubkey::default(), vec![value])], 0), @@ -449,7 +449,7 @@ mod tests { .into_iter() .map(|wallclock| { let mut peer = ContactInfo::new_rand(&mut rng, /*pubkey=*/ None); - peer.wallclock = wallclock; + peer.set_wallclock(wallclock); ping_cache.mock_pong(peer.id, peer.gossip().unwrap(), Instant::now()); CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(peer)) }) @@ -575,7 +575,7 @@ mod tests { ); let mut ci = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0); - ci.wallclock = 1; + ci.set_wallclock(1); let new_msg = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci)); let expected = HashMap::new(); let origin = new_msg.pubkey(); @@ -600,7 +600,7 @@ mod tests { let crds = RwLock::::default(); let push = CrdsGossipPush::default(); let mut ci = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0); - ci.wallclock = 0; + ci.set_wallclock(0); let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci)); let label = value.label(); // push a new message diff --git a/gossip/src/crds_value.rs b/gossip/src/crds_value.rs index e910fda68..a0302dee7 100644 --- a/gossip/src/crds_value.rs +++ b/gossip/src/crds_value.rs @@ -582,7 +582,7 @@ impl CrdsValue { /// This is used to time out push messages. pub fn wallclock(&self) -> u64 { match &self.data { - CrdsData::LegacyContactInfo(contact_info) => contact_info.wallclock, + CrdsData::LegacyContactInfo(contact_info) => contact_info.wallclock(), CrdsData::Vote(_, vote) => vote.wallclock, CrdsData::LowestSlot(_, obj) => obj.wallclock, CrdsData::LegacySnapshotHashes(hash) => hash.wallclock, diff --git a/gossip/src/legacy_contact_info.rs b/gossip/src/legacy_contact_info.rs index 503b6ef83..35078cb1e 100644 --- a/gossip/src/legacy_contact_info.rs +++ b/gossip/src/legacy_contact_info.rs @@ -41,7 +41,7 @@ pub struct LegacyContactInfo { /// address to send repair requests to serve_repair: SocketAddr, /// latest wallclock picked - pub wallclock: u64, + wallclock: u64, /// node shred version pub shred_version: u16, } @@ -155,6 +155,15 @@ impl LegacyContactInfo { } } + #[inline] + pub fn wallclock(&self) -> u64 { + self.wallclock + } + + pub fn set_wallclock(&mut self, wallclock: u64) { + self.wallclock = wallclock; + } + get_socket!(gossip); get_socket!(tvu); get_socket!(tvu_forwards); diff --git a/gossip/tests/crds_gossip.rs b/gossip/tests/crds_gossip.rs index 8e0c3f108..e727f17b0 100644 --- a/gossip/tests/crds_gossip.rs +++ b/gossip/tests/crds_gossip.rs @@ -288,7 +288,7 @@ fn network_simulator(thread_pool: &ThreadPool, network: &mut Network, max_conver let node_crds = node.gossip.crds.read().unwrap(); node_crds.get::<&ContactInfo>(node_pubkey).cloned().unwrap() }; - m.wallclock = now; + m.set_wallclock(now); node.gossip.process_push_message( vec![( Pubkey::default(), diff --git a/gossip/tests/gossip.rs b/gossip/tests/gossip.rs index 65baeb51c..7589a2f18 100644 --- a/gossip/tests/gossip.rs +++ b/gossip/tests/gossip.rs @@ -162,7 +162,7 @@ fn gossip_ring() { let x = (n + 1) % listen.len(); let yv = &listen[y].0; let mut d = yv.lookup_contact_info(&yv.id(), |ci| ci.clone()).unwrap(); - d.wallclock = timestamp(); + d.set_wallclock(timestamp()); listen[x].0.insert_legacy_info(d); } }); @@ -180,7 +180,7 @@ fn gossip_ring_large() { let x = (n + 1) % listen.len(); let yv = &listen[y].0; let mut d = yv.lookup_contact_info(&yv.id(), |ci| ci.clone()).unwrap(); - d.wallclock = timestamp(); + d.set_wallclock(timestamp()); listen[x].0.insert_legacy_info(d); } }); @@ -196,7 +196,7 @@ fn gossip_star() { let y = (n + 1) % listen.len(); let yv = &listen[y].0; let mut yd = yv.lookup_contact_info(&yv.id(), |ci| ci.clone()).unwrap(); - yd.wallclock = timestamp(); + yd.set_wallclock(timestamp()); let xv = &listen[x].0; xv.insert_legacy_info(yd); trace!("star leader {}", &xv.id());