Resetting and snapshotting the blockchain

It is recommended to perform a backup/snapshot before resetting the blockchain. The backup can then be used to restore the blockchain.

Database locations

The data of a blockchain application is stored in the following key-value stores listed below:

blockchain.db

This database stores blocks, transactions, and states.

node.db

This database stores peer data, or data unique to each node.

generator.db

This database stores generator-specific data unique to each validator, such as the public key, generated blocks, balance, accumulated rewards, etc., and is important for enabling block generation.

legacy.db

This database is used to store legacy blocks and transactions, which are used to verify/provide legacy blocks to the network.

module.db

This database is used by the modules to store off-chain data. Currently, only the random module is used to store seedReveals.

state.db

This database stores on-chain data, specifically, the state of each module with the state Merkle tree.

All databases are located under ~/.klayr/BAPP-NAME/data/

If plugins are registered in the application, they will have a separate key-value store for the plugin-specific off-chain data under ~/.klayr/BAPP-NAME/plugins/data/.

Creating snapshots of the blockchain

To export the blockchain data of an application, run the following command:

Before using the command, ensure the application is stopped and is not running anymore.
./bin/run blockchain:export

In order to view the blockchain:export command reference, check out the Client CLI page.

Resetting the blockchain

This will remove all existing on-chain data of the blockchain application!
Please note that the blockchain height will be reset back to 1 again the next time the application is started, and all existing accounts will be deleted. In addition, the genesis accounts will be reset to the state defined in the respective genesis block.

To reset the blockchain data of an application, it is therefore only necessary to reset the blockchain.db.

This can be achieved by using the blockchain:reset command of the client CLI.

Before using the command, please ensure the application is stopped and is not running anymore.
./bin/run blockchain:reset

For more information about the blockchain:reset command, see the Client CLI page.

Importing a snapshot

To import a snapshot of blockchain data, run the following command:

Before using the command, ensure the application is stopped and is not running anymore.
./bin/run blockchain:import blockchain.db.tar.gz

A command reference can be viewed by adding the --help parameter:

In order to view the blockchain:import command reference, check out the Client CLI page.