Created
July 31, 2024 08:05
-
-
Save shapeshed/704eb9f7f26d2e0e5e10f646b8f6d514 to your computer and use it in GitHub Desktop.
Reset validator state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Configuration | |
SNAPSHOT_URL=https://osmosis.fra1.cdn.digitaloceanspaces.com/osmosis-1/snapshots/v25/osmosis-snapshot-202407310709-18675339.tar.lz4 | |
OSMOSIS_HOME=$HOME/.osmosisd | |
COSMOVISOR_SERVICE=cosmovisor | |
# Stop the Cosmovisor service | |
sudo systemctl stop $COSMOVISOR_SERVICE | |
if [ $? -ne 0 ]; then | |
echo "Failed to stop Cosmovisor service. Exiting." | |
exit 1 | |
fi | |
# Backup priv_validator_state.json | |
cp $OSMOSIS_HOME/data/priv_validator_state.json $OSMOSIS_HOME/priv_validator_state.json | |
if [ $? -ne 0 ]; then | |
echo "Failed to backup priv_validator_state.json. Exiting." | |
exit 1 | |
fi | |
# Reset the blockchain state | |
$OSMOSIS_HOME/cosmovisor/current/bin/osmosisd tendermint unsafe-reset-all --home $OSMOSIS_HOME --keep-addr-book | |
if [ $? -ne 0 ]; then | |
echo "Failed to reset the blockchain state. Exiting." | |
exit 1 | |
fi | |
# Remove the wasm folder | |
rm -r $OSMOSIS_HOME/wasm | |
if [ $? -ne 0 ]; then | |
echo "Failed to remove wasm folder. Exiting." | |
exit 1 | |
fi | |
# Download and extract the snapshot | |
curl -o - -L $SNAPSHOT_URL | lz4 -c -d - | tar -x -C $OSMOSIS_HOME | |
if [ $? -ne 0 ]; then | |
echo "Failed to download and extract the snapshot. Exiting." | |
exit 1 | |
fi | |
# Restore priv_validator_state.json | |
cp $OSMOSIS_HOME/priv_validator_state.json $OSMOSIS_HOME/data/priv_validator_state.json | |
if [ $? -ne 0 ]; then | |
echo "Failed to restore priv_validator_state.json. Exiting." | |
exit 1 | |
fi | |
# Start the Cosmovisor service | |
sudo systemctl start $COSMOVISOR_SERVICE | |
if [ $? -ne 0 ]; then | |
echo "Failed to start Cosmovisor service. Exiting." | |
exit 1 | |
fi | |
echo "Snapshot restoration completed successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment