diff --git a/docs/docs/users/reference/env_variables.md b/docs/docs/users/reference/env_variables.md index b6a5f197ddd..366eb6aa851 100644 --- a/docs/docs/users/reference/env_variables.md +++ b/docs/docs/users/reference/env_variables.md @@ -28,8 +28,7 @@ process. | `FOREST_MAX_FILTER_HEIGHT_RANGE` | positive integer | 2880 | 2880 | The maximum filter height range allowed, a conservative limit of one day | | `FOREST_STATE_MIGRATION_THREADS` | integer | Depends on the machine. | 3 | The number of threads for state migration thread-pool. Advanced users only. | | `FOREST_CONFIG_PATH` | string | /$FOREST_HOME/com.ChainSafe.Forest/config.toml | `/path/to/config.toml` | Forest configuration path. Alternatively supplied via `--config` cli parameter. | -| `FOREST_TEST_RNG_FIXED_SEED` | non-negative integer | empty | 0 | Override thread RNG with a reproducible one seeded by the value | -| `FOREST_TEST_OS_RNG_FIXED_SEED` | non-negative integer | empty | 0 | Override OS RNG with a reproducible one seeded by the value | +| `FOREST_TEST_RNG_FIXED_SEED` | non-negative integer | empty | 0 | Override RNG with a reproducible one seeded by the value | | `RUST_LOG` | string | empty | `debug,forest_libp2p::service=info` | Allows for log level customization. | | `FOREST_IGNORE_DRAND` | 1 or true | empty | 1 | Ignore Drand validation. | | `FOREST_F3_SIDECAR_RPC_ENDPOINT` | string | 127.0.0.1:23456 | `127.0.0.1:23456` | An RPC endpoint of F3 sidecar. | diff --git a/src/utils/rand/mod.rs b/src/utils/rand/mod.rs index 844a4922847..d22f71373e3 100644 --- a/src/utils/rand/mod.rs +++ b/src/utils/rand/mod.rs @@ -7,29 +7,25 @@ use rand::{CryptoRng, Rng, RngCore, SeedableRng as _}; /// [`rand_chacha::ChaChaRng`] via `FOREST_TEST_RNG_FIXED_SEED` environment variable. /// This is required for reproducible test cases for normally non-deterministic methods. pub fn forest_rng() -> impl Rng + CryptoRng { - const ENV_KEY: &str = "FOREST_TEST_RNG_FIXED_SEED"; - forest_rng_internal(ENV_KEY, false) + forest_rng_internal(false) } /// A wrapper of [`rand::rngs::OsRng`] that can be overridden by reproducible seeded /// [`rand_chacha::ChaChaRng`] via `FOREST_TEST_RNG_FIXED_SEED` environment variable. /// This is required for reproducible test cases for normally non-deterministic methods. pub fn forest_os_rng() -> impl Rng + CryptoRng { - const ENV_KEY: &str = "FOREST_TEST_OS_RNG_FIXED_SEED"; - forest_rng_internal(ENV_KEY, true) + forest_rng_internal(true) } -fn forest_rng_internal( - env_key: &str, - prefer_os_rng_for_enhanced_security: bool, -) -> impl Rng + CryptoRng { - if let Ok(v) = std::env::var(env_key) { +fn forest_rng_internal(prefer_os_rng_for_enhanced_security: bool) -> impl Rng + CryptoRng { + const ENV_KEY: &str = "FOREST_TEST_RNG_FIXED_SEED"; + if let Ok(v) = std::env::var(ENV_KEY) { if let Ok(seed) = v.parse() { - tracing::warn!("[security] using test RNG with fixed seed {seed} set by {env_key}"); + tracing::warn!("[security] using test RNG with fixed seed {seed} set by {ENV_KEY}"); return Either::Left(rand_chacha::ChaChaRng::seed_from_u64(seed)); } else { tracing::warn!( - "invalid u64 seed set by {env_key}: {v}. Falling back to the default RNG." + "invalid u64 seed set by {ENV_KEY}: {v}. Falling back to the default RNG." ); } }