State Sync

State sync lets a new node join a network quickly by using a recent application state snapshot instead of replaying all historical blocks. However, older data won't be accessible.

WARNING

Install and initialize the node on your server, as this script works with your config files and service. For other setups, modify the script as needed.

Enable the State Sync and Start Your Node
# Set variables
daemon_name="celestiad"
statesync_rpc="https://rpc-3.celestia.nodes.guru"
rpc_servers="https:\\/\\/rpc-3.celestia.nodes.guru:443,https:\\/\\/rpc-3.celestia.nodes.guru:443"
statesync_homedir="$HOME/.celestia-app"
height_offset=2000
# Get height and hash
latest_height=$(curl -s $statesync_rpc/block | jq -r .result.block.header.height)
height=$((latest_height - $height_offset))
hash=$(curl -s "$statesync_rpc/block?height=$height" | jq -r .result.block_id.hash)
# Get peer
peer_status=$(curl -s "$statesync_rpc"/status | jq .result)
peer_node_id=$(echo $peer_status | jq .node_info.id | sed 's/"//g')
striped_rpc=$(echo $statesync_rpc | sed 's/https\?:\/\///')
peer_port=$(echo $peer_status | jq .node_info.listen_addr | sed 's/"//g' | awk -F'[/:]' '{print $NF}')
peer_id="${peer_node_id}@${striped_rpc}:${peer_port}"
# Setup
sed -i '/\[statesync\]/{:a;n;/enable/s/false/true/;Ta;}' $statesync_homedir/config/config.toml
sed -i.bak -e "s/rpc_servers *=.*/rpc_servers = \"$rpc_servers\"/g" $statesync_homedir/config/config.toml
sed -i.bak -e "s/trust_height *=.*/trust_height = \"$height\"/g" $statesync_homedir/config/config.toml
sed -i.bak -e "s/trust_hash *=.*/trust_hash = \"$hash\"/g" $statesync_homedir/config/config.toml
sed -i "s/^persistent_peers *=.*/persistent_peers = \"$peer_id\"/;" $statesync_homedir/config/config.toml
# Wipe database
sudo systemctl stop $daemon_name
unsafe_reset_response=$($daemon_name unsafe-reset-all --home $statesync_homedir 2>&1)
if echo "$unsafe_reset_response" | grep -q -E "Error|error"; then
$daemon_name tendermint unsafe-reset-all --home $statesync_homedir --keep-addr-book
fi
# Restart service
sudo systemctl restart $daemon_name
sudo journalctl -u $daemon_name -f -o cat