renames ContactInfo to LegacyContactInfo (#29566)

Working towards adding a new ContactInfo where new sockets can be
added in a backward compatible way.
This commit is contained in:
behzad nouri 2023-01-08 16:00:55 +00:00 committed by GitHub
parent aa3aa5cc9c
commit 8c212f59ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 281 additions and 273 deletions

View File

@ -12,7 +12,7 @@ use {
},
solana_gossip::{
cluster_info::{ClusterInfo, Node},
contact_info::ContactInfo,
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::{
genesis_utils::{create_genesis_config, GenesisConfigInfo},

View File

@ -8,7 +8,7 @@ use {
cluster_nodes::{make_test_cluster, new_cluster_nodes, ClusterNodes},
retransmit_stage::RetransmitStage,
},
solana_gossip::contact_info::ContactInfo,
solana_gossip::legacy_contact_info::LegacyContactInfo as ContactInfo,
solana_ledger::{
genesis_utils::{create_genesis_config, GenesisConfigInfo},
shred::{Shred, ShredFlags},

View File

@ -10,7 +10,7 @@ use {
solana_entry::entry::Entry,
solana_gossip::{
cluster_info::{ClusterInfo, Node},
contact_info::ContactInfo,
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::{
genesis_utils::{create_genesis_config, GenesisConfigInfo},

View File

@ -467,7 +467,10 @@ mod tests {
use {
super::*,
rand::seq::SliceRandom,
solana_gossip::{cluster_info::make_accounts_hashes_message, contact_info::ContactInfo},
solana_gossip::{
cluster_info::make_accounts_hashes_message,
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_sdk::{
hash::hash,
signature::{Keypair, Signer},

View File

@ -772,7 +772,7 @@ mod test {
},
solana_gossip::{
cluster_info::{ClusterInfo, Node},
contact_info::ContactInfo,
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::{blockstore::make_many_slot_entries, get_tmp_ledger_path, shred::Nonce},
solana_runtime::{accounts_background_service::AbsRequestSender, bank_forks::BankForks},

View File

@ -30,7 +30,9 @@ use {
itertools::Itertools,
solana_client::{connection_cache::ConnectionCache, tpu_connection::TpuConnection},
solana_entry::entry::hash_transactions,
solana_gossip::{cluster_info::ClusterInfo, contact_info::ContactInfo},
solana_gossip::{
cluster_info::ClusterInfo, legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::{
blockstore_processor::TransactionStatusSender, token_balances::collect_token_balances,
},
@ -1964,7 +1966,7 @@ mod tests {
crossbeam_channel::{unbounded, Receiver},
solana_address_lookup_table_program::state::{AddressLookupTable, LookupTableMeta},
solana_entry::entry::{next_entry, next_versioned_entry, Entry, EntrySlice},
solana_gossip::{cluster_info::Node, contact_info::ContactInfo},
solana_gossip::cluster_info::Node,
solana_ledger::{
blockstore::{entries_to_test_shreds, Blockstore},
genesis_utils::{create_genesis_config, GenesisConfigInfo},

View File

@ -16,7 +16,7 @@ use {
itertools::Itertools,
solana_gossip::{
cluster_info::{ClusterInfo, ClusterInfoError},
contact_info::ContactInfo,
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::{blockstore::Blockstore, shred::Shred},
solana_measure::measure::Measure,

View File

@ -3,7 +3,7 @@ use {
crate::cluster_nodes::ClusterNodesCache,
itertools::Itertools,
solana_entry::entry::Entry,
solana_gossip::contact_info::ContactInfo,
solana_gossip::legacy_contact_info::LegacyContactInfo as ContactInfo,
solana_ledger::shred::{ProcessShredsStats, ReedSolomonCache, Shredder},
solana_sdk::{
hash::Hash,

View File

@ -159,7 +159,7 @@ impl BroadcastRun for BroadcastFakeShredsRun {
mod tests {
use {
super::*,
solana_gossip::contact_info::ContactInfo,
solana_gossip::legacy_contact_info::LegacyContactInfo as ContactInfo,
solana_streamer::socket::SocketAddrSpace,
std::net::{IpAddr, Ipv4Addr, SocketAddr},
};

View File

@ -6,10 +6,10 @@ use {
rand_chacha::ChaChaRng,
solana_gossip::{
cluster_info::{compute_retransmit_peers, ClusterInfo, DATA_PLANE_FANOUT},
contact_info::ContactInfo,
crds::GossipRoute,
crds_gossip_pull::CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS,
crds_value::{CrdsData, CrdsValue},
legacy_contact_info::LegacyContactInfo as ContactInfo,
weighted_shuffle::WeightedShuffle,
},
solana_ledger::shred::ShredId,
@ -475,7 +475,7 @@ pub fn make_test_cluster<R: Rng>(
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 = CrdsData::LegacyContactInfo(node.clone());
let node = CrdsValue::new_unsigned(node);
assert_eq!(
gossip_crds.insert(node, now, GossipRoute::LocalMessage),

View File

@ -1,7 +1,8 @@
use {
itertools::Itertools,
solana_gossip::{
cluster_info::ClusterInfo, contact_info::ContactInfo, crds::Cursor, epoch_slots::EpochSlots,
cluster_info::ClusterInfo, crds::Cursor, epoch_slots::EpochSlots,
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_runtime::{bank::Bank, epoch_stakes::NodeIdToVoteAccounts},
solana_sdk::{

View File

@ -760,7 +760,9 @@ impl RepairService {
mod test {
use {
super::*,
solana_gossip::{cluster_info::Node, contact_info::ContactInfo},
solana_gossip::{
cluster_info::Node, legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::{
blockstore::{
make_chaining_slot_entries, make_many_slot_entries, make_slot_entries, Blockstore,

View File

@ -10,7 +10,9 @@ use {
itertools::{izip, Itertools},
lru::LruCache,
rayon::{prelude::*, ThreadPool, ThreadPoolBuilder},
solana_gossip::{cluster_info::ClusterInfo, contact_info::ContactInfo},
solana_gossip::{
cluster_info::ClusterInfo, legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::{
leader_schedule_cache::LeaderScheduleCache,
shred::{self, ShredId},

View File

@ -15,7 +15,7 @@ use {
},
solana_gossip::{
cluster_info::{ClusterInfo, ClusterInfoError},
contact_info::ContactInfo,
legacy_contact_info::{LegacyContactInfo as ContactInfo, LegacyContactInfo},
ping_pong::{self, PingCache, Pong},
weighted_shuffle::WeightedShuffle,
},
@ -208,13 +208,13 @@ pub(crate) type Ping = ping_pong::Ping<[u8; REPAIR_PING_TOKEN_SIZE]>;
/// Window protocol messages
#[derive(Serialize, Deserialize, Debug)]
pub enum RepairProtocol {
LegacyWindowIndex(ContactInfo, Slot, u64),
LegacyHighestWindowIndex(ContactInfo, Slot, u64),
LegacyOrphan(ContactInfo, Slot),
LegacyWindowIndexWithNonce(ContactInfo, Slot, u64, Nonce),
LegacyHighestWindowIndexWithNonce(ContactInfo, Slot, u64, Nonce),
LegacyOrphanWithNonce(ContactInfo, Slot, Nonce),
LegacyAncestorHashes(ContactInfo, Slot, Nonce),
LegacyWindowIndex(LegacyContactInfo, Slot, u64),
LegacyHighestWindowIndex(LegacyContactInfo, Slot, u64),
LegacyOrphan(LegacyContactInfo, Slot),
LegacyWindowIndexWithNonce(LegacyContactInfo, Slot, u64, Nonce),
LegacyHighestWindowIndexWithNonce(LegacyContactInfo, Slot, u64, Nonce),
LegacyOrphanWithNonce(LegacyContactInfo, Slot, Nonce),
LegacyAncestorHashes(LegacyContactInfo, Slot, Nonce),
Pong(ping_pong::Pong),
WindowIndex {
header: RepairRequestHeader,

View File

@ -35,9 +35,9 @@ use {
ClusterInfo, Node, DEFAULT_CONTACT_DEBUG_INTERVAL_MILLIS,
DEFAULT_CONTACT_SAVE_INTERVAL_MILLIS,
},
contact_info::ContactInfo,
crds_gossip_pull::CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS,
gossip_service::GossipService,
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::{
bank_forks_utils,

View File

@ -480,7 +480,7 @@ mod test {
use {
super::*,
solana_entry::entry::{create_ticks, Entry},
solana_gossip::contact_info::ContactInfo,
solana_gossip::legacy_contact_info::LegacyContactInfo as ContactInfo,
solana_ledger::{
blockstore::{make_many_slot_entries, Blockstore},
get_tmp_ledger_path,

View File

@ -5,7 +5,9 @@ use {
accounts_hash_verifier::AccountsHashVerifier,
snapshot_packager_service::SnapshotPackagerService,
},
solana_gossip::{cluster_info::ClusterInfo, contact_info::ContactInfo},
solana_gossip::{
cluster_info::ClusterInfo, legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_runtime::{
accounts_background_service::{
AbsRequestHandlers, AbsRequestSender, AccountsBackgroundService, DroppedSlotsReceiver,

View File

@ -10,7 +10,9 @@ use {
accounts_hash_verifier::AccountsHashVerifier,
snapshot_packager_service::SnapshotPackagerService,
},
solana_gossip::{cluster_info::ClusterInfo, contact_info::ContactInfo},
solana_gossip::{
cluster_info::ClusterInfo, legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_runtime::{
accounts_background_service::{
AbsRequestHandlers, AbsRequestSender, AccountsBackgroundService,

View File

@ -49,8 +49,8 @@ use {
solana_core::serve_repair::{RepairProtocol, RepairRequestHeader, ServeRepair},
solana_dos::cli::*,
solana_gossip::{
contact_info::ContactInfo,
gossip_service::{discover, get_multi_client},
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_measure::measure::Measure,
solana_rpc_client::rpc_client::RpcClient,

View File

@ -24,7 +24,6 @@ use {
cluster_info_metrics::{
submit_gossip_stats, Counter, GossipStats, ScopedTimer, TimedGuard,
},
contact_info::ContactInfo,
crds::{Crds, Cursor, GossipRoute},
crds_gossip::CrdsGossip,
crds_gossip_error::CrdsGossipError,
@ -36,6 +35,7 @@ use {
duplicate_shred::DuplicateShred,
epoch_slots::EpochSlots,
gossip_error::GossipError,
legacy_contact_info::LegacyContactInfo as ContactInfo,
ping_pong::{self, PingCache, Pong},
socketaddr, socketaddr_any,
weighted_shuffle::WeightedShuffle,
@ -267,7 +267,7 @@ pub fn make_accounts_hashes_message(
pub(crate) type Ping = ping_pong::Ping<[u8; GOSSIP_PING_TOKEN_SIZE]>;
// TODO These messages should go through the gpu pipeline for spam filtering
#[frozen_abi(digest = "9YNaHHwzwQaAaXDXW5A8k47HDuUzRYNjTAdARoAgVvPU")]
#[frozen_abi(digest = "Hsj6a2bmzxno1RUcSM1gzHAg2zxgw15E3feb2SimieBA")]
#[derive(Serialize, Deserialize, Debug, AbiEnumVisitor, AbiExample)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum Protocol {
@ -377,7 +377,7 @@ impl Sanitize for Protocol {
fn retain_staked(values: &mut Vec<CrdsValue>, stakes: &HashMap<Pubkey, u64>) {
values.retain(|value| {
match value.data {
CrdsData::ContactInfo(_) => true,
CrdsData::LegacyContactInfo(_) => true,
// May Impact new validators starting up without any stake yet.
CrdsData::Vote(_, _) => true,
// Unstaked nodes can still help repair.
@ -471,7 +471,7 @@ impl ClusterInfo {
let now = timestamp();
self.my_contact_info.write().unwrap().wallclock = now;
let entries: Vec<_> = vec![
CrdsData::ContactInfo(self.my_contact_info()),
CrdsData::LegacyContactInfo(self.my_contact_info()),
CrdsData::NodeInstance(self.instance.read().unwrap().with_wallclock(now)),
]
.into_iter()
@ -524,7 +524,8 @@ impl ClusterInfo {
// TODO kill insert_info, only used by tests
pub fn insert_info(&self, contact_info: ContactInfo) {
let value = CrdsValue::new_signed(CrdsData::ContactInfo(contact_info), &self.keypair());
let value =
CrdsValue::new_signed(CrdsData::LegacyContactInfo(contact_info), &self.keypair());
let mut gossip_crds = self.gossip.crds.write().unwrap();
let _ = gossip_crds.insert(value, timestamp(), GossipRoute::LocalMessage);
}
@ -1356,7 +1357,7 @@ impl ClusterInfo {
fn insert_self(&self) {
let value = CrdsValue::new_signed(
CrdsData::ContactInfo(self.my_contact_info()),
CrdsData::LegacyContactInfo(self.my_contact_info()),
&self.keypair(),
);
let mut gossip_crds = self.gossip.crds.write().unwrap();
@ -1492,7 +1493,7 @@ impl ClusterInfo {
self.gossip.mark_pull_request_creation_time(peer.id, now);
}
}
let self_info = CrdsData::ContactInfo(self.my_contact_info());
let self_info = CrdsData::LegacyContactInfo(self.my_contact_info());
let self_info = CrdsValue::new_signed(self_info, &self.keypair());
let pulls = pulls
.into_iter()
@ -2030,7 +2031,7 @@ impl ClusterInfo {
score
};
let score = match response.data {
CrdsData::ContactInfo(_) => 2 * score,
CrdsData::LegacyContactInfo(_) => 2 * score,
_ => score,
};
((addr, response), score)
@ -3077,7 +3078,7 @@ fn filter_on_shred_version(
if crds.get_shred_version(from) == Some(self_shred_version) {
values.retain(|value| match &value.data {
// Allow contact-infos so that shred-versions are updated.
CrdsData::ContactInfo(_) => true,
CrdsData::LegacyContactInfo(_) => true,
CrdsData::NodeInstance(_) => true,
// Only retain values with the same shred version.
_ => crds.get_shred_version(&value.pubkey()) == Some(self_shred_version),
@ -3086,7 +3087,7 @@ fn filter_on_shred_version(
values.retain(|value| match &value.data {
// Allow node to update its own contact info in case their
// shred-version changes
CrdsData::ContactInfo(node) => node.id == *from,
CrdsData::LegacyContactInfo(node) => node.id == *from,
CrdsData::NodeInstance(_) => true,
_ => false,
})
@ -3099,7 +3100,7 @@ fn filter_on_shred_version(
match &mut msg {
Protocol::PullRequest(_, caller) => match &caller.data {
// Allow spy nodes with shred-verion == 0 to pull from other nodes.
CrdsData::ContactInfo(node)
CrdsData::LegacyContactInfo(node)
if node.shred_version == 0 || node.shred_version == self_shred_version =>
{
Some(msg)
@ -3420,7 +3421,7 @@ RPC Enabled Nodes: 1"#;
fn test_crds_values(pubkey: Pubkey) -> Vec<CrdsValue> {
let entrypoint = ContactInfo::new_localhost(&pubkey, timestamp());
let entrypoint_crdsvalue = CrdsValue::new_unsigned(CrdsData::ContactInfo(entrypoint));
let entrypoint_crdsvalue = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(entrypoint));
vec![entrypoint_crdsvalue]
}
@ -3622,7 +3623,7 @@ RPC Enabled Nodes: 1"#;
let cluster_info =
ClusterInfo::new(d, Arc::new(Keypair::new()), SocketAddrSpace::Unspecified);
let d = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), timestamp());
let label = CrdsValueLabel::ContactInfo(d.id);
let label = CrdsValueLabel::LegacyContactInfo(d.id);
cluster_info.insert_info(d);
let gossip_crds = cluster_info.gossip.crds.read().unwrap();
assert!(gossip_crds.get::<&CrdsValue>(&label).is_some());
@ -4001,7 +4002,7 @@ RPC Enabled Nodes: 1"#;
node.shred_version = 42;
let epoch_slots = EpochSlots::new_rand(&mut rng, Some(node_pubkey));
let entries = vec![
CrdsValue::new_unsigned(CrdsData::ContactInfo(node)),
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(node)),
CrdsValue::new_unsigned(CrdsData::EpochSlots(0, epoch_slots)),
];
{
@ -4058,7 +4059,7 @@ RPC Enabled Nodes: 1"#;
}
// now add this message back to the table and make sure after the next pull, the entrypoint is unset
let entrypoint_crdsvalue =
CrdsValue::new_unsigned(CrdsData::ContactInfo(entrypoint.clone()));
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(entrypoint.clone()));
let cluster_info = Arc::new(cluster_info);
let timeouts = cluster_info.gossip.make_timeouts(
cluster_info.id(),
@ -4079,7 +4080,7 @@ RPC Enabled Nodes: 1"#;
#[test]
fn test_split_messages_small() {
let value = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default()));
let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default()));
test_split_messages(value);
}
@ -4181,7 +4182,7 @@ RPC Enabled Nodes: 1"#;
}
fn check_pull_request_size(filter: CrdsFilter) {
let value = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default()));
let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default()));
let protocol = Protocol::PullRequest(filter, value);
assert!(serialized_size(&protocol).unwrap() <= PACKET_DATA_SIZE as u64);
}
@ -4348,7 +4349,7 @@ RPC Enabled Nodes: 1"#;
.expect("unable to serialize default filter") as usize;
let protocol = Protocol::PullRequest(
CrdsFilter::default(),
CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default())),
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default())),
);
let protocol_size =
serialized_size(&protocol).expect("unable to serialize gossip protocol") as usize;
@ -4689,7 +4690,7 @@ RPC Enabled Nodes: 1"#;
let mut rand_ci = ContactInfo::new_rand(&mut rng, Some(keypair.pubkey()));
rand_ci.shred_version = shred_version;
rand_ci.wallclock = timestamp();
CrdsValue::new_signed(CrdsData::ContactInfo(rand_ci), &keypair)
CrdsValue::new_signed(CrdsData::LegacyContactInfo(rand_ci), &keypair)
})
.take(NO_ENTRIES)
.collect();

View File

@ -613,8 +613,8 @@ pub(crate) fn submit_gossip_stats(
);
datapoint_info!(
"cluster_info_crds_stats",
("ContactInfo-push", crds_stats.push.counts[0], i64),
("ContactInfo-pull", crds_stats.pull.counts[0], i64),
("LegacyContactInfo-push", crds_stats.push.counts[0], i64),
("LegacyContactInfo-pull", crds_stats.pull.counts[0], i64),
("Vote-push", crds_stats.push.counts[1], i64),
("Vote-pull", crds_stats.pull.counts[1], i64),
("LowestSlot-push", crds_stats.push.counts[2], i64),
@ -656,8 +656,8 @@ pub(crate) fn submit_gossip_stats(
);
datapoint_info!(
"cluster_info_crds_stats_fails",
("ContactInfo-push", crds_stats.push.fails[0], i64),
("ContactInfo-pull", crds_stats.pull.fails[0], i64),
("LegacyContactInfo-push", crds_stats.push.fails[0], i64),
("LegacyContactInfo-pull", crds_stats.pull.fails[0], i64),
("Vote-push", crds_stats.push.fails[1], i64),
("Vote-pull", crds_stats.pull.fails[1], i64),
("LowestSlot-push", crds_stats.push.fails[2], i64),

View File

@ -26,10 +26,10 @@
use {
crate::{
contact_info::ContactInfo,
crds_entry::CrdsEntry,
crds_shards::CrdsShards,
crds_value::{CrdsData, CrdsValue, CrdsValueLabel},
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
bincode::serialize,
indexmap::{
@ -220,7 +220,7 @@ impl Crds {
let entry_index = entry.index();
self.shards.insert(entry_index, &value);
match &value.value.data {
CrdsData::ContactInfo(node) => {
CrdsData::LegacyContactInfo(node) => {
self.nodes.insert(entry_index);
self.shred_versions.insert(pubkey, node.shred_version);
}
@ -247,11 +247,14 @@ impl Crds {
self.shards.remove(entry_index, entry.get());
self.shards.insert(entry_index, &value);
match &value.value.data {
CrdsData::ContactInfo(node) => {
CrdsData::LegacyContactInfo(node) => {
self.shred_versions.insert(pubkey, node.shred_version);
// self.nodes does not need to be updated since the
// entry at this index was and stays contact-info.
debug_assert_matches!(entry.get().value.data, CrdsData::ContactInfo(_));
debug_assert_matches!(
entry.get().value.data,
CrdsData::LegacyContactInfo(_)
);
}
CrdsData::Vote(_, _) => {
self.votes.remove(&entry.get().ordinal);
@ -319,7 +322,7 @@ impl Crds {
/// Returns ContactInfo of all known nodes.
pub(crate) fn get_nodes_contact_info(&self) -> impl Iterator<Item = &ContactInfo> {
self.get_nodes().map(|v| match &v.value.data {
CrdsData::ContactInfo(info) => info,
CrdsData::LegacyContactInfo(info) => info,
_ => panic!("this should not happen!"),
})
}
@ -448,7 +451,7 @@ impl Crds {
// It suffices to only overwrite the origin's timestamp since that is
// used when purging old values. If the origin does not exist in the
// table, fallback to exhaustive update on all associated records.
let origin = CrdsValueLabel::ContactInfo(*pubkey);
let origin = CrdsValueLabel::LegacyContactInfo(*pubkey);
if let Some(origin) = self.table.get_mut(&origin) {
if origin.local_timestamp < now {
origin.local_timestamp = now;
@ -480,7 +483,7 @@ impl Crds {
let timeout = timeouts.get(pubkey).copied().unwrap_or(default_timeout);
// If the origin's contact-info hasn't expired yet then preserve
// all associated values.
let origin = CrdsValueLabel::ContactInfo(*pubkey);
let origin = CrdsValueLabel::LegacyContactInfo(*pubkey);
if let Some(origin) = self.table.get(&origin) {
if now < origin.local_timestamp.saturating_add(timeout) {
return vec![];
@ -515,7 +518,7 @@ impl Crds {
self.purged.push_back((value.value_hash, now));
self.shards.remove(index, &value);
match value.value.data {
CrdsData::ContactInfo(_) => {
CrdsData::LegacyContactInfo(_) => {
self.nodes.swap_remove(&index);
}
CrdsData::Vote(_, _) => {
@ -552,7 +555,7 @@ impl Crds {
self.shards.remove(size, value);
self.shards.insert(index, value);
match value.value.data {
CrdsData::ContactInfo(_) => {
CrdsData::LegacyContactInfo(_) => {
self.nodes.swap_remove(&size);
self.nodes.insert(index);
}
@ -686,7 +689,7 @@ impl CrdsDataStats {
fn ordinal(entry: &VersionedCrdsValue) -> usize {
match &entry.value.data {
CrdsData::ContactInfo(_) => 0,
CrdsData::LegacyContactInfo(_) => 0,
CrdsData::Vote(_, _) => 1,
CrdsData::LowestSlot(_, _) => 2,
CrdsData::SnapshotHashes(_) => 3,
@ -726,8 +729,8 @@ mod tests {
use {
super::*,
crate::{
contact_info::ContactInfo,
crds_value::{new_rand_timestamp, NodeInstance, SnapshotHashes},
socketaddr,
},
rand::{thread_rng, Rng, SeedableRng},
rand_chacha::ChaChaRng,
@ -742,7 +745,7 @@ mod tests {
#[test]
fn test_insert() {
let mut crds = Crds::default();
let val = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default()));
let val = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default()));
assert_eq!(
crds.insert(val.clone(), 0, GossipRoute::LocalMessage),
Ok(())
@ -754,7 +757,7 @@ mod tests {
#[test]
fn test_update_old() {
let mut crds = Crds::default();
let val = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default()));
let val = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default()));
assert_eq!(
crds.insert(val.clone(), 0, GossipRoute::LocalMessage),
Ok(())
@ -769,13 +772,12 @@ mod tests {
#[test]
fn test_update_new() {
let mut crds = Crds::default();
let original = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&Pubkey::default(),
0,
)));
let original = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&Pubkey::default(), 0),
));
let value_hash = hash(&serialize(&original).unwrap());
assert_matches!(crds.insert(original, 0, GossipRoute::LocalMessage), Ok(()));
let val = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
let val = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::new_localhost(
&Pubkey::default(),
1,
)));
@ -789,7 +791,7 @@ mod tests {
#[test]
fn test_update_timestamp() {
let mut crds = Crds::default();
let val = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
let val = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::new_localhost(
&Pubkey::default(),
0,
)));
@ -799,7 +801,7 @@ mod tests {
);
assert_eq!(crds.table[&val.label()].ordinal, 0);
let val2 = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default()));
let val2 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default()));
let value_hash = hash(&serialize(&val2).unwrap());
assert_eq!(val2.label().pubkey(), val.label().pubkey());
assert_eq!(
@ -819,7 +821,7 @@ mod tests {
let mut ci = ContactInfo::default();
ci.wallclock += 1;
let val3 = CrdsValue::new_unsigned(CrdsData::ContactInfo(ci));
let val3 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci));
assert_eq!(crds.insert(val3, 3, GossipRoute::LocalMessage), Ok(()));
assert_eq!(*crds.purged.back().unwrap(), (value_hash, 3));
assert_eq!(crds.table[&val2.label()].local_timestamp, 3);
@ -888,7 +890,7 @@ mod tests {
fn test_find_old_records_default() {
let thread_pool = ThreadPoolBuilder::new().build().unwrap();
let mut crds = Crds::default();
let val = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default()));
let val = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default()));
assert_eq!(
crds.insert(val.clone(), 1, GossipRoute::LocalMessage),
Ok(())
@ -940,7 +942,7 @@ mod tests {
fn test_remove_default() {
let thread_pool = ThreadPoolBuilder::new().build().unwrap();
let mut crds = Crds::default();
let val = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default()));
let val = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default()));
assert_matches!(
crds.insert(val.clone(), 1, GossipRoute::LocalMessage),
Ok(_)
@ -958,7 +960,7 @@ mod tests {
fn test_find_old_records_staked() {
let thread_pool = ThreadPoolBuilder::new().build().unwrap();
let mut crds = Crds::default();
let val = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default()));
let val = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default()));
assert_eq!(
crds.insert(val.clone(), 1, GossipRoute::LocalMessage),
Ok(())
@ -1111,7 +1113,7 @@ mod tests {
let num_nodes = crds
.table
.values()
.filter(|v| matches!(v.value.data, CrdsData::ContactInfo(_)))
.filter(|v| matches!(v.value.data, CrdsData::LegacyContactInfo(_)))
.count();
let num_votes = crds
.table
@ -1237,7 +1239,7 @@ mod tests {
let mut node = ContactInfo::new_rand(&mut rng, Some(pubkey));
let wallclock = node.wallclock;
node.shred_version = 42;
let node = CrdsData::ContactInfo(node);
let node = CrdsData::LegacyContactInfo(node);
let node = CrdsValue::new_unsigned(node);
assert_eq!(
crds.insert(node, timestamp(), GossipRoute::LocalMessage),
@ -1248,7 +1250,7 @@ mod tests {
let mut node = ContactInfo::new_rand(&mut rng, Some(pubkey));
node.wallclock = wallclock - 1; // outdated.
node.shred_version = 8;
let node = CrdsData::ContactInfo(node);
let node = CrdsData::LegacyContactInfo(node);
let node = CrdsValue::new_unsigned(node);
assert_eq!(
crds.insert(node, timestamp(), GossipRoute::LocalMessage),
@ -1259,7 +1261,7 @@ mod tests {
let mut node = ContactInfo::new_rand(&mut rng, Some(pubkey));
node.wallclock = wallclock + 1; // so that it overrides the prev one.
node.shred_version = 8;
let node = CrdsData::ContactInfo(node);
let node = CrdsData::LegacyContactInfo(node);
let node = CrdsValue::new_unsigned(node);
assert_eq!(
crds.insert(node, timestamp(), GossipRoute::LocalMessage),
@ -1277,7 +1279,7 @@ mod tests {
assert_eq!(crds.get_shred_version(&pubkey), Some(8));
// Remove contact-info. Shred version should stay there since there
// are still values associated with the pubkey.
crds.remove(&CrdsValueLabel::ContactInfo(pubkey), timestamp());
crds.remove(&CrdsValueLabel::LegacyContactInfo(pubkey), timestamp());
assert_eq!(crds.get::<&ContactInfo>(pubkey), None);
assert_eq!(crds.get_shred_version(&pubkey), Some(8));
// Remove the remaining entry with the same pubkey.
@ -1350,7 +1352,7 @@ mod tests {
fn test_remove_staked() {
let thread_pool = ThreadPoolBuilder::new().build().unwrap();
let mut crds = Crds::default();
let val = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default()));
let val = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default()));
assert_matches!(
crds.insert(val.clone(), 1, GossipRoute::LocalMessage),
Ok(_)
@ -1371,7 +1373,7 @@ mod tests {
#[test]
#[allow(clippy::neg_cmp_op_on_partial_ord)]
fn test_equal() {
let val = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default()));
let val = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default()));
let v1 = VersionedCrdsValue::new(val.clone(), Cursor::default(), 1);
let v2 = VersionedCrdsValue::new(val, Cursor::default(), 1);
assert_eq!(v1, v2);
@ -1383,7 +1385,7 @@ mod tests {
#[allow(clippy::neg_cmp_op_on_partial_ord)]
fn test_hash_order() {
let v1 = VersionedCrdsValue::new(
CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::new_localhost(
&Pubkey::default(),
0,
))),
@ -1394,7 +1396,7 @@ mod tests {
{
let mut contact_info = ContactInfo::new_localhost(&Pubkey::default(), 0);
contact_info.rpc = socketaddr!("0.0.0.0:0");
CrdsValue::new_unsigned(CrdsData::ContactInfo(contact_info))
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(contact_info))
},
Cursor::default(),
1, // local_timestamp
@ -1417,7 +1419,7 @@ mod tests {
#[allow(clippy::neg_cmp_op_on_partial_ord)]
fn test_wallclock_order() {
let v1 = VersionedCrdsValue::new(
CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::new_localhost(
&Pubkey::default(),
1,
))),
@ -1425,7 +1427,7 @@ mod tests {
1, // local_timestamp
);
let v2 = VersionedCrdsValue::new(
CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::new_localhost(
&Pubkey::default(),
0,
))),
@ -1443,7 +1445,7 @@ mod tests {
#[allow(clippy::neg_cmp_op_on_partial_ord)]
fn test_label_order() {
let v1 = VersionedCrdsValue::new(
CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
))),
@ -1451,7 +1453,7 @@ mod tests {
1, // local_timestamp
);
let v2 = VersionedCrdsValue::new(
CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
))),

View File

@ -1,11 +1,11 @@
use {
crate::{
contact_info::ContactInfo,
crds::VersionedCrdsValue,
crds_value::{
CrdsData, CrdsValue, CrdsValueLabel, IncrementalSnapshotHashes, LegacyVersion,
LowestSlot, SnapshotHashes, Version,
},
legacy_contact_info::LegacyContactInfo,
},
indexmap::IndexMap,
solana_sdk::pubkey::Pubkey,
@ -53,7 +53,7 @@ impl_crds_entry!(CrdsValue, |entry| Some(&entry?.value));
impl_crds_entry!(VersionedCrdsValue, |entry| entry);
// Lookup by Pubkey.
impl_crds_entry!(ContactInfo, CrdsData::ContactInfo(node), node);
impl_crds_entry!(LegacyContactInfo, CrdsData::LegacyContactInfo(node), node);
impl_crds_entry!(LegacyVersion, CrdsData::LegacyVersion(version), version);
impl_crds_entry!(LowestSlot, CrdsData::LowestSlot(_, slot), slot);
impl_crds_entry!(Version, CrdsData::Version(version), version);
@ -114,8 +114,8 @@ mod tests {
assert_eq!(crds.get::<&VersionedCrdsValue>(&key).unwrap().value, *entry);
let key = entry.pubkey();
match &entry.data {
CrdsData::ContactInfo(node) => {
assert_eq!(crds.get::<&ContactInfo>(key), Some(node))
CrdsData::LegacyContactInfo(node) => {
assert_eq!(crds.get::<&LegacyContactInfo>(key), Some(node))
}
CrdsData::LowestSlot(_, slot) => {
assert_eq!(crds.get::<&LowestSlot>(key), Some(slot))

View File

@ -8,13 +8,13 @@ use {
crate::{
cluster_info::Ping,
cluster_info_metrics::GossipStats,
contact_info::ContactInfo,
crds::{Crds, GossipRoute},
crds_gossip_error::CrdsGossipError,
crds_gossip_pull::{CrdsFilter, CrdsGossipPull, ProcessPullStats},
crds_gossip_push::{CrdsGossipPush, CRDS_GOSSIP_NUM_ACTIVE},
crds_value::{CrdsData, CrdsValue},
duplicate_shred::{self, DuplicateShredIndex, LeaderScheduleFn, MAX_DUPLICATE_SHREDS},
legacy_contact_info::LegacyContactInfo as ContactInfo,
ping_pong::PingCache,
},
itertools::Itertools,
@ -374,7 +374,7 @@ where
mod test {
use {
super::*,
crate::{contact_info::ContactInfo, crds_value::CrdsData},
crate::crds_value::CrdsData,
solana_sdk::{hash::hash, timing::timestamp},
};
@ -390,7 +390,7 @@ mod test {
.write()
.unwrap()
.insert(
CrdsValue::new_unsigned(CrdsData::ContactInfo(ci.clone())),
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci.clone())),
0,
GossipRoute::LocalMessage,
)

View File

@ -15,11 +15,11 @@ use {
crate::{
cluster_info::{Ping, CRDS_UNIQUE_PUBKEY_CAPACITY},
cluster_info_metrics::GossipStats,
contact_info::ContactInfo,
crds::{Crds, GossipRoute, VersionedCrdsValue},
crds_gossip::{self, get_stake, get_weight},
crds_gossip_error::CrdsGossipError,
crds_value::CrdsValue,
legacy_contact_info::LegacyContactInfo as ContactInfo,
ping_pong::PingCache,
},
itertools::Itertools,
@ -662,8 +662,8 @@ pub(crate) mod tests {
super::*,
crate::{
cluster_info::MAX_BLOOM_SIZE,
contact_info::ContactInfo,
crds_value::{CrdsData, Vote},
socketaddr,
},
itertools::Itertools,
rand::{seq::SliceRandom, thread_rng, SeedableRng},
@ -722,17 +722,16 @@ pub(crate) mod tests {
let mut crds = Crds::default();
let mut stakes = HashMap::new();
let node = CrdsGossipPull::default();
let me = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
let me = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
)));
crds.insert(me.clone(), 0, GossipRoute::LocalMessage)
.unwrap();
for i in 1..=30 {
let entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
)));
let entry = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0),
));
let id = entry.label().pubkey();
crds.insert(entry.clone(), 0, GossipRoute::LocalMessage)
.unwrap();
@ -763,25 +762,25 @@ pub(crate) mod tests {
let gossip = socketaddr!("127.0.0.1:1234");
let me = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let me = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
shred_version: 123,
gossip,
..ContactInfo::default()
}));
let spy = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let spy = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
shred_version: 0,
gossip,
..ContactInfo::default()
}));
let node_123 = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let node_123 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
shred_version: 123,
gossip,
..ContactInfo::default()
}));
let node_456 = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let node_456 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
shred_version: 456,
gossip,
@ -843,12 +842,12 @@ pub(crate) mod tests {
let node = CrdsGossipPull::default();
let gossip = socketaddr!("127.0.0.1:1234");
let me = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let me = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
gossip,
..ContactInfo::default()
}));
let node_123 = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let node_123 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
gossip,
..ContactInfo::default()
@ -1006,10 +1005,9 @@ pub(crate) mod tests {
let thread_pool = ThreadPoolBuilder::new().build().unwrap();
let crds = RwLock::<Crds>::default();
let node_keypair = Keypair::new();
let entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&node_keypair.pubkey(),
0,
)));
let entry = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&node_keypair.pubkey(), 0),
));
let node = CrdsGossipPull::default();
let mut pings = Vec::new();
let ping_cache = Mutex::new(PingCache::new(
@ -1060,7 +1058,7 @@ pub(crate) mod tests {
.lock()
.unwrap()
.mock_pong(new.id, new.gossip, Instant::now());
let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(new));
let new = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(new));
crds.write()
.unwrap()
.insert(new.clone(), now, GossipRoute::LocalMessage)
@ -1083,7 +1081,7 @@ pub(crate) mod tests {
node.mark_pull_request_creation_time(new.contact_info().unwrap().id, now);
let offline = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), now);
let offline = CrdsValue::new_unsigned(CrdsData::ContactInfo(offline));
let offline = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(offline));
crds.write()
.unwrap()
.insert(offline, now, GossipRoute::LocalMessage)
@ -1118,20 +1116,19 @@ pub(crate) mod tests {
);
let mut crds = Crds::default();
let node_keypair = Keypair::new();
let entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&node_keypair.pubkey(),
0,
)));
let entry = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&node_keypair.pubkey(), 0),
));
let node = CrdsGossipPull::default();
crds.insert(entry, now, GossipRoute::LocalMessage).unwrap();
let old = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0);
ping_cache.mock_pong(old.id, old.gossip, Instant::now());
let old = CrdsValue::new_unsigned(CrdsData::ContactInfo(old));
let old = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(old));
crds.insert(old.clone(), now, GossipRoute::LocalMessage)
.unwrap();
let new = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0);
ping_cache.mock_pong(new.id, new.gossip, Instant::now());
let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(new));
let new = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(new));
crds.insert(new.clone(), now, GossipRoute::LocalMessage)
.unwrap();
let crds = RwLock::new(crds);
@ -1216,10 +1213,9 @@ pub(crate) mod tests {
Duration::from_secs(20 * 60) / 64, // rate_limit_delay
128, // capacity
);
let entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&node_keypair.pubkey(),
0,
)));
let entry = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&node_keypair.pubkey(), 0),
));
let caller = entry.clone();
let node = CrdsGossipPull::default();
node_crds
@ -1227,7 +1223,7 @@ pub(crate) mod tests {
.unwrap();
let new = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0);
ping_cache.mock_pong(new.id, new.gossip, Instant::now());
let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(new));
let new = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(new));
node_crds.insert(new, 0, GossipRoute::LocalMessage).unwrap();
let node_crds = RwLock::new(node_crds);
let mut pings = Vec::new();
@ -1259,7 +1255,7 @@ pub(crate) mod tests {
assert_eq!(rsp[0].len(), 0);
let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
let new = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
CRDS_GOSSIP_PULL_MSG_TIMEOUT_MS,
)));
@ -1288,7 +1284,7 @@ pub(crate) mod tests {
// Should return new value since caller is new.
let now = CRDS_GOSSIP_PULL_MSG_TIMEOUT_MS + 1;
let caller = ContactInfo::new_localhost(&Pubkey::new_unique(), now);
let caller = CrdsValue::new_unsigned(CrdsData::ContactInfo(caller));
let caller = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(caller));
filters
.iter()
.map(|(_, filter)| (caller.clone(), filter.clone()))
@ -1315,10 +1311,9 @@ pub(crate) mod tests {
let thread_pool = ThreadPoolBuilder::new().build().unwrap();
let node_keypair = Keypair::new();
let mut node_crds = Crds::default();
let entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&node_keypair.pubkey(),
0,
)));
let entry = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&node_keypair.pubkey(), 0),
));
let caller = entry.clone();
let node = CrdsGossipPull::default();
node_crds
@ -1331,7 +1326,7 @@ pub(crate) mod tests {
);
let new = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0);
ping_cache.mock_pong(new.id, new.gossip, Instant::now());
let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(new));
let new = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(new));
node_crds.insert(new, 0, GossipRoute::LocalMessage).unwrap();
let node_crds = RwLock::new(node_crds);
let mut pings = Vec::new();
@ -1375,10 +1370,9 @@ pub(crate) mod tests {
let thread_pool = ThreadPoolBuilder::new().build().unwrap();
let node_keypair = Keypair::new();
let mut node_crds = Crds::default();
let entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&node_keypair.pubkey(),
1,
)));
let entry = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&node_keypair.pubkey(), 1),
));
let caller = entry.clone();
let node_pubkey = entry.label().pubkey();
let node = CrdsGossipPull::default();
@ -1392,14 +1386,14 @@ pub(crate) mod tests {
);
let new = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 1);
ping_cache.mock_pong(new.id, new.gossip, Instant::now());
let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(new));
let new = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(new));
node_crds.insert(new, 0, GossipRoute::LocalMessage).unwrap();
let mut dest_crds = Crds::default();
let new_id = solana_sdk::pubkey::new_rand();
let new = ContactInfo::new_localhost(&new_id, 1);
ping_cache.mock_pong(new.id, new.gossip, Instant::now());
let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(new));
let new = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(new));
dest_crds
.insert(new.clone(), 0, GossipRoute::LocalMessage)
.unwrap();
@ -1408,7 +1402,7 @@ pub(crate) mod tests {
// node contains a key from the dest node, but at an older local timestamp
let same_key = ContactInfo::new_localhost(&new_id, 0);
ping_cache.mock_pong(same_key.id, same_key.gossip, Instant::now());
let same_key = CrdsValue::new_unsigned(CrdsData::ContactInfo(same_key));
let same_key = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(same_key));
assert_eq!(same_key.label(), new.label());
assert!(same_key.wallclock() < new.wallclock());
node_crds
@ -1492,17 +1486,16 @@ pub(crate) mod tests {
fn test_gossip_purge() {
let thread_pool = ThreadPoolBuilder::new().build().unwrap();
let mut node_crds = Crds::default();
let entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
)));
let entry = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0),
));
let node_label = entry.label();
let node_pubkey = node_label.pubkey();
let node = CrdsGossipPull::default();
node_crds
.insert(entry, 0, GossipRoute::LocalMessage)
.unwrap();
let old = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
let old = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
)));
@ -1632,7 +1625,7 @@ pub(crate) mod tests {
let node = CrdsGossipPull::default();
let peer_pubkey = solana_sdk::pubkey::new_rand();
let peer_entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(
let peer_entry = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&peer_pubkey, 0),
));
let mut timeouts = HashMap::new();
@ -1652,7 +1645,7 @@ pub(crate) mod tests {
);
let node_crds = RwLock::<Crds>::default();
let unstaked_peer_entry = CrdsValue::new_unsigned(CrdsData::ContactInfo(
let unstaked_peer_entry = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&peer_pubkey, 0),
));
// check that old contact infos fail if they are too old, regardless of "timeouts"

View File

@ -14,10 +14,10 @@
use {
crate::{
cluster_info::{Ping, CRDS_UNIQUE_PUBKEY_CAPACITY},
contact_info::ContactInfo,
crds::{Crds, CrdsError, Cursor, GossipRoute},
crds_gossip::{self, get_stake, get_weight},
crds_value::CrdsValue,
legacy_contact_info::LegacyContactInfo as ContactInfo,
ping_pong::PingCache,
received_cache::ReceivedCache,
weighted_shuffle::WeightedShuffle,
@ -438,7 +438,7 @@ impl CrdsGossipPush {
mod tests {
use {
super::*,
crate::{contact_info::ContactInfo, crds_value::CrdsData},
crate::{crds_value::CrdsData, socketaddr},
std::time::Duration,
};
@ -454,10 +454,9 @@ mod tests {
fn test_process_push_one() {
let crds = RwLock::<Crds>::default();
let push = CrdsGossipPush::default();
let value = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
)));
let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0),
));
let label = value.label();
// push a new message
assert_eq!(
@ -477,7 +476,7 @@ mod tests {
let push = CrdsGossipPush::default();
let mut ci = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0);
ci.wallclock = 1;
let value = CrdsValue::new_unsigned(CrdsData::ContactInfo(ci.clone()));
let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci.clone()));
// push a new message
assert_eq!(
@ -487,7 +486,7 @@ mod tests {
// push an old version
ci.wallclock = 0;
let value = CrdsValue::new_unsigned(CrdsData::ContactInfo(ci));
let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci));
assert!(push
.process_push_message(&crds, vec![(Pubkey::default(), vec![value])], 0)
.is_empty());
@ -501,14 +500,14 @@ mod tests {
// push a version to far in the future
ci.wallclock = timeout + 1;
let value = CrdsValue::new_unsigned(CrdsData::ContactInfo(ci.clone()));
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;
let value = CrdsValue::new_unsigned(CrdsData::ContactInfo(ci));
let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci));
assert!(push
.process_push_message(&crds, vec![(Pubkey::default(), vec![value])], timeout + 1)
.is_empty());
@ -520,7 +519,7 @@ mod tests {
let mut ci = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0);
let origin = ci.id;
ci.wallclock = 0;
let value_old = CrdsValue::new_unsigned(CrdsData::ContactInfo(ci.clone()));
let value_old = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci.clone()));
// push a new message
assert_eq!(
@ -530,7 +529,7 @@ mod tests {
// push an old version
ci.wallclock = 1;
let value = CrdsValue::new_unsigned(CrdsData::ContactInfo(ci));
let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci));
assert_eq!(
push.process_push_message(&crds, vec![(Pubkey::default(), vec![value])], 0),
[origin].into_iter().collect()
@ -552,7 +551,7 @@ mod tests {
let mut ping_cache = new_ping_cache();
let value1 = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0);
ping_cache.mock_pong(value1.id, value1.gossip, Instant::now());
let value1 = CrdsValue::new_unsigned(CrdsData::ContactInfo(value1));
let value1 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(value1));
assert_eq!(
crds.insert(value1.clone(), now, GossipRoute::LocalMessage),
@ -582,7 +581,7 @@ mod tests {
.lock()
.unwrap()
.mock_pong(value2.id, value2.gossip, Instant::now());
let value2 = CrdsValue::new_unsigned(CrdsData::ContactInfo(value2));
let value2 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(value2));
assert!(active_set.get(&value2.label().pubkey()).is_none());
drop(active_set);
assert_eq!(
@ -620,7 +619,7 @@ mod tests {
.lock()
.unwrap()
.mock_pong(value2.id, value2.gossip, Instant::now());
let value2 = CrdsValue::new_unsigned(CrdsData::ContactInfo(value2));
let value2 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(value2));
assert_eq!(
crds.write()
.unwrap()
@ -651,10 +650,9 @@ mod tests {
let push = CrdsGossipPush::default();
let mut stakes = HashMap::new();
for i in 1..=100 {
let peer = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
time,
)));
let peer = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), time),
));
let id = peer.label().pubkey();
crds.insert(peer.clone(), time, GossipRoute::LocalMessage)
.unwrap();
@ -685,25 +683,25 @@ mod tests {
let gossip = socketaddr!("127.0.0.1:1234");
let me = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let me = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
shred_version: 123,
gossip,
..ContactInfo::default()
}));
let spy = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let spy = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
shred_version: 0,
gossip,
..ContactInfo::default()
}));
let node_123 = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let node_123 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
shred_version: 123,
gossip,
..ContactInfo::default()
}));
let node_456 = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let node_456 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
shred_version: 456,
gossip,
@ -757,12 +755,12 @@ mod tests {
let node = CrdsGossipPush::default();
let gossip = socketaddr!("127.0.0.1:1234");
let me = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let me = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
gossip,
..ContactInfo::default()
}));
let node_123 = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo {
let node_123 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo {
id: solana_sdk::pubkey::new_rand(),
gossip,
..ContactInfo::default()
@ -822,7 +820,7 @@ mod tests {
let mut ping_cache = new_ping_cache();
let peer = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0);
ping_cache.mock_pong(peer.id, peer.gossip, Instant::now());
let peer = CrdsValue::new_unsigned(CrdsData::ContactInfo(peer));
let peer = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(peer));
assert_eq!(
crds.insert(peer.clone(), now, GossipRoute::LocalMessage),
Ok(())
@ -842,10 +840,9 @@ mod tests {
&SocketAddrSpace::Unspecified,
);
let new_msg = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
)));
let new_msg = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0),
));
let mut expected = HashMap::new();
expected.insert(peer.label().pubkey(), vec![new_msg.clone()]);
let origin = new_msg.pubkey();
@ -869,7 +866,7 @@ mod tests {
let mut peer = ContactInfo::new_rand(&mut rng, /*pubkey=*/ None);
peer.wallclock = wallclock;
ping_cache.mock_pong(peer.id, peer.gossip, Instant::now());
CrdsValue::new_unsigned(CrdsData::ContactInfo(peer))
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(peer))
})
.collect();
let origin: Vec<_> = peers.iter().map(|node| node.pubkey()).collect();
@ -919,10 +916,9 @@ mod tests {
let mut crds = Crds::default();
let self_id = solana_sdk::pubkey::new_rand();
let push = CrdsGossipPush::default();
let peer = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
)));
let peer = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0),
));
assert_eq!(
crds.insert(peer.clone(), 0, GossipRoute::LocalMessage),
Ok(())
@ -942,10 +938,9 @@ mod tests {
&SocketAddrSpace::Unspecified,
);
let new_msg = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
)));
let new_msg = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0),
));
let expected = HashMap::new();
let origin = new_msg.pubkey();
assert_eq!(
@ -963,10 +958,9 @@ mod tests {
fn test_purge_old_pending_push_messages() {
let mut crds = Crds::default();
let push = CrdsGossipPush::default();
let peer = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&solana_sdk::pubkey::new_rand(),
0,
)));
let peer = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0),
));
assert_eq!(crds.insert(peer, 0, GossipRoute::LocalMessage), Ok(()));
let crds = RwLock::new(crds);
let ping_cache = Mutex::new(new_ping_cache());
@ -985,7 +979,7 @@ mod tests {
let mut ci = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0);
ci.wallclock = 1;
let new_msg = CrdsValue::new_unsigned(CrdsData::ContactInfo(ci));
let new_msg = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci));
let expected = HashMap::new();
let origin = new_msg.pubkey();
assert_eq!(
@ -1001,7 +995,7 @@ mod tests {
let push = CrdsGossipPush::default();
let mut ci = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0);
ci.wallclock = 0;
let value = CrdsValue::new_unsigned(CrdsData::ContactInfo(ci));
let value = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci));
let label = value.label();
// push a new message
assert_eq!(

View File

@ -1,10 +1,10 @@
use {
crate::{
cluster_info::MAX_SNAPSHOT_HASHES,
contact_info::ContactInfo,
deprecated,
duplicate_shred::{DuplicateShred, DuplicateShredIndex, MAX_DUPLICATE_SHREDS},
epoch_slots::EpochSlots,
legacy_contact_info::LegacyContactInfo,
},
bincode::{serialize, serialized_size},
rand::{CryptoRng, Rng},
@ -81,7 +81,7 @@ impl Signable for CrdsValue {
#[allow(clippy::large_enum_variant)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample, AbiEnumVisitor)]
pub enum CrdsData {
ContactInfo(ContactInfo),
LegacyContactInfo(LegacyContactInfo),
Vote(VoteIndex, Vote),
LowestSlot(/*DEPRECATED:*/ u8, LowestSlot),
SnapshotHashes(SnapshotHashes),
@ -97,7 +97,7 @@ pub enum CrdsData {
impl Sanitize for CrdsData {
fn sanitize(&self) -> Result<(), SanitizeError> {
match self {
CrdsData::ContactInfo(val) => val.sanitize(),
CrdsData::LegacyContactInfo(val) => val.sanitize(),
CrdsData::Vote(ix, val) => {
if *ix >= MAX_VOTES {
return Err(SanitizeError::ValueOutOfBounds);
@ -147,7 +147,7 @@ impl CrdsData {
// TODO: Assign ranges to each arm proportional to their frequency in
// the mainnet crds table.
match kind {
0 => CrdsData::ContactInfo(ContactInfo::new_rand(rng, pubkey)),
0 => CrdsData::LegacyContactInfo(LegacyContactInfo::new_rand(rng, pubkey)),
// Index for LowestSlot is deprecated and should be zero.
1 => CrdsData::LowestSlot(0, LowestSlot::new_rand(rng, pubkey)),
2 => CrdsData::SnapshotHashes(SnapshotHashes::new_rand(rng, pubkey)),
@ -481,7 +481,7 @@ impl Sanitize for NodeInstance {
/// These are labels for values in a record that is associated with `Pubkey`
#[derive(PartialEq, Hash, Eq, Clone, Debug)]
pub enum CrdsValueLabel {
ContactInfo(Pubkey),
LegacyContactInfo(Pubkey),
Vote(VoteIndex, Pubkey),
LowestSlot(Pubkey),
SnapshotHashes(Pubkey),
@ -497,7 +497,9 @@ pub enum CrdsValueLabel {
impl fmt::Display for CrdsValueLabel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CrdsValueLabel::ContactInfo(_) => write!(f, "ContactInfo({})", self.pubkey()),
CrdsValueLabel::LegacyContactInfo(_) => {
write!(f, "LegacyContactInfo({})", self.pubkey())
}
CrdsValueLabel::Vote(ix, _) => write!(f, "Vote({}, {})", ix, self.pubkey()),
CrdsValueLabel::LowestSlot(_) => write!(f, "LowestSlot({})", self.pubkey()),
CrdsValueLabel::SnapshotHashes(_) => write!(f, "SnapshotHashes({})", self.pubkey()),
@ -517,7 +519,7 @@ impl fmt::Display for CrdsValueLabel {
impl CrdsValueLabel {
pub fn pubkey(&self) -> Pubkey {
match self {
CrdsValueLabel::ContactInfo(p) => *p,
CrdsValueLabel::LegacyContactInfo(p) => *p,
CrdsValueLabel::Vote(_, p) => *p,
CrdsValueLabel::LowestSlot(p) => *p,
CrdsValueLabel::SnapshotHashes(p) => *p,
@ -566,7 +568,7 @@ impl CrdsValue {
/// This is used to time out push messages.
pub fn wallclock(&self) -> u64 {
match &self.data {
CrdsData::ContactInfo(contact_info) => contact_info.wallclock,
CrdsData::LegacyContactInfo(contact_info) => contact_info.wallclock,
CrdsData::Vote(_, vote) => vote.wallclock,
CrdsData::LowestSlot(_, obj) => obj.wallclock,
CrdsData::SnapshotHashes(hash) => hash.wallclock,
@ -581,7 +583,7 @@ impl CrdsValue {
}
pub fn pubkey(&self) -> Pubkey {
match &self.data {
CrdsData::ContactInfo(contact_info) => contact_info.id,
CrdsData::LegacyContactInfo(contact_info) => contact_info.id,
CrdsData::Vote(_, vote) => vote.from,
CrdsData::LowestSlot(_, slots) => slots.from,
CrdsData::SnapshotHashes(hash) => hash.from,
@ -596,7 +598,7 @@ impl CrdsValue {
}
pub fn label(&self) -> CrdsValueLabel {
match &self.data {
CrdsData::ContactInfo(_) => CrdsValueLabel::ContactInfo(self.pubkey()),
CrdsData::LegacyContactInfo(_) => CrdsValueLabel::LegacyContactInfo(self.pubkey()),
CrdsData::Vote(ix, _) => CrdsValueLabel::Vote(*ix, self.pubkey()),
CrdsData::LowestSlot(_, _) => CrdsValueLabel::LowestSlot(self.pubkey()),
CrdsData::SnapshotHashes(_) => CrdsValueLabel::SnapshotHashes(self.pubkey()),
@ -611,9 +613,9 @@ impl CrdsValue {
}
}
}
pub fn contact_info(&self) -> Option<&ContactInfo> {
pub fn contact_info(&self) -> Option<&LegacyContactInfo> {
match &self.data {
CrdsData::ContactInfo(contact_info) => Some(contact_info),
CrdsData::LegacyContactInfo(contact_info) => Some(contact_info),
_ => None,
}
}
@ -683,7 +685,6 @@ pub(crate) fn sanitize_wallclock(wallclock: u64) -> Result<(), SanitizeError> {
mod test {
use {
super::*,
crate::contact_info::ContactInfo,
bincode::{deserialize, Options},
rand::SeedableRng,
rand_chacha::ChaChaRng,
@ -699,10 +700,10 @@ mod test {
#[test]
fn test_keys_and_values() {
let mut rng = rand::thread_rng();
let v = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::default()));
let v = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(LegacyContactInfo::default()));
assert_eq!(v.wallclock(), 0);
let key = v.contact_info().unwrap().id;
assert_eq!(v.label(), CrdsValueLabel::ContactInfo(key));
assert_eq!(v.label(), CrdsValueLabel::LegacyContactInfo(key));
let v = Vote::new(Pubkey::default(), new_test_vote_tx(&mut rng), 0).unwrap();
let v = CrdsValue::new_unsigned(CrdsData::Vote(0, v));
@ -756,10 +757,9 @@ mod test {
let mut rng = rand::thread_rng();
let keypair = Keypair::new();
let wrong_keypair = Keypair::new();
let mut v = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost(
&keypair.pubkey(),
timestamp(),
)));
let mut v = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
LegacyContactInfo::new_localhost(&keypair.pubkey(), timestamp()),
));
verify_signatures(&mut v, &keypair, &wrong_keypair);
let v = Vote::new(keypair.pubkey(), new_test_vote_tx(&mut rng), timestamp()).unwrap();
let mut v = CrdsValue::new_unsigned(CrdsData::Vote(0, v));
@ -1035,8 +1035,8 @@ mod test {
assert_eq!(node.overrides(&other_crds), None);
assert_eq!(other.overrides(&node_crds), None);
// Differnt crds value is not a duplicate.
let other = ContactInfo::new_rand(&mut rng, Some(pubkey));
let other = CrdsValue::new_unsigned(CrdsData::ContactInfo(other));
let other = LegacyContactInfo::new_rand(&mut rng, Some(pubkey));
let other = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(other));
assert!(!node.check_duplicate(&other));
assert_eq!(node.overrides(&other), None);
}
@ -1045,13 +1045,10 @@ mod test {
fn test_should_force_push() {
let mut rng = rand::thread_rng();
let pubkey = Pubkey::new_unique();
assert!(
!CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_rand(
&mut rng,
Some(pubkey),
)))
.should_force_push(&pubkey)
);
assert!(!CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
LegacyContactInfo::new_rand(&mut rng, Some(pubkey))
))
.should_force_push(&pubkey));
let node = CrdsValue::new_unsigned(CrdsData::NodeInstance(NodeInstance::new(
&mut rng,
pubkey,

View File

@ -1,7 +1,7 @@
//! The `gossip_service` module implements the network control plane.
use {
crate::{cluster_info::ClusterInfo, contact_info::ContactInfo},
crate::{cluster_info::ClusterInfo, legacy_contact_info::LegacyContactInfo as ContactInfo},
crossbeam_channel::{unbounded, Sender},
rand::{thread_rng, Rng},
solana_client::{connection_cache::ConnectionCache, thin_client::ThinClient},

View File

@ -15,7 +15,7 @@ use {
#[derive(
Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, AbiExample, Deserialize, Serialize,
)]
pub struct ContactInfo {
pub struct LegacyContactInfo {
pub id: Pubkey,
/// gossip address
pub gossip: SocketAddr,
@ -43,7 +43,7 @@ pub struct ContactInfo {
pub shred_version: u16,
}
impl Sanitize for ContactInfo {
impl Sanitize for LegacyContactInfo {
fn sanitize(&self) -> std::result::Result<(), SanitizeError> {
if self.wallclock >= MAX_WALLCLOCK {
return Err(SanitizeError::ValueOutOfBounds);
@ -68,9 +68,9 @@ macro_rules! socketaddr_any {
};
}
impl Default for ContactInfo {
impl Default for LegacyContactInfo {
fn default() -> Self {
ContactInfo {
LegacyContactInfo {
id: Pubkey::default(),
gossip: socketaddr_any!(),
tvu: socketaddr_any!(),
@ -88,7 +88,7 @@ impl Default for ContactInfo {
}
}
impl ContactInfo {
impl LegacyContactInfo {
pub fn new_localhost(id: &Pubkey, now: u64) -> Self {
Self {
id: *id,
@ -107,18 +107,18 @@ impl ContactInfo {
}
}
/// New random ContactInfo for tests and simulations.
/// New random LegacyContactInfo for tests and simulations.
pub fn new_rand<R: rand::Rng>(rng: &mut R, pubkey: Option<Pubkey>) -> Self {
let delay = 10 * 60 * 1000; // 10 minutes
let now = timestamp() - delay + rng.gen_range(0, 2 * delay);
let pubkey = pubkey.unwrap_or_else(solana_sdk::pubkey::new_rand);
let mut node = ContactInfo::new_localhost(&pubkey, now);
let mut node = LegacyContactInfo::new_localhost(&pubkey, now);
node.gossip.set_port(rng.gen_range(1024, u16::MAX));
node
}
#[cfg(test)]
/// ContactInfo with multicast addresses for adversarial testing.
/// LegacyContactInfo with multicast addresses for adversarial testing.
pub fn new_multicast() -> Self {
let addr = socketaddr!("224.0.1.255:1000");
assert!(addr.ip().is_multicast());
@ -180,13 +180,13 @@ impl ContactInfo {
Self::new_with_pubkey_socketaddr(&keypair.pubkey(), bind_addr)
}
// Construct a ContactInfo that's only usable for gossip
// Construct a LegacyContactInfo that's only usable for gossip
pub fn new_gossip_entry_point(gossip_addr: &SocketAddr) -> Self {
Self {
id: Pubkey::default(),
gossip: *gossip_addr,
wallclock: timestamp(),
..ContactInfo::default()
..LegacyContactInfo::default()
}
}
@ -219,8 +219,8 @@ impl ContactInfo {
&self,
socket_addr_space: &SocketAddrSpace,
) -> Option<(SocketAddr, SocketAddr)> {
if ContactInfo::is_valid_address(&self.rpc, socket_addr_space)
&& ContactInfo::is_valid_address(&self.tpu, socket_addr_space)
if LegacyContactInfo::is_valid_address(&self.rpc, socket_addr_space)
&& LegacyContactInfo::is_valid_address(&self.tpu, socket_addr_space)
{
Some((self.rpc, self.tpu))
} else {
@ -236,31 +236,31 @@ mod tests {
#[test]
fn test_is_valid_address() {
let bad_address_port = socketaddr!("127.0.0.1:0");
assert!(!ContactInfo::is_valid_address(
assert!(!LegacyContactInfo::is_valid_address(
&bad_address_port,
&SocketAddrSpace::Unspecified
));
let bad_address_unspecified = socketaddr!(0, 1234);
assert!(!ContactInfo::is_valid_address(
assert!(!LegacyContactInfo::is_valid_address(
&bad_address_unspecified,
&SocketAddrSpace::Unspecified
));
let bad_address_multicast = socketaddr!([224, 254, 0, 0], 1234);
assert!(!ContactInfo::is_valid_address(
assert!(!LegacyContactInfo::is_valid_address(
&bad_address_multicast,
&SocketAddrSpace::Unspecified
));
let loopback = socketaddr!("127.0.0.1:1234");
assert!(ContactInfo::is_valid_address(
assert!(LegacyContactInfo::is_valid_address(
&loopback,
&SocketAddrSpace::Unspecified
));
// assert!(!ContactInfo::is_valid_ip_internal(loopback.ip(), false));
// assert!(!LegacyContactInfo::is_valid_ip_internal(loopback.ip(), false));
}
#[test]
fn test_default() {
let ci = ContactInfo::default();
let ci = LegacyContactInfo::default();
assert!(ci.gossip.ip().is_unspecified());
assert!(ci.tvu.ip().is_unspecified());
assert!(ci.tpu_forwards.ip().is_unspecified());
@ -272,7 +272,7 @@ mod tests {
}
#[test]
fn test_multicast() {
let ci = ContactInfo::new_multicast();
let ci = LegacyContactInfo::new_multicast();
assert!(ci.gossip.ip().is_multicast());
assert!(ci.tvu.ip().is_multicast());
assert!(ci.tpu_forwards.ip().is_multicast());
@ -285,7 +285,7 @@ mod tests {
#[test]
fn test_entry_point() {
let addr = socketaddr!("127.0.0.1:10");
let ci = ContactInfo::new_gossip_entry_point(&addr);
let ci = LegacyContactInfo::new_gossip_entry_point(&addr);
assert_eq!(ci.gossip, addr);
assert!(ci.tvu.ip().is_unspecified());
assert!(ci.tpu_forwards.ip().is_unspecified());
@ -298,7 +298,7 @@ mod tests {
#[test]
fn test_socketaddr() {
let addr = socketaddr!("127.0.0.1:10");
let ci = ContactInfo::new_with_socketaddr(&addr);
let ci = LegacyContactInfo::new_with_socketaddr(&addr);
assert_eq!(ci.tpu, addr);
assert_eq!(ci.tpu_vote.port(), 17);
assert_eq!(ci.gossip.port(), 11);
@ -312,7 +312,7 @@ mod tests {
#[test]
fn replayed_data_new_with_socketaddr_with_pubkey() {
let keypair = Keypair::new();
let d1 = ContactInfo::new_with_pubkey_socketaddr(
let d1 = LegacyContactInfo::new_with_pubkey_socketaddr(
&keypair.pubkey(),
&socketaddr!("127.0.0.1:1234"),
);
@ -337,7 +337,7 @@ mod tests {
#[test]
fn test_valid_client_facing() {
let mut ci = ContactInfo::default();
let mut ci = LegacyContactInfo::default();
assert_eq!(
ci.valid_client_facing_addr(&SocketAddrSpace::Unspecified),
None
@ -355,7 +355,7 @@ mod tests {
#[test]
fn test_sanitize() {
let mut ci = ContactInfo::default();
let mut ci = LegacyContactInfo::default();
assert_eq!(ci.sanitize(), Ok(()));
ci.wallclock = MAX_WALLCLOCK;
assert_eq!(ci.sanitize(), Err(SanitizeError::ValueOutOfBounds));

View File

@ -3,8 +3,6 @@
pub mod cluster_info;
pub mod cluster_info_metrics;
#[macro_use]
pub mod contact_info;
pub mod crds;
pub mod crds_entry;
pub mod crds_gossip;
@ -18,6 +16,8 @@ pub mod duplicate_shred;
pub mod epoch_slots;
pub mod gossip_error;
pub mod gossip_service;
#[macro_use]
pub mod legacy_contact_info;
pub mod ping_pong;
mod received_cache;
pub mod weighted_shuffle;

View File

@ -9,7 +9,9 @@ use {
input_parsers::keypair_of,
input_validators::{is_keypair_or_ask_keyword, is_port, is_pubkey},
},
solana_gossip::{contact_info::ContactInfo, gossip_service::discover},
solana_gossip::{
gossip_service::discover, legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_sdk::pubkey::Pubkey,
solana_streamer::socket::SocketAddrSpace,
std::{

View File

@ -8,7 +8,7 @@ use {
serial_test::serial,
solana_gossip::{
cluster_info::{compute_retransmit_peers, ClusterInfo},
contact_info::ContactInfo,
legacy_contact_info::LegacyContactInfo as ContactInfo,
weighted_shuffle::WeightedShuffle,
},
solana_sdk::{pubkey::Pubkey, signer::keypair::Keypair},

View File

@ -7,13 +7,13 @@ use {
solana_gossip::{
cluster_info,
cluster_info_metrics::GossipStats,
contact_info::ContactInfo,
crds::GossipRoute,
crds_gossip::*,
crds_gossip_error::CrdsGossipError,
crds_gossip_pull::{ProcessPullStats, CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS},
crds_gossip_push::CRDS_GOSSIP_PUSH_MSG_TIMEOUT_MS,
crds_value::{CrdsData, CrdsValue, CrdsValueLabel},
legacy_contact_info::LegacyContactInfo as ContactInfo,
ping_pong::PingCache,
},
solana_rayon_threadlimit::get_thread_count,
@ -98,12 +98,12 @@ fn stakes(network: &Network) -> HashMap<Pubkey, u64> {
fn star_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_unsigned(CrdsData::LegacyContactInfo(contact_info.clone()));
let mut network: HashMap<_, _> = (1..num)
.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_unsigned(CrdsData::LegacyContactInfo(contact_info.clone()));
let node = CrdsGossip::default();
{
let mut node_crds = node.crds.write().unwrap();
@ -133,7 +133,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_unsigned(CrdsData::LegacyContactInfo(contact_info.clone()));
let origin = CrdsGossip::default();
let id = entry.label().pubkey();
origin
@ -146,7 +146,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_unsigned(CrdsData::LegacyContactInfo(contact_info.clone()));
let node = CrdsGossip::default();
node.crds
.write()
@ -173,7 +173,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_unsigned(CrdsData::LegacyContactInfo(contact_info.clone()));
let node = CrdsGossip::default();
node.crds
.write()
@ -189,7 +189,7 @@ fn ring_network_create(num: usize) -> Network {
let start_info = {
let start = &network[&keys[k]];
let start_id = keys[k];
let label = CrdsValueLabel::ContactInfo(start_id);
let label = CrdsValueLabel::LegacyContactInfo(start_id);
let gossip_crds = start.gossip.crds.read().unwrap();
gossip_crds.get::<&CrdsValue>(&label).unwrap().clone()
};
@ -208,7 +208,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_unsigned(CrdsData::LegacyContactInfo(contact_info.clone()));
let node = CrdsGossip::default();
node.crds
.write()
@ -225,7 +225,7 @@ fn connected_staked_network_create(stakes: &[u64]) -> Network {
.iter()
.map(|k| {
let start = &network[k];
let start_label = CrdsValueLabel::ContactInfo(*k);
let start_label = CrdsValueLabel::LegacyContactInfo(*k);
let gossip_crds = start.gossip.crds.read().unwrap();
gossip_crds.get::<&CrdsValue>(&start_label).unwrap().clone()
})
@ -292,7 +292,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_unsigned(CrdsData::LegacyContactInfo(m))],
)],
now,
);
@ -508,7 +508,7 @@ fn network_run_pull(
)
.unwrap_or_default();
let from_pubkey = from.keypair.pubkey();
let label = CrdsValueLabel::ContactInfo(from_pubkey);
let label = CrdsValueLabel::LegacyContactInfo(from_pubkey);
let gossip_crds = from.gossip.crds.read().unwrap();
let self_info = gossip_crds.get::<&CrdsValue>(&label).unwrap().clone();
requests
@ -734,7 +734,7 @@ fn test_prune_errors() {
.write()
.unwrap()
.insert(
CrdsValue::new_unsigned(CrdsData::ContactInfo(ci.clone())),
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci.clone())),
0,
GossipRoute::LocalMessage,
)

View File

@ -6,9 +6,9 @@ use {
rayon::iter::*,
solana_gossip::{
cluster_info::{ClusterInfo, Node},
contact_info::ContactInfo,
crds::Cursor,
gossip_service::GossipService,
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_perf::packet::Packet,
solana_runtime::bank_forks::BankForks,

View File

@ -1,7 +1,7 @@
use {
solana_client::thin_client::ThinClient,
solana_core::validator::{Validator, ValidatorConfig},
solana_gossip::{cluster_info::Node, contact_info::ContactInfo},
solana_gossip::{cluster_info::Node, legacy_contact_info::LegacyContactInfo as ContactInfo},
solana_sdk::{pubkey::Pubkey, signature::Keypair},
solana_streamer::socket::SocketAddrSpace,
std::{path::PathBuf, sync::Arc},

View File

@ -11,10 +11,10 @@ use {
solana_entry::entry::{Entry, EntrySlice},
solana_gossip::{
cluster_info,
contact_info::ContactInfo,
crds_value::{self, CrdsData, CrdsValue},
gossip_error::GossipError,
gossip_service::discover_cluster,
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::blockstore::Blockstore,
solana_sdk::{

View File

@ -12,7 +12,8 @@ use {
validator::{Validator, ValidatorConfig, ValidatorStartProgress},
},
solana_gossip::{
cluster_info::Node, contact_info::ContactInfo, gossip_service::discover_cluster,
cluster_info::Node, gossip_service::discover_cluster,
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::create_new_tmp_ledger,
solana_runtime::{

View File

@ -59,7 +59,7 @@ impl TpuInfo for ClusterTpuInfo {
mod test {
use {
super::*,
solana_gossip::contact_info::ContactInfo,
solana_gossip::legacy_contact_info::LegacyContactInfo as ContactInfo,
solana_ledger::{
blockstore::Blockstore, get_tmp_ledger_path, leader_schedule_cache::LeaderScheduleCache,
},

View File

@ -16,7 +16,9 @@ use {
solana_client::connection_cache::ConnectionCache,
solana_entry::entry::Entry,
solana_faucet::faucet::request_airdrop_transaction,
solana_gossip::{cluster_info::ClusterInfo, contact_info::ContactInfo},
solana_gossip::{
cluster_info::ClusterInfo, legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::{
blockstore::{Blockstore, SignatureInfosForAddress},
blockstore_db::BlockstoreError,
@ -4597,7 +4599,7 @@ pub mod tests {
serde::de::DeserializeOwned,
solana_address_lookup_table_program::state::{AddressLookupTable, LookupTableMeta},
solana_entry::entry::next_versioned_entry,
solana_gossip::{contact_info::ContactInfo, socketaddr},
solana_gossip::socketaddr,
solana_ledger::{
blockstore_meta::PerfSample,
blockstore_processor::fill_blockstore_slot_with_ticks,

View File

@ -129,8 +129,8 @@ impl RpcHealth {
#[cfg(test)]
pub(crate) fn stub() -> Arc<Self> {
use {
solana_gossip::contact_info::ContactInfo, solana_sdk::signer::keypair::Keypair,
solana_streamer::socket::SocketAddrSpace,
solana_gossip::legacy_contact_info::LegacyContactInfo as ContactInfo,
solana_sdk::signer::keypair::Keypair, solana_streamer::socket::SocketAddrSpace,
};
Arc::new(Self::new(
Arc::new(ClusterInfo::new(

View File

@ -575,9 +575,9 @@ mod tests {
super::*,
crate::rpc::create_validator_exit,
solana_gossip::{
contact_info::ContactInfo,
crds::GossipRoute,
crds_value::{CrdsData, CrdsValue, SnapshotHashes},
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_ledger::{
genesis_utils::{create_genesis_config, GenesisConfigInfo},

View File

@ -9,7 +9,9 @@ use {
solana_core::{
consensus::Tower, tower_storage::TowerStorage, validator::ValidatorStartProgress,
},
solana_gossip::{cluster_info::ClusterInfo, contact_info::ContactInfo},
solana_gossip::{
cluster_info::ClusterInfo, legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_rpc::rpc::verify_pubkey,
solana_rpc_client_api::{config::RpcAccountIndex, custom_error::RpcCustomError},
solana_runtime::{accounts_index::AccountIndex, bank_forks::BankForks},

View File

@ -7,9 +7,9 @@ use {
solana_genesis_utils::download_then_check_genesis_hash,
solana_gossip::{
cluster_info::{ClusterInfo, Node},
contact_info::ContactInfo,
crds_value,
gossip_service::GossipService,
legacy_contact_info::LegacyContactInfo as ContactInfo,
},
solana_rpc_client::rpc_client::RpcClient,
solana_runtime::{

View File

@ -14,7 +14,7 @@ use {
tpu::DEFAULT_TPU_COALESCE_MS,
validator::{is_snapshot_config_valid, Validator, ValidatorConfig, ValidatorStartProgress},
},
solana_gossip::{cluster_info::Node, contact_info::ContactInfo},
solana_gossip::{cluster_info::Node, legacy_contact_info::LegacyContactInfo as ContactInfo},
solana_ledger::blockstore_options::{
BlockstoreCompressionType, BlockstoreRecoveryMode, LedgerColumnOptions, ShredStorageType,
},