Skip to content

Commit

Permalink
adds extensions to contact-info (solana-labs#32309)
Browse files Browse the repository at this point in the history
The commit adds a Vec<Extension> to ContactInfo so that future additions
to ContactInfo can be done by only adding new Extensions instead of
modifying the entire ContactInfo.
  • Loading branch information
behzadnouri authored Aug 9, 2023
1 parent 6ff3908 commit b06500e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 29 additions & 1 deletion gossip/src/contact_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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<SocketEntry>,
#[serde(with = "short_vec")]
extensions: Vec<Extension>,
#[serde(skip_serializing)]
cache: [SocketAddr; SOCKET_CACHE_SIZE],
}
Expand All @@ -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.
Expand All @@ -110,6 +115,8 @@ struct ContactInfoLite {
addrs: Vec<IpAddr>,
#[serde(with = "short_vec")]
sockets: Vec<SocketEntry>,
#[serde(with = "short_vec")]
extensions: Vec<Extension>,
}

macro_rules! get_socket {
Expand Down Expand Up @@ -183,6 +190,7 @@ impl ContactInfo {
version: solana_version::Version::default(),
addrs: Vec::<IpAddr>::default(),
sockets: Vec::<SocketEntry>::default(),
extensions: Vec::<Extension>::default(),
cache: [SOCKET_ADDR_UNSPECIFIED; SOCKET_CACHE_SIZE],
}
}
Expand Down Expand Up @@ -415,6 +423,7 @@ impl TryFrom<ContactInfoLite> for ContactInfo {
version,
addrs,
sockets,
extensions,
} = node;
sanitize_entries(&addrs, &sockets)?;
let mut node = ContactInfo {
Expand All @@ -425,6 +434,7 @@ impl TryFrom<ContactInfoLite> for ContactInfo {
version,
addrs,
sockets,
extensions,
cache: [SOCKET_ADDR_UNSPECIFIED; SOCKET_CACHE_SIZE],
};
// Populate node.cache.
Expand Down Expand Up @@ -540,6 +550,23 @@ pub(crate) fn get_quic_socket(socket: &SocketAddr) -> Result<SocketAddr, Error>
))
}

#[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::<IpAddr>::example(),
sockets: Vec::<SocketEntry>::example(),
extensions: vec![],
cache: <[SocketAddr; SOCKET_CACHE_SIZE]>::example(),
}
}
}

#[cfg(test)]
mod tests {
use {
Expand Down Expand Up @@ -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::<u8, SocketAddr>::new();
Expand Down

0 comments on commit b06500e

Please sign in to comment.