State Syncing [Desmos]

Cat Boss
4 min readJan 10, 2022

Hello Cat Boss here! Today we’re going to talk about state syncing.

Whether you have run out of space or need to quickly sync up a node, this is a skillset we believe validators should master

The original documentation can be found here: https://docs.desmos.network/mainnet/state-sync

Note: This method works with most Cosmos SDK chains but we will be focusing on Desmos in this post. (And we say this with caution, please test this out on a new server and make sure it works before doing anything you’ll regret)

Prerequisites

Before we start you’ll need access to a RPC that has snapshots enabled. If it is your own you can check it at `/.desmos/data/snapshots`

If you’re unable to get snapshots you can always set it up on a node inside `/.desmos/config/app.toml`. Make sure to restart the node if you make any changes to this file.

###############################################################################
### State Sync Configuration ###
###############################################################################
# State sync snapshots allow other nodes to rapidly join the network without replaying historical
# blocks, instead downloading and applying a snapshot of the application state at a given height.
[state-sync]
# snapshot-interval specifies the block interval at which local state sync snapshots are
# taken (0 to disable). Must be a multiple of pruning-keep-every.
snapshot-interval = 1500
# snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all).
snapshot-keep-recent = 2

Proceed to the next steps once you start having snapshots.

Setup

In a new node setup we should enable state sync inside `/.desmos/config/config.toml`.

Below you will want to fill out the following:

rpc_servers — This is where we put in the rpc with snapshots. While state sync requires 2 rpcs, we have found out they don’t stop you from using the same RPC twice. So if this is a RPC you fully trust we believe it’s okay to just repeat it like the example below.

trust_height — get the latest block height and go a ~thousand blocks back. ex — if the latest block height is 1415137 we would use 1414000. There is no right or wrong here but we have found going a thousand blocks back works better than going a few hundred.

trust_hash — the block hash of your trust_height

#######################################################
### State Sync Configuration Options ###
#######################################################
[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 = false
# 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 = "<rpc>,<rpc>"
trust_height = 1414000
trust_hash = "81FBAC1952121951E7A3D485CC8908D5BA30D3C4E14738F6FFA1C59A0E9F6886"
trust_period = "336h0m0s"

Test Run

If this is not a new server then please run desmos unsafe-reset-all to remove all existing data (make sure you understand what this does and backup anything you may need).

We can now test this out by running desmos start . If it is successful you should see something like the following:

Then finally you should see something like this,

12:28PM INF Snapshot restored format=1 hash="uu��7��[G�5p����\x16��*^|U���V�iʵw" height=1400000 module=statesync

Followed by a bunch of commits to catchup from the snapshot to the latest block height:

Once it’s okay, feel free to stop it and run it back as a background service.

If you check the server size now you should see how empty and happy it is
ヾ(=`ω´=)ノ”)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Cat Boss
Cat Boss

Written by Cat Boss

We’re dPoS validators and we like writing medium posts documenting our journey, sharing tips we learn along the way. Trust me, I am a Cat.

No responses yet

Write a response