Add CrdsData::IncrementalSnapshotHashes (backport #20374) (#20983)

* Add CrdsData::IncrementalSnapshotHashes (#20374)

(cherry picked from commit 4e3818e5c1)

# Conflicts:
#	gossip/src/cluster_info.rs

* removes backport merge conflicts

Co-authored-by: Brooks Prumo <brooks@solana.com>
Co-authored-by: behzad nouri <behzadnouri@gmail.com>
This commit is contained in:
mergify[bot]
2021-10-26 17:24:39 +00:00
committed by GitHub
parent 5f86735382
commit b216e3c9f7
2 changed files with 41 additions and 2 deletions

View File

@ -255,7 +255,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 = "3qq56sFGXGbNqr7qKq8x47t144ugdfv5adCkVJUMnMf3")]
#[frozen_abi(digest = "D2ebKKmm6EQ8JJjYc3xUpzpBTJguqgEzShhj9fiUcP6F")]
#[derive(Serialize, Deserialize, Debug, AbiEnumVisitor, AbiExample)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum Protocol {
@ -372,7 +372,7 @@ fn retain_staked(values: &mut Vec<CrdsValue>, stakes: &HashMap<Pubkey, u64>) {
// Unstaked nodes can still help repair.
CrdsData::EpochSlots(_, _) => true,
// Unstaked nodes can still serve snapshots.
CrdsData::SnapshotHashes(_) => true,
CrdsData::SnapshotHashes(_) | CrdsData::IncrementalSnapshotHashes(_) => true,
// Otherwise unstaked voting nodes will show up with no version in
// the various dashboards.
CrdsData::Version(_) => true,

View File

@ -91,6 +91,7 @@ pub enum CrdsData {
Version(Version),
NodeInstance(NodeInstance),
DuplicateShred(DuplicateShredIndex, DuplicateShred),
IncrementalSnapshotHashes(IncrementalSnapshotHashes),
}
impl Sanitize for CrdsData {
@ -127,6 +128,7 @@ impl Sanitize for CrdsData {
shred.sanitize()
}
}
CrdsData::IncrementalSnapshotHashes(val) => val.sanitize(),
}
}
}
@ -204,6 +206,33 @@ impl SnapshotHash {
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, AbiExample)]
pub struct IncrementalSnapshotHashes {
from: Pubkey,
base: (Slot, Hash),
hashes: Vec<(Slot, Hash)>,
wallclock: u64,
}
impl Sanitize for IncrementalSnapshotHashes {
fn sanitize(&self) -> Result<(), SanitizeError> {
sanitize_wallclock(self.wallclock)?;
if self.base.0 >= MAX_SLOT {
return Err(SanitizeError::ValueOutOfBounds);
}
for (slot, _) in &self.hashes {
if *slot >= MAX_SLOT {
return Err(SanitizeError::ValueOutOfBounds);
}
if self.base.0 >= *slot {
return Err(SanitizeError::InvalidValue);
}
}
self.from.sanitize()
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, AbiExample)]
pub struct LowestSlot {
pub from: Pubkey,
@ -470,6 +499,7 @@ pub enum CrdsValueLabel {
Version(Pubkey),
NodeInstance(Pubkey),
DuplicateShred(DuplicateShredIndex, Pubkey),
IncrementalSnapshotHashes(Pubkey),
}
impl fmt::Display for CrdsValueLabel {
@ -485,6 +515,9 @@ impl fmt::Display for CrdsValueLabel {
CrdsValueLabel::Version(_) => write!(f, "Version({})", self.pubkey()),
CrdsValueLabel::NodeInstance(pk) => write!(f, "NodeInstance({})", pk),
CrdsValueLabel::DuplicateShred(ix, pk) => write!(f, "DuplicateShred({}, {})", ix, pk),
CrdsValueLabel::IncrementalSnapshotHashes(_) => {
write!(f, "IncrementalSnapshotHashes({})", self.pubkey())
}
}
}
}
@ -502,6 +535,7 @@ impl CrdsValueLabel {
CrdsValueLabel::Version(p) => *p,
CrdsValueLabel::NodeInstance(p) => *p,
CrdsValueLabel::DuplicateShred(_, p) => *p,
CrdsValueLabel::IncrementalSnapshotHashes(p) => *p,
}
}
}
@ -550,6 +584,7 @@ impl CrdsValue {
CrdsData::Version(version) => version.wallclock,
CrdsData::NodeInstance(node) => node.wallclock,
CrdsData::DuplicateShred(_, shred) => shred.wallclock,
CrdsData::IncrementalSnapshotHashes(hash) => hash.wallclock,
}
}
pub fn pubkey(&self) -> Pubkey {
@ -564,6 +599,7 @@ impl CrdsValue {
CrdsData::Version(version) => version.from,
CrdsData::NodeInstance(node) => node.from,
CrdsData::DuplicateShred(_, shred) => shred.from,
CrdsData::IncrementalSnapshotHashes(hash) => hash.from,
}
}
pub fn label(&self) -> CrdsValueLabel {
@ -578,6 +614,9 @@ impl CrdsValue {
CrdsData::Version(_) => CrdsValueLabel::Version(self.pubkey()),
CrdsData::NodeInstance(node) => CrdsValueLabel::NodeInstance(node.from),
CrdsData::DuplicateShred(ix, shred) => CrdsValueLabel::DuplicateShred(*ix, shred.from),
CrdsData::IncrementalSnapshotHashes(_) => {
CrdsValueLabel::IncrementalSnapshotHashes(self.pubkey())
}
}
}
pub fn contact_info(&self) -> Option<&ContactInfo> {