Skip to main content

State Sync

State sync allows new nodes to sync quickly by downloading a recent snapshot instead of replaying all blocks.

Overview

MethodSync TimeTrust Assumption
Full syncDaysNone (verify all)
State syncMinutesTrust snapshot providers
Snapshot restoreMinutesTrust snapshot provider

How State Sync Works

  1. Node requests trusted block hash at a trusted height
  2. Node downloads state snapshot from peers
  3. Node verifies state matches trusted hash
  4. 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:

  1. Disable state sync in config (or it will try again on restart)
  2. Node continues syncing normally from snapshot height
  3. Verify sync status:
curl -s localhost:26657/status | jq '.result.sync_info'

Comparison with Snapshots

FeatureState SyncSnapshot Restore
Download methodP2PDirect download
TrustMultiple peersSingle provider
SetupConfig-basedManual restore
SpeedFastFastest

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.