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

Set DefaultPowerReduction in app.go, added flags to script, changed swap calculation, made backup folder unique and added useful swap scripts. #8

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b01b9c7
--x-crisis-skip-assert-invariants flag in genesisd.service added
zenodeapp Sep 4, 2023
9ba0459
Changed MemTotal and SwapTotal to MemAvailable and SwapFree
zenodeapp Sep 4, 2023
8ff32b1
Had to get dependencies back on top else snap ponysay would fail
zenodeapp Sep 4, 2023
d0e3694
Forgot to move open file limits
zenodeapp Sep 4, 2023
432176c
Separated the stopping of the genesis services in order to properly c…
zenodeapp Sep 4, 2023
74bf910
Added a sleep command after stopping of services
zenodeapp Sep 4, 2023
576f0da
Added useful swap scripts to remove and create genesisd swapfiles
zenodeapp Sep 4, 2023
49eef19
Forgot to add /bin/bash in genesisd_swap_add.sh
zenodeapp Sep 4, 2023
cb48742
Renamed swap scripts
zenodeapp Sep 4, 2023
34971e5
Update swap_add.sh
zenodeapp Sep 5, 2023
bb4eb5e
Set DefaultPowerReduction in app.go
zenodeapp Sep 13, 2023
78168c6
Merge pull request #3 from zenodeapp/release.46.15-fix
zenodeapp Sep 13, 2023
e4d26c7
Script changes and flags added
zenodeapp Sep 13, 2023
40775f5
Double brackets didn't work
zenodeapp Sep 13, 2023
7321349
Syntax error
zenodeapp Sep 13, 2023
f6144b8
Wasn't POSIX sh compatible
zenodeapp Sep 13, 2023
3544704
POSIX issue
zenodeapp Sep 13, 2023
131b044
Added extra info considering priv_val_state
zenodeapp Sep 13, 2023
0920a45
Forgot space at negation
zenodeapp Sep 13, 2023
ee2bf9b
fixed priv_val_state.json to priv_validator_state.json
zenodeapp Sep 13, 2023
bb469cc
Made backup dir name based on timestamp
zenodeapp Sep 13, 2023
e9df678
Echo more info concerning priv_validator_state.json backup/restore
zenodeapp Sep 13, 2023
7c27a6e
Added no-service and no-start flags
zenodeapp Sep 13, 2023
0b0290a
Added info considering no_service and no_start
zenodeapp Sep 13, 2023
a3c6159
Fixed ponysay's and bugfix
zenodeapp Sep 13, 2023
452fb02
Made sure that priv_validator_state.json is always backed up, but res…
zenodeapp Sep 13, 2023
3aed0aa
Misplaced ponysay message
zenodeapp Sep 13, 2023
76651ab
Refactoring
zenodeapp Sep 13, 2023
31baf66
Refactoring
zenodeapp Sep 13, 2023
bc181c5
Moved repo dir to fixed variables
zenodeapp Sep 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func init() {
}

DefaultNodeHome = filepath.Join(userHomeDir, "."+Name+"d")
sdk.DefaultPowerReduction = sdk.NewIntFromUint64(1000000000000000000)
}

// GenModuleBasics generate basic module manager according to experimental flag
Expand Down
15 changes: 15 additions & 0 deletions genesisd-crisis.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=genesisd daemon
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root
ExecStart=/root/go/bin/genesisd start --x-crisis-skip-assert-invariants --log_level info
Restart=on-failure
RestartSec=60
LimitNOFILE=50000

[Install]
WantedBy=multi-user.target
181 changes: 132 additions & 49 deletions genesisd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,19 @@ THIS IS AN UPGRADE TO COSMOS SDK V0.46.15 BASED ON CRONOS RELEASE SOURCE CODE, T

EOF

moniker=""
# User-configurable variables
minimum_combined_gb=150
repo_dir=$(cd "$(dirname "$0")" && pwd)
total_ram_kb=$(grep MemTotal /proc/meminfo | awk '{print $2}')
total_swap_kb=$(grep SwapTotal /proc/meminfo | awk '{print $2}')
total_combined_gb=$((($total_ram_kb + $total_swap_kb) / 1024 / 1024))
available_disk_gb=$(df -BG --output=avail / | awk 'NR==2 {print $1}' | tr -d 'G')
disk_headroom_gb=50
backup_dir=".genesisd_backup_$(date +"%Y%m%d%H%M%S")"

