Source code commands

This section covers how to manage a Source code 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 the pm2 list.

pm2 delete lisk

Add

In case this was not completed during the installation process, add your Lisk Core process to pm2 under the name lisk.

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

It is possible to choose the devnet (default), testnet or mainnet for the [network] option.

Logs

Display Lisk Core logs in streaming.

pm2 logs

Utility scripts

There are some command line scripts available that will assist the Lisk user, by performing certain helpful and convenient operations.

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

Generate config

This script shown below will help to generate a unified version of the configuration file for any network:

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 it may be either devnet, testnet, mainnet or any other network folder available under ./config directory.

Update config

This next script is designed to keep track of all changes introduced in Lisk over time in different versions. If you have one config file existing in any specific version, and you wish to make it compatible with other versions of the Lisk, then execute this update config script shown below:

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 can be seen 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, it will have to be loaded from LISK_NETWORK env variable.

Creating snapshots

For creating snapshots in the most convenient manner, it is recommended to use Lisk Core from the Lisk Core application. Execute the script lisk-snapshot.sh, which will then perform all the 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 to be used should be the actual database defined in the components.storage.database in the config.json file of Lisk Core. It is 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 Stops the Lisk Core node.
2 Copies the 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 Restarts the Lisk Core node again.
4 Remove the redundant data.
5 Executes this SQL query to acquire the last block height of the snapshot.
6 Dumps the database and compresses it. Replaces the current block-height with the height that was returned by the SQL query above.
7 Deletes the snapshot database.

Rebuild from a snapshot

In certain scenarios, it is recommended to restore the blockchain from a snapshot. The command lines shown below will perform this process. The URL can be substituted for another blockchain.db.gz snapshot file if so 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 Stops the Lisk Core node.
2 Deletes the Lisk Mainnet database.
3 Downloads the Lisk snapshot.
4 Creates a fresh Lisk Mainnet database.
5 Imports the downloaded snapshot into the new database.
6 Restarts the 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 Stops the Lisk Core node.
2 Deletes the Lisk Testnet database.
3 Downloads the Lisk snapshot.
4 Creates a fresh Lisk Testnet database.
5 Imports the downloaded snapshot into the new database.
6 Restarts the Lisk Core node again.