diff --git a/src/auth/mod.rs b/src/auth/mod.rs index 4647d56b0a21..b61d9205b60a 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -3,7 +3,6 @@ use crate::key_management::KeyInfo; use crate::shim::crypto::SignatureType; -use crate::utils::misc::env::is_env_truthy; use chrono::{Duration, Utc}; use jsonwebtoken::{DecodingKey, EncodingKey, Header, decode, encode, errors::Result as JWTResult}; use rand::Rng; @@ -42,8 +41,9 @@ pub fn create_token(perms: Vec, key: &[u8], token_exp: Duration) -> JWTR /// Verify JWT Token and return the allowed permissions from token pub fn verify_token(token: &str, key: &[u8]) -> JWTResult> { + crate::def_is_env_truthy!(disable_exp_validation, "FOREST_JWT_DISABLE_EXP_VALIDATION"); let mut validation = jsonwebtoken::Validation::new(jsonwebtoken::Algorithm::default()); - if is_env_truthy("FOREST_JWT_DISABLE_EXP_VALIDATION") { + if disable_exp_validation() { let mut claims = validation.required_spec_claims.clone(); claims.remove("exp"); let buff: Vec<_> = claims.iter().collect(); diff --git a/src/beacon/drand.rs b/src/beacon/drand.rs index 528853061291..db18eda2b887 100644 --- a/src/beacon/drand.rs +++ b/src/beacon/drand.rs @@ -1,6 +1,7 @@ // Copyright 2019-2026 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT +use std::sync::LazyLock; use std::time::Duration; use std::{borrow::Cow, num::NonZeroUsize}; @@ -13,6 +14,7 @@ use super::{ use crate::shim::clock::ChainEpoch; use crate::shim::version::NetworkVersion; use crate::utils::cache::SizeTrackingLruCache; +use crate::utils::misc::env::is_env_truthy; use crate::utils::net::global_http_client; use anyhow::Context as _; use backon::{ExponentialBuilder, Retryable}; @@ -28,6 +30,9 @@ use url::Url; /// `LOTUS_IGNORE_DRAND` pub const IGNORE_DRAND_VAR: &str = "FOREST_IGNORE_DRAND"; +/// Whether to ignore `Drand`. +pub static IGNORE_DRAND: LazyLock = LazyLock::new(|| is_env_truthy(IGNORE_DRAND_VAR)); + /// Type of the `drand` network. `mainnet` is chained and `quicknet` is unchained. /// For the details, see #[derive(PartialEq, Eq, Copy, Clone, Debug, SerdeSerialize, SerdeDeserialize)] diff --git a/src/chain/store/index.rs b/src/chain/store/index.rs index 2d8febeb00d6..c78501129bbc 100644 --- a/src/chain/store/index.rs +++ b/src/chain/store/index.rs @@ -4,19 +4,18 @@ use std::num::NonZeroUsize; use std::sync::LazyLock; -use crate::beacon::{BeaconEntry, IGNORE_DRAND_VAR}; +use crate::beacon::{BeaconEntry, IGNORE_DRAND}; use crate::blocks::{Tipset, TipsetKey}; use crate::chain::Error; use crate::metrics; use crate::shim::clock::ChainEpoch; use crate::utils::cache::SizeTrackingLruCache; -use crate::utils::misc::env::is_env_truthy; use fvm_ipld_blockstore::Blockstore; use itertools::Itertools; use nonzero_ext::nonzero; use num::Integer; -const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(131072_usize); +const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(2880_usize); type TipsetCache = SizeTrackingLruCache; @@ -52,8 +51,10 @@ impl ChainIndex { /// Loads a tipset from memory given the tipset keys and cache. Semantically /// identical to [`Tipset::load`] but the result is cached. pub fn load_tipset(&self, tsk: &TipsetKey) -> Result, Error> { - let cache_enabled = !is_env_truthy("FOREST_TIPSET_CACHE_DISABLED"); - if cache_enabled && let Some(ts) = self.ts_cache.get_cloned(tsk) { + crate::def_is_env_truthy!(cache_disabled, "FOREST_TIPSET_CACHE_DISABLED"); + if !cache_disabled() + && let Some(ts) = self.ts_cache.get_cloned(tsk) + { metrics::LRU_CACHE_HIT .get_or_create(&metrics::values::TIPSET) .inc(); @@ -61,7 +62,9 @@ impl ChainIndex { } let ts_opt = Tipset::load(&self.db, tsk)?; - if cache_enabled && let Some(ts) = &ts_opt { + if !cache_disabled() + && let Some(ts) = &ts_opt + { self.ts_cache.push(tsk.clone(), ts.clone()); metrics::LRU_CACHE_MISS .get_or_create(&metrics::values::TIPSET) @@ -162,7 +165,7 @@ impl ChainIndex { ))); } - for (child, parent) in self.chain(from).tuple_windows() { + for (child, parent) in from.chain(&self.db).tuple_windows() { // use `child.epoch() + CHAIN_FINALITY <= from_epoch` // to ensure the cached child is finalized(not on a fork). if child.epoch() % CHAIN_FINALITY == 0 && child.epoch() + CHAIN_FINALITY <= from_epoch { @@ -185,18 +188,6 @@ impl ChainIndex { ))) } - /// Iterate from the given tipset to genesis. Missing tipsets cut the chain - /// short. Semantically identical to [`Tipset::chain`] but the results are - /// cached. - pub fn chain(&self, from: Tipset) -> impl Iterator + '_ { - let mut tipset = Some(from); - std::iter::from_fn(move || { - let child = tipset.take()?; - tipset = self.load_required_tipset(child.parents()).ok(); - Some(child) - }) - } - /// Finds the latest beacon entry given a tipset up to 20 tipsets behind pub fn latest_beacon_entry(&self, tipset: Tipset) -> Result { for ts in tipset.chain(&self.db).take(20) { @@ -210,7 +201,7 @@ impl ChainIndex { } } - if is_env_truthy(IGNORE_DRAND_VAR) { + if *IGNORE_DRAND { return Ok(BeaconEntry::new(0, vec![9; 16])); } diff --git a/src/chain_sync/chain_follower.rs b/src/chain_sync/chain_follower.rs index ee52cdcb677c..dc097e15e952 100644 --- a/src/chain_sync/chain_follower.rs +++ b/src/chain_sync/chain_follower.rs @@ -31,7 +31,6 @@ use crate::{ networks::calculate_expected_epoch, shim::clock::ChainEpoch, state_manager::StateManager, - utils::misc::env::is_env_truthy, }; use ahash::{HashMap, HashSet}; use chrono::Utc; @@ -90,14 +89,14 @@ impl ChainFollower { stateless_mode: bool, mem_pool: Arc>>>, ) -> Self { + crate::def_is_env_truthy!(cache_disabled, "FOREST_DISABLE_BAD_BLOCK_CACHE"); let (tipset_sender, tipset_receiver) = flume::bounded(20); - let disable_bad_block_cache = is_env_truthy("FOREST_DISABLE_BAD_BLOCK_CACHE"); Self { sync_status: Arc::new(RwLock::new(SyncStatusReport::init())), state_manager, network, genesis, - bad_blocks: if disable_bad_block_cache { + bad_blocks: if cache_disabled() { tracing::warn!("bad block cache is disabled by `FOREST_DISABLE_BAD_BLOCK_CACHE`"); None } else { diff --git a/src/cli_shared/cli/config.rs b/src/cli_shared/cli/config.rs index 2a3cddbc710b..1c02bc5f3f49 100644 --- a/src/cli_shared/cli/config.rs +++ b/src/cli_shared/cli/config.rs @@ -6,7 +6,7 @@ use crate::db::db_engine::DbConfig; use crate::libp2p::Libp2pConfig; use crate::shim::clock::ChainEpoch; use crate::shim::econ::TokenAmount; -use crate::utils::misc::env::is_env_set_and_truthy; +use crate::utils::misc::env::is_env_truthy; use crate::{chain_sync::SyncConfig, networks::NetworkChain}; use serde::{Deserialize, Serialize}; use std::path::PathBuf; @@ -86,7 +86,7 @@ pub struct ChainIndexerConfig { impl Default for ChainIndexerConfig { fn default() -> Self { Self { - enable_indexer: is_env_set_and_truthy(FOREST_CHAIN_INDEXER_ENABLED).unwrap_or(false), + enable_indexer: is_env_truthy(FOREST_CHAIN_INDEXER_ENABLED), gc_retention_epochs: None, } } diff --git a/src/dev/subcommands/state_cmd.rs b/src/dev/subcommands/state_cmd.rs index d5f97de1e70a..b8b4ef79b4d5 100644 --- a/src/dev/subcommands/state_cmd.rs +++ b/src/dev/subcommands/state_cmd.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0, MIT use crate::{ - blocks::Tipset, chain::{ChainStore, index::ResolveNullTipset}, chain_sync::{load_full_tipset, tipset_syncer::validate_tipset}, cli_shared::{chain_path, read_config}, @@ -82,10 +81,11 @@ impl ComputeCommand { chain_config, genesis_header, )?); + let chain_index = chain_store.chain_index(); let (ts, ts_next) = { // We don't want to track all entries that are visited by `tipset_by_height` db.pause_tracking(); - let ts = chain_store.chain_index().tipset_by_height( + let ts = chain_index.tipset_by_height( epoch, chain_store.heaviest_tipset(), ResolveNullTipset::TakeOlder, @@ -99,8 +99,8 @@ impl ComputeCommand { )?; // Only track the desired tipsets ( - Tipset::load_required(&db, ts.key())?, - Tipset::load_required(&db, ts_next.key())?, + chain_index.load_required_tipset(ts.key())?, + chain_index.load_required_tipset(ts_next.key())?, ) }; let epoch = ts.epoch(); @@ -207,10 +207,11 @@ impl ValidateCommand { chain_config, genesis_header, )?); + let chain_index = chain_store.chain_index(); let ts = { // We don't want to track all entries that are visited by `tipset_by_height` db.pause_tracking(); - let ts = chain_store.chain_index().tipset_by_height( + let ts = chain_index.tipset_by_height( epoch, chain_store.heaviest_tipset(), ResolveNullTipset::TakeOlder, @@ -218,7 +219,7 @@ impl ValidateCommand { db.resume_tracking(); SettingsStoreExt::write_obj(&db.tracker, crate::db::setting_keys::HEAD_KEY, ts.key())?; // Only track the desired tipset - Tipset::load_required(&db, ts.key())? + chain_index.load_required_tipset(ts.key())? }; let epoch = ts.epoch(); let fts = load_full_tipset(&chain_store, ts.key())?; diff --git a/src/f3/mod.rs b/src/f3/mod.rs index 43e39bd9a94c..734821722b0c 100644 --- a/src/f3/mod.rs +++ b/src/f3/mod.rs @@ -5,7 +5,10 @@ #[cfg(all(f3sidecar, not(feature = "no-f3-sidecar")))] mod go_ffi; -use std::path::{Path, PathBuf}; +use std::{ + path::{Path, PathBuf}, + sync::LazyLock, +}; #[cfg(all(f3sidecar, not(feature = "no-f3-sidecar")))] use go_ffi::*; @@ -146,8 +149,9 @@ pub fn import_f3_snapshot( /// Whether F3 sidecar via FFI is enabled. pub fn is_sidecar_ffi_enabled(chain_config: &ChainConfig) -> bool { // Respect the environment variable when set, and fallback to chain config when not set. - let enabled = - is_env_set_and_truthy("FOREST_F3_SIDECAR_FFI_ENABLED").unwrap_or(chain_config.f3_enabled); + static ENV_ENABLED: LazyLock> = + LazyLock::new(|| is_env_set_and_truthy("FOREST_F3_SIDECAR_FFI_ENABLED")); + let enabled = ENV_ENABLED.unwrap_or(chain_config.f3_enabled); cfg_if::cfg_if! { if #[cfg(all(f3sidecar, not(feature = "no-f3-sidecar")))] { enabled diff --git a/src/fil_cns/validation.rs b/src/fil_cns/validation.rs index b30614c83b64..ffb6ddd17328 100644 --- a/src/fil_cns/validation.rs +++ b/src/fil_cns/validation.rs @@ -3,7 +3,7 @@ use std::{collections::BTreeMap, sync::Arc}; -use crate::beacon::{BeaconEntry, BeaconSchedule, IGNORE_DRAND_VAR}; +use crate::beacon::{BeaconEntry, BeaconSchedule, IGNORE_DRAND}; use crate::blocks::{Block, CachingBlockHeader, Tipset}; use crate::chain::ChainStore; use crate::chain_sync::collect_errs; @@ -22,7 +22,6 @@ use crate::shim::{ }; use crate::state_manager::StateManager; use crate::utils::encoding::prover_id_from_u64; -use crate::utils::misc::env::is_env_truthy; use cid::Cid; use fil_actors_shared::filecoin_proofs_api::{PublicReplicaInfo, SectorId, post}; use fil_actors_shared::v10::runtime::DomainSeparationTag; @@ -127,7 +126,7 @@ pub(in crate::fil_cns) async fn validate_block = cs - .chain_index() - .chain(root) + let chain: Vec<_> = root + .chain(cs.blockstore()) .take(request.request_len as _) .map(|tipset| { let mut tipset_bundle: TipsetBundle = TipsetBundle::default(); diff --git a/src/libp2p/service.rs b/src/libp2p/service.rs index f4a7c42b35ff..ab7fb019330e 100644 --- a/src/libp2p/service.rs +++ b/src/libp2p/service.rs @@ -78,9 +78,7 @@ pub(in crate::libp2p) mod metrics { } } -fn libp2p_metrics_enabled() -> bool { - crate::utils::misc::env::is_env_truthy("FOREST_LIBP2P_METRICS_ENABLED") -} +crate::def_is_env_truthy!(libp2p_metrics_enabled, "FOREST_LIBP2P_METRICS_ENABLED"); /// `Gossipsub` Filecoin blocks topic identifier. pub const PUBSUB_BLOCK_STR: &str = "/fil/blocks"; diff --git a/src/rpc/json_validator.rs b/src/rpc/json_validator.rs index f8dc71b42562..6d63356c921e 100644 --- a/src/rpc/json_validator.rs +++ b/src/rpc/json_validator.rs @@ -10,24 +10,7 @@ use ahash::HashSet; pub const STRICT_JSON_ENV: &str = "FOREST_STRICT_JSON"; -#[cfg(not(test))] -use std::sync::LazyLock; - -#[cfg(not(test))] -static STRICT_MODE: LazyLock = - LazyLock::new(|| crate::utils::misc::env::is_env_truthy(STRICT_JSON_ENV)); - -#[inline] -pub fn is_strict_mode() -> bool { - #[cfg(test)] - { - crate::utils::misc::env::is_env_truthy(STRICT_JSON_ENV) - } - #[cfg(not(test))] - { - *STRICT_MODE - } -} +crate::def_is_env_truthy!(is_strict_mode, STRICT_JSON_ENV); /// validates JSON for duplicate keys by parsing at the token level. pub fn validate_json_for_duplicates(json_str: &str) -> Result<(), String> { diff --git a/src/rpc/methods/chain.rs b/src/rpc/methods/chain.rs index 35b9dfa1eac9..001e6372879d 100644 --- a/src/rpc/methods/chain.rs +++ b/src/rpc/methods/chain.rs @@ -295,7 +295,9 @@ impl RpcMethod<1> for ChainGetParentMessages { if block_header.epoch == 0 { Ok(vec![]) } else { - let parent_tipset = Tipset::load_required(store, &block_header.parents)?; + let parent_tipset = ctx + .chain_index() + .load_required_tipset(&block_header.parents)?; load_api_messages_from_tipset(&ctx, parent_tipset.key()).await } } diff --git a/src/rpc/methods/eth.rs b/src/rpc/methods/eth.rs index 801486b68ffd..fa06619e6e3c 100644 --- a/src/rpc/methods/eth.rs +++ b/src/rpc/methods/eth.rs @@ -57,7 +57,7 @@ use crate::utils::cache::SizeTrackingLruCache; use crate::utils::db::BlockstoreExt as _; use crate::utils::encoding::from_slice_with_fallback; use crate::utils::get_size::{CidWrapper, big_int_heap_size_helper}; -use crate::utils::misc::env::{env_or_default, is_env_truthy}; +use crate::utils::misc::env::env_or_default; use crate::utils::multihash::prelude::*; use ahash::HashSet; use anyhow::{Context, Error, Result, anyhow, bail, ensure}; @@ -931,7 +931,7 @@ fn get_tipset_from_hash( block_hash: &EthHash, ) -> anyhow::Result { let tsk = chain_store.get_required_tipset_key(block_hash)?; - Tipset::load_required(chain_store.blockstore(), &tsk) + Ok(chain_store.chain_index().load_required_tipset(&tsk)?) } fn resolve_block_number_tipset( diff --git a/src/rpc/methods/eth/filter/mod.rs b/src/rpc/methods/eth/filter/mod.rs index b724553f77ab..327d7643a480 100644 --- a/src/rpc/methods/eth/filter/mod.rs +++ b/src/rpc/methods/eth/filter/mod.rs @@ -378,7 +378,7 @@ impl EthEventHandler { .await?; } ParsedFilterTipsets::Key(tsk) => { - let tipset = Arc::new(Tipset::load_required(ctx.store(), tsk)?); + let tipset = ctx.chain_index().load_required_tipset(tsk)?; Self::collect_events(ctx, &tipset, Some(pf), skip_event, &mut collected_events) .await?; } diff --git a/src/rpc/methods/eth/tipset_resolver.rs b/src/rpc/methods/eth/tipset_resolver.rs index bccea571b9df..8ac6158ff041 100644 --- a/src/rpc/methods/eth/tipset_resolver.rs +++ b/src/rpc/methods/eth/tipset_resolver.rs @@ -89,10 +89,13 @@ where async fn resolve_predefined_tipset_v1(&self, tag: Predefined) -> anyhow::Result { const ETH_V1_DISABLE_F3_FINALITY_RESOLUTION_ENV_KEY: &str = "FOREST_ETH_V1_DISABLE_F3_FINALITY_RESOLUTION"; - static ETH_V1_F3_FINALITY_RESOLUTION_DISABLED: LazyLock = - LazyLock::new(|| is_env_truthy(ETH_V1_DISABLE_F3_FINALITY_RESOLUTION_ENV_KEY)); - if *ETH_V1_F3_FINALITY_RESOLUTION_DISABLED { + crate::def_is_env_truthy!( + f3_finality_disabled, + ETH_V1_DISABLE_F3_FINALITY_RESOLUTION_ENV_KEY + ); + + if f3_finality_disabled() { if let Some(ts) = self.resolve_common_predefined_tipset(tag)? { Ok(ts) } else { diff --git a/src/rpc/methods/f3.rs b/src/rpc/methods/f3.rs index 8991299606e9..b3bc2fd47728 100644 --- a/src/rpc/methods/f3.rs +++ b/src/rpc/methods/f3.rs @@ -519,8 +519,9 @@ impl RpcMethod<1> for Finalize { _: &http::Extensions, ) -> Result { // Respect the environment variable when set, and fallback to chain config when not set. - let enabled = is_env_set_and_truthy("FOREST_F3_CONSENSUS_ENABLED") - .unwrap_or(ctx.chain_config().f3_consensus); + static ENV_ENABLED: LazyLock> = + LazyLock::new(|| is_env_set_and_truthy("FOREST_F3_CONSENSUS_ENABLED")); + let enabled = ENV_ENABLED.unwrap_or(ctx.chain_config().f3_consensus); if !enabled { return Ok(()); } diff --git a/src/state_manager/mod.rs b/src/state_manager/mod.rs index a60b9aaa23d4..cc814d9da5b8 100644 --- a/src/state_manager/mod.rs +++ b/src/state_manager/mod.rs @@ -238,8 +238,8 @@ where // validation, and it prevents duplicate migrations. pub fn populate_cache(&self) { for (child, parent) in self - .chain_index() - .chain(self.heaviest_tipset()) + .heaviest_tipset() + .chain(self.blockstore()) .tuple_windows() .take(DEFAULT_TIPSET_CACHE_SIZE.into()) { @@ -1612,10 +1612,9 @@ where })?; // lookup tipset parents as we go along, iterating DOWN from `end` - let tipsets = self - .chain_index() - .chain(end) - .take_while(|tipset| tipset.epoch() >= *epochs.start()); + let tipsets = end + .chain(self.blockstore()) + .take_while(|ts| ts.epoch() >= *epochs.start()); self.validate_tipsets(tipsets) } @@ -1925,8 +1924,10 @@ impl<'a, DB: Blockstore + Send + Sync + 'static> TipsetExecutor<'a, DB> { use crate::shim::clock::EPOCH_DURATION_SECONDS; let mut parent_state = *self.tipset.parent_state(); - let parent_epoch = - Tipset::load_required(self.chain_index.db(), self.tipset.parents())?.epoch(); + let parent_epoch = self + .chain_index + .load_required_tipset(self.tipset.parents())? + .epoch(); let epoch = self.tipset.epoch(); for epoch_i in parent_epoch..epoch { diff --git a/src/tool/subcommands/snapshot_cmd.rs b/src/tool/subcommands/snapshot_cmd.rs index ae9ab0a4eccf..16a6d19c2184 100644 --- a/src/tool/subcommands/snapshot_cmd.rs +++ b/src/tool/subcommands/snapshot_cmd.rs @@ -428,8 +428,8 @@ where let chain_index = Arc::new(ChainIndex::new(Arc::new(db.clone()))); // Prepare tipsets for validation - let tipsets = chain_index - .chain(ts) + let tipsets = ts + .chain(&db) .take_while(|tipset| tipset.epoch() >= last_epoch) .inspect(|tipset| { pb.set_message(format!("epoch queue: {}", tipset.epoch() - last_epoch)); diff --git a/src/utils/io/mmap.rs b/src/utils/io/mmap.rs index daf32fafa169..c4dd34cf7dad 100644 --- a/src/utils/io/mmap.rs +++ b/src/utils/io/mmap.rs @@ -6,8 +6,6 @@ use std::{fs, io, path::Path}; use memmap2::MmapAsRawDesc; use positioned_io::{RandomAccessFile, ReadAt, Size}; -use crate::utils::misc::env::is_env_truthy; - /// Wrapper type of [`memmap2::Mmap`] that implements [`ReadAt`] and [`Size`] pub struct Mmap(memmap2::Mmap); @@ -82,10 +80,8 @@ impl Size for EitherMmapOrRandomAccessFile { } } -fn should_use_file_io() -> bool { - // Use mmap by default, switch to file-io when `FOREST_CAR_LOADER_FILE_IO` is set to `1` or `true` - is_env_truthy("FOREST_CAR_LOADER_FILE_IO") -} +// Use mmap by default, switch to file-io when `FOREST_CAR_LOADER_FILE_IO` is set to `1` or `true` +crate::def_is_env_truthy!(should_use_file_io, "FOREST_CAR_LOADER_FILE_IO"); #[cfg(test)] mod tests { diff --git a/src/utils/misc/env.rs b/src/utils/misc/env.rs index 46d53f36a8c5..220f172ebe65 100644 --- a/src/utils/misc/env.rs +++ b/src/utils/misc/env.rs @@ -26,6 +26,24 @@ pub fn is_env_set_and_truthy(env: &str) -> Option { .map(|var| matches!(var.to_lowercase().as_str(), "1" | "true" | "yes" | "_yes_")) } +#[macro_export] +macro_rules! def_is_env_truthy { + ($fn_name:ident, $env: expr) => { + #[inline] + pub fn $fn_name() -> bool { + cfg_if::cfg_if! { + if #[cfg(test)] { + $crate::utils::misc::env::is_env_truthy($env) + } else{ + static ENV: std::sync::LazyLock = + std::sync::LazyLock::new(|| $crate::utils::misc::env::is_env_truthy($env)); + *ENV + } + } + } + }; +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/utils/proofs_api/parameters.rs b/src/utils/proofs_api/parameters.rs index b2e989a970b8..b982e5870f6b 100644 --- a/src/utils/proofs_api/parameters.rs +++ b/src/utils/proofs_api/parameters.rs @@ -18,8 +18,6 @@ use cid::Cid; use serde::{Deserialize, Serialize}; use tracing::{debug, warn}; -use crate::utils::misc::env::is_env_truthy; - const PROOF_DIGEST_LEN: usize = 16; /// Environment variable that allows skipping checksum verification of the parameter files. @@ -52,7 +50,9 @@ pub(super) struct ParameterData { /// Ensures the parameter file is downloaded and has the correct checksum. /// This behavior can be disabled by setting the [`FOREST_FORCE_TRUST_PARAMS_ENV`] environment variable to 1. pub(super) async fn check_parameter_file(path: &Path, info: &ParameterData) -> anyhow::Result<()> { - if is_env_truthy(FOREST_FORCE_TRUST_PARAMS_ENV) { + crate::def_is_env_truthy!(force_trust_params, FOREST_FORCE_TRUST_PARAMS_ENV); + + if force_trust_params() { warn!("Assuming parameter files are okay. Do not use in production!"); return Ok(()); } diff --git a/src/utils/proofs_api/paramfetch.rs b/src/utils/proofs_api/paramfetch.rs index 367bb33776cc..ad456245dc4a 100644 --- a/src/utils/proofs_api/paramfetch.rs +++ b/src/utils/proofs_api/paramfetch.rs @@ -15,10 +15,7 @@ use std::{ use crate::{ shim::sector::SectorSize, - utils::{ - misc::env::is_env_truthy, - net::{download_ipfs_file_trustlessly, global_http_client}, - }, + utils::net::{download_ipfs_file_trustlessly, global_http_client}, }; use anyhow::{Context, bail}; use backon::{ExponentialBuilder, Retryable}; @@ -61,7 +58,7 @@ pub enum SectorSizeOpt { /// Ensures the parameter files are downloaded to cache dir pub async fn ensure_proof_params_downloaded() -> anyhow::Result<()> { #[cfg(test)] - if is_env_truthy("FOREST_TEST_SKIP_PROOF_PARAM_CHECK") { + if crate::utils::misc::env::is_env_truthy("FOREST_TEST_SKIP_PROOF_PARAM_CHECK") { return Ok(()); } @@ -135,6 +132,8 @@ async fn fetch_verify_params( name: &str, info: Arc, ) -> Result<(), anyhow::Error> { + crate::def_is_env_truthy!(force_ipfs_gateway, PROOFS_ONLY_IPFS_GATEWAY_ENV); + let path: PathBuf = param_dir(data_dir).join(name); match check_parameter_file(&path, &info).await { @@ -150,7 +149,7 @@ async fn fetch_verify_params( } } - if is_env_truthy(PROOFS_ONLY_IPFS_GATEWAY_ENV) { + if force_ipfs_gateway() { fetch_params_ipfs_gateway(&path, &info).await?; } else if let Err(e) = fetch_params_cloudflare(name, &path).await { warn!("Failed to fetch param file from Cloudflare R2: {e:?}. Falling back to IPFS gateway",);