# Function to add a line to a file if it doesn't already exist (to prevent duplicates)
# Usage: add_line_to_file "line" file [use_sudo]
add_line_to_file() {
local line="$1"
local file="$2"
local use_sudo="$3"

if ! grep -qF "$line" "$file"; then
if $use_sudo; then
echo "$line" | sudo tee -a "$file" > /dev/null
else
echo "$line" >> "$file"
fi

echo "Line '$line' added to $file."
else
echo "Line '$line' already exists in $file."
fi
}
# Fixed/default variables (do not modify)
moniker=""
repo_dir=$(cd "$(dirname "$0")" && pwd)
crisis_skip=false
skip_state_download=false
reset_priv_val_state=false
no_service=false
no_start=false

if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as the root user."
Expand All @@ -69,12 +54,19 @@ fi
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <command> [moniker]"
echo " <command> should be either 'upgrade' or 'init'"
echo ""
echo " Options:"
echo " --crisis-skip Makes sure that genesisd starts with the --x-crisis-skip-assert-invariants flag (default: false)"
echo " --skip-state-download Skips downloading the genesis.json file, only do this if you're certain to have the correct state file already (default: false)"
echo " --reset-priv-val-state Resets data/priv_validator_state.json file [UNSAFE] (default: false)"
echo " --no-service This prevents the genesisd service from being made (default: false)"
echo " --no-start This prevents the genesisd service from starting at the end of the script (default: false)"
exit 1
fi

case "$1" in
"upgrade")
if [ "$#" -eq 1 ]; then
if [ "$#" -eq 1 ] || { [ "$#" -ge 2 ] && [ "$(echo "$2" | cut -c 1-2)" = "--" ]; }; then
moniker=$(grep "moniker" ~/.genesisd/config/config.toml | cut -d'=' -f2 | tr -d '[:space:]"')

if [ -z "$moniker" ]; then
Expand All @@ -83,7 +75,7 @@ case "$1" in
fi

echo "Upgrade mode with moniker from previous configuration: $moniker"
elif [ "$#" -eq 2 ]; then
elif [ "$#" -ge 2 ]; then
moniker="$2"
echo "Upgrade mode with moniker: $moniker"
else
Expand All @@ -92,7 +84,12 @@ case "$1" in
fi
;;
"init")
if [ "$#" -eq 2 ]; then
if [ "$#" -ge 2 ]; then
if [ "$(echo "$2" | cut -c 1-2)" = "--" ]; then
echo "Missing or invalid argument for 'init' mode. Usage: $0 init <moniker>"
exit 1
fi

moniker="$2"
echo "Init mode with moniker: $moniker"
else
Expand All @@ -106,7 +103,73 @@ case "$1" in
;;
esac

# Process command-line arguments and set corresponding flags
for arg in "$@"; do
case "$arg" in
--crisis-skip)
crisis_skip=true
;;
--skip-state-download)
skip_state_download=true
;;
--reset-priv-val-state)
reset_priv_val_state=true
;;
--no-service)
no_service=true
;;
--no-start)
no_start=true
;;
*)
# Handle other arguments or flags here
;;
esac
done

$crisis_skip && echo "o Will add the '--x-crisis-skip-assert-invariants'-flag to the genesisd.service (--crisis-skip: $crisis_skip)"
$skip_state_download && echo "o Will skip downloading the genesis.json file (--skip-state-download: $skip_state_download)"
$reset_priv_val_state && echo "o Will reset the data/priv_validator_state.json file [UNSAFE] (--reset-priv-val-state: $reset_priv_val_state)"
! $reset_priv_val_state && echo "o Will preserve the data/priv_validator_state.json (--reset-priv-val-state: $reset_priv_val_state)"
$no_service && echo "o Will skip installing genesisd as a service (--no-service: $no_service)"
if ! $no_service && $no_start; then
echo "o Will skip starting the genesisd service at the end of the script (--no-start: $no_start)"
fi

echo ""
echo "Please note that the Genesis daemon will be halted before proceeding. You will have a 20-second window to cancel this action."
sleep 20s

service genesis stop
service genesisd stop

sleep 3s

