Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Report new received crds signatures and their respective origins to metrics #32504

Merged
merged 28 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
84ac269
screwed up old branch and syncing with upstream branch
Jul 11, 2023
c23e5c0
add fixed size ring buff instead of variable sized vecdeque for repor…
Jul 12, 2023
6166f59
modify difficulty to take in n 0 bits and check if signature ending e…
Jul 14, 2023
5116f36
update to only push every 18 trailing zero bits. and clean up
Jul 14, 2023
b81f7c3
report origin with signature. and set trailing 0s to 8 for local testing
Jul 14, 2023
27a899d
change back to 18 trailing zeros and rm unused imports
Jul 14, 2023
2d4d251
run cargo rmt
Jul 14, 2023
13aad24
run ./scripts/cargo-for-all-lock-files.sh tree
Jul 14, 2023
3360748
allow integer arithmetic for bit comparison
Jul 14, 2023
c09b643
rm unused lifetime
Jul 14, 2023
66a7336
rm duplicate entry?
Jul 14, 2023
d2ef0d0
re implement ring buf
Jul 14, 2023
15956f0
put ringbuf in sorted order
Jul 14, 2023
0908dc3
ringbuf in cargo.toml now in sorted order
Jul 15, 2023
65bcb06
Merge branch 'master' into coverage-reporting-v2
Jul 15, 2023
4e15905
rm ring buf, refactor, fix trailing zero bug
Jul 17, 2023
b505537
fix bug in trailing zeros. was comparing wrong ones
Jul 17, 2023
0b0d90f
fix needless range loop bug
Jul 17, 2023
8603569
fix bug
Jul 17, 2023
886f39e
change trailing zero checking to build in methods and only report fir…
Jul 18, 2023
5068f9d
report full origin string and first 8 bytes of signature
Jul 18, 2023
1550d26
set SIGNATURE_SAMPLE_TRAILING_ZEROS back to 18
Jul 18, 2023
4613833
forgot to run cargo tree
Jul 18, 2023
9e2e843
avoid panic and change working
Jul 19, 2023
f94afc8
rm bs58
Jul 19, 2023
616326b
pass in Option<String> into datapoint_info
Jul 19, 2023
61151c1
shorten metric names
Jul 19, 2023
da2db53
Merge branch 'master' into coverage-reporting-v2
Jul 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ rayon = "1.7.0"
rcgen = "0.10.0"
reed-solomon-erasure = "6.0.0"
regex = "1.9.1"
ringbuf = "0.3.3"
rolling-file = "0.2.0"
reqwest = { version = "0.11.17", default-features = false }
rpassword = "7.2"
Expand Down
1 change: 1 addition & 0 deletions gossip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ num-traits = { workspace = true }
rand = { workspace = true }
rand_chacha = { workspace = true }
rayon = { workspace = true }
ringbuf = { workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
serde_derive = { workspace = true }
Expand Down
32 changes: 30 additions & 2 deletions gossip/src/cluster_info_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use {
crate::crds_gossip::CrdsGossip,
itertools::Itertools,
ringbuf::{HeapRb, Rb},
solana_measure::measure::Measure,
solana_sdk::{clock::Slot, pubkey::Pubkey},
solana_sdk::{clock::Slot, pubkey::Pubkey, signature::Signature},
std::{
cmp::Reverse,
collections::HashMap,
Expand Down Expand Up @@ -189,7 +190,14 @@ pub(crate) fn submit_gossip_stats(
gossip: &CrdsGossip,
stakes: &HashMap<Pubkey, u64>,
) {
let (crds_stats, table_size, num_nodes, num_pubkeys, purged_values_size, failed_inserts_size) = {
let (
mut crds_stats,
table_size,
num_nodes,
num_pubkeys,
purged_values_size,
failed_inserts_size,
) = {
let gossip_crds = gossip.crds.read().unwrap();
(
gossip_crds.take_stats(),
Expand Down Expand Up @@ -675,6 +683,12 @@ pub(crate) fn submit_gossip_stats(
("all-push", crds_stats.push.fails.iter().sum::<usize>(), i64),
("all-pull", crds_stats.pull.fails.iter().sum::<usize>(), i64),
);

gregcusack marked this conversation as resolved.
Show resolved Hide resolved
submit_crds_signature_stats(
"cluster_info_crds_stats_message_signatures_received",
gregcusack marked this conversation as resolved.
Show resolved Hide resolved
&mut crds_stats.push.crds_signatures,
);

if !log::log_enabled!(log::Level::Trace) {
return;
}
Expand Down Expand Up @@ -704,3 +718,17 @@ where
datapoint_trace!(name, ("slot", slot, i64), ("num_votes", num_votes, i64));
}
}

fn submit_crds_signature_stats(
name: &'static str,
crds_signatures: &mut HeapRb<(Pubkey, Signature)>,
) {
// submit all message signatures to metrics.
while let Some((origin, signature)) = crds_signatures.pop() {
datapoint_info!(
name,
("crds_origin", origin.to_string(), String),
("crds_signature", signature.to_string(), String)
);
}
}
19 changes: 19 additions & 0 deletions gossip/src/crds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ use {
lru::LruCache,
matches::debug_assert_matches,
rayon::{prelude::*, ThreadPool},
ringbuf::{HeapRb, Rb},
solana_sdk::{
clock::Slot,
hash::{hash, Hash},
pubkey::Pubkey,
signature::Signature,
},
std::{
cmp::Ordering,
Expand All @@ -56,6 +58,15 @@ use {
const CRDS_SHARDS_BITS: u32 = 12;
// Number of vote slots to track in an lru-cache for metrics.
const VOTE_SLOTS_METRICS_CAP: usize = 100;
// Number of ending zero bits for crds signature to get reported to influx
// mean new push messages received per minute per node
// testnet: ~500k,
// mainnet: ~280k
// target: 1-2 signatures reported per minute
// log2(250k) = ~17.9.
const TRAILING_ZEROS: u8 = 18;
gregcusack marked this conversation as resolved.
Show resolved Hide resolved
// size of ring buffer to store signatures for metrics
const SIGNATURE_SLOTS_METRICS_CAP: usize = 64;

pub struct Crds {
/// Stores the map of labels and values
Expand Down Expand Up @@ -101,6 +112,7 @@ pub(crate) struct CrdsDataStats {
pub(crate) counts: CrdsCountsArray,
pub(crate) fails: CrdsCountsArray,
pub(crate) votes: LruCache<Slot, /*count:*/ usize>,
pub(crate) crds_signatures: HeapRb<(Pubkey, Signature)>, // crds origin and signature
}

#[derive(Default)]
Expand Down Expand Up @@ -656,6 +668,7 @@ impl Default for CrdsDataStats {
counts: CrdsCountsArray::default(),
fails: CrdsCountsArray::default(),
votes: LruCache::new(VOTE_SLOTS_METRICS_CAP),
crds_signatures: HeapRb::<(Pubkey, Signature)>::new(SIGNATURE_SLOTS_METRICS_CAP),
}
}
}
Expand All @@ -669,6 +682,12 @@ impl CrdsDataStats {
self.votes.put(slot, num_nodes + 1);
}
}

// check trailing zero bits on signature for metrics
if entry.value.signature.last_n_bits_are_zero(TRAILING_ZEROS) {
self.crds_signatures
.push_overwrite((entry.value.pubkey(), entry.value.signature));
}
gregcusack marked this conversation as resolved.
Show resolved Hide resolved
}

fn record_fail(&mut self, entry: &VersionedCrdsValue) {
Expand Down
10 changes: 10 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions sdk/src/signature.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Functionality for public and private keys.
#![cfg(feature = "full")]
#![allow(clippy::integer_arithmetic)]

// legacy module paths
pub use crate::signer::{keypair::*, null_signer::*, presigner::*, *};
Expand Down Expand Up @@ -54,6 +55,21 @@ impl Signature {
pub fn verify(&self, pubkey_bytes: &[u8], message_bytes: &[u8]) -> bool {
self.verify_verbose(pubkey_bytes, message_bytes).is_ok()
}

pub fn last_n_bits_are_zero(&self, n: u8) -> bool {
gregcusack marked this conversation as resolved.
Show resolved Hide resolved
let signature_bytes: &[u8] = self.0.as_slice();
let num_bytes = (n as usize + 7) / 8; // Number of bytes required to represent n bits
let last_signature_byte_index = signature_bytes.len() - 1;

let mut signature_ending: u64 = 0;
for i in 0..num_bytes {
let shift = (num_bytes - i - 1) * 8;
signature_ending |= (signature_bytes[last_signature_byte_index - i] as u64) << shift;
}

// check if last n bits of signature (aka signature_ending) are all 0.
(signature_ending & ((1 << n) - 1)) == 0
}
}

pub trait Signable {
Expand Down