Skip to content

Commit

Permalink
adds metrics for num merkle shreds on the receiving end
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadnouri committed Jan 14, 2023
1 parent d4ce59e commit c56a47b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 1 addition & 2 deletions core/src/shred_fetch_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use {
};

const DEFAULT_LRU_SIZE: usize = 10_000;
type ShredsReceived = LruCache<u64, ()>;

pub(crate) struct ShredFetchStage {
thread_hdls: Vec<JoinHandle<()>>,
Expand Down Expand Up @@ -229,7 +228,7 @@ fn should_discard_packet(
max_slot: Slot, // Max slot to ingest shreds for.
shred_version: u16,
packet_hasher: &PacketHasher,
shreds_received: &mut ShredsReceived,
shreds_received: &mut LruCache<u64, ()>,
stats: &mut ShredFetchStats,
) -> bool {
if should_discard_shred(packet, root, max_slot, shred_version, stats) {
Expand Down
15 changes: 12 additions & 3 deletions ledger/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,8 @@ pub fn should_discard_shred(
}
}
}
let shred_type = match layout::get_shred_type(shred) {
Ok(shred_type) => shred_type,
let shred_variant = match layout::get_shred_variant(shred) {
Ok(shred_variant) => shred_variant,
Err(_) => {
stats.bad_shred_type += 1;
return true;
Expand All @@ -939,7 +939,7 @@ pub fn should_discard_shred(
return true;
}
};
match shred_type {
match ShredType::from(shred_variant) {
ShredType::Code => {
if index >= shred_code::MAX_CODE_SHREDS_PER_SLOT as u32 {
stats.index_out_of_bounds += 1;
Expand Down Expand Up @@ -975,6 +975,15 @@ pub fn should_discard_shred(
}
}
}
match shred_variant {
ShredVariant::LegacyCode | ShredVariant::LegacyData => (),
ShredVariant::MerkleCode(_) => {
stats.num_shreds_merkle_code = stats.num_shreds_merkle_code.saturating_add(1);
}
ShredVariant::MerkleData(_) => {
stats.num_shreds_merkle_data = stats.num_shreds_merkle_data.saturating_add(1);
}
}
false
}

Expand Down
4 changes: 4 additions & 0 deletions ledger/src/shred/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct ProcessShredsStats {
pub struct ShredFetchStats {
pub index_overrun: usize,
pub shred_count: usize,
pub(crate) num_shreds_merkle_code: usize,
pub(crate) num_shreds_merkle_data: usize,
pub ping_count: usize,
pub ping_err_verify_count: usize,
pub(crate) index_bad_deserialize: usize,
Expand Down Expand Up @@ -115,6 +117,8 @@ impl ShredFetchStats {
name,
("index_overrun", self.index_overrun, i64),
("shred_count", self.shred_count, i64),
("num_shreds_merkle_code", self.num_shreds_merkle_code, i64),
("num_shreds_merkle_data", self.num_shreds_merkle_data, i64),
("ping_count", self.ping_count, i64),
("ping_err_verify_count", self.ping_err_verify_count, i64),
("slot_bad_deserialize", self.slot_bad_deserialize, i64),
Expand Down

0 comments on commit c56a47b

Please sign in to comment.