Join the mainnet and testnet network using StateSync
Follow this guide to join an existing network through statesync. To quickly spin up a fresh full node and join in the network, it’s recommended to sync through state sync.
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 days to minutes.
Clean Up
If you are not starting a node from fresh, then you need to do some backups and clean ups.
Assuming your sei home directory is $HOME/.sei
, back up priv_validator_key.json
and priv_validator_state.json
:
cp $HOME/.sei/data/priv_validator_state.json $HOME/priv_validator_state.json
cp $HOME/.sei/config/priv_validator_key.json $HOME/priv_validator_key.json
Reset the state:
seid tendermint unsafe-reset-all --home $HOME/.sei --keep-addr-book
Finally, remove the existing data and wasm folders and restore the priv_validator_state.json
:
rm -rf $HOME/.sei/data/\*
rm -rf $HOME/.sei/wasm
cp $HOME/priv_validator_state.json $HOME/.sei/data/priv_validator_state.json
Statesync script
Set up the RPC servers for primary and secondary endpoints. You can use one of these RPC endpoints for Statesyning
For STATE_SYNC_RPC
, pick:
- mainnet (pacific-1):
https://sei-rpc.polkachu.com:443
orhttps://rpc.sei-apis.com:443
- testnet (atlantic-2):
https://sei-testnet-rpc.polkachu.com:443
orhttps://rpc-testnet.sei-apis.com:443
For STATE_SYNC_PEER
, pick one of these here persistent_peers
:
- mainnet (pacific-1):
3be6b24cf86a5938cce7d48f44fb6598465a9924@p2p.state-sync-0.pacific-1.seinetwork.io:26656
b21279d7092fde2e41770832a1cacc7d0051e9dc@p2p.state-sync-1.pacific-1.seinetwork.io:26656
616c05e9ba24acc89c0de630b5e3adbedaebb478@p2p.state-sync-2.pacific-1.seinetwork.io:26656
- testnet (atlantic-2):
b2664ccaa84a04b67683093fefb802b172ead6d1@sei-a2-rpc.p2p.brocha.in:30612
babc3f3f7804933265ec9c40ad94f4da8e9e0017@testnet-seed.rhinostake.com:11956
The script sets up trust_height
and trust_hash
automatically. Each statesync snapshot is created at a certain block height. The script uses the best practice here and sets the trust height to be earlier than the latest snapshot block height to avoid backward verifications.
Script that you can use:
#!/bin/bash
# Prompt for the State Sync RPC Endpoint and store it in STATE_SYNC_RPC
echo -n State Sync RPC Endpoint:
read STATE_SYNC_RPC
echo
# Prompt for the State Sync Peer and store it in STATE_SYNC_PEER
echo -n State Sync Peer:
read STATE_SYNC_PEER
echo
# Create a backup directory for keys
mkdir -p $HOME/key_backup
# Backup the validator key and state files
cp $HOME/.sei/config/priv_validator_key.json $HOME/key_backup
cp $HOME/.sei/data/priv_validator_state.json $HOME/key_backup
# Create a backup directory for the entire .sei configuration
mkdir -p $HOME/.sei_backup
# Move existing config, data, and wasm directories to the backup directory
mv $HOME/.sei/config $HOME/.sei_backup
mv $HOME/.sei/data $HOME/.sei_backup
mv $HOME/.sei/wasm $HOME/.sei_backup
# Remove the data and wasm folder
cd $HOME/.sei && ls | grep -xv "cosmovisor" | xargs rm -rf
# Restore the validator key and state files from the backup
mkdir -p $HOME/.sei/config
mkdir -p $HOME/.sei/data
cp $HOME/key_backup/priv_validator_key.json $HOME/.sei/config/
cp $HOME/key_backup/priv_validator_state.json $HOME/.sei/data/
# Set up /tmp as a 12G RAM disk to allow for more than 400 state sync chunks
sudo umount -l /tmp && sudo mount -t tmpfs -o size=12G,mode=1777 overflow /tmp
# Fetch the latest block height from the State Sync RPC endpoint
LATEST_HEIGHT=$(curl -s $STATE_SYNC_RPC/block | jq -r .result.block.header.height)
# Calculate the trust height (rounded down to the nearest 100,000)
BLOCK_HEIGHT=$(( (LATEST_HEIGHT / 100000) * 100000 ))
# Fetch the block hash at the trust height
TRUST_HASH=$(curl -s "$STATE_SYNC_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)
# Update the config.toml file to enable state sync with the appropriate settings
sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$STATE_SYNC_RPC,$STATE_SYNC_RPC\"| ; \
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"|" $HOME/.sei/config/config.toml
# Set the persistent peers in the config.toml file to the specified State Sync Peer
sed -i.bak -e "s|^persistent_peers *=.*|persistent_peers = \"$STATE_SYNC_PEER\"|" \
$HOME/.sei/config/config.toml
# Restore previously backed up files
cp $HOME/priv_validator_state.json $HOME/.sei/data/priv_validator_state.json
cp $HOME/priv_validator_key.json $HOME/.sei/config/priv_validator_key.json
cp $HOME/genesis.json $HOME/.sei/config/genesis.json
Troubleshooting statesync
Q: I can’t connect to the state sync url.
A: Try another statesync url in that case and inform us in the Sei Tech Chat .
Q: The statesync finishes, but immediately get AppHash
errors upon regular block sycing:
A: Make sure that you use the latest version of the chain node when you state-sync.
Q: The statesync randomly stops.
A: State-sync can be flaky at times, just try again. Please give it around 4-5 tries. Join our Sei Tech Chat for help if you have any issues.