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:
parent
6ff390802b
commit
b06500ee66
|
@ -271,7 +271,7 @@ pub fn make_accounts_hashes_message(
|
||||||
pub(crate) type Ping = ping_pong::Ping<[u8; GOSSIP_PING_TOKEN_SIZE]>;
|
pub(crate) type Ping = ping_pong::Ping<[u8; GOSSIP_PING_TOKEN_SIZE]>;
|
||||||
|
|
||||||
// TODO These messages should go through the gpu pipeline for spam filtering
|
// 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)]
|
#[derive(Serialize, Deserialize, Debug, AbiEnumVisitor, AbiExample)]
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub(crate) enum Protocol {
|
pub(crate) enum Protocol {
|
||||||
|
|
|
@ -66,7 +66,7 @@ pub enum Error {
|
||||||
UnusedIpAddr(IpAddr),
|
UnusedIpAddr(IpAddr),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, AbiExample, Serialize)]
|
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
|
||||||
pub struct ContactInfo {
|
pub struct ContactInfo {
|
||||||
pubkey: Pubkey,
|
pubkey: Pubkey,
|
||||||
#[serde(with = "serde_varint")]
|
#[serde(with = "serde_varint")]
|
||||||
|
@ -82,6 +82,8 @@ pub struct ContactInfo {
|
||||||
// All sockets have a unique key and a valid IP address index.
|
// All sockets have a unique key and a valid IP address index.
|
||||||
#[serde(with = "short_vec")]
|
#[serde(with = "short_vec")]
|
||||||
sockets: Vec<SocketEntry>,
|
sockets: Vec<SocketEntry>,
|
||||||
|
#[serde(with = "short_vec")]
|
||||||
|
extensions: Vec<Extension>,
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
cache: [SocketAddr; SOCKET_CACHE_SIZE],
|
cache: [SocketAddr; SOCKET_CACHE_SIZE],
|
||||||
}
|
}
|
||||||
|
@ -94,6 +96,9 @@ struct SocketEntry {
|
||||||
offset: u16, // Port offset with respect to the previous entry.
|
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
|
// 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
|
// verified and self.cache needs to be populated. This type serves as a
|
||||||
// workaround since serde does not have an initializer.
|
// workaround since serde does not have an initializer.
|
||||||
|
@ -110,6 +115,8 @@ struct ContactInfoLite {
|
||||||
addrs: Vec<IpAddr>,
|
addrs: Vec<IpAddr>,
|
||||||
#[serde(with = "short_vec")]
|
#[serde(with = "short_vec")]
|
||||||
sockets: Vec<SocketEntry>,
|
sockets: Vec<SocketEntry>,
|
||||||
|
#[serde(with = "short_vec")]
|
||||||
|
extensions: Vec<Extension>,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! get_socket {
|
macro_rules! get_socket {
|
||||||
|
@ -183,6 +190,7 @@ impl ContactInfo {
|
||||||
version: solana_version::Version::default(),
|
version: solana_version::Version::default(),
|
||||||
addrs: Vec::<IpAddr>::default(),
|
addrs: Vec::<IpAddr>::default(),
|
||||||
sockets: Vec::<SocketEntry>::default(),
|
sockets: Vec::<SocketEntry>::default(),
|
||||||
|
extensions: Vec::<Extension>::default(),
|
||||||
cache: [SOCKET_ADDR_UNSPECIFIED; SOCKET_CACHE_SIZE],
|
cache: [SOCKET_ADDR_UNSPECIFIED; SOCKET_CACHE_SIZE],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,6 +423,7 @@ impl TryFrom<ContactInfoLite> for ContactInfo {
|
||||||
version,
|
version,
|
||||||
addrs,
|
addrs,
|
||||||
sockets,
|
sockets,
|
||||||
|
extensions,
|
||||||
} = node;
|
} = node;
|
||||||
sanitize_entries(&addrs, &sockets)?;
|
sanitize_entries(&addrs, &sockets)?;
|
||||||
let mut node = ContactInfo {
|
let mut node = ContactInfo {
|
||||||
|
@ -425,6 +434,7 @@ impl TryFrom<ContactInfoLite> for ContactInfo {
|
||||||
version,
|
version,
|
||||||
addrs,
|
addrs,
|
||||||
sockets,
|
sockets,
|
||||||
|
extensions,
|
||||||
cache: [SOCKET_ADDR_UNSPECIFIED; SOCKET_CACHE_SIZE],
|
cache: [SOCKET_ADDR_UNSPECIFIED; SOCKET_CACHE_SIZE],
|
||||||
};
|
};
|
||||||
// Populate node.cache.
|
// 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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use {
|
use {
|
||||||
|
@ -679,6 +706,7 @@ mod tests {
|
||||||
version: solana_version::Version::default(),
|
version: solana_version::Version::default(),
|
||||||
addrs: Vec::default(),
|
addrs: Vec::default(),
|
||||||
sockets: Vec::default(),
|
sockets: Vec::default(),
|
||||||
|
extensions: Vec::default(),
|
||||||
cache: [SOCKET_ADDR_UNSPECIFIED; SOCKET_CACHE_SIZE],
|
cache: [SOCKET_ADDR_UNSPECIFIED; SOCKET_CACHE_SIZE],
|
||||||
};
|
};
|
||||||
let mut sockets = HashMap::<u8, SocketAddr>::new();
|
let mut sockets = HashMap::<u8, SocketAddr>::new();
|
||||||
|
|
Loading…
Reference in New Issue