⏩ State Sync

◻️ How to use?

Stop the service and reset the data

sudo systemctl stop initiad
cp $HOME/.initia/data/priv_validator_state.json $HOME/.initia/priv_validator_state.json.backup
initiad tendermint unsafe-reset-all --keep-addr-book --home $HOME/.initia

Get and configure the state sync information

SNAP_RPC="https://rpc.symphony-testnet.unitynodes.com:443"

LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height); \
BLOCK_HEIGHT=$((LATEST_HEIGHT - 2000)); \
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$SNAP_RPC,$SNAP_RPC\"| ; \
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"|" $HOME/.symphonyd/config/config.toml
  
mv $HOME/.symphonyd/priv_validator_state.json.backup $HOME/.symphonyd/data/priv_validator_state.json

Restart the service

sudo systemctl restart symphonyd
sudo journalctl -u symphonyd -f -o cat

◻️ How to check?

After using State Sync, you can check the synchronization of your node with the following command:

local_height=$(symphonyd status | jq -r .sync_info.latest_block_height); network_height=$(curl -s https://rpc.symphony-testnet.unitynodes.com/status | jq -r .result.sync_info.latest_block_height); blocks_left=$((network_height - local_height)); echo "Your node height: $local_height"; echo "Network height: $network_height"; echo "Blocks left: $blocks_left"
  • Your node height - the current block of your node

  • Network height - the last block of the network

  • Blocks left - how many blocks your node has left to sync.

Example:

◻️ How does it work?

State Sync allows new nodes to join a blockchain network by downloading a recent snapshot of the application state instead of processing all historical blocks. This approach is typically faster and requires less data, as the application state is usually more concise than the entire block history.

◽ The difference between using State Sync and Snapshots

State Sync:

  • Working Principle: Downloads only the latest application state at a specific block height.

  • Data Volume: Smaller data volume as only the application state is downloaded.

  • Speed: Significantly faster synchronization process as it does not require processing all historical blocks.

  • Usage: Suitable for quickly connecting new nodes, especially in large networks.

Snapshot:

  • Working Principle: Downloads a complete copy of the blockchain data up to a certain point.

  • Data Volume: Larger data volume as it includes all blocks and transactions up to the snapshot point.

  • Speed: Synchronization process may take longer compared to State Sync, especially if the snapshot contains a lot of data.

  • Usage: Suitable for nodes that need the complete transaction and block history.

Last updated