Skip to content

Commit

Permalink
feat: lock the setup for sharing instance (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
johntaiko authored May 23, 2024
1 parent 6bb70b1 commit 04d3197
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions provers/sgx/setup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ url = { workspace = true }
cfg-if = { workspace = true }
cap = { workspace = true }
dirs = { workspace = true }
file-lock = "2.1.11"

[dev-dependencies]
assert_cmd = { workspace = true }
Expand All @@ -76,7 +77,4 @@ default = ["sgx"]
# "dep:risc0-driver",
# "risc0-driver/enable",
# ]
sgx = [
"dep:sgx-prover",
"sgx-prover/enable",
]
sgx = ["dep:sgx-prover", "sgx-prover/enable"]
10 changes: 10 additions & 0 deletions provers/sgx/setup/src/setup_bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{

use crate::app_args::BootstrapArgs;
use anyhow::{anyhow, Context, Result};
use file_lock::{FileLock, FileOptions};
use raiko_lib::consts::SupportedChainSpecs;
use serde_json::{Number, Value};
use sgx_prover::{
Expand All @@ -20,6 +21,15 @@ pub(crate) async fn setup_bootstrap(
config_dir: PathBuf,
bootstrap_args: &BootstrapArgs,
) -> Result<()> {
// Lock the bootstrap process to prevent multiple instances from running concurrently.
// Block until the lock is acquired.
// Create the lock file if it does not exist.
// Drop the lock file when the lock goes out of scope by drop guard.
let _filelock = FileLock::lock(
config_dir.join("bootstrap.lock"),
true,
FileOptions::new().create(true),
)?;
let chain_specs = SupportedChainSpecs::merge_from_file(bootstrap_args.chain_spec_path.clone())?;
let l1_chain_spec = chain_specs
.get_chain_spec(&bootstrap_args.l1_network)
Expand Down

0 comments on commit 04d3197

Please sign in to comment.