Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs/Tools] Validator: support multiple networks + cheat sheet #941

Merged
merged 18 commits into from
Nov 27, 2024
136 changes: 117 additions & 19 deletions tools/installer/full-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# DEV_NOTE: For testing purposes, you can change the branch name before merging to master.
GENESIS_BRANCH="master"
okdas marked this conversation as resolved.
Show resolved Hide resolved

# Function to print colored output
print_color() {
COLOR=$1
Expand All @@ -23,19 +26,72 @@
fi
}

# Function to install jq if not installed
install_jq() {
if ! command -v jq &> /dev/null; then
print_color $YELLOW "Installing jq..."
if [ -f /etc/debian_version ]; then
apt-get update
apt-get install -y jq
elif [ -f /etc/redhat-release ]; then
yum update -y
yum install -y jq
else
print_color $RED "Unsupported distribution. Please install jq manually."
exit 1
fi
print_color $GREEN "jq installed successfully."
else
print_color $YELLOW "jq is already installed."
fi
}

# Function to get user input
get_user_input() {
# Ask user which network to install
echo "Which network would you like to install?"
echo "1) testnet-alpha"
echo "2) testnet-beta"
echo "3) mainnet"
read -p "Enter your choice (1-3): " network_choice
okdas marked this conversation as resolved.
Show resolved Hide resolved

case $network_choice in
1) NETWORK="testnet-alpha" ;;
2) NETWORK="testnet-beta" ;;
3) NETWORK="mainnet" ;;
*) print_color $RED "Invalid choice. Exiting."; exit 1 ;;
okdas marked this conversation as resolved.
Show resolved Hide resolved
esac

print_color $GREEN "You have chosen to install the $NETWORK network."
okdas marked this conversation as resolved.
Show resolved Hide resolved

read -p "Enter the desired username to run poktrolld (default: poktroll): " POKTROLL_USER
POKTROLL_USER=${POKTROLL_USER:-poktroll}

read -p "Enter the node moniker (default: $(hostname)): " NODE_MONIKER
NODE_MONIKER=${NODE_MONIKER:-$(hostname)}

read -p "Enter the chain-id (default: poktroll): " CHAIN_ID
CHAIN_ID=${CHAIN_ID:-"poktroll"}
# Update URLs to use the branch constant
BASE_URL="https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/${GENESIS_BRANCH}/shannon/$NETWORK"
okdas marked this conversation as resolved.
Show resolved Hide resolved
SEEDS_URL="$BASE_URL/seeds"
GENESIS_URL="$BASE_URL/genesis.json"

# Download genesis.json and store it
GENESIS_FILE="/tmp/genesis.json"
curl -s -o "$GENESIS_FILE" "$GENESIS_URL"
if [ $? -ne 0 ]; then
print_color $RED "Failed to download genesis file. Please check your internet connection and try again."
exit 1
fi

# Extract chain_id from genesis.json
CHAIN_ID=$(jq -r '.chain_id' < "$GENESIS_FILE")
if [ -z "$CHAIN_ID" ]; then
print_color $RED "Failed to extract chain_id from genesis file."
exit 1
fi
print_color $GREEN "Using chain_id: $CHAIN_ID from genesis file"

# Fetch seeds from the provided URL
SEEDS_URL="https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/master/shannon/alpha/testnet-validated.seeds"
SEEDS=$(curl -s "$SEEDS_URL")
if [ -z "$SEEDS" ]; then
print_color $RED "Failed to fetch seeds from $SEEDS_URL. Please check your internet connection and try again."
Expand Down Expand Up @@ -125,6 +181,7 @@
print_color $GREEN "Cosmovisor set up successfully."
}


# Function to download and set up Poktrolld
setup_poktrolld() {
print_color $YELLOW "Setting up Poktrolld..."
Expand All @@ -138,37 +195,62 @@
exit 1
fi

# Get the version genesis started from. We can't just use `latest` as the new binary won't sync from genesis.
# We need to start syncing from scratch using the version that was used when the network started.
POKTROLLD_VERSION=$(curl -s https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/master/shannon/alpha/testnet-validated.init-version)
# Extract the version from genesis.json using jq
POKTROLLD_VERSION=$(jq -r '.app_version' < "$GENESIS_FILE")
print_color $YELLOW "Detected version from genesis: $POKTROLLD_VERSION"

if [ -z "$POKTROLLD_VERSION" ]; then
print_color $RED "Failed to extract version information from genesis file."
exit 1
fi

# Use the direct download link for the correct release
RELEASE_URL="https://github.com/pokt-network/poktroll/releases/download/${POKTROLLD_VERSION}/poktroll_linux_${ARCH}.tar.gz"
# Construct the release URL with proper version format
RELEASE_URL="https://github.com/pokt-network/poktroll/releases/download/v${POKTROLLD_VERSION}/poktroll_linux_${ARCH}.tar.gz"
print_color $YELLOW "Attempting to download from: $RELEASE_URL"

# Download and extract directly as the POKTROLL_USER
sudo -u "$POKTROLL_USER" bash << EOF
mkdir -p \$HOME/.poktroll/cosmovisor/genesis/bin
curl -L "$RELEASE_URL" | tar -zxvf - -C \$HOME/.poktroll/cosmovisor/genesis/bin
if [ \$? -ne 0 ]; then
echo "Failed to download or extract binary"
exit 1
fi
chmod +x \$HOME/.poktroll/cosmovisor/genesis/bin/poktrolld
ln -sf \$HOME/.poktroll/cosmovisor/genesis/bin/poktrolld \$HOME/bin/poktrolld
okdas marked this conversation as resolved.
Show resolved Hide resolved
source \$HOME/.profile
EOF

if [ $? -ne 0 ]; then
print_color $RED "Failed to set up Poktrolld"
exit 1
fi

print_color $GREEN "Poktrolld set up successfully."
}

