Skip to content

Commit

Permalink
variable renaming + bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs committed Apr 11, 2024
1 parent a85a55d commit 59e6923
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

### Breaking

- [#4177](https://github.com/ChainSafe/forest/pull/4177) Rename environment
variable `TRUST_PARAMS` to `FOREST_FORCE_TRUST_PARAMS`.

### Added

- [#4084](https://github.com/ChainSafe/forest/pull/4084) Add support for the
Expand All @@ -48,6 +51,9 @@

### Fixed

- [#4177](https://github.com/ChainSafe/forest/pull/4177) Fixed a bug where the
environment variable `IPFS_GATEWAY` was not used to change the IPFS gateway.

## Forest 0.17.2 "Dovakhin"

This is a **mandatory** release for all mainnet node operators. It changes the
Expand Down
2 changes: 1 addition & 1 deletion documentation/src/environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ process.
| FOREST_ACTOR_BUNDLE_PATH | file path | empty | Path to the local actor bundle, download from remote servers when not set |
| FIL_PROOFS_PARAMETER_CACHE | dir path | empty | Path to folder that caches fil proof parameter files |
| FOREST_PROOFS_ONLY_IPFS_GATEWAY | 1 or true | false | Use only IPFS gateway for proofs parameters download |
| TRUST_PARAMS | 1 or true | false | Trust the parameters downloaded from the Cloudflare/IPFS |
| FOREST_FORCE_TRUST_PARAMS | 1 or true | false | Trust the parameters downloaded from the Cloudflare/IPFS |
| IPFS_GATEWAY | URL | https://proofs.filecoin.io/ipfs/ | The IPFS gateway to use for downloading proofs parameters |

### FOREST_DB_DEV_MODE
Expand Down
7 changes: 2 additions & 5 deletions src/utils/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ pub fn global_http_client() -> reqwest::Client {
/// See <https://github.com/ipfs/specs/blob/main/http-gateways/TRUSTLESS_GATEWAY.md>
pub async fn download_ipfs_file_trustlessly(
cid: &Cid,
gateway: Option<&str>,
gateway: &Url,
destination: &Path,
) -> anyhow::Result<()> {
let url = {
// https://docs.ipfs.tech/concepts/ipfs-gateway/
const DEFAULT_IPFS_GATEWAY: &str = "https://ipfs.io/ipfs/";
let mut url =
Url::parse(gateway.unwrap_or(DEFAULT_IPFS_GATEWAY))?.join(&format!("{cid}"))?;
let mut url = gateway.join(&cid.to_string())?;
url.set_query(Some("format=car"));
Ok::<_, anyhow::Error>(url)
}?;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/proofs_api/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::is_env_truthy;
const PROOF_DIGEST_LEN: usize = 16;

/// Environment variable that allows skipping checksum verification of the parameter files.
const TRUST_PARAMS_ENV: &str = "TRUST_PARAMS";
const FOREST_FORCE_TRUST_PARAMS_ENV: &str = "FOREST_FORCE_TRUST_PARAMS";

/// Environment variable to set the directory where proofs parameters are stored. Defaults to
/// [`PARAM_DIR`] in the data directory.
Expand All @@ -50,9 +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 [`TRUST_PARAMS_ENV`] environment variable to 1.
/// 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(TRUST_PARAMS_ENV) {
if is_env_truthy(FOREST_FORCE_TRUST_PARAMS_ENV) {
warn!("Assuming parameter files are okay. Do not use in production!");
return Ok(());
}
Expand Down Expand Up @@ -104,7 +104,7 @@ pub(super) fn param_dir(data_dir: &Path) -> PathBuf {
/// directory. To this end, the `FIL_PROOFS_PARAMETER_CACHE` environment
/// variable is updated before the parameters are downloaded.
///
/// More information available here: <https://github.com/filecoin-project/rust-fil-proofs#parameter-file-location>
/// More information available [here](https://github.com/filecoin-project/rust-fil-proofs/blob/8f5bd86be36a55e33b9b293ba22ea13ca1f28163/README.md?plain=1#L219-L235).
pub fn set_proofs_parameter_cache_dir_env(data_dir: &Path) {
std::env::set_var(PROOFS_PARAMETER_CACHE_ENV, param_dir(data_dir));
}
Expand Down
25 changes: 19 additions & 6 deletions src/utils/proofs_api/paramfetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ use super::{
},
};

const IPFS_GATEWAY: &str = "https://proofs.filecoin.io/ipfs/";

/// Default IPFS gateway to use for fetching parameters.
/// Set via the [`IPFS_GATEWAY_ENV`] environment variable.
const DEFAULT_IPFS_GATEWAY: &str = "https://proofs.filecoin.io/ipfs/";
/// Domain bound to the Cloudflare R2 bucket.
const CLOUDFLARE_PROOF_PARAMETER_DOMAIN: &str = "filecoin-proof-parameters.chainsafe.dev";

/// If set to 1, enforce using the IPFS gateway for fetching parameters.
const PROOFS_ONLY_IPFS_GATEWAY_ENV: &str = "FOREST_PROOFS_ONLY_IPFS_GATEWAY";

/// Running Forest requires the download of chain’s proof parameters which are large files, by default are hosted outside of China and very slow to download there.
/// To get around that, users should set this variable to:
/// <https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/>
const IPFS_GATEWAY_ENV: &str = "IPFS_GATEWAY";

/// Sector size options for fetching.
Expand Down Expand Up @@ -144,19 +149,27 @@ async fn fetch_verify_params(
}

async fn fetch_params_ipfs_gateway(path: &Path, info: &ParameterData) -> anyhow::Result<()> {
let gw = std::env::var(IPFS_GATEWAY_ENV).unwrap_or_else(|_| IPFS_GATEWAY.to_owned());
info!("Fetching param file {} from {gw}", path.display());
let gateway = std::env::var(IPFS_GATEWAY_ENV)
.unwrap_or_else(|_| DEFAULT_IPFS_GATEWAY.to_owned())
.parse()?;
info!(
"Fetching param file {path} from {gateway}",
path = path.display()
);
let backoff = ExponentialBackoffBuilder::default()
// Up to 30 minutes for downloading the file. This may be drastic,
// but the gateway proved to be unreliable at times and we
// don't want to get stuck here. Better to fail fast and retry.
.with_max_elapsed_time(Some(Duration::from_secs(60 * 30)))
.build();
let result = retry(backoff, || async {
Ok(download_ipfs_file_trustlessly(&info.cid, Some(IPFS_GATEWAY), path).await?)
Ok(download_ipfs_file_trustlessly(&info.cid, &gateway, path).await?)
})
.await;
debug!("Done fetching param file {:?} from {}", path, gw);
debug!(
"Done fetching param file {path} from {gateway}",
path = path.display(),
);
result
}

Expand Down

0 comments on commit 59e6923

Please sign in to comment.