Browse Source

Improve save/load utxo

feature/auto_ssh
nicolas.dorier 6 years ago
parent
commit
9f7d768fab
  1. 58
      contrib/load-utxo-set.sh
  2. 28
      contrib/save-utxo-set-in-bitcoind.sh
  3. 45
      contrib/save-utxo-set.sh

58
contrib/load-utxo-set.sh

@ -2,26 +2,51 @@
# This script shows the steps to download and update an archive of the current UTXO Set # This script shows the steps to download and update an archive of the current UTXO Set
exit # This script is not meant to run automatically if ! [ "$0" = "$BASH_SOURCE" ]; then
echo "This script must not be sourced"
exit 1
fi
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root after running \"sudo su -\""
exit 1
fi
## ARGS# : "${UTXO_DOWNLOAD_LINK:=http://utxosets.blob.core.windows.net/public/utxo-snapshot-bitcoin-mainnet-551636.tar}"
NETWORK="testnet" NETWORK=""
DOWNLOAD_LINK="http://utxosets.blob.core.windows.net/public/utxo-snapshot-bitcoin-testnet-1445586.tar" [[ $DOWNLOAD_LINK == *-testnet-* ]] && NETWORK="testnet"
TAR_FILE_HASH="eabaaa717bb8eeaf603e383dd8642d9d34df8e767fccbd208b0c936b79c82742" [[ $DOWNLOAD_LINK == *-mainnet-* ]] && NETWORK="mainnet"
####### [[ $DOWNLOAD_LINK == *-regtest-* ]] && NETWORK="regtest"
BITCOIN_DATA_DIR="/var/lib/docker/volumes/generated_bitcoin_datadir/_data" BITCOIN_DATA_DIR="/var/lib/docker/volumes/generated_bitcoin_datadir/_data"
[ ! -d "$BITCOIN_DATA_DIR" ] && mkdir -p "$BITCOIN_DATA_DIR" [ ! -d "$BITCOIN_DATA_DIR" ] && mkdir -p "$BITCOIN_DATA_DIR"
TAR_FILE="$BITCOIN_DATA_DIR/snapshot.tar" TAR_NAME="$(basename $DOWNLOAD_LINK)"
TAR_FILE="$BITCOIN_DATA_DIR/$TAR_NAME"
echo "Downloading $DOWNLOAD_LINK to $TAR_FILE" echo "Downloading $DOWNLOAD_LINK to $TAR_FILE"
wget "$DOWNLOAD_LINK" -q --show-progress -O "$TAR_FILE" cd "$BITCOIN_DATA_DIR"
if [ ! -f "$TAR_FILE" ]; then
wget "$DOWNLOAD_LINK" -q --show-progress
else
echo "$TAR_FILE already exists"
fi
if ! echo "$TAR_FILE_HASH" "$TAR_FILE" | sha256sum -c -; then echo "
echo "Invalid hash" fab994299273080bf7124c8c45c4ada867974ca747900178496a69e450cf713f utxo-snapshot-bitcoin-mainnet-551636.tar
eabaaa717bb8eeaf603e383dd8642d9d34df8e767fccbd208b0c936b79c82742 utxo-snapshot-bitcoin-testnet-1445586.tar
" > "trusted-utxo-sets.asc"
grep "$TAR_NAME" "trusted-utxo-sets.asc" | tee "sig.asc"
rm "trusted-utxo-sets.asc"
if ! sha256sum -c "sig.asc"; then
echo "$TAR_FILE is not trusted"
rm "sig.asc"
cd -
exit 1 exit 1
fi fi
rm "sig.asc"
cd -
NETWORK_DIRECTORY=$NETWORK NETWORK_DIRECTORY=$NETWORK
if [[ $NETWORK == "mainnet" ]]; then if [[ $NETWORK == "mainnet" ]]; then
@ -37,7 +62,14 @@ NETWORK_DIRECTORY="$BITCOIN_DATA_DIR/$NETWORK_DIRECTORY"
[ ! -d "$NETWORK_DIRECTORY" ] && mkdir "$NETWORK_DIRECTORY" [ ! -d "$NETWORK_DIRECTORY" ] && mkdir "$NETWORK_DIRECTORY"
echo "Extracting..." echo "Extracting..."
tar -xf "$TAR_FILE" -C "$BITCOIN_DATA_DIR" if ! tar -xf "$TAR_FILE" -C "$BITCOIN_DATA_DIR"; then
echo "Failed extracting, did you turned bitcoin off? (btcpay-down.sh)"
exit 1
fi
rm "$TAR_FILE"
BTCPAY_DATA_DIR="/var/lib/docker/volumes/generated_btcpay_datadir/_data"
[ ! -d "$BTCPAY_DATA_DIR" ] && mkdir -p "$BTCPAY_DATA_DIR"
echo "$TAR_NAME" > "$BTCPAY_DATA_DIR/FastSynced"
echo "Extracted" echo "Successfully downloaded and extracted, you can run btcpay again (btcpay-up.sh)"
rm "$TAR_FILE"

