From 2e113f6b9d68ccba73333fc70c43157c6c0ab8b2 Mon Sep 17 00:00:00 2001 From: Kevin Gallagher Date: Thu, 22 Sep 2016 03:08:42 -0700 Subject: [PATCH] Lock to prevent parallel execution of fetch-params.sh Two instances of the fetch-params.sh script running at once will result in corruption of the proving key and an error when the hashes are computed. This implements a lock to stop such a scenario from occurring. We also terminate and don't create the symlinks if the downloaded parameters fail the checksum command. --- zcutil/fetch-params.sh | 83 ++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 28 deletions(-) diff --git a/zcutil/fetch-params.sh b/zcutil/fetch-params.sh index 20cc8315..8ca8477a 100755 --- a/zcutil/fetch-params.sh +++ b/zcutil/fetch-params.sh @@ -13,7 +13,6 @@ REGTEST_DIR="$PARAMS_DIR/regtest" # This should have the same params as regtest. We use symlinks for now. TESTNET3_DIR="$PARAMS_DIR/testnet3" - function fetch_params { local url="$1" local output="$2" @@ -38,26 +37,47 @@ function fetch_params { fi } -cat </$lockfile" + # acquire the lock + flock -n 200 \ + && return 0 \ + || return 1 +} + +function exit_locked_error { + echo "Only one instance of fetch-params.sh can be run at a time." >&2 + exit 1 +} + +function main() { + + lock fetch-params.sh \ + || exit_locked_error + + cat <> "$README_PATH" <> "$README_PATH" <