diff --git a/Cargo.lock b/Cargo.lock index 3ec1a1df..3564b83b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3335,6 +3335,16 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" +[[package]] +name = "file-lock" +version = "2.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "040b48f80a749da50292d0f47a1e2d5bf1d772f52836c07f64bfccc62ba6e664" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "find_cuda_helper" version = "0.2.0" @@ -6222,6 +6232,7 @@ dependencies = [ "dirs", "env_logger", "ethers-core 2.0.10", + "file-lock", "flate2", "lazy_static", "lru_time_cache", diff --git a/provers/sgx/setup/Cargo.toml b/provers/sgx/setup/Cargo.toml index fd020a0a..ecf9c025 100644 --- a/provers/sgx/setup/Cargo.toml +++ b/provers/sgx/setup/Cargo.toml @@ -57,6 +57,8 @@ cfg-if = { workspace = true } cap = { workspace = true } dirs = { workspace = true } +file-lock = "2.1.11" + [dev-dependencies] assert_cmd = { workspace = true } @@ -64,4 +66,4 @@ rstest = { workspace = true } ethers-core = { workspace = true } [features] -sgx = [] \ No newline at end of file +sgx = [] diff --git a/provers/sgx/setup/src/setup_bootstrap.rs b/provers/sgx/setup/src/setup_bootstrap.rs index 6747f531..1958b167 100644 --- a/provers/sgx/setup/src/setup_bootstrap.rs +++ b/provers/sgx/setup/src/setup_bootstrap.rs @@ -7,6 +7,7 @@ use std::{ }; use anyhow::{anyhow, Context, Result}; +use file_lock::{FileLock, FileOptions}; use raiko_lib::consts::{SupportedChainSpecs, VerifierType}; use serde_json::{Number, Value}; use sgx_prover::{ @@ -21,6 +22,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).write(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) diff --git a/script/publish-image.sh b/script/publish-image.sh index 7cad6d2e..12e2e706 100755 --- a/script/publish-image.sh +++ b/script/publish-image.sh @@ -13,12 +13,15 @@ if [[ -z "$tag" ]]; then tag="latest" fi +TASKDB=${TASKDB:-raiko-tasks/in-memory} + echo "Build and push $1:$tag..." docker buildx build ./ \ --load \ --platform linux/amd64 \ -t raiko:$tag \ $build_flags \ + --build-arg TASKDB=${TASKDB} \ --build-arg TARGETPLATFORM=linux/amd64 \ --progress=plain