- Docs
- Run a node
- Sync with state-sync
Sync with state-sync
state-sync is a feature that allows nodes to quickly sync their state by fetching a snapshot of the application state at a specific block height. This greatly reduces the time required for node to sync with the network, compared to the default method of replaying all blocks from the genesis block. There are two ways for syncing your node with state-sync:
- Through a snapshot-enabled RPC and from a trusted block height.
- Through the validated archival snapshots by KYVE.
An advantage of state-sync is that the database is very small in comparison to a fully synced node, therefore using state-sync to resync your node to the network can help keep running costs lower by minimizing storage usage.
Info
When syncing a node through a snapshot-enabled RPC, you won't have the full transaction history of the network, but only the most recent state that the state-sync RPC has stored. With the validated snapshots by KYVE, it is possible to sync to any height.
1. How to sync through RPC
First,make sure to have installed the necessary dependencies, installed archwayd and set up your keys.
Info
Before going any further, it is recommended to set up Cosmovisor.
Then:
- in the .archwayd/config folder, open the config.toml file with:
nano ~/.archwayd/config/config.toml
and go to in the statesync section.
- Set enable to true to enable state sync:
enable = true
- Set rpc_servers to a list of trusted nodes with state sync enabled:
rpc_servers = "<trusted_node_1>,<trusted_node_2>,<trusted_node_3>"
For example:
mainnet
testnet
rpc_servers = "https://rpc.mainnet.archway.io:443"
Alternatively, if you prefer using snap, you could also set a local variable in your terminal shell, by typing:
mainnet
testnet
SNAP_RPC= https://rpc.mainnet.archway.io:443
and making sure that the local variable is correctly set:
echo $SNAP_RPC
- Set trust_height and trust_hash to the block height and hash of a trusted block, and replace <trusted_block_height> and <trusted_block_hash> with the actual values:
trust_height = <trusted_block_height>trust_hash = "<trusted_block_hash>"
For example:
trust_height = 1354507trust_hash = 0101585D26CB0CCB1FBDADA8A91DB88A9FE4D15D517804EEFA337613F07F3F36
In order to fetch the correct values, we can use local variable and use curl.
In your terminal shell, get the latest block height by launching:
LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height)
Then you can get the trusted block height, which is a previous block:
BLOCK_HEIGHT=$((LATEST_HEIGHT - 100))
And then get the hash of the trusted block by launching:
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)
Now, make sure that those variables are properly set:
echo $LATEST_HEIGHT $BLOCK_HEIGHT $TRUST_HASH
The console should output some values, such as:
1355507 1354507 0101585D26CB0CCB1FBDADA8A91DB88A9FE4D15D517804EEFA337613F07F3F36
You can update the config.toml with those values:
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/.archway/config/config.toml
2. How to sync through KYVE
KYVE is a blockchain that validates and archives chain data like Archway blocks and state-sync snapshots. The tool KSYNC provides the possibility to use the validated data in order to sync an Archway node to any height.
Info
More information about KSYNC can be found in the KYVE Docs.
Prerequisites
First, make sure to have installed the correct archwayd
version of the target height.
Initialize the node with:
archwayd init <moniker> --chain-id archway-1
Download the correct genesis file:
wget -qO- https://github.com/archway-network/networks/raw/main/archway/genesis/genesis.json.gz | zcat > ~/.archway/config/genesis.json
KSYNC Installation
Install with Go (recommended)
Install the latest version:
go install github.com/KYVENetwork/ksync/cmd/ksync@latest
Run ksync version
to verify the installation.
Install from source
You can also install from source by pulling the ksync repository and switching to the correct version and building as follows:
git clone [email protected]:KYVENetwork/ksync.gitcd ksyncgit checkout tags/vx.x.x -b vx.x.xmake ksync
This will build ksync in /build
directory. Afterwards, you may want to put it into your machine's PATH like
as follows:
cp build/ksync ~/go/bin/ksync
KSYNC usage
After the correct setup, KSYNC will manage the state-sync process completely. There are 2 different ways of state-syncing your node with KSYNC:
1. State-Sync
You can state-sync a node to the latest available snapshot archived by KYVE with the following command:
ksync state-sync --binary="/path/to/archwayd" --source="archway"
You can also state-sync a node to a specific snapshot with --target-height
(KSYNC will use the nearest available snapshot):
ksync state-sync --binary="/path/to/archwayd" --source="archway" --target-height=<height>
2. Height-Sync
Because KYVE not only validates and archives state snapshots but also blocks, it is possible to sync to any height. Therefore, the nearest state snapshot will be used in order to sync to the target height with the validated blocks. Simply run:
ksync height-sync --binary="/path/to/archwayd" --source="archway" --target-height=<height>
Info
To get information about the latest available block and snapshot height, run ksync info
.
Start the node
Starting archwayd (default)
Before going any further, it is recommended to set up Cosmovisor.
Please verify the seeds in the Archway networks repo:
- Testnet: https://github.com/archway-network/networks/blob/main/testnets/archwaytestnet/chain.json#L75-L81
- Mainnet: https://github.com/archway-network/networks/blob/main/archway/chain.json#L142-L146
Now you can start the node:
Mainnet
Binary
Docker
archwayd start \ --p2p.seeds [email protected]:26656
Testnet
Binary
Docker
archwayd start \ --p2p.seeds [email protected]:26656
Start archwayd as a service
Remember that you can start the node as a service by creating a service file:
sudo /etc/systemd/system/archwayd.service
[Unit]Description=Archway NodeAfter=network.target[Service]User=$USERType=simpleExecStart=$(which archwayd) startRestart=on-failureLimitNOFILE=65535[Install]WantedBy=multi-user.target
Start the service by: Reloading the daemon:
sudo systemctl daemon-reload
Enable archwayd:
sudo systemctl enable archwayd
Start archwayd as a service:
sudo systemctl restart archwayd
Keep track of the logs:
sudo journalctl -u archwayd -f -o cat
Start the archwayd docker as a service
A service file can be used to allow the automatic restart of the service, and it helps to enhance the reliability of your node.
You can create a service file with:
nano /etc/systemd/system/archwayd.service
And add the following content to the file:
[Unit]Description=Archway NodeAfter=network-online.target[Service]User=$USERExecStart=/usr/bin/docker run --rm -it -v ~/.archway:/root/.archwayghcr.io/archway-network/archwayd-dev:v9.0.0Restart=alwaysRestartSec=3LimitNOFILE=4096[Install]WantedBy=multi-user.target
You can then reload the systemctl daemon:
sudo systemctl daemon-reload
Enable the service:
sudo -S systemctl enable archwayd
And then start archwayd as a service:
sudo systemctl start archwayd
You can then check that the service is properly running with:
sudo systemctl status archwayd
Community partners
As you dive deeper into the state sync solutions for Archway, we recommend exploring these invaluable resources provided by our community partners:
- KSYNC Overview: Understand the mechanics of KSYNC and how to utilize it effectively. Read more
- Archway // State-Sync Pool: Delve into the intricacies of how the Archway State-Sync pool operates. Read more
- KSYNC Codebase: For the developers out there, here's the codebase for KSYNC, granting you direct access to its workings. Check it out on GitHub