Skip to content

Commit

Permalink
feat: introduce file lock for share instance bootstrap (#405)
Browse files Browse the repository at this point in the history
* feat: introduce file lock for share instance bootstrap

* feat(script): allow configurable TASKDB in publish-image.sh
  • Loading branch information
johntaiko authored Nov 8, 2024
1 parent d85cb13 commit 9317ca1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
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.

4 changes: 3 additions & 1 deletion provers/sgx/setup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ cfg-if = { workspace = true }
cap = { workspace = true }
dirs = { workspace = true }

file-lock = "2.1.11"


[dev-dependencies]
assert_cmd = { workspace = true }
rstest = { workspace = true }
ethers-core = { workspace = true }

[features]
sgx = []
sgx = []
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 anyhow::{anyhow, Context, Result};
use file_lock::{FileLock, FileOptions};
use raiko_lib::consts::{SupportedChainSpecs, VerifierType};
use serde_json::{Number, Value};
use sgx_prover::{
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions script/publish-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9317ca1

Please sign in to comment.