State Sync
State sync allows new nodes to sync quickly by downloading a recent snapshot instead of replaying all blocks.
Overview
| Method | Sync Time | Trust Assumption |
|---|---|---|
| Full sync | Days | None (verify all) |
| State sync | Minutes | Trust snapshot providers |
| Snapshot restore | Minutes | Trust snapshot provider |
How State Sync Works
- Node requests trusted block hash at a trusted height
- Node downloads state snapshot from peers
- Node verifies state matches trusted hash
- Node continues syncing from snapshot height
Prerequisites
- Fresh or reset node
- At least 2 state sync peers
- Recent trusted height and hash
Configuration
Edit ~/.monod/config/config.toml:
[statesync]
enable = true
# Trusted block height and hash
trust_height = 1000000
trust_hash = "ABCD1234..."
# RPC endpoints for verification
rpc_servers = "https://rpc1.example.com:443,https://rpc2.example.com:443"
# Discovery time
discovery_time = "15s"
# Chunk request timeout
chunk_request_timeout = "10s"
# Fetchers
chunk_fetchers = "4"
Finding Trust Height and Hash
Query a trusted RPC endpoint:
# Get latest height
LATEST=$(curl -s https://rpc.sprintnet.monolythium.com/block | jq -r '.result.block.header.height')
# Use height from ~1000 blocks ago (for safety margin)
TRUST_HEIGHT=$((LATEST - 1000))
# Get block hash at that height
TRUST_HASH=$(curl -s "https://rpc.sprintnet.monolythium.com/block?height=$TRUST_HEIGHT" | jq -r '.result.block_id.hash')
echo "Trust Height: $TRUST_HEIGHT"
echo "Trust Hash: $TRUST_HASH"
Step-by-Step Setup
1. Stop Node (if running)
sudo systemctl stop monod
2. Reset Data
monod tendermint unsafe-reset-all --home ~/.monod --keep-addr-book
3. Configure State Sync
# Set variables
SNAP_RPC="https://rpc.sprintnet.monolythium.com:443"
LATEST=$(curl -s $SNAP_RPC/block | jq -r '.result.block.header.height')
TRUST_HEIGHT=$((LATEST - 1000))
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$TRUST_HEIGHT" | jq -r '.result.block_id.hash')
# Update config
sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true|" ~/.monod/config/config.toml
sed -i.bak -E "s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$TRUST_HEIGHT|" ~/.monod/config/config.toml
sed -i.bak -E "s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"|" ~/.monod/config/config.toml
sed -i.bak -E "s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$SNAP_RPC,$SNAP_RPC\"|" ~/.monod/config/config.toml
4. Start Node
sudo systemctl start monod
5. Monitor Progress
sudo journalctl -u monod -f
Look for:
Discovered new snapshot height=1000000
Fetching snapshot chunk chunk=0
Applied snapshot chunk chunk=0
...
State sync complete
State Sync Providers
State sync requires peers that serve snapshots. Check community resources for current providers.
Serving Snapshots
To enable snapshot serving on your node:
# app.toml
[state-sync]
snapshot-interval = 1000
snapshot-keep-recent = 2
Troubleshooting
No Snapshots Available
- Verify RPC endpoints are correct
- Check that providers have snapshots enabled
- Try different RPC endpoints
Chunk Fetch Timeout
Increase timeouts in config:
chunk_request_timeout = "30s"
Hash Mismatch
- Use a more recent trust height
- Verify RPC endpoints are on same network
- Try different trust height/hash pair
Reset and Retry
If state sync fails:
sudo systemctl stop monod
monod tendermint unsafe-reset-all --home ~/.monod
# Reconfigure and try again
sudo systemctl start monod
After State Sync
Once synced:
- Disable state sync in config (or it will try again on restart)
- Node continues syncing normally from snapshot height
- Verify sync status:
curl -s localhost:26657/status | jq '.result.sync_info'
Comparison with Snapshots
| Feature | State Sync | Snapshot Restore |
|---|---|---|
| Download method | P2P | Direct download |
| Trust | Multiple peers | Single provider |
| Setup | Config-based | Manual restore |
| Speed | Fast | Fastest |
Consider Snapshots as an alternative.
FAQ
Is state sync secure?
You trust the RPC servers to provide correct state. Use multiple trusted sources.
Can validators use state sync?
Yes, for initial sync. Ensure you're fully synced before validating.
What if no peers have snapshots?
Use full sync or restore from a snapshot file instead.
How recent is the state?
Depends on provider snapshot intervals. Usually within hours of latest.
Related
- Join Network - Full sync method
- Snapshots - Snapshot restore method