Skip to content

Commit 89ba6d9

Browse files
committed
fetch proof params only once
1 parent 836b7a2 commit 89ba6d9

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/tool/subcommands/api_cmd/test_snapshot.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ mod tests {
190190
use ahash::HashSet;
191191
use anyhow::Context as _;
192192
use directories::ProjectDirs;
193-
use std::sync::LazyLock;
194193
use std::time::{Duration, Instant};
195-
use tokio::sync::Mutex;
196194
use url::Url;
197195

198196
// To run a single test: cargo test --lib filecoin_multisig_statedecodeparams_1754230255631789 -- --nocapture
@@ -201,8 +199,6 @@ mod tests {
201199
async fn rpc_regression_test_run(name: &str) {
202200
// Set proof parameter data dir and make sure the proofs are available
203201
{
204-
static PROOF_PARAMS_LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
205-
let _guard = PROOF_PARAMS_LOCK.lock().await;
206202
crate::utils::proofs_api::maybe_set_proofs_parameter_cache_dir_env(
207203
&Config::default().client.data_dir,
208204
);

src/utils/proofs_api/paramfetch.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use std::{
1111
io::{self, ErrorKind},
1212
path::{Path, PathBuf},
13-
sync::Arc,
13+
sync::{Arc, LazyLock},
1414
};
1515

1616
use crate::{
@@ -23,7 +23,10 @@ use crate::{
2323
use anyhow::{Context, bail};
2424
use backon::{ExponentialBuilder, Retryable};
2525
use futures::{AsyncWriteExt, TryStreamExt, stream::FuturesUnordered};
26-
use tokio::fs::{self};
26+
use tokio::{
27+
fs::{self},
28+
sync::Mutex,
29+
};
2730
use tracing::{debug, info, warn};
2831

2932
use super::parameters::{
@@ -61,8 +64,15 @@ pub async fn ensure_proof_params_downloaded() -> anyhow::Result<()> {
6164
if data_dir.is_empty() {
6265
anyhow::bail!("Proof parameter data dir is not set");
6366
}
64-
get_params_default(Path::new(&data_dir), SectorSizeOpt::Keys, false).await?;
65-
Ok(())
67+
static RUN_ONCE: LazyLock<Mutex<bool>> = LazyLock::new(|| Mutex::new(false));
68+
let mut run_once = RUN_ONCE.lock().await;
69+
if *run_once {
70+
Ok(())
71+
} else {
72+
get_params_default(Path::new(&data_dir), SectorSizeOpt::Keys, false).await?;
73+
*run_once = true;
74+
Ok(())
75+
}
6676
}
6777

6878
/// Get proofs parameters and all verification keys for a given sector size

0 commit comments

Comments
 (0)