Skip to content

Commit

Permalink
updated from ZEN and tested; hosting keys on BTCZ infra now
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptorex committed May 28, 2021
1 parent 8e85a88 commit 23413d1
Showing 1 changed file with 64 additions and 37 deletions.
101 changes: 64 additions & 37 deletions zcutil/fetch-params.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,64 @@ SPROUT_VKEY_NAME='sprout-verifying.key'
SAPLING_SPEND_NAME='sapling-spend.params'
SAPLING_OUTPUT_NAME='sapling-output.params'
SAPLING_SPROUT_GROTH16_NAME='sprout-groth16.params'
SPROUT_URL="https://download.z.cash/downloads"
SPROUT_URL="https://d.btcz.rocks"
SPROUT_IPFS="/ipfs/QmZKKx7Xup7LiAtFRhYsE1M7waXcv9ir9eCECyXAFGxhEo"

SHA256CMD="$(command -v sha256sum || echo shasum)"
SHA256ARGS="$(command -v sha256sum >/dev/null || echo '-a 256')"

ARIA2CMD="$(command -v aria2c || echo '')"
WGETCMD="$(command -v wget || echo '')"
IPFSCMD="$(command -v ipfs || echo '')"
CURLCMD="$(command -v curl || echo '')"

# fetch methods can be disabled with ZC_DISABLE_SOMETHING=1
ZC_DISABLE_ARIA2="${ZC_DISABLE_ARIA2:-}"
ZC_DISABLE_WGET="${ZC_DISABLE_WGET:-}"
ZC_DISABLE_IPFS="${ZC_DISABLE_IPFS:-}"
ZC_DISABLE_CURL="${ZC_DISABLE_CURL:-}"

function fetch_aria2 {
if [ -z "$ARIA2CMD" ] || ! [ -z "$ZC_DISABLE_ARIA2" ]; then
return 1
fi

local filename="$1"
local dlname="$(basename "$2")"

cat <<EOF
Retrieving (aria2): $SPROUT_URL/$filename
EOF

aria2c \
--out="$dlname" \
--continue=true \
--max-tries=3 \
--retry-wait=2 \
--split=4 \
--max-connection-per-server=4 \
--timeout=90 \
--auto-save-interval=5 \
--always-resume=false \
--allow-overwrite=true \
--download-result=full \
--summary-interval=10 \
"$SPROUT_URL/$filename" || \
{ echo -e "\n\nResume failed, downloading $filename from scratch.\n\n" \
&& aria2c \
--out="$dlname" \
--continue=false \
--remove-control-file=true \
--max-tries=3 \
--timeout=30 \
--always-resume=false \
--allow-overwrite=true \
--download-result=full \
--summary-interval=10 \
"$SPROUT_URL/$filename"
}
}

function fetch_wget {
if [ -z "$WGETCMD" ] || ! [ -z "$ZC_DISABLE_WGET" ]; then
return 1
Expand All @@ -37,16 +80,23 @@ function fetch_wget {
local dlname="$2"

cat <<EOF
Retrieving (wget): $SPROUT_URL/$filename
EOF

wget \
--progress=dot:giga \
--output-document="$dlname" \
--continue \
--retry-connrefused --waitretry=3 --timeout=30 \
"$SPROUT_URL/$filename"
--continue --tries=3 \
--retry-connrefused --waitretry=3 --timeout=90 \
"$SPROUT_URL/$filename" || \
{ echo -e "\n\nResume failed, downloading $filename from scratch.\n\n" \
&& wget \
--progress=dot:giga \
--output-document="$dlname" \
--tries=3 \
--retry-connrefused --waitretry=3 --timeout=30 \
"$SPROUT_URL/$filename"
}
}

function fetch_ipfs {
Expand All @@ -58,7 +108,6 @@ function fetch_ipfs {
local dlname="$2"

cat <<EOF
Retrieving (ipfs): $SPROUT_IPFS/$filename
EOF

Expand All @@ -74,7 +123,6 @@ function fetch_curl {
local dlname="$2"

cat <<EOF
Retrieving (curl): $SPROUT_URL/$filename
EOF

Expand All @@ -87,14 +135,12 @@ EOF

function fetch_failure {
cat >&2 <<EOF
Failed to fetch the Zcash zkSNARK parameters!
Try installing one of the following programs and make sure you're online:
* aria2
* ipfs
* wget
* curl
EOF
exit 1
}
Expand All @@ -107,27 +153,13 @@ function fetch_params {

if ! [ -f "$output" ]
then
for i in 1 2
do
for method in wget ipfs curl failure; do
if "fetch_$method" "${filename}.part.${i}" "${dlname}.part.${i}"; then
echo "Download of part ${i} successful!"
break
fi
done
done

for i in 1 2
do
if ! [ -f "${dlname}.part.${i}" ]
then
fetch_failure
for method in aria2 wget ipfs curl failure; do
if "fetch_$method" "$filename" "$dlname"; then
echo "Download successful!"
break
fi
done

cat "${dlname}.part.1" "${dlname}.part.2" > "${dlname}"
rm "${dlname}.part.1" "${dlname}.part.2"

"$SHA256CMD" $SHA256ARGS -c <<EOF
$expectedhash $dlname
EOF
Expand Down Expand Up @@ -174,10 +206,9 @@ function main() {

cat <<EOF
Zcash - fetch-params.sh
Zen uses the same zkSNARK parameters generated by ZCash.
This script will fetch the Zcash zkSNARK parameters and verify their
integrity with sha256sum.
If they already exist locally, it will exit now and do nothing else.
EOF

Expand All @@ -196,15 +227,11 @@ EOF
# This may be the first time the user's run this script, so give
# them some info, especially about bandwidth usage:
cat <<EOF
The complete parameters are currently just under 1.7GB in size, so plan
accordingly for your bandwidth constraints. If the Sprout parameters are
already present the additional Sapling parameters required are just under
800MB in size. If the files are already present and have the correct
sha256sum, no networking is used.
The parameters are currently just under 911MB in size, so plan accordingly
for your bandwidth constraints. If the files are already present and
have the correct sha256sum, no networking is used.
Creating params directory. For details about this directory, see:
$README_PATH
EOF
fi

Expand Down

0 comments on commit 23413d1

Please sign in to comment.