28
contrib/save-utxo-set-in-bitcoind.sh

@ -0,0 +1,28 @@
BITCOIND="bitcoind -datadir=/data"
BITCOIN_CLI="bitcoin-cli -datadir=/data"
$BITCOIND &
BITCOIND_PID=$!
CURRENT_HEIGHT="$($BITCOIN_CLI -rpcwait getblockcount)"
let "PRUNED_HEIGHT=$CURRENT_HEIGHT - 289"
echo "Pruning to $PRUNED_HEIGHT"
$BITCOIN_CLI pruneblockchain "$PRUNED_HEIGHT"
echo "Waiting bitcoind to stop..."
$BITCOIN_CLI stop
wait $BITCOIND_PID
NETWORK_DIRECTORY=$NETWORK
if [[ $NETWORK == "mainnet" ]]; then
NETWORK_DIRECTORY="."
fi
if [[ $NETWORK == "testnet" ]]; then
NETWORK_DIRECTORY="testnet3"
fi
cd /data
TAR_NAME="utxo-snapshot-bitcoin-$NETWORK-$PRUNED_HEIGHT.tar"
echo "Creating $TAR_NAME..."
tar -cf "$TAR_NAME" "$NETWORK_DIRECTORY/blocks/"
tar -rf "$TAR_NAME" "$NETWORK_DIRECTORY/chainstate/"

45
contrib/save-utxo-set.sh

@ -2,11 +2,11 @@
# This script shows the steps to create an archive of the current UTXO Set # This script shows the steps to create an archive of the current UTXO Set
exit # This script is not meant to run automatically exit 1 # This script is not meant to run automatically
## ARGS# ## ARGS#
NETWORK="testnet" NETWORK="mainnet"
export AZURE_STORAGE_CONTAINER="public" export AZURE_STORAGE_CONTAINER="public"
export AZURE_STORAGE_CONNECTION_STRING="" export AZURE_STORAGE_CONNECTION_STRING=""
####### #######
@ -17,46 +17,9 @@ export AZURE_STORAGE_CONNECTION_STRING=""
btcpay-down.sh btcpay-down.sh
# Run only bitcoind and connect to it # Run only bitcoind and connect to it
SCRIPT="$(cat save-utxo-set-in-bitcoind.sh)"
cd "`dirname $BTCPAY_ENV_FILE`" cd "`dirname $BTCPAY_ENV_FILE`"
docker-compose -f $BTCPAY_DOCKER_COMPOSE run -e "NETWORK=$NETWORK" bitcoind bash docker-compose -f $BTCPAY_DOCKER_COMPOSE run -e "NETWORK=$NETWORK" bitcoind bash -c "$SCRIPT"
# IN THE CONTAINER #############################################################
ENVIRONMENT=""
BITCOIND="bitcoind -datadir=/data"
BITCOIN_CLI="bitcoin-cli -datadir=/data"
$BITCOIND &
BITCOIND_PID=$!
CURRENT_HEIGHT="$($BITCOIN_CLI -rpcwait getblockcount)"
let "PRUNED_HEIGHT=$CURRENT_HEIGHT - 289"
echo "Pruning to $PRUNED_HEIGHT"
$BITCOIN_CLI pruneblockchain "$PRUNED_HEIGHT"
echo "Waiting bitcoind to stop..."
$BITCOIN_CLI stop
wait $BITCOIND_PID
NETWORK_DIRECTORY=$NETWORK
if [[ $NETWORK == "mainnet" ]]; then
NETWORK_DIRECTORY="."
fi
if [[ $NETWORK == "testnet" ]]; then
NETWORK_DIRECTORY="testnet3"
fi
cd /data
TAR_NAME="utxo-snapshot-bitcoin-$NETWORK-$PRUNED_HEIGHT.tar"
echo "Creating $TAR_NAME..."
tar -cf "$TAR_NAME" "$NETWORK_DIRECTORY/blocks/"
tar -rf "$TAR_NAME" "$NETWORK_DIRECTORY/chainstate/"
# Exit from the container
exit
# IN THE HOST #############################################################
# Restart btcpay
btcpay-up.sh btcpay-up.sh
TAR_FILE="$(echo /var/lib/docker/volumes/generated_bitcoin_datadir/_data/utxo-snapshot-*)" TAR_FILE="$(echo /var/lib/docker/volumes/generated_bitcoin_datadir/_data/utxo-snapshot-*)"

Loading…
Cancel
Save