📸Cosmos SDK State Sync
Для чего нужен. Как создать. Как использовать.
Snapshots that based on State-sync, a feature built into the Cosmos SDK that allows validators to quickly synchronize by downloading a network snapshot from an RPC node.
The advantage of State Sync synchronization is that a snapshot weighs very little compared to a fully synchronized blockchain database. Synchronizing with a State-sync snapshot reduces the time it takes for a Validator or Sentry nodes to synchronize with the network to a few minutes. In addition, this method saves a lot of disk space. By synchronizing with the network using state-sync, the node avoids going through all update procedures and can only synchronize with the most recent binary update. There must be only one private-validator-state.json file in the data folder for synchronization. It is not recommended to produce and distribute to the community snapshots on a node with a validator, since distribution requires the operation of the node in the public blockchain network, while this exposes the Validator to the risk of DDoS attacks.
The downside of this synchronization option is that instead of the full transaction history, there is a snapshot of the last state of the network, which was saved by RPC with state-sync enabled. Therefore, for nodes running to transfer data to sites and dapps that require information about all transactions, synchronization using Snapshot is not suitable.
Official resources:
Information about RPC
Snapshot Theory
State Sync Snapshotting Article on the Go website
Another article from Erik Grinaker "Tendermint Core State Sync"
Article by Erik Grinaker published on the Cosmos Blog Cosmos SDK State Sync Guide
Setting RPC options for State-sync snapshots
You have to configure in your app.toml snapshot-interval and snapshot-keep-recent.
Setting app.toml
You need to change certain parameters that are required to create a Snapshot. We will set them in the app.toml file
Snapshot-interval and snapshot-keep-recent
To create snapshots, you need to set the snapshot-interval parameter. This is a parameter that sets the interval of blocks through which snapshots will be created.
For example, let's set it to 1000. We go down to the end of the file in the State Sync Configuration section. Set the values below:
Рекомендуется сохранять как минимум 2 последних снэпшота, чтобы снэпшот не удалялся нодой-донором, в то время, пока нода-приемник пытается скачать файл снэпшота. Для этого ставим snapshot-keep-recent=2.
It is recommended to save at least 2 recent snapshots so that the snapshot is not deleted by the donor node while the destination node is trying to download the snapshot file. To do this, set snapshot-keep-recent=2.
snapshot-interval must be a multiple of the pruning-keep-every parameter to protect the snapshot from prunning while the snapshot is being written and writing the wrong block height to the snapshot.
Pruning
Если раньше вы уже настраивали pruning для экономии места на диске, то теперь надо изменить, подставив pruning-keep-every = "1000" ( так как snapshot-interval = 1000):
If you have already configured pruning to save disk space before, now you need to change it by substituting pruning-keep-every = "1000" (since snapshot-interval = 1000):
Setting config.toml
You have to open your rpc port and configure it in config.toml to listen the desire address ( 0.0.0.0 if you want to listen to all )
Port и ip
Open the config.toml file
and change the parameter as written below
Setting laddr = "tcp://0.0.0.0:26657" allows listening to all addresses from port 26657.
Configuring Visible RPC
Also you have to open the p2p too . Clients needs it to check snapshots . add your rpcaddress:port on peers of clients
Opening the config file:
set the pex parameter to allow our RPC to work on the public network
Now our RPC is open and other nodes can be loaded from it.
Restart and waiting for a snapshot
restart yoru service and wait for your node create the snapshots in data/snapshots
Now restart the node for the changes to take effect.
Waiting for the production of snapshots. By setting above, snapshots will be taken once every 1000 blocks.
Snapshots will be saved to ~/.axelar/data/snapshots/
Usage
Now that the snapshot has been taken, check the result on another node:
If snapshot-interval is set differently on RPC, then In the line BLOCK_HEIGHT=$((LATEST_HEIGHT - 1000)); \ you need to substitute a number equal to your snapshot-interval instead of 1000.
Last updated