From b06500ee669a1ab1f03d8cc1a0610cb4d9ef7b64 Mon Sep 17 00:00:00 2001 From: behzad nouri Date: Wed, 9 Aug 2023 22:01:20 +0000 Subject: [PATCH] adds extensions to contact-info (#32309) The commit adds a Vec to ContactInfo so that future additions to ContactInfo can be done by only adding new Extensions instead of modifying the entire ContactInfo. --- gossip/src/cluster_info.rs | 2 +- gossip/src/contact_info.rs | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gossip/src/cluster_info.rs b/gossip/src/cluster_info.rs index e5aa91d22..52360105f 100644 --- a/gossip/src/cluster_info.rs +++ b/gossip/src/cluster_info.rs @@ -271,7 +271,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 = "3U6DqJ4X4UE1DxRP1sbwP5QtyFxexMxzjLSKXXRDrt4q")] +#[frozen_abi(digest = "9eS1agTwFQxCcCWgoBYhPfEVBfXkppan1zbob5rRRu7u")] #[derive(Serialize, Deserialize, Debug, AbiEnumVisitor, AbiExample)] #[allow(clippy::large_enum_variant)] pub(crate) enum Protocol { diff --git a/gossip/src/contact_info.rs b/gossip/src/contact_info.rs index 2162c8ac9..063838ad7 100644 --- a/gossip/src/contact_info.rs +++ b/gossip/src/contact_info.rs @@ -66,7 +66,7 @@ pub enum Error { UnusedIpAddr(IpAddr), } -#[derive(Clone, Debug, Eq, PartialEq, AbiExample, Serialize)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize)] pub struct ContactInfo { pubkey: Pubkey, #[serde(with = "serde_varint")] @@ -82,6 +82,8 @@ pub struct ContactInfo { // All sockets have a unique key and a valid IP address index. #[serde(with = "short_vec")] sockets: Vec, + #[serde(with = "short_vec")] + extensions: Vec, #[serde(skip_serializing)] cache: [SocketAddr; SOCKET_CACHE_SIZE], } @@ -94,6 +96,9 @@ struct SocketEntry { offset: u16, // Port offset with respect to the previous entry. } +#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)] +enum Extension {} + // As part of deserialization, self.addrs and self.sockets should be cross // verified and self.cache needs to be populated. This type serves as a // workaround since serde does not have an initializer. @@ -110,6 +115,8 @@ struct ContactInfoLite { addrs: Vec, #[serde(with = "short_vec")] sockets: Vec, + #[serde(with = "short_vec")] + extensions: Vec, } macro_rules! get_socket { @@ -183,6 +190,7 @@ impl ContactInfo { version: solana_version::Version::default(), addrs: Vec::::default(), sockets: Vec::::default(), + extensions: Vec::::default(), cache: [SOCKET_ADDR_UNSPECIFIED; SOCKET_CACHE_SIZE], } } @@ -415,6 +423,7 @@ impl TryFrom for ContactInfo { version, addrs, sockets, + extensions, } = node; sanitize_entries(&addrs, &sockets)?; let mut node = ContactInfo { @@ -425,6 +434,7 @@ impl TryFrom for ContactInfo { version, addrs, sockets, + extensions, cache: [SOCKET_ADDR_UNSPECIFIED; SOCKET_CACHE_SIZE], }; // Populate node.cache. @@ -540,6 +550,23 @@ pub(crate) fn get_quic_socket(socket: &SocketAddr) -> Result )) } +#[cfg(all(test, RUSTC_WITH_SPECIALIZATION))] +impl solana_frozen_abi::abi_example::AbiExample for ContactInfo { + fn example() -> Self { + Self { + pubkey: Pubkey::example(), + wallclock: u64::example(), + outset: u64::example(), + shred_version: u16::example(), + version: solana_version::Version::example(), + addrs: Vec::::example(), + sockets: Vec::::example(), + extensions: vec![], + cache: <[SocketAddr; SOCKET_CACHE_SIZE]>::example(), + } + } +} + #[cfg(test)] mod tests { use { @@ -679,6 +706,7 @@ mod tests { version: solana_version::Version::default(), addrs: Vec::default(), sockets: Vec::default(), + extensions: Vec::default(), cache: [SOCKET_ADDR_UNSPECIFIED; SOCKET_CACHE_SIZE], }; let mut sockets = HashMap::::new();