- 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. The syncing happens through a snapshot-enabled RPC and from a trusted block height.
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 with state-sync , you won't have the full transaction history of the network, but only the most recent state that the state-sync RPC has stored.
How to sync with state-sync
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
Start the node
Starting archwayd (default)
Before going any further, it is recommended to set up Cosmovisor.
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:v4.0.2Restart=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