Skip to content

Commit

Permalink
Merge pull request #62 from dusk-network/enhance-state-downloader
Browse files Browse the repository at this point in the history
Enhance state downloader
  • Loading branch information
HDauven authored Mar 13, 2024
2 parents 008c35e + 30e4340 commit e0d56bf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ service rusk status

## Fast Syncing with Archival State Download

To significantly reduce the time required to sync your node, you can use the `/opt/dusk/bin/download_state` command. This command stops your node and replaces its current state with the latest published state from one of Dusk's archival nodes.
To significantly reduce the time required to sync your node to the latest published state, you can use the `download_state` command. This command stops your node and replaces its current state with the latest published state from one of Dusk's archival nodes.

To see the available published states, run:
```sh
download_state --list
```

### Using the Fast Sync Command

Expand Down
46 changes: 41 additions & 5 deletions bin/download_state.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

set -e

STATE_LIST_URL="https://nodes.dusk.network/state/list"

# Function to display a warning message
display_warning() {
echo "WARNING: This operation will STOP your node and REPLACE the current state with a new one."
Expand All @@ -18,11 +19,47 @@ display_warning() {
esac
}

# Function to display all published states
list_states() {
echo "Fetching available states..."
if ! curl -f -L -s "$STATE_LIST_URL"; then
echo "Error: Failed to fetch the list of states."
exit 1
fi
}

# Function to check if a specific state exists
state_exists() {
local state=$1
while : ; do
if curl -f -L -s "$STATE_LIST_URL" | grep -q "^$state$"; then
return 0 # State exists
else
echo "State does not exist. Please enter a state from the list below:"
list_states
read -p "Enter a valid state number: " state
# Update the state_number variable in the global scope
state_number=$state
fi
done
}

# Function to get the latest state
get_latest_state() {
curl -f -L -s "$STATE_LIST_URL" | tail -n 1
}

# Check if an argument is provided, otherwise use the fallback value (348211)
if [ $# -eq 0 ]; then
state_number=348211
if [ "$1" = "--list" ]; then
# List all possible states
list_states
exit 0
elif [ -n "$1" ]; then
# User provided a specific state, check if it exists
state_exists "$1"
else
state_number=$1
# No argument provided, use the latest state
state_number=$(get_latest_state)
fi

# Display warning and get user confirmation
Expand All @@ -32,7 +69,6 @@ display_warning
STATE_URL="https://nodes.dusk.network/state/$state_number"
echo "Downloading state $state_number from $STATE_URL..."


if ! curl -f -so /tmp/state.tar.gz -L "$STATE_URL"; then
echo "Error: Download failed. Exiting."
exit 1
Expand Down
1 change: 1 addition & 0 deletions itn-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ mv -f /opt/dusk/conf/wallet.toml /root/.dusk/rusk-wallet/config.toml
chmod +x /opt/dusk/bin/*
ln -sf /opt/dusk/bin/rusk /usr/bin/rusk
ln -sf /opt/dusk/bin/ruskquery /usr/bin/ruskquery
ln -sf /opt/dusk/bin/download_state /usr/bin/download_state
ln -sf /opt/dusk/bin/rusk-wallet /usr/bin/rusk-wallet

echo "Downloading verifier keys"
Expand Down

0 comments on commit e0d56bf

Please sign in to comment.