⏩ State Sync

◻️ How to use?

Stop the service and reset the data

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

Get and configure the state sync information

SNAP_RPC=https://rpc.nillion-testnet.unitynodes.com:443
LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height); \
BLOCK_HEIGHT=$((LATEST_HEIGHT - 1000)); \
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

echo $LATEST_HEIGHT $BLOCK_HEIGHT $TRUST_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\"| ; \
s|^(seeds[[:space:]]+=[[:space:]]+).*$|\1\"\"|" $HOME/.nillionapp/config/config.toml
nilchaind tendermint unsafe-reset-all --home /root/.nillionapp
curl -Ls https://snapshots-testnet.unitynodes.com/nillion-testnet/addrbook.json > $HOME/.nillionapp/config/addrbook.json
sudo systemctl restart nilchaind && journalctl -fu nilchaind -o cat

Restart the service

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

◻️ How to check?

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

while true; do 
  local_height=$(nilchaind status | jq -r .sync_info.latest_block_height)
  network_height=$(curl -s https://rpc.nillion-testnet.unitynodes.com/status | jq -r '.result.sync_info.latest_block_height')
  blocks_left=$((network_height - local_height))

  echo -e "\033[1;33m[Sync Status]\033[0m \033[1;32mNode Height:\033[0m \033[1;37m$local_height\033[0m | \033[1;32mNetwork Height:\033[0m \033[1;37m$network_height\033[0m | \033[1;32mBlocks Left:\033[0m \033[1;31m$blocks_left\033[0m"

  sleep 5
done
  • 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.

◻️ 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