NG
Celestia

Celestia

mainnet

Celestia

Celestia

search

beta v.0.321.084

State Sync

What's State Sync?

State sync allows a new node to join a network by fetching a snapshot of the application state at a recent height instead of fetching and replaying all historical blocks. This can reduce the time needed to sync with the network from hours/days to minutes, but you will not have an old data (earlier than snapshot height).

WARNING

You should have installed and initialized node on your server, this script works with your config files and service, if you are running a node without a service or in any other ways you should be able to modify this script by your needs.

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