From c478980ec70bde4ef0141a71ddd18d33db8d02ad Mon Sep 17 00:00:00 2001 From: Julian Rubino Date: Wed, 6 Dec 2023 15:27:03 -0300 Subject: [PATCH] create state-sync documentation (#199) Co-authored-by: Denis Fadeev --- docs/validators/node.mdx | 62 ------------------- docs/validators/state-sync.mdx | 109 +++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 62 deletions(-) create mode 100644 docs/validators/state-sync.mdx diff --git a/docs/validators/node.mdx b/docs/validators/node.mdx index f9181aa9..e3159088 100644 --- a/docs/validators/node.mdx +++ b/docs/validators/node.mdx @@ -136,65 +136,3 @@ app.toml file. See the for more information. See more about your Validator Monitoring [here](/reference/validators-monitoring). - -# Syncing from a StateSync node - -## Testnet - -| Region | IP | -| :-------------------------- | :------------- | -| US | 35.224.160.108 | -| Singapore | 3.0.80.230 | - -## Mainnet - -| Region | IP | -| :-------------------------- | :-- | -| | TBD | - - -## State Sync - -Use the state sync node closer your node. Run the following command to collect -the `latest block height` and `latest block hash`: - -```bash -curl -s http://:26657/block | jq -r '.result.block.header.height + "\n" + .result.block_id.hash' -``` - -Example Output - -``` -$ curl -s http://35.224.160.108:26657/block | jq -r '.result.block.header.height + "\n" + .result.block_id.hash' -120659 -2554175FC58E5AC01723903971D1153BC1AF5341A51E5EABC22904730085B3CA -``` - -Use the return values to edit the following variables in -`/home/zetachain/.zetacored/config/config.toml` - -```bash -[statesync] -# State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine -# snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in -# the network to take and serve state machine snapshots. State sync is not attempted if the node -# has any local state (LastBlockHeight > 0). The node will have a truncated block history, -# starting from the height of the snapshot. -enable = true - -# RPC servers (comma-separated) for light client verification of the synced state machine and -# retrieval of state data for node bootstrapping. Also needs a trusted height and corresponding -# header hash obtained from a trusted source, and a period during which validators can be trusted. -# -# For Cosmos SDK-based chains, trust_period should usually be about 2/3 of the unbonding time (~2 -# weeks) during which they can be financially punished (slashed) for misbehavior. -rpc_servers = ":26657,:26657" -trust_height = -trust_hash = "" -``` - -Start the ZetaChain node: - -```bash -zetacored start -``` diff --git a/docs/validators/state-sync.mdx b/docs/validators/state-sync.mdx new file mode 100644 index 00000000..6977fe49 --- /dev/null +++ b/docs/validators/state-sync.mdx @@ -0,0 +1,109 @@ +--- +sidebar_position: 4 +sidebar_label: State-sync +hide_title: false +id: state-sync +title: Syncing a node using state-sync +--- + +# Syncing a node using state-sync + +Follow this guide to setup a RPC node using state-sync. +This guide was created and tested in MacOS and may need to be modified slightly for your local system. + +## State-sync nodes +### Testnet + +| Region | IP | +| :-------------------------- | :------------- | +| US | 35.224.160.108 | + +### Mainnet + +| Region | IP | +| :-------------------------- | :-- | +| | TBD | + +## Download binary +Make sure you are downloading the same version as our network is using. +You can find the available `zetacored` versions here: https://github.com/zeta-chain/node/tags + +1. Download the binary and give execution perms to the binary: + +```bash +wget https://github.com/zeta-chain/node/releases/download/v10.1.0/zetacored_testnet-darwin-amd64 -O /usr/local/bin/zetacored +chmod a+x /usr/local/bin/zetacored +``` + +## Init base config + +1. Initialize the base folder and config with the following command: + +```bash +MONIKER=$(hostname) +zetacored init ${MONIKER} --chain-id athens_7001-1 +``` + +## Download config files +1. Download the genesis.json file and *.toml configuration files: + +```bash +wget https://raw.githubusercontent.com/zeta-chain/network-athens3/main/network_files/config/genesis.json -O ~/.zetacored/config/genesis.json +wget https://raw.githubusercontent.com/zeta-chain/network-athens3/main/network_files/config/config.toml -O ~/.zetacored/config/config.toml +wget https://raw.githubusercontent.com/zeta-chain/network-athens3/main/network_files/config/app.toml -O ~/.zetacored/config/app.toml +wget https://raw.githubusercontent.com/zeta-chain/network-athens3/main/network_files/config/client.toml -O ~/.zetacored/config/client.toml +``` + +## State sync +1. Fetch the height and hash from our state-sync servers (make sure to replace `` with the IP from our state-sync node): +```bash +STATE_SYNC_SERVER="[closest StateSync IP]:26657" +TRUST_HEIGHT=$(curl -s http://${STATE_SYNC_SERVER}/block | jq -r '.result.block.header.height') +HEIGHT=$((TRUST_HEIGHT-40000)) +TRUST_HASH=$(curl -s "http://${STATE_SYNC_SERVER}/block?height=${HEIGHT}" | jq -r '.result.block_id.hash') +``` + +NOTE: You need to sync from LATEST_HEIGHT - 40000 to make sure that the node will fetch an existing state-sync snapshot. + +## Replace config values +1. Make sure to replace `[closest StateSync IP]` with the IP from our state-sync node and run this block of code: +```bash +RPC_STATE_SYNC_SERVERS="[closest StateSync IP]:26657,[closest StateSync IP]:26657" +SEED="5aaa51a3b9465a32f7f6c9df1d46d4bfcc16aecb@34.30.34.119:26656" +EXTERNAL_IP=$(curl -4 icanhazip.com) +sed -i "" -e "s/-=RPC_SERVERS=-/${RPC_STATE_SYNC_SERVERS}/g" ~/.zetacored/config/config.toml && +sed -i "" -e "s/-=SYNC_HEIGHT=-/${HEIGHT}/g" ~/.zetacored/config/config.toml && +sed -i "" -e "s/-=TRUST_HASH=-/${TRUST_HASH}/g" ~/.zetacored/config/config.toml && +sed -i "" -e "s/-=MONIKER=-/${MONIKER}/g" ~/.zetacored/config/config.toml && +sed -i "" -e "s/-=external_ip_address=-/${EXTERNAL_IP}/g" ~/.zetacored/config/config.toml +sed -i "" -e "s/^seeds = .*/seeds = \"${SEED}\"/" ~/.zetacored/config/config.toml +sed -i "" -e 's/^max_num_inbound_peers = .*/max_num_inbound_peers = 120/' ~/.zetacored/config/config.toml +sed -i "" -e 's/^max_num_outbound_peers = .*/max_num_outbound_peers = 60/' ~/.zetacored/config/config.toml +``` + +## Generate keys +```bash +zetacored keys add ${MONIKER} --keyring-backend test +``` + +## Start node +```bash +zetacored start --home ~/.zetacored/ --log_level info --moniker ${MONIKER} --rpc.laddr tcp://0.0.0.0:26657 --minimum-gas-prices 1.0azeta "--grpc.enable=true" +``` +The node will fetch a snapshot and start applying chunks. Once it gets to the last chunk, it will take a few more minutes to finish the state-sync and start commiting new blocks. + +## Common errors +### Port error +```bash +accept tcp [::]:26657: use of closed network connection +``` + +1. Check if something is running on port 26657 +```bash +sudo lsof -i :26657 +``` + +2. Kill any process running on that port +```bash +kill -9 PID +``` \ No newline at end of file