Skip to content

Commit 33a84ab

Browse files
committed
basic ideas
1 parent 566bb95 commit 33a84ab

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

Cargo.lock

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gossip/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ license = { workspace = true }
1010
edition = { workspace = true }
1111

1212
[dependencies]
13+
anyhow = { workspace = true }
1314
assert_matches = { workspace = true }
1415
bincode = { workspace = true }
1516
bv = { workspace = true, features = ["serde"] }
17+
cfg-if = { workspace = true }
1618
clap = { workspace = true }
1719
crossbeam-channel = { workspace = true }
1820
flate2 = { workspace = true }
@@ -21,13 +23,15 @@ itertools = { workspace = true }
2123
log = { workspace = true }
2224
lru = { workspace = true }
2325
num-traits = { workspace = true }
26+
pcap-file = "2.0.0"
2427
rand = { workspace = true }
2528
rand_chacha = { workspace = true }
2629
rayon = { workspace = true }
2730
serde = { workspace = true }
2831
serde-big-array = { workspace = true }
2932
serde_bytes = { workspace = true }
3033
serde_derive = { workspace = true }
34+
serde_json = { workspace = true, optional = true }
3135
siphasher = { workspace = true }
3236
solana-bloom = { workspace = true }
3337
solana-clap-utils = { workspace = true }
@@ -62,18 +66,17 @@ solana-vote = { workspace = true }
6266
solana-vote-program = { workspace = true }
6367
static_assertions = { workspace = true }
6468
thiserror = { workspace = true }
65-
6669
[dev-dependencies]
6770
bs58 = { workspace = true }
6871
criterion = { workspace = true }
6972
num_cpus = { workspace = true }
7073
rand0-7 = { workspace = true }
7174
rand_chacha0-2 = { workspace = true }
7275
serial_test = { workspace = true }
76+
solana-gossip = { workspace = true, features = ["dev-context-only-utils"] }
7377
solana-perf = { workspace = true, features = ["dev-context-only-utils"] }
7478
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
7579
test-case = { workspace = true }
76-
7780
[features]
7881
frozen-abi = [
7982
"dep:solana-frozen-abi",
@@ -88,6 +91,7 @@ frozen-abi = [
8891
"solana-vote/frozen-abi",
8992
"solana-vote-program/frozen-abi",
9093
]
94+
dev-context-only-utils = []
9195

9296
[[bench]]
9397
name = "crds"

gossip/src/crds_data.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use {
77
legacy_contact_info::LegacyContactInfo,
88
restart_crds_values::{RestartHeaviestFork, RestartLastVotedForkSlots},
99
},
10-
rand::Rng,
1110
serde::de::{Deserialize, Deserializer},
1211
solana_sanitize::{Sanitize, SanitizeError},
1312
solana_sdk::{
@@ -21,6 +20,9 @@ use {
2120
std::{cmp::Ordering, collections::BTreeSet},
2221
};
2322

23+
#[cfg(feature = "dev-context-only-utils")]
24+
use {crate::format_validation::FormatValidation, rand::Rng, std::hint::black_box};
25+
2426
pub(crate) const MAX_WALLCLOCK: u64 = 1_000_000_000_000_000;
2527
pub(crate) const MAX_SLOT: u64 = 1_000_000_000_000_000;
2628
/// Maximum number of hashes in AccountsHashes a node publishes
@@ -233,9 +235,9 @@ impl Sanitize for AccountsHashes {
233235
}
234236
}
235237

236-
impl AccountsHashes {
237-
/// New random AccountsHashes for tests and benchmarks.
238-
pub(crate) fn new_rand<R: Rng>(rng: &mut R, pubkey: Option<Pubkey>) -> Self {
238+
#[cfg(feature = "dev-context-only-utils")]
239+
impl FormatValidation for AccountsHashes {
240+
fn new_rand<R: Rng>(rng: &mut R, pubkey: Option<Pubkey>) -> Self {
239241
let num_hashes = rng.gen_range(0..MAX_ACCOUNTS_HASHES) + 1;
240242
let hashes = std::iter::repeat_with(|| {
241243
let slot = 47825632 + rng.gen_range(0..512);
@@ -250,6 +252,13 @@ impl AccountsHashes {
250252
wallclock: new_rand_timestamp(rng),
251253
}
252254
}
255+
256+
fn exercise(&self) -> anyhow::Result<()> {
257+
FormatValidation::exercise(&self)?;
258+
let s: u64 = self.hashes.iter().map(|v| v.0).sum();
259+
black_box(s);
260+
Ok(())
261+
}
253262
}
254263

255264
type LegacySnapshotHashes = AccountsHashes;
@@ -303,8 +312,10 @@ impl LowestSlot {
303312
wallclock,
304313
}
305314
}
315+
}
306316

307-
/// New random LowestSlot for tests and benchmarks.
317+
#[cfg(feature = "dev-context-only-utils")]
318+
impl FormatValidation for LowestSlot {
308319
fn new_rand<R: Rng>(rng: &mut R, pubkey: Option<Pubkey>) -> Self {
309320
Self {
310321
from: pubkey.unwrap_or_else(pubkey::new_rand),

gossip/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ extern crate solana_frozen_abi_macro;
4646

4747
#[macro_use]
4848
extern crate solana_metrics;
49+
50+
#[cfg(feature = "dev-context-only-utils")]
51+
pub mod format_validation;

0 commit comments

Comments
 (0)