adds extensions to contact-info (#32309)

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.
This commit is contained in:
behzad nouri 2023-08-09 22:01:20 +00:00 committed by GitHub
parent 6ff390802b
commit b06500ee66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -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 {

View File

@ -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<SocketEntry>,
#[serde(with = "short_vec")]
extensions: Vec<Extension>,
#[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<IpAddr>,
#[serde(with = "short_vec")]
sockets: Vec<SocketEntry>,
#[serde(with = "short_vec")]
extensions: Vec<Extension>,
}
macro_rules! get_socket {
@ -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],
}
}
@ -415,6 +423,7 @@ impl TryFrom<ContactInfoLite> for ContactInfo {
version,
addrs,
sockets,
extensions,
} = node;
sanitize_entries(&addrs, &sockets)?;
let mut node = ContactInfo {
@ -425,6 +434,7 @@ impl TryFrom<ContactInfoLite> 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<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 {
@ -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();