# Function: adds a line to a file if it doesn't already exist (to prevent duplicates)
add_line_to_file() {
local line="$1"
local file="$2"
local use_sudo="$3"

if ! grep -qF "$line" "$file"; then
if $use_sudo; then
echo "$line" | sudo tee -a "$file" > /dev/null
else
echo "$line" >> "$file"
fi

echo "Line '$line' added to $file."
else
echo "Line '$line' already exists in $file."
fi
}

# ADD ADDITIONAL SWAP (IF NECESSARY)
total_ram_kb=$(grep MemAvailable /proc/meminfo | awk '{print $2}')
total_swap_kb=$(grep SwapFree /proc/meminfo | awk '{print $2}')
total_combined_gb=$((($total_ram_kb + $total_swap_kb) / 1024 / 1024))
available_disk_gb=$(df -BG --output=avail / | awk 'NR==2 {print $1}' | tr -d 'G')

if [ "$total_combined_gb" -lt "$minimum_combined_gb" ]; then
# Calculate additional swap space needed in gigabytes
additional_swap_gb=$((minimum_combined_gb - total_combined_gb + 1))
Expand Down Expand Up @@ -143,7 +206,7 @@ else
echo "No additional swap space needed."
fi

sleep 15s
sleep 3s

# SYSTEM UPDATE, INSTALLATION OF THE FOLLOWING PACKAGES: jq git wget make gcc build-essential snapd wget ponysay, INSTALLATION OF GO 1.20 via snap

Expand All @@ -165,20 +228,22 @@ ulimit -n 50000
snap install ponysay
ponysay "Installing genesisd from source code with updated genesis_29-2 mainnet!"
sleep 5s
ponysay "WARNING: cosmosvisor, evmosd processes will be killed and genesis, genesisd, evmos, evmosd system services will be stopped with this script on the next step. If you have other blockchains running, you might want to delete those parts of the script!"
ponysay "WARNING: cosmosvisor, evmosd processes will be killed and evmos, evmosd system services will be stopped with this script on the next step. If you have other blockchains running, you might want to delete those parts of the script!"
sleep 20s

#STOPPING EVMOSD DAEMON AND COSMOVISOR IF IT WAS NOT STOPPED
pkill evmosd
pkill cosmovisor
service genesis stop
service genesisd stop
service evmos stop
service evmosd stop

# BACKUP genesis_29-2 (evmos version) .genesisd
cd
rsync -r --verbose --exclude 'data' ./.genesisd/ ./.genesisd_backup/
rsync -r --verbose --exclude 'data' ./.genesisd/ ./"$backup_dir"/
mkdir -p ./"$backup_dir"/data
if cp ./.genesisd/data/priv_validator_state.json ./"$backup_dir"/data/priv_validator_state.json; then
echo "Backed up priv_validator_state.json file"
fi

# DELETING OF .genesisd FOLDER (PREVIOUS INSTALLATIONS)
cd
Expand All @@ -191,7 +256,7 @@ make install

# COPY .genesisd_backup FOLDER to .genesisd FOLDER, EXCLUDE data
cd
rsync -r --verbose --exclude 'data' ./.genesisd_backup/ ./.genesisd/
rsync -r --verbose --exclude 'data' ./"$backup_dir"/ ./.genesisd/

# SETTING UP THE NEW chain-id in CONFIG
genesisd config chain-id genesis_29-2
Expand All @@ -213,15 +278,23 @@ if [ "$1" = "init" ]; then
fi

#IMPORTING GENESIS STATE
cd
cd .genesisd/config
rm -r genesis.json
wget http://135.181.135.29/genesisd/genesis.json
if ! $skip_state_download; then
cd
cd .genesisd/config
rm -r genesis.json
wget http://135.181.135.29/genesisd/genesis.json
fi
cd

# RESET TO IMPORTED genesis.json
genesisd tendermint unsafe-reset-all

if ! $reset_priv_val_state; then
if cp ./"$backup_dir"/data/priv_validator_state.json ./.genesisd/data/priv_validator_state.json; then
echo "Restored backed up priv_validator_state.json file"
fi
fi

# CONFIG FILES
cd ~/.genesisd/config

Expand All @@ -234,13 +307,19 @@ sed -i "s/moniker = \"\"/moniker = \"$moniker\"/" config.toml
echo "Moniker value set to: $moniker"

