Skip to Content
OperateStatesync

Join the testnet and mainnet networks using StateSync

Follow this guide to join an existing network through statesync. To quickly stand up a fresh full node and join in the network, it’s recommended to sync through state sync.

Install Seid Binary

To stand up a sei node, the first step is to download and install seid on your machine. If you have not done so, follow the steps in Install Seid.

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.

Note: This step is not needed for fresh nodes.

Assuming your sei home directory is $HOME/.sei, backup priv_validator_state.json:

cp $HOME/.sei/data/priv_validator_state.json $HOME/priv_validator_state.json

backup priv_validator_key.json

cp $HOME/.sei/config/priv_validator_key.json $HOME/priv_validator_key.json

backup genesis.json

cp $HOME/.sei/config/genesis.json /genesis.json rm -rf $HOME/.sei/data/\* rm -rf $HOME/.sei/wasm rm -rf $HOME/.sei/config/priv_validator_key.json rm -rf $HOME/.sei/config/genesis.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 or https://rpc.sei-apis.com:443
  • testnet (atlantic-2): https://sei-testnet-rpc.polkachu.com:443 or https://rpc-testnet.sei-apis.com:443

For STATE_SYNC_PEER, pick:

  • mainnet (pacific-1): d7ad900ff4bd1cdb37b69ce0ae631b98ef2506e7@p2p.state-sync-0.pacific-1.seinetwork.io:26656 or 42f5eaf8e43b17c2e5c72c3ba8c0aea9e3e114fb@statesync-sei.rhinostake.com:11956 or 0232ab909dd71fee56076b6a00f2883a1912ffd0@sei-state-sync.p2p.brocha.in:30615
  • testnet (atlantic-2): b2664ccaa84a04b67683093fefb802b172ead6d1@sei-a2-rpc.p2p.brocha.in:30612 or babc3f3f7804933265ec9c40ad94f4da8e9e0017@testnet-seed.rhinostake.com:11956

The script sets up trust height and trust hash. 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:

state_sync.sh
#!/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 (https://t.me/+KZdhZ1eE-G01NmZk)

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 (https://t.me/+KZdhZ1eE-G01NmZk) if you have any issues.

Happy State-Syncing!

Last updated on