Skip to content

Commit

Permalink
create state-sync documentation (#199)
Browse files Browse the repository at this point in the history
Co-authored-by: Denis Fadeev <[email protected]>
  • Loading branch information
julianrubino and fadeev authored Dec 6, 2023
1 parent 0543eb6 commit c478980
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 62 deletions.
62 changes: 0 additions & 62 deletions docs/validators/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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://<closest StateSync IP>: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 = "<closest StateSync IP>:26657,<closest StateSync IP>:26657"
trust_height = <return value for the latest block height>
trust_hash = "<return value for the latest block hash>"
```

Start the ZetaChain node:

```bash
zetacored start
```
109 changes: 109 additions & 0 deletions docs/validators/state-sync.mdx
Original file line number Diff line number Diff line change
@@ -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 `<closest StateSync IP>` 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="[email protected]: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
```

0 comments on commit c478980

Please sign in to comment.