# SETTING genesisd AS A SYSTEMD SERVICE
sudo cp "$repo_dir/genesisd.service" /etc/systemd/system/genesisd.service
systemctl daemon-reload
systemctl enable genesisd
# echo "All set!"
sleep 3s
if ! $no_service; then
if $crisis_skip; then
sudo cp "$repo_dir/genesisd-crisis.service" /etc/systemd/system/genesisd.service
else
sudo cp "$repo_dir/genesisd.service" /etc/systemd/system/genesisd.service
fi

# STARTING NODE
systemctl daemon-reload
systemctl enable genesisd
sleep 3s

# STARTING NODE
if ! $no_start; then
cat << "EOF"
\\
\\_
Expand All @@ -249,8 +328,12 @@ cat << "EOF"
Node start
EOF

sleep 5s
systemctl start genesisd

# genesisd start
ponysay "genesisd node service started, you may try *journalctl -fu genesisd -ocat* or *service genesisd status* command to see it! Welcome to GenesisL1 blockchain!"
sleep 5s
systemctl start genesisd
ponysay "genesisd node service started, you may try *journalctl -fu genesisd -ocat* or *service genesisd status* command to see it! Welcome to GenesisL1 blockchain!"
else
ponysay "genesisd node service installed, use *service genesisd start* to start it! Welcome to GenesisL1 blockchain!"
fi
else
ponysay "genesisd node is ready, use *service genesisd start* to start it! Welcome to GenesisL1 blockchain!"
fi
49 changes: 49 additions & 0 deletions genesisd_scripts/swap_add.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <swap_size_in_gb>"
echo " <swap_size_in_gb> should be the desired size of the swap file in gigabytes (GB)."
exit 1
fi

swap_size_in_gb="$1"

# Validate that the argument is a positive integer
if ! expr "$swap_size_in_gb" : '^[0-9]\+$' > /dev/null; then
echo "Error: <swap_size_in_gb> must be a positive integer."
exit 1
fi

available_disk_gb=$(df -BG --output=avail / | awk 'NR==2 {print $1}' | tr -d 'G')
if [ "$available_disk_gb" -lt "$((swap_size_in_gb))" ]; then
echo "Sorry, you don't have enough space."
exit 1
fi

echo "Adding ${swap_size_in_gb}GB of swap space..."

# Find a suitable name for the new swap file
index=2
new_swapfile="/genesisd_swapfile"
while [ -e $new_swapfile ]; do
new_swapfile="/genesisd_swapfile_$index"
index=$((index + 1))
done

# Create new swap file
fallocate -l ${swap_size_in_gb}G $new_swapfile
chmod 600 $new_swapfile
mkswap $new_swapfile
swapon $new_swapfile

echo "Additional ${swap_size_in_gb}GB of swap space added in $new_swapfile."

# Add entry to /etc/fstab to make swapfile persistent
line="$new_swapfile none swap sw 0 0"
file=/etc/fstab
if ! grep -qF "$line" "$file"; then
echo "$line" | sudo tee -a "$file" > /dev/null
echo "Line '$line' added to $file."
else
echo "Line '$line' already exists in $file."
fi
40 changes: 40 additions & 0 deletions genesisd_scripts/swap_remove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Check if an argument is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <swapfile_to_remove>"
echo " <swapfile_to_remove> is the full path to the swap file you wish to remove."
exit 1
fi

# Get the provided swap file as an argument
swapfile_to_remove="$1"

# Check if the swap file starts with '/genesisd_swapfile'
if [ "$(echo "$swapfile_to_remove" | cut -c 1-18)" != "/genesisd_swapfile" ]; then
echo "Error: The specified swap file does not start with '/genesisd_swapfile'."
exit 1
fi

# Remove the corresponding entry from /etc/fstab
swapfile_name=$(basename "$swapfile_to_remove")
sed -i "/^\/$swapfile_name /d" /etc/fstab
echo "Removed entry for $swapfile_name from /etc/fstab"

# Attempt to disable the swap file
swapoff -v "$swapfile_to_remove"

# Check if the swap file is still listed as active
if swapon --show | grep -q "^$swapfile_to_remove "; then
echo "Swap file $swapfile_to_remove was not removed because it is still in use."
else
# Check if the provided swap file exists
if [ ! -f "$swapfile_to_remove" ]; then
echo "Error: The specified swap file does not exist."
exit 1
fi

# Remove the swap file
rm -f "$swapfile_to_remove"
echo "Removed swap file: $swapfile_to_remove"
fi
Loading