# Function to configure Poktrolld
configure_poktrolld() {
print_color $YELLOW "Configuring Poktrolld..."

# Ask for confirmation to download the genesis file
GENESIS_URL="https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/master/shannon/alpha/testnet-validated.json"
print_color $YELLOW "The script will download the genesis file from:"
# Ask for confirmation to use the downloaded genesis file
print_color $YELLOW "The script has downloaded the genesis file from:"
print_color $YELLOW "$GENESIS_URL"
read -p "Are you OK with downloading and using this genesis file? (y/N): " confirm_genesis
read -p "Are you OK with using this genesis file? (y/N): " confirm_genesis
if [[ ! $confirm_genesis =~ ^[Yy] ]]; then
print_color $RED "Genesis file download cancelled. Exiting."
print_color $RED "Genesis file usage cancelled. Exiting."

Check warning on line 241 in tools/installer/full-node.sh

View workflow job for this annotation

GitHub Actions / misspell

[misspell] tools/installer/full-node.sh#L241

"cancelled" is a misspelling of "canceled"
Raw output
./tools/installer/full-node.sh:241:45: "cancelled" is a misspelling of "canceled"
exit 1
fi

# Detect external IP address
EXTERNAL_IP=$(curl -s https://api.ipify.org)
print_color $YELLOW "Detected external IP address: $EXTERNAL_IP"
read -p "Is this your correct external IP address? (Y/n): " confirm_ip
okdas marked this conversation as resolved.
Show resolved Hide resolved
if [[ $confirm_ip =~ ^[Nn] ]]; then
read -p "Please enter your external IP address: " custom_ip
EXTERNAL_IP=${custom_ip:-$EXTERNAL_IP}
fi

sudo -u "$POKTROLL_USER" bash << EOF
source \$HOME/.profile

Expand All @@ -177,12 +259,9 @@
echo "Poktrolld version: \$POKTROLLD_VERSION"

poktrolld init "$NODE_MONIKER" --chain-id="$CHAIN_ID" --home=\$HOME/.poktroll
curl -o \$HOME/.poktroll/config/genesis.json $GENESIS_URL
if [ \$? -ne 0 ]; then
echo "Failed to download genesis file. Please check your internet connection and try again."
exit 1
fi
cp "$GENESIS_FILE" \$HOME/.poktroll/config/genesis.json
sed -i -e "s|^seeds *=.*|seeds = \"$SEEDS\"|" \$HOME/.poktroll/config/config.toml
sed -i -e "s|^external_address *=.*|external_address = \"$EXTERNAL_IP:26656\"|" \$HOME/.poktroll/config/config.toml
okdas marked this conversation as resolved.
Show resolved Hide resolved
EOF
if [ $? -eq 0 ]; then
print_color $GREEN "Poktrolld configured successfully."
Expand Down Expand Up @@ -223,10 +302,28 @@
print_color $GREEN "Systemd service set up and started successfully."
}

# Function to check if ufw is installed and open port 26656. We need to open the port to keep the network healthy.
# By default, at least on Debian vultr, this port is not open to the internet.
configure_ufw() {
if command -v ufw &> /dev/null; then
print_color $YELLOW "ufw is installed."
read -p "Do you want to open port 26656 for p2p communication? (Y/n): " open_port
okdas marked this conversation as resolved.
Show resolved Hide resolved
if [[ $open_port =~ ^[Yy] ]]; then
ufw allow 26656
okdas marked this conversation as resolved.
Show resolved Hide resolved
print_color $GREEN "Port 26656 opened successfully."
else
print_color $YELLOW "Port 26656 not opened."
okdas marked this conversation as resolved.
Show resolved Hide resolved
fi
else
print_color $YELLOW "ufw is not installed. Skipping port configuration."
okdas marked this conversation as resolved.
Show resolved Hide resolved
fi
}

# Main function
main() {
print_color $GREEN "Welcome to the Poktroll Full Node Install Script!"
check_root
install_jq
get_user_input
create_user
install_dependencies
Expand All @@ -235,7 +332,8 @@
setup_poktrolld
configure_poktrolld
setup_systemd
print_color $GREEN "Poktroll Full Node installation completed successfully!"
configure_ufw
print_color $GREEN "Poktroll Full Node installation for $NETWORK completed successfully!"
print_color $YELLOW "You can check the status of your node with: sudo systemctl status cosmovisor.service"
print_color $YELLOW "View logs with: sudo journalctl -u cosmovisor.service -f"
}
Expand Down
Loading