diff --git a/.gitignore b/.gitignore index a97077919d..29acd9e66a 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,6 @@ go.work.sum integration_tests/configs/*.yaml # Utils -utils/quick-shift.sh -utils/shift-wizard.sh -utils/restate-sync.sh \ No newline at end of file +utils/tools/quick-shift.sh +utils/tools/shift-wizard.sh +utils/tools/_restate-sync.sh \ No newline at end of file diff --git a/README.md b/README.md index 5b064e8278..69598296d4 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ This script takes care of the needed steps to join the network via _state sync_. > [!WARNING] > Running this will **wipe the entire database** (the _/data_-folder **excluding** the priv_validator_state.json file). Therefore if you already have a node set up and you prefer not to have your GenesisL1 database lost, create a backup. > -> You could use [utils/create-backup.sh](/utils/create-backup.sh) for this. +> You could use [utils/backup/create.sh](/utils/backup/create.sh) for this. ``` sh setup/state-sync.sh @@ -88,13 +88,13 @@ sh setup/upgrade.sh A key is necessary to interact with the network/node. If you haven't already created one, either import one or generate a new one, using: ``` -sh utils/create-key.sh +sh utils/key/create.sh ``` OR ``` -sh utils/import-key.sh +sh utils/key/create.sh ``` > __ is the private key for a (wallet) address you already own. diff --git a/setup/README.md b/setup/README.md index f68e12ac6b..1185f09898 100644 --- a/setup/README.md +++ b/setup/README.md @@ -14,6 +14,7 @@ This script installs all the dependencies (and system configurations) that are n This script takes care of the needed steps to upgrade the node to the new fork: - It stops the node (the service) +- Installs all the necessary dependencies - Creates a backup of existing _config.toml_ or _app.toml_ files (as _.toml.bak_) - Introduces new config files - Fetches latest seeds and peers @@ -31,7 +32,7 @@ sh setup/upgrade.sh > [!CAUTION] > Running this will **wipe the entire database** (the _/data_-folder **excluding** the priv_validator_state.json file). > -> Make a backup if needed: [utils/create-backup.sh](/utils/create-backup.sh). +> Make a backup if needed: [utils/backup/create.sh](/utils/backup/create.sh). This script takes care of the needed steps to join the network via State Sync: @@ -51,14 +52,14 @@ This script takes care of the needed steps to join the network via State Sync: ``` sh setup/state-sync.sh ``` -> If you wish to change the default _[height_interval]_ of `2000`, run [utils/recalibrate-state-sync.sh](/utils/recalibrate-state-sync.sh) _[height_interval]_ yourself _after_ having run _setup/state-sync.sh_; see [utils/README.md](/utils) for more information. +> If you wish to change the default _[height_interval]_ of `2000`, run [utils/tools/restate-sync.sh](/utils/tools/restate-sync.sh) _[height_interval]_ yourself _after_ having run _setup/state-sync.sh_; see [utils/README.md](/utils) for more information. ## create-validator.sh > [!IMPORTANT] > _create-validator.sh_ requires a key. > -> If you haven't already created or imported one, use: [utils/create-key.sh](/utils/create-key.sh) _or_ [utils/import-key.sh](/utils/import-key.sh). +> If you haven't already created or imported one, use: [utils/key/create.sh](/utils/key/create.sh) _or_ [utils/key/import.sh](/utils/key/import.sh). This script should only be run once you're **fully synced**. It's a wizard; prompting the user only the required fields for creating a validator. diff --git a/setup/state-sync.sh b/setup/state-sync.sh index 1c371eecaf..6c39f60416 100644 --- a/setup/state-sync.sh +++ b/setup/state-sync.sh @@ -33,7 +33,7 @@ echo "So take this into consideration when deciding to state sync or not." echo "" echo "WARNING: Any config files will get overwritten and the data folder shall be removed, but there" echo "will be a backup and restore of the priv_validator_state.json file. If needed, use" -echo "utils/create-backup.sh to create a backup." +echo "utils/backup/create.sh to create a backup." echo "" read -p "Do you want to continue? (y/N): " ANSWER @@ -79,16 +79,16 @@ cp "./configs/default_config.toml" $CONFIG_DIR/config.toml sed -i "s/moniker = .*/moniker = \"$MONIKER\"/" $CONFIG_DIR/config.toml # Fetch latest seeds and peers list from genesis-parameters repo -sh ./utils/fetch-peers.sh +sh ./utils/fetch/peers.sh # Fetch state file from genesis-parameters repo -sh ./utils/fetch-state.sh +sh ./utils/fetch/state.sh # Fetch latest rpc_servers from genesis-parameters repo -sh ./utils/fetch-rpcs.sh +sh ./utils/fetch/rpcs.sh # Install service -sh ./utils/install-service.sh +sh ./utils/service/install.sh # Recalibrate state sync -sh ./utils/recalibrate-state-sync.sh \ No newline at end of file +sh ./utils/tools/restate-sync.sh diff --git a/setup/upgrade.sh b/setup/upgrade.sh index 89bd3d857c..f1b38e1b86 100644 --- a/setup/upgrade.sh +++ b/setup/upgrade.sh @@ -42,6 +42,9 @@ systemctl stop $BINARY_NAME # cd to root of the repository cd $REPO_ROOT +# System update and installation of dependencies +sh ./setup/dependencies.sh + # Create a backup of old config files and moniker cp $CONFIG_DIR/app.toml $CONFIG_DIR/app.toml.bak cp $CONFIG_DIR/config.toml $CONFIG_DIR/config.toml.bak @@ -55,7 +58,7 @@ cp ./configs/default_config.toml $CONFIG_DIR/config.toml sed -i "s/moniker = .*/moniker = \"$MONIKER\"/" $CONFIG_DIR/config.toml # Fetch latest seeds and peers list from genesis-parameters repo -sh ./utils/fetch-peers.sh +sh ./utils/fetch/peers.sh # Install binaries go mod tidy @@ -68,4 +71,4 @@ make install && { echo "you ever need to restore some of your previous settings." echo "" echo "When ready, turn on your node again using '$BINARY_NAME start' or 'systemctl start $BINARY_NAME'!" -} \ No newline at end of file +} diff --git a/utils/.install/.config b/utils/.install/.config new file mode 100644 index 0000000000..5d0431151a --- /dev/null +++ b/utils/.install/.config @@ -0,0 +1 @@ +version=main diff --git a/utils/.install/.versionmap b/utils/.install/.versionmap new file mode 100644 index 0000000000..bbf9622e59 --- /dev/null +++ b/utils/.install/.versionmap @@ -0,0 +1,20 @@ +.install/updater.sh v1.0.0 r +.install/_variables.sh.example v1.0.1 a +backup/create.sh v1.0.0 u +backup/README.md v1.0.0 d +fetch/peers.sh v1.0.0 u +fetch/rpcs.sh v1.0.0 u +fetch/state.sh v1.0.0 u +fetch/README.md v1.0.1 d +info/my-peer.sh v1.0.0 u +info/README.md v1.0.1 d +key/create.sh v1.0.0 u +key/import.sh v1.0.0 u +key/README.md v1.0.0 d +service/install.sh v1.0.0 u +service/uninstall.sh v1.0.0 u +service/README.md v1.0.1 d +tools/restate-sync.sh v1.0.0 u +tools/port-shifter.sh v1.0.1 u +tools/README.md v1.0.0 d +LICENSE v1.0.0 a diff --git a/utils/.install/_variables.sh.example b/utils/.install/_variables.sh.example new file mode 100644 index 0000000000..c3ef7e57e8 --- /dev/null +++ b/utils/.install/_variables.sh.example @@ -0,0 +1,28 @@ +#!/bin/bash + +# This is an example. +# Create a _variables.sh file in the root and add these variables to allow the scripts to work their magic. + +# Variables for all modules +CHAIN_ID=genesis_29-2 +BINARY_NAME=genesisd +NODE_DIR_NAME=.genesis +NODE_DIR=$HOME/$NODE_DIR_NAME +CONFIG_DIR=$NODE_DIR/config +DATA_DIR=$NODE_DIR/data + +# /fetch module variables. +# Adviced is to create a repo containing a genesis.json, seeds.txt, peers.txt and rpc_servers.txt file. +# See: https://github.com/zenodeapp/genesis-parameters/tree/main/genesis_29-2 for an example. +FETCH_URL=https://raw.githubusercontent.com/zenodeapp/genesis-parameters/main/$CHAIN_ID +SEEDS_URL=$FETCH_URL/seeds.txt +PEERS_URL=$FETCH_URL/peers.txt +STATE_URL=$FETCH_URL/genesis.json +RPC_SERVERS_URL=$FETCH_URL/rpc_servers.txt + +# /info module variables. +IP_INFO_PROVIDER=ipinfo.io/ip + +# /service module variables. +SERVICE_DIR=$(cd "$(dirname "$0")"/../.. && pwd)/services # Where the service file is located, this example points two directories back based on /service/* (e.g. /service/install.sh/../../services). +SERVICE_FILE=$BINARY_NAME.service diff --git a/utils/.install/updater.sh b/utils/.install/updater.sh new file mode 100644 index 0000000000..84010b52f1 --- /dev/null +++ b/utils/.install/updater.sh @@ -0,0 +1,274 @@ +#!/bin/bash + +UPDATER_VERSION=v1.0.0 + +usage() { + echo "COSMOS UTILS UPGRADER" + echo "" + echo "The upgrader is set to use tag/commit/branch '$VERSION' (add the flag \e[3m--version [tag|commit|branch]\e[0m to change this)." + echo "" + echo "CAUTION: running this will regenerate the README.md, if you made any custom changes, make sure to create a backup before continuing." + echo "" + read -p "Do you want to perform the upgrade using '$VERSION'? (y/N): " RESPONSE +} + +usageInstall() { + echo "COSMOS UTILS INSTALLER" + echo "" + echo "This will install the Cosmos Utilities from https://github.com/zenodeapp/cosmos-utils using tag/commit/branch '$VERSION' (add the flag \e[3m--version [tag|commit|branch]\e[0m to change this)." + echo "The user will be able to choose which utilities will be downloaded and which won't." + echo "" + read -p "Do you want to install using '$VERSION'? (y/N): " RESPONSE +} + +# Function to prompt the user for a yes/no answer (defaults to yes) +askYesNo() { + local ANSWER + ( exec /dev/null 2>&1 +} + +# Clean up temporary files +cleanup + +# Set up trap to call cleanup function on SIGINT (Ctrl+C) +trap 'cleanup; echo; exit 1' INT + +# Download necessary files for readme alterations +mkdir -p "$ROOT/.readme" +wget --no-cache -qO- "$REPO/.readme/generate.sh" > $ROOT/.readme/generate.sh +wget --no-cache -qO- "$REPO/.readme/filter.sh" > $ROOT/.readme/filter.sh +wget --no-cache -qO- "$REPO/.readme/template-installed.md" > $ROOT/.readme/template-installed.md + +# Create local versionmap if it doesn't exist +if [ ! -e "$LOCAL_VERSION_MAP" ]; then + echo ".install/updater.sh $UPDATER_VERSION r" > "$LOCAL_VERSION_MAP" +fi + +# Function to download a file +downloadFile() { + local remote_file="$1" + local remote_version="$2" + local remote_type="$3" + local prompt="$4" + local auto_yes=$5 + + if $auto_yes || askYesNo "$prompt"; then + mkdir -p "$(dirname "$ROOT/$remote_file")" + wget --no-cache -q "$REPO/$remote_file" -O "$ROOT/$remote_file" + echo "$remote_file $remote_version $remote_type" >> "$NEW_VERSION_MAP" + + case "$remote_type" in + d) + bash $ROOT/.readme/filter.sh "$ROOT/$remote_file" "$ROOT/$remote_file.tmp" "$EXCLUDE" + cat "$ROOT/$remote_file.tmp" > "$ROOT/$remote_file" + rm "$ROOT/$remote_file.tmp" + ;; + r) + # Custom behavior for updater.sh + tail -n +2 "$LOCAL_VERSION_MAP" >> "$NEW_VERSION_MAP" + cat $NEW_VERSION_MAP > "$LOCAL_VERSION_MAP" + + # Clean up temporary files + cleanup + + echo "The updater.sh script has been updated. Please restart the script for changes to take effect." + exit 0 + ;; + esac + + CHANGE_MADE=true + return 0 # Indicates success + else + return 1 # Indicates "No" response + fi +} + +# Download the remote version map +mkdir -p "$(dirname "$REMOTE_VERSION_MAP")" +wget --no-cache -qO- "$REPO_VERSION_MAP" > $REMOTE_VERSION_MAP + +# Compare local and remote version maps +while IFS= read -r remote_line; do + remote_file=$(echo "$remote_line" | awk '{print $1}') + remote_version=$(echo "$remote_line" | awk '{print $2}') + remote_type=$(echo "$remote_line" | awk '{print $3}') + + # Check if the line exists in the local version map + local_version=$(awk -v file="$remote_file" '$1==file {print $2}' "$LOCAL_VERSION_MAP") + + next_module="${remote_file%%/*}" + + if [ "$next_module" != "$current_module" ]; then + module_included=false + current_module="$next_module" + fi + + # File is not present in local version map + if [ -z "$local_version" ]; then + if ! [ "$remote_type" = "d" ] || $module_included; then + # Default prompt + prompt="File '$remote_file' is not present locally. Do you want to download it?" + + # Utility prompt + if [ "$remote_type" = "u" ]; then + prompt="New utility '$remote_file' detected. Do you want to download it?" + fi + + if [ "$remote_type" = "a" ] || [ "$remote_type" = "d" ]; then + auto_yes=true + else + auto_yes=false + fi + + if ! downloadFile "$remote_file" "$remote_version" "$remote_type" "$prompt" $auto_yes; then + EXCLUDE="$EXCLUDE,$remote_file" + else + module_included=true + fi + fi + else + if [ "$local_version" != "$remote_version" ]; then + # Default prompt + prompt="Different version found for '$remote_file' (current: $local_version). Do you want to update to $remote_version?" + + UPGRADE_FOUND=true + + # Versions differ + if ! downloadFile "$remote_file" "$remote_version" "$remote_type" "$prompt" false; then + echo "$remote_file $local_version $remote_type" >> "$NEW_VERSION_MAP" + fi + else + echo "$remote_file $remote_version $remote_type" >> "$NEW_VERSION_MAP" + fi + fi +done < $REMOTE_VERSION_MAP + +# Check for files in local version map not present in remote version map +while IFS= read -r local_line; do + local_file=$(echo "$local_line" | awk '{print $1}') + + # Check if the file is not present in the remote version map + if ! grep -q "$local_file" $REMOTE_VERSION_MAP; then + # File is not present in remote version map + if askYesNo "File '$local_file' is not present in the remote version map. Do you want to remove it?"; then + rm "$ROOT/$local_file" + + # Check if the directory is empty and remove it + DIR=$(dirname "$ROOT/$local_file") + if [ -z "$(ls -A "$DIR")" ]; then + rmdir "$DIR" # Remove the directory if it's empty + fi + + # Exclude from readme + EXCLUDE="$EXCLUDE,$local_file" + CHANGE_MADE=true + else + # Keep the local version in the new version map + local_version=$(awk -v file="$local_file" '$1==file {print $2}' "$LOCAL_VERSION_MAP") + local_type=$(awk -v file="$local_file" '$1==file {print $3}' "$LOCAL_VERSION_MAP") + echo "$local_file $local_version $local_type" >> "$NEW_VERSION_MAP" + fi + fi +done < "$LOCAL_VERSION_MAP" + +# Recreate the new local version map +cat $NEW_VERSION_MAP > "$LOCAL_VERSION_MAP" + +if ! $CHANGE_MADE && ! $UPGRADE_FOUND; then + echo "Already up to date." +elif $CHANGE_MADE; then + echo "Changes made successfully." +fi + +# Regenerate README if change detected +sh $ROOT/.readme/generate.sh --template "template-installed" + +# Add _variables.sh file if we're resetting +if $RESET; then + cat "$ROOT/.install/_variables.sh.example" > "$ROOT/_variables.sh" + echo "$ROOT/_variables.sh was overwritten by $ROOT/.install/_variables.sh.example, make sure to adapt this accordingly." +fi + +# Clean up temporary files +cleanup \ No newline at end of file diff --git a/utils/LICENSE b/utils/LICENSE new file mode 100644 index 0000000000..d200b18536 --- /dev/null +++ b/utils/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 ZENODE + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/utils/README.md b/utils/README.md index 73444025d6..bc5a92ae32 100644 --- a/utils/README.md +++ b/utils/README.md @@ -1,65 +1,112 @@ # Utilities +This contains useful scripts for maintaining a Cosmos SDK based node setup and comes from the [`cosmos-utils`](https://github.com/zenodeapp/cosmos-utils) repository. + +This has been written by ZENODE and is licensed under the MIT-license (see [LICENSE](./LICENSE)). + ## \_variables.sh -This script holds all the repository-specific variables shared with most of the scripts in the [utils](/utils) and [setup](/setup)-folder. This makes it easier to adjust the chain-id, binary name or node directory without having to change it in a lot of different scripts. +This holds all the repository-specific variables shared with most of the scripts. This makes it easier to adjust the chain-id, binary name or node directory without having to change it in a lot of different files. + +## /backup -## create-backup.sh +### [create.sh](./backup/create.sh) This script creates a backup for the current node-setup, if one existed. ``` -sh utils/create-backup.sh [backup_dir_path] +sh backup/create.sh [backup_dir_path] ``` > _[backup_dir_path]_ is optional (defaults: to a directory in the $HOME folder with a _unique_ name based on the system's current time). -## create-key.sh +## /fetch -This script creates a _new_ key (or prompts to overwrite one if the _alias_ already exists). +### [peers.sh](./fetch/peers.sh) + +This script fetches the (most recent) seeds and peers for the chain-id configured in the [\_variables.sh](./_variables.sh) file and adds it to the `seeds` and `persistent_peers` fields in the config.toml file residing in the node's directory. + +``` +sh fetch/peers.sh +``` + +### [rpcs.sh](./fetch/rpcs.sh) + +This script fetches the (most recent) rpc_servers (state sync) for the chain-id configured in the [\_variables.sh](./_variables.sh) file and adds it to the `rpc_servers` field in the config.toml file residing in the node's directory. ``` -sh utils/create-key.sh +sh fetch/rpcs.sh ``` -## fetch-peers.sh +### [state.sh](./fetch/state.sh) -This script fetches the (most recent) seeds and peers list for the chain-id configured in the [\_variables.sh](/utils/_variables.sh) file and adds it to the config.toml file residing in the node's directory. This script leverages the [`genesis-parameters`](https://github.com/zenodeapp/genesis-parameters) repo. +This script fetches the (most recent) `genesis.json` file for the chain-id configured in the [\_variables.sh](./_variables.sh) file and places it inside of the /config-folder residing in the node's directory. -## fetch-rpcs.sh +``` +sh fetch/state.sh +``` + +## /info + +### [my-peer.sh](./info/my-peer.sh) + +This script will print out your peer-id: _node-id@ip-address:port_. This is useful for sharing your node with others so that they can add you as a persistent peer. -This script fetches the (most recent) rpc_servers (state sync) for the chain-id configured in the [\_variables.sh](/utils/_variables.sh) file. This script leverages the [`genesis-parameters`](https://github.com/zenodeapp/genesis-parameters) repo. +Bear in mind that the _port_ being echo'd is extracted from the _config.toml_-file. So if you start the node on a different port without explicitly stating this in the _config.toml_-file, then the outputted port may not represent the actual port this node uses. -## fetch-state.sh +``` +sh info/my-peer.sh +``` -This script fetches the (most recent) `genesis.json` file for the chain-id configured in the [\_variables.sh](/utils/_variables.sh) file. This script leverages the [`genesis-parameters`](https://github.com/zenodeapp/genesis-parameters) repo. +> Add a --local flag to echo a local IP address, instead of your (public) external address. -## import-key.sh +## /key + +### [create.sh](./key/create.sh) + +This script creates a _new_ key (or prompts to overwrite one if the _alias_ already exists). + +``` +sh key/create.sh +``` + +### [import.sh](./key/import.sh) This script imports an _existing_ key using the provided _private Ethereum key_. ``` -sh utils/import-key.sh +sh key/import.sh ``` -## install-service.sh +## /service -This script installs the daemon as a service, which will automatically start the node whenever the device reboots (see [tgenesisd.service](/services/tgenesisd.service)). The setup scripts usually already call this, therefore it is not required to run this yourself. +### [install.sh](./service/install.sh) -## my-peer-id.sh +This script installs the daemon as a service, which will automatically start the node whenever the device reboots. See the `$SERVICE_DIR` and `$SERVICE_FILE` variables in [\_variables.sh](./_variables.sh) to see which service gets installed. -This script will print out your peer-id: _node-id@ip-address:port_. This is useful for sharing your node with others so that they can add you as a persistent peer. +``` +sh service/install.sh +``` -Bear in mind that the _port_ being echo'd is extracted from the _config.toml_-file. So if you start the node on a different port without explicitly stating this in the _config.toml_-file, then the outputted port may not represent the actual port this node uses. +### [uninstall.sh](./service/uninstall.sh) -> Add a --local flag to echo a local IP address, instead of your (public) external address. +This script uninstalls the daemon as a service. See the `$SERVICE_FILE` variable in [\_variables.sh](./_variables.sh) to see which service gets uninstalled. + +``` +sh service/uninstall.sh +``` -## recalibrate-state-sync.sh +## /tools -This script is useful if you want to recalibrate your state-sync configurations to a more recent height. **WARNING: this wipes your entire data folder, but will backup and restore the priv_validator_state.json file**. It uses the script(s) from the [`restate-sync`](https://github.com/zenodeapp/restate-sync/tree/v1.0.0) repository (`v1.0.0`). If in doubt whether this is safe, you could always check the repository to see how it works. +### [restate-sync.sh](./tools/restate-sync.sh) + +> [!CAUTION] +> Only use this if the network your node is connected to supports state-sync! + +This tool recalibrates your state-sync configurations to a more recent height. **WARNING: this wipes your entire data folder, but will backup and restore the priv_validator_state.json file**. It uses the script(s) from the [`restate-sync`](https://github.com/zenodeapp/restate-sync/tree/v1.0.0) repository (`v1.0.0`). If in doubt whether this is safe, you could always check the repository to see how it works. ``` -sh utils/recalibrate-state-sync.sh [height_interval] [rpc_server_1] [rpc_server_2] +sh tools/restate-sync.sh [height_interval] [rpc_server_1] [rpc_server_2] ``` > [height_interval] is optional (default: 2000). This means it will set the trust_height to: latest_height - height_interval (rounded to nearest multiple of height_interval). @@ -71,12 +118,17 @@ sh utils/recalibrate-state-sync.sh [height_interval] [rpc_server_1] [rpc_server_ > [!NOTE] > Leaving the __-arguments empty will leave the rpc_servers field in your config.toml untouched. -## shift-ports.sh +### [port-shifter.sh](./tools/port-shifter.sh) This script is useful if you quickly want to replace the ports in the `client.toml`, `config.toml` and `app.toml` files. It uses the script(s) from the [`port-shifter`](https://github.com/zenodeapp/port-shifter/tree/v1.0.1) repository (`v1.0.1`). If in doubt whether this is safe, you could always check the repository to see how it works. ``` -sh utils/shift-ports.sh +sh tools/port-shifter.sh ``` > is how much you would like to increment the value of the ports based on the default port values. + +
+ +

— ZEN

+

Copyright (c) 2024 ZENODE

diff --git a/utils/_variables.sh b/utils/_variables.sh index 8d19f7f833..ba3881e27e 100644 --- a/utils/_variables.sh +++ b/utils/_variables.sh @@ -1,9 +1,23 @@ #!/bin/bash +# Variables for all modules CHAIN_ID=genesis_29-2 BINARY_NAME=genesisd NODE_DIR_NAME=.genesis NODE_DIR=$HOME/$NODE_DIR_NAME CONFIG_DIR=$NODE_DIR/config DATA_DIR=$NODE_DIR/data -NETWORK_PARAMETERS_URL=https://raw.githubusercontent.com/zenodeapp/genesis-parameters/main/$CHAIN_ID \ No newline at end of file + +# /fetch module variables. +FETCH_URL=https://raw.githubusercontent.com/zenodeapp/genesis-parameters/main/$CHAIN_ID +SEEDS_URL=$FETCH_URL/seeds.txt +PEERS_URL=$FETCH_URL/peers.txt +STATE_URL=$FETCH_URL/genesis.json +RPC_SERVERS_URL=$FETCH_URL/rpc_servers.txt + +# /info module variables. +IP_INFO_PROVIDER=ipinfo.io/ip + +# /service module variables. +SERVICE_DIR=$(cd "$(dirname "$0")"/../.. && pwd)/services +SERVICE_FILE=$BINARY_NAME.service diff --git a/utils/backup/README.md b/utils/backup/README.md new file mode 100644 index 0000000000..11e6555708 --- /dev/null +++ b/utils/backup/README.md @@ -0,0 +1,11 @@ +## /backup + +### [create.sh](../backup/create.sh) + +This script creates a backup for the current node-setup, if one existed. + +``` +sh backup/create.sh [backup_dir_path] +``` + +> _[backup_dir_path]_ is optional (defaults: to a directory in the $HOME folder with a _unique_ name based on the system's current time). diff --git a/utils/create-backup.sh b/utils/backup/create.sh similarity index 94% rename from utils/create-backup.sh rename to utils/backup/create.sh index 5bc0f324fb..cf9c54c608 100644 --- a/utils/create-backup.sh +++ b/utils/backup/create.sh @@ -1,10 +1,7 @@ #!/bin/bash -# Root of the current repository -REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd) - -# Source the variables file -. "$REPO_ROOT/utils/_variables.sh" +# Source the _variables.sh file +. "$(cd "$(dirname "$0")"/.. && pwd)/_variables.sh" # Node directory check if [ ! -e "$NODE_DIR" ]; then diff --git a/utils/fetch-state.sh b/utils/fetch-state.sh deleted file mode 100644 index 69ba2c99be..0000000000 --- a/utils/fetch-state.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Root of the current repository -REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd) - -# Source the variables file -. "$REPO_ROOT/utils/_variables.sh" - -# Fetch genesis.json -wget -qO "$CONFIG_DIR/genesis.json" $NETWORK_PARAMETERS_URL/genesis.json - -# Echo result -echo "Added genesis.json file to $CONFIG_DIR" \ No newline at end of file diff --git a/utils/fetch/README.md b/utils/fetch/README.md new file mode 100644 index 0000000000..3c1bc390f9 --- /dev/null +++ b/utils/fetch/README.md @@ -0,0 +1,25 @@ +## /fetch + +### [peers.sh](../fetch/peers.sh) + +This script fetches the (most recent) seeds and peers for the chain-id configured in the [\_variables.sh](../_variables.sh) file and adds it to the `seeds` and `persistent_peers` fields in the config.toml file residing in the node's directory. + +``` +sh fetch/peers.sh +``` + +### [rpcs.sh](../fetch/rpcs.sh) + +This script fetches the (most recent) rpc_servers (state sync) for the chain-id configured in the [\_variables.sh](../_variables.sh) file and adds it to the `rpc_servers` field in the config.toml file residing in the node's directory. + +``` +sh fetch/rpcs.sh +``` + +### [state.sh](../fetch/state.sh) + +This script fetches the (most recent) `genesis.json` file for the chain-id configured in the [\_variables.sh](../_variables.sh) file and places it inside of the /config-folder residing in the node's directory. + +``` +sh fetch/state.sh +``` diff --git a/utils/fetch-peers.sh b/utils/fetch/peers.sh similarity index 55% rename from utils/fetch-peers.sh rename to utils/fetch/peers.sh index b13d9b3f82..3a7168e536 100644 --- a/utils/fetch-peers.sh +++ b/utils/fetch/peers.sh @@ -1,14 +1,11 @@ #!/bin/bash -# Root of the current repository -REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd) - -# Source the variables file -. "$REPO_ROOT/utils/_variables.sh" +# Source the _variables.sh file +. "$(cd "$(dirname "$0")"/.. && pwd)/_variables.sh" # Fetch latest seeds and peers -SEEDS=$(wget -qO - $NETWORK_PARAMETERS_URL/seeds.txt | head -n 1) -PERSISTENT_PEERS=$(wget -qO - $NETWORK_PARAMETERS_URL/peers.txt | head -n 1) +SEEDS=$(wget -qO - $SEEDS_URL | head -n 1) +PERSISTENT_PEERS=$(wget -qO - $PEERS_URL | head -n 1) # Add latest seeds and peers to the config.toml file sed -i "s#seeds = .*#seeds = $SEEDS#" "$CONFIG_DIR/config.toml" diff --git a/utils/fetch-rpcs.sh b/utils/fetch/rpcs.sh similarity index 62% rename from utils/fetch-rpcs.sh rename to utils/fetch/rpcs.sh index 2c955704e2..2881be17cf 100644 --- a/utils/fetch-rpcs.sh +++ b/utils/fetch/rpcs.sh @@ -1,13 +1,10 @@ #!/bin/bash -# Root of the current repository -REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd) - -# Source the variables file -. "$REPO_ROOT/utils/_variables.sh" +# Source the _variables.sh file +. "$(cd "$(dirname "$0")"/.. && pwd)/_variables.sh" # Fetch latest rpc_servers -RPC_SERVERS=$(wget -qO - $NETWORK_PARAMETERS_URL/rpc_servers.txt | head -n 1) +RPC_SERVERS=$(wget -qO - $RPC_SERVERS_URL | head -n 1) if [ -z "$RPC_SERVERS" ] || [ "$RPC_SERVERS" = '""' ]; then # Echo result diff --git a/utils/fetch/state.sh b/utils/fetch/state.sh new file mode 100644 index 0000000000..d64efd8df8 --- /dev/null +++ b/utils/fetch/state.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Source the _variables.sh file +. "$(cd "$(dirname "$0")"/.. && pwd)/_variables.sh" + +# Fetch genesis.json +wget -qO "$CONFIG_DIR/genesis.json" $STATE_URL + +# Echo result +echo "Added genesis.json file to $CONFIG_DIR" \ No newline at end of file diff --git a/utils/info/README.md b/utils/info/README.md new file mode 100644 index 0000000000..38d3c6dcf7 --- /dev/null +++ b/utils/info/README.md @@ -0,0 +1,13 @@ +## /info + +### [my-peer.sh](../info/my-peer.sh) + +This script will print out your peer-id: _node-id@ip-address:port_. This is useful for sharing your node with others so that they can add you as a persistent peer. + +Bear in mind that the _port_ being echo'd is extracted from the _config.toml_-file. So if you start the node on a different port without explicitly stating this in the _config.toml_-file, then the outputted port may not represent the actual port this node uses. + +``` +sh info/my-peer.sh +``` + +> Add a --local flag to echo a local IP address, instead of your (public) external address. diff --git a/utils/my-peer-id.sh b/utils/info/my-peer.sh similarity index 70% rename from utils/my-peer-id.sh rename to utils/info/my-peer.sh index 36d7c86942..d09cce43dd 100644 --- a/utils/my-peer-id.sh +++ b/utils/info/my-peer.sh @@ -1,13 +1,9 @@ #!/bin/bash -# Root of the current repository -REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd) - -# Source the variables file -. "$REPO_ROOT/utils/_variables.sh" +# Source the _variables.sh file +. "$(cd "$(dirname "$0")"/.. && pwd)/_variables.sh" # IP addresss -IP_INFO_PROVIDER=ipinfo.io/ip if [ "$1" = "--local" ]; then IP_ADDRESS="127.0.0.1" else diff --git a/utils/install-service.sh b/utils/install-service.sh deleted file mode 100644 index 04c5574c48..0000000000 --- a/utils/install-service.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -# Root of the current repository -REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd) - -# Source the variables file -. "$REPO_ROOT/utils/_variables.sh" - -# Install service -cp $REPO_ROOT/services/$BINARY_NAME.service /etc/systemd/system/$BINARY_NAME.service -systemctl daemon-reload -systemctl enable $BINARY_NAME \ No newline at end of file diff --git a/utils/key/README.md b/utils/key/README.md new file mode 100644 index 0000000000..e064b48e06 --- /dev/null +++ b/utils/key/README.md @@ -0,0 +1,17 @@ +## /key + +### [create.sh](../key/create.sh) + +This script creates a _new_ key (or prompts to overwrite one if the _alias_ already exists). + +``` +sh key/create.sh +``` + +### [import.sh](../key/import.sh) + +This script imports an _existing_ key using the provided _private Ethereum key_. + +``` +sh key/import.sh +``` diff --git a/utils/create-key.sh b/utils/key/create.sh similarity index 64% rename from utils/create-key.sh rename to utils/key/create.sh index d44493b86c..2b2ec53e91 100644 --- a/utils/create-key.sh +++ b/utils/key/create.sh @@ -6,11 +6,8 @@ if [ -z "$1" ]; then exit 1 fi -# Root of the current repository -REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd) - -# Source the variables file -. "$REPO_ROOT/utils/_variables.sh" +# Source the _variables.sh file +. "$(cd "$(dirname "$0")"/.. && pwd)/_variables.sh" # Arguments KEY_ALIAS=$1 diff --git a/utils/import-key.sh b/utils/key/import.sh similarity index 69% rename from utils/import-key.sh rename to utils/key/import.sh index 97d71f44c1..9e1edd1ae1 100644 --- a/utils/import-key.sh +++ b/utils/key/import.sh @@ -6,11 +6,8 @@ if [ -z "$1" ] || [ -z "$2" ]; then exit 1 fi -# Root of the current repository -REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd) - -# Source the variables file -. "$REPO_ROOT/utils/_variables.sh" +# Source the _variables.sh file +. "$(cd "$(dirname "$0")"/.. && pwd)/_variables.sh" # Arguments KEY_ALIAS=$1 diff --git a/utils/recalibrate-state-sync.sh b/utils/recalibrate-state-sync.sh deleted file mode 100644 index 514b95e34d..0000000000 --- a/utils/recalibrate-state-sync.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# RESTATE SYNC for recalibrating to a more recent height. -# Original: https://github.com/zenodeapp/restate-sync -# ZENODE (https://zenode.app) - Adapted for GenesisL1 - -# $1 is [height_interval] (default: 2000) -# $2 is [rpc_server_1] (default: the first rpc configured in rpc_servers) -# $3 is [rpc_server_2] (default: [rpc_server_1]) - -# Root of the current repository -REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd) - -# Source the variables file -. "$REPO_ROOT/utils/_variables.sh" - -# Repository where the port shifter resides -VERSION=v1.0.0 # Added versioning for non-breaking changes and security measures -EXTERNAL_REPO=https://raw.githubusercontent.com/zenodeapp/restate-sync/$VERSION - -# restate-sync.sh -# See https://github.com/zenodeapp/restate-sync/blob/v1.0.0/restate-sync.sh -curl -sO $EXTERNAL_REPO/restate-sync.sh -if sh ./restate-sync.sh "$BINARY_NAME" "$NODE_DIR_NAME" "$1" "$2" "$3"; then - rm restate-sync.sh -else - rm restate-sync.sh - exit 1 -fi \ No newline at end of file diff --git a/utils/service/README.md b/utils/service/README.md new file mode 100644 index 0000000000..d57278cc3a --- /dev/null +++ b/utils/service/README.md @@ -0,0 +1,17 @@ +## /service + +### [install.sh](../service/install.sh) + +This script installs the daemon as a service, which will automatically start the node whenever the device reboots. See the `$SERVICE_DIR` and `$SERVICE_FILE` variables in [\_variables.sh](../_variables.sh) to see which service gets installed. + +``` +sh service/install.sh +``` + +### [uninstall.sh](../service/uninstall.sh) + +This script uninstalls the daemon as a service. See the `$SERVICE_FILE` variable in [\_variables.sh](../_variables.sh) to see which service gets uninstalled. + +``` +sh service/uninstall.sh +``` diff --git a/utils/service/install.sh b/utils/service/install.sh new file mode 100644 index 0000000000..0b4840b737 --- /dev/null +++ b/utils/service/install.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Source the _variables.sh file +. "$(cd "$(dirname "$0")"/.. && pwd)/_variables.sh" + +# Stop service if it exists +systemctl stop $SERVICE_FILE + +# Install service +cp $SERVICE_DIR/$SERVICE_FILE /etc/systemd/system/$SERVICE_FILE +systemctl daemon-reload +systemctl enable $SERVICE_FILE \ No newline at end of file diff --git a/utils/service/uninstall.sh b/utils/service/uninstall.sh new file mode 100644 index 0000000000..5484a917c8 --- /dev/null +++ b/utils/service/uninstall.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Source the _variables.sh file +. "$(cd "$(dirname "$0")"/.. && pwd)/_variables.sh" + +# Stop service if it exists +systemctl stop $SERVICE_FILE + +# Uninstall service +systemctl disable $SERVICE_FILE +rm /etc/systemd/system/$SERVICE_FILE +systemctl daemon-reload \ No newline at end of file diff --git a/utils/shift-ports.sh b/utils/shift-ports.sh deleted file mode 100644 index 3474c7dc60..0000000000 --- a/utils/shift-ports.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# PORT SHIFTER for app.toml and config.toml files. -# Original: https://github.com/zenodeapp/port-shifter -# ZENODE (https://zenode.app) - Adapted for GenesisL1 - -# Root of the current repository -REPO_ROOT=$(cd "$(dirname "$0")"/.. && pwd) - -# Source the variables file -. "$REPO_ROOT/utils/_variables.sh" - -# Repository where the port shifter resides -VERSION=v1.0.1 # Added versioning for non-breaking changes and security measures -EXTERNAL_REPO=https://raw.githubusercontent.com/zenodeapp/port-shifter/$VERSION - -# quick-shift.sh (simple variant, $1 is , e.g.: 1000) -# See https://github.com/zenodeapp/port-shifter/blob/v1.0.1/quick-shift.sh -curl -sO $EXTERNAL_REPO/quick-shift.sh -sh ./quick-shift.sh "$CONFIG_DIR" $1 -rm quick-shift.sh - -# shift-wizard.sh (more advanced, if you prefer to edit individual ports) -# See: https://github.com/zenodeapp/port-shifter/blob/v1.0.1/shift-wizard.sh -# curl -sO $EXTERNAL_REPO/shift-wizard.sh -# sh ./shift-wizard.sh "$CONFIG_DIR" -# rm shift-wizard.sh diff --git a/utils/tools/README.md b/utils/tools/README.md new file mode 100644 index 0000000000..f53452dc56 --- /dev/null +++ b/utils/tools/README.md @@ -0,0 +1,31 @@ +## /tools + +### [restate-sync.sh](../tools/restate-sync.sh) + +> [!CAUTION] +> Only use this if the network your node is connected to supports state-sync! + +This tool recalibrates your state-sync configurations to a more recent height. **WARNING: this wipes your entire data folder, but will backup and restore the priv_validator_state.json file**. It uses the script(s) from the [`restate-sync`](https://github.com/zenodeapp/restate-sync/tree/v1.0.0) repository (`v1.0.0`). If in doubt whether this is safe, you could always check the repository to see how it works. + +``` +sh tools/restate-sync.sh [height_interval] [rpc_server_1] [rpc_server_2] +``` + +> [height_interval] is optional (default: 2000). This means it will set the trust_height to: latest_height - height_interval (rounded to nearest multiple of height_interval). +> +> [rpc_server_1] is optional (default: first rpc server configured in your config.toml file). If there is no rpc server configured, the script will abort. +> +> [rpc_server_2] is optional (default: rpc_server_1). + +> [!NOTE] +> Leaving the __-arguments empty will leave the rpc_servers field in your config.toml untouched. + +### [port-shifter.sh](../tools/port-shifter.sh) + +This script is useful if you quickly want to replace the ports in the `client.toml`, `config.toml` and `app.toml` files. It uses the script(s) from the [`port-shifter`](https://github.com/zenodeapp/port-shifter/tree/v1.0.1) repository (`v1.0.1`). If in doubt whether this is safe, you could always check the repository to see how it works. + +``` +sh tools/port-shifter.sh +``` + +> is how much you would like to increment the value of the ports based on the default port values. diff --git a/utils/tools/port-shifter.sh b/utils/tools/port-shifter.sh new file mode 100644 index 0000000000..e705b4d0ef --- /dev/null +++ b/utils/tools/port-shifter.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# PORT SHIFTER for client.toml, app.toml and config.toml files (Wrapper variant) +# Original: https://github.com/zenodeapp/port-shifter +# ZENODE (https://zenode.app) + +# Root of repository +ROOT=$(cd "$(dirname "$0")"/.. && pwd) + +# Source the _variables.sh file +. "$ROOT/_variables.sh" + +# Where the downloaded script has to be saved +SAVE_AS="$ROOT/tools/_port-shifter.sh" + +# Repository where the port shifter resides +VERSION=v1.0.1 # Added versioning for non-breaking changes and security measures +EXTERNAL_REPO=https://raw.githubusercontent.com/zenodeapp/port-shifter/$VERSION + +# quick-shift.sh (simple variant, $1 is , e.g.: 1000) +# See https://github.com/zenodeapp/port-shifter/blob/v1.0.1/quick-shift.sh +wget -O $SAVE_AS $EXTERNAL_REPO/quick-shift.sh +# shift-wizard.sh (more advanced, if you prefer to edit individual ports) +# See: https://github.com/zenodeapp/port-shifter/blob/v1.0.1/shift-wizard.sh +# wget -O $SAVE_AS $EXTERNAL_REPO/shift-wizard.sh + +# Execute script +sh $SAVE_AS "$CONFIG_DIR" $1 + +# Capture the exit status of the script execution +RESULT=$? + +# Cleanup +rm $SAVE_AS + +# Exit the script with the captured exit status, indicating success (0) or failure (non-zero) +exit $RESULT diff --git a/utils/tools/restate-sync.sh b/utils/tools/restate-sync.sh new file mode 100644 index 0000000000..f643aaf1ec --- /dev/null +++ b/utils/tools/restate-sync.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# RESTATE SYNC for recalibrating to a more recent height (Wrapper variant) +# Original: https://github.com/zenodeapp/restate-sync +# ZENODE (https://zenode.app) + +# $1 is [height_interval] (default: 2000) +# $2 is [rpc_server_1] (default: the first rpc configured in rpc_servers) +# $3 is [rpc_server_2] (default: [rpc_server_1]) + +# Root of repository +ROOT=$(cd "$(dirname "$0")"/.. && pwd) + +# Source the _variables.sh file +. "$ROOT/_variables.sh" + +# Where the downloaded script has to be saved +SAVE_AS="$ROOT/tools/_restate-sync.sh" + +# Repository where the port shifter resides +VERSION=v1.0.0 # Added versioning for non-breaking changes and security measures +EXTERNAL_REPO=https://raw.githubusercontent.com/zenodeapp/restate-sync/$VERSION + +# restate-sync.sh +# See https://github.com/zenodeapp/restate-sync/blob/v1.0.0/restate-sync.sh +wget -O $SAVE_AS $EXTERNAL_REPO/restate-sync.sh + +# Execute script +sh $SAVE_AS "$BINARY_NAME" "$NODE_DIR_NAME" "$1" "$2" "$3" + +# Capture the exit status of the script execution +RESULT=$? + +# Cleanup +rm $SAVE_AS + +# Exit the script with the captured exit status, indicating success (0) or failure (non-zero) +exit $RESULT