Skip to content

Commit

Permalink
Merge pull request #324 from ethstorage/fix_rpc_scripts
Browse files Browse the repository at this point in the history
Fix scripts for RPC node setup
  • Loading branch information
syntrust authored Oct 29, 2024
2 parents e2ed917 + e65e899 commit 854e30f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 58 deletions.
123 changes: 66 additions & 57 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data_dir="./es-data"

remaining_args=""
shards="--shard_index 0"
use_miner=1

while [ $# -gt 0 ]; do
if [[ $1 == --miner.zk-prover-impl ]]; then
Expand All @@ -28,81 +29,89 @@ while [ $# -gt 0 ]; do
elif [[ $1 == --datadir ]]; then
data_dir=$2
shift 2
elif [[ $1 == --shard_index ]]; then
shards=""
remaining_args="$remaining_args $1"
shift
elif [[ $1 == --encoding_type=0 ]]; then # from init-rpc.sh
use_miner=0
remaining_args="$remaining_args $1"
shift
else
if [[ $1 == --shard_index ]]; then
shards=""
fi
remaining_args="$remaining_args $1"
shift
fi
done

if [ -n "$zkp_mode" ] && [ "$zkp_mode" != 1 ] && [ "$zkp_mode" != 2 ]; then
echo "Error: zk prover mode can only be 1 or 2."
exit 1
fi

# download zkey if not yet
zkey_name="blob_poseidon2.zkey"
zkey_size=560301223
zkey_url="https://es-node-zkey.s3.us-west-1.amazonaws.com/blob_poseidon2_testnet1.zkey"
if [ "$zkp_mode" = 1 ]; then
zkey_name="blob_poseidon.zkey"
zkey_size=280151245
zkey_url="https://drive.usercontent.google.com/download?id=1ZLfhYeCXMnbk6wUiBADRAn1mZ8MI_zg-&export=download&confirm=t&uuid=16ddcd58-2498-4d65-8931-934df3d0065c"
exit 1
fi
zkey_file="./build/bin/snark_lib/zkey/$zkey_name"
if [ ! -e ${zkey_file} ] || [ $(wc -c < ${zkey_file}) -ne ${zkey_size} ]; then
echo "Start downloading ${zkey_file}..."
curl $zkey_url -o ${zkey_file}
if [ ! -e ${zkey_file} ]; then
echo "Error: The zkey file was not downloaded. Please try again."
exit 1

if [ $use_miner = 1 ]; then
# download zkey if not yet
zkey_name="blob_poseidon2.zkey"
zkey_size=560301223
zkey_url="https://es-node-zkey.s3.us-west-1.amazonaws.com/blob_poseidon2_testnet1.zkey"
if [ "$zkp_mode" = 1 ]; then
zkey_name="blob_poseidon.zkey"
zkey_size=280151245
zkey_url="https://drive.usercontent.google.com/download?id=1ZLfhYeCXMnbk6wUiBADRAn1mZ8MI_zg-&export=download&confirm=t&uuid=16ddcd58-2498-4d65-8931-934df3d0065c"
fi
if [ $(wc -c < ${zkey_file}) -ne ${zkey_size} ]; then
echo "Error: The zkey file was not downloaded correctly. You can check the file content for more information."
exit 1
zkey_file="./build/bin/snark_lib/zkey/$zkey_name"
if [ ! -e ${zkey_file} ] || [ $(wc -c < ${zkey_file}) -ne ${zkey_size} ]; then
echo "Start downloading ${zkey_file}..."
curl $zkey_url -o ${zkey_file}
if [ ! -e ${zkey_file} ]; then
echo "Error: The zkey file was not downloaded. Please try again."
exit 1
fi
if [ $(wc -c < ${zkey_file}) -ne ${zkey_size} ]; then
echo "Error: The zkey file was not downloaded correctly. You can check the file content for more information."
exit 1
fi
else
echo "${zkey_file} already exists."
fi
else
echo "${zkey_file} already exists."
fi

if [ -n "$zkp_impl" ] && [ "$zkp_impl" != 1 ] && [ "$zkp_impl" != 2 ]; then
echo "Error: miner.zk-prover-impl can only be 1 or 2"
exit 1
fi

if [ -n "$zkp_impl" ] && [ "$zkp_impl" != 1 ] && [ "$zkp_impl" != 2 ]; then
echo "Error: miner.zk-prover-impl can only be 1 or 2"
exit 1
fi

if [ "$zkp_impl" = 1 ]; then

if ! [ -x "$(command -v node)" ]; then
echo 'Error: Node.js is not installed.'
exit 1
fi
if [ "$zkp_impl" = 1 ]; then

# check node js version
node_version=$(node -v)
major_version=$(echo $node_version | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$major_version" -lt 16 ]; then
echo "Error: Node.js version is too old: $node_version; must be 16 and above."
if ! [ -x "$(command -v node)" ]; then
echo 'Error: Node.js is not installed.'
exit 1
else
echo "√ Node.js version is compatible."
fi
fi

# install snarkjs if not
if ! [ "$(command -v snarkjs)" ]; then
echo "snarkjs not found, start installing..."
snarkjs_install=$(npm install -g snarkjs 2>&1)
if [ $? -eq 0 ]; then
echo "√ snarkjs installed successfully."
else
echo "Error: snarkjs install failed with the following error:"
echo "$snarkjs_install"
# check node js version
node_version=$(node -v)
major_version=$(echo $node_version | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$major_version" -lt 16 ]; then
echo "Error: Node.js version is too old: $node_version; must be 16 and above."
exit 1
fi
else
echo "√ snarkjs is already installed."
else
echo "√ Node.js version is compatible."
fi

# install snarkjs if not
if ! [ "$(command -v snarkjs)" ]; then
echo "snarkjs not found, start installing..."
snarkjs_install=$(npm install -g snarkjs 2>&1)
if [ $? -eq 0 ]; then
echo "√ snarkjs installed successfully."
else
echo "Error: snarkjs install failed with the following error:"
echo "$snarkjs_install"
exit 1
fi
else
echo "√ snarkjs is already installed."
fi

fi

fi
Expand Down
3 changes: 2 additions & 1 deletion run-rpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

./run.sh \
--rpc.addr 0.0.0.0 \
--miner.enabled=false
--miner.enabled=false \
$@

0 comments on commit 854e30f

Please sign in to comment.