Skip to content

Commit

Permalink
Support snapshots with and without indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
h0ngcha0 committed Sep 2, 2024
1 parent 285bac5 commit f3c98cb
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ RUN rm -rf /alephium-home/.alephium/user.conf
COPY snapshot-loader.sh /snapshot-loader.sh
COPY entrypoint-wrapper.sh /entrypoint-wrapper.sh

COPY user-mainnet.conf /user-mainnet.conf
COPY user-testnet.conf /user-testnet.conf
COPY user-mainnet-with-indexes.conf /user-mainnet-with-indexes.conf
COPY user-mainnet-without-indexes.conf /user-mainnet-without-indexes.conf
COPY user-testnet-with-indexes.conf /user-testnet-with-indexes.conf
COPY user-testnet-without-indexes.conf /user-testnet-without-indexes.conf

EXPOSE 39973/tcp
EXPOSE 39973/udp
Expand Down
3 changes: 2 additions & 1 deletion entrypoint-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ALEPHIUM_HOME=${ALEPHIUM_HOME:-/alephium-home/.alephium}
ALEPHIUM_NETWORK=${ALEPHIUM_NETWORK:-mainnet}
NODE_INDEXES_CONFIG=${NODE_INDEXES_CONFIG:-with-indexes}

# Call snapshot-loader.sh and ensure it completed successfully, stopping the execution otherwise.
if ! ./snapshot-loader.sh
Expand All @@ -14,7 +15,7 @@ fi
if [ ! -f "$ALEPHIUM_HOME/user.conf" ]
then
echo "Copying standalone user.conf file"
cp "/user-$ALEPHIUM_NETWORK.conf" "$ALEPHIUM_HOME/user.conf"
cp "/user-$ALEPHIUM_NETWORK-$NODE_INDEXES_CONFIG.conf" "$ALEPHIUM_HOME/user.conf"
fi

echo "Now starting Alephium full node!"
Expand Down
18 changes: 10 additions & 8 deletions snapshot-loader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ ALEPHIUM_NETWORK=${ALEPHIUM_NETWORK:-mainnet}
ALEPHIUM_FORCE_RELOAD_SNAPSHOT=${ALEPHIUM_FORCE_RELOAD_SNAPSHOT:-0}
# Node type: full or pruned. Any other value might cause unexpected behaviour
NODE_TYPE=${NODE_TYPE:-pruned}
NODE_INDEXES_CONFIG=${NODE_INDEXES_CONFIG:-with-indexes}

# If tee-hash (https://github.com/touilleio/tee-hash) is available, validates the checksum of the downloaded file.
# Do not validate the checksum otherwise
TEE_HASH_CMD=$(which cat)
VALIDATE_CHECKSUM=0
CHECKSUM_FILE=${CHECKSUM_FILE:-/var/tmp/sha256sum}
if which tee-hash >/dev/null
then
TEE_HASH_CMD="tee-hash --output ${CHECKSUM_FILE}"
VALIDATE_CHECKSUM=1
fi
# TODO: Disable for now
#if which tee-hash >/dev/null
#then
# TEE_HASH_CMD="tee-hash --output ${CHECKSUM_FILE}"
# VALIDATE_CHECKSUM=1
#fi

# Check if ALEPHIUM_HOME folder is writable
if [ ! -w "$ALEPHIUM_HOME" ]
Expand Down Expand Up @@ -46,7 +48,7 @@ then

# Check if enough disk space available
availableSpace=$(df -B1 "$ALEPHIUM_HOME" | tail -n 1 | awk '{print $4}' | head -n 1)
neededSpace=$(curl -s -I -L "$(curl -sL https://archives.alephium.org/archives/$ALEPHIUM_NETWORK/${NODE_TYPE}-node-data/_latest.txt)" | grep -i 'Content-Length:' | awk '{print $2}' | tr -d '\r')
neededSpace=$(curl -s -I -L "$(curl -sL https://archives.alephium.org/archives/$ALEPHIUM_NETWORK/${NODE_TYPE}-node-data/_latest_$NODE_INDEXES_CONFIG.txt)" | grep -i 'Content-Length:' | awk '{print $2}' | tr -d '\r')
neededSpaceWithMargin=$(echo "${neededSpace} * 1.2 / 1" | bc)
neededSpaceInGB=$(echo "${neededSpaceWithMargin} / 1000 / 1000 / 1000 / 1" | bc)
availableSpaceInGB=$(echo "${availableSpace} / 1000 / 1000 / 1000 / 1" | bc)
Expand All @@ -59,7 +61,7 @@ then
echo "Loading $ALEPHIUM_NETWORK snapshot from official https://archives.alephium.org"
# Creating a temp folder (on the same volume) where snapshot will be loaded
mkdir "$ALEPHIUM_HOME/${ALEPHIUM_NETWORK}-snapshot"
curl -L "$(curl -sL https://archives.alephium.org/archives/$ALEPHIUM_NETWORK/${NODE_TYPE}-node-data/_latest.txt)" | $TEE_HASH_CMD | tar xf - -C "$ALEPHIUM_HOME/${ALEPHIUM_NETWORK}-snapshot"
curl -L "$(curl -sL https://archives.alephium.org/archives/$ALEPHIUM_NETWORK/${NODE_TYPE}-node-data/_latest_$NODE_INDEXES_CONFIG.txt)" | $TEE_HASH_CMD | tar xf - -C "$ALEPHIUM_HOME/${ALEPHIUM_NETWORK}-snapshot"
res=$?
if [ "$res" != "0" ]; # If curl or tar command failed, stopping the load of the snapshot.
then
Expand All @@ -69,7 +71,7 @@ then
if [ "${VALIDATE_CHECKSUM}" = "1" ]
then
# Check sha256 of what has been downloaded
remote_sha256sum="$(curl -sL https://archives.alephium.org/archives/$ALEPHIUM_NETWORK/${NODE_TYPE}-node-data/_latest.txt.sha256sum)"
remote_sha256sum="$(curl -sL https://archives.alephium.org/archives/$ALEPHIUM_NETWORK/${NODE_TYPE}-node-data/_latest_$NODE_INDEXES_CONFIG.txt.sha256sum)"
local_sha256sum=$(cat "${CHECKSUM_FILE}")
if [ "$remote_sha256sum" != "$local_sha256sum" ]
then
Expand Down
2 changes: 2 additions & 0 deletions user-mainnet.conf → user-mainnet-with-indexes.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ alephium.api.api-key-enabled = false
alephium.node.event-log.enabled=true
alephium.node.event-log.index-by-tx-id = true
alephium.node.event-log.index-by-block-hash = true
alephium.node.indexes.subcontract-index = true
alephium.node.indexes.tx-output-ref-index = true
7 changes: 7 additions & 0 deletions user-mainnet-without-indexes.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
alephium.network.network-id = 0
alephium.network.bind-address = "0.0.0.0:39973"
alephium.api.network-interface = "0.0.0.0"
alephium.mining.api-interface = "0.0.0.0"
alephium.api.api-key-enabled = false

alephium.node.event-log.enabled=false
2 changes: 2 additions & 0 deletions user-testnet.conf → user-testnet-with-indexes.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ alephium.api.api-key-enabled = false
alephium.node.event-log.enabled=true
alephium.node.event-log.index-by-tx-id = true
alephium.node.event-log.index-by-block-hash = true
alephium.node.indexes.subcontract-index = true
alephium.node.indexes.tx-output-ref-index = true
8 changes: 8 additions & 0 deletions user-testnet-without-indexes.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
alephium.network.network-id = 1
alephium.network.bind-address = "0.0.0.0:39973"
alephium.discovery.bootstrap = ["bootstrap0.testnet.alephium.org:9973", "bootstrap1.testnet.alephium.org:9973"]
alephium.api.network-interface = "0.0.0.0"
alephium.mining.api-interface = "0.0.0.0"
alephium.api.api-key-enabled = false

alephium.node.event-log.enabled=false

0 comments on commit f3c98cb

Please sign in to comment.