Lisk Core Source Administration

This section details how to manage a Source installation of Lisk Core.

Basic Commands

Status

Check the status of the Lisk Core Node.

pm2 status lisk

Start

Start Lisk Core.

pm2 start lisk

Stop

Stop Lisk Core.

pm2 stop lisk

Restart

Restart Lisk Core.

pm2 restart lisk

Delete

Remove Lisk Core process from pm2 list.

pm2 delete lisk

Add

In case you haven’t done this during the Installation process, add your Lisk Core process to pm2 under the name lisk.

pm2 start --name lisk dist/index.js -- --network [network]

You can pass devnet (default), alphanet, betanet, testnet or mainnet for the [network] option.

Logs

Display Lisk Core logs in streaming.

pm2 logs

Utility scripts

There are a couple of command line scripts that facilitate users of lisk to perform handy operations.

All scripts are located under ./scripts/ directory and can be executed directly by node scripts/<file_name>.

Generate Config

This script will help you to generate a unified version of the configuration file for any network. Here is the usage of the script:

Usage: node scripts/generate_config.js [options]

Options:

-h, --help               output usage information
-V, --version            output the version number
-c, --config [config]    custom config file
-n, --network [network]  specify the network or use LISK_NETWORK

Argument network is required and may be devnet, testnet, mainnet or any other network folder available under ./config directory.

Update Config

This script keeps track of all changes introduced in Lisk over time in different versions. If you have one config file in any of specific version and you want to make it compatible with other versions of the Lisk, this scripts will do it for you.

Usage: node scripts/update_config.js [options] <input_file> <from_version> [to_version]

Options:

-h, --help               output usage information
-V, --version            output the version number
-n, --network [network]  specify the network or use LISK_NETWORK
-o, --output [output]    output file path

As you can see from the usage guide, input_file and from_version are required. If you skip to_version argument changes in config.json will be applied up to the latest version of Lisk Core. If you do not specify --output path the final config.json will be printed to stdout. If you do not specify --network argument you will have to load it from LISK_NETWORK env variable.

Creating snapshots

For creating snapshots the most convenient way, it is recommended to use Lisk Core from binary distribution. Just execute the script lisk-snapshot.sh, what will perform all necessary steps to create a snapshot of the blockchain.

To create a snapshot manually, perform the following steps:

Example: Creating a snapshot for Lisk Mainnet.

The template database should be the one defined in components.storage.database in the config.json file of Lisk Core. Its recommended to document the current block height of the snapshot and to include it in the snapshots’ filename.

pm2 stop lisk (1)
createdb --template="lisk_main" lisk_snapshot (2)
pm2 start lisk (3)
psql --dbname=lisk_snapshot --command='TRUNCATE peers, mem_accounts2u_delegates, mem_accounts2u_multisignatures;' (4)
psql --dbname=lisk_snapshot --tuples-only --command='SELECT height FROM blocks ORDER BY height DESC LIMIT 1;' | xargs (5)
pg_dump --no-owner lisk_snapshot |gzip -9 > snapshot-lisk_mainnet-<current-block-height>.gz (6)
dropdb lisk_snapshot (7)
1 stop Lisk Core node
2 copy Lisk Mainnet database to a new database lisk_snapshot. During this process, no open connections are allowed to lisk_main or it will fail.
3 start Lisk Core node again
4 remove redundant data
5 execute this SQL query to get the last block height of the snapshot
6 dump the database and compress it. Replace <current-block-height> with the height that was returned by the SQL query above.
7 delete the snapshot database

Rebuild from a snapshot

In some scenarios, it is recommended to restore the blockchain from a snapshot. The command blocks below will perform this process. The URL can be substituted for another blockchain.db.gz snapshot file if desired.

  • Mainnet

  • Testnet

pm2 stop lisk (1)
dropdb lisk_main (2)
wget https://downloads.lisk.io/lisk/main/blockchain.db.gz (3)
createdb lisk_main (4)
gunzip -fcq blockchain.db.gz | psql -d lisk_main (5)
pm2 start lisk (6)
1 stop Lisk Core node
2 delete Lisk Mainnet database
3 download Lisk snapshot
4 create fresh Lisk Mainnet database
5 import the downloaded snapshot into the new database
6 start Lisk Core node again
pm2 stop lisk (1)
dropdb lisk_test (2)
wget https://downloads.lisk.io/lisk/test/blockchain.db.gz (3)
createdb lisk_test (4)
gunzip -fcq blockchain.db.gz | psql -d lisk_test (5)
pm2 start lisk (6)
1 stop Lisk Core node
2 delete Lisk Testnet database
3 download Lisk snapshot
4 create fresh Lisk Testnet database
5 import the downloaded snapshot into the new database
6 start Lisk Core node again