@liskhq/lisk-chain implements blocks and state management that are used for block processing according to the Lisk protocol.


npm install @liskhq/lisk-chain


To perform an upgrade, execute the following command:

npm update @liskhq/lisk-chain

State store and database mechanism

Lisk-chain manages the fundamental blockchain logic including the data schema of blocks, transactions, and accounts. This includes the following points listed below:

  • Validating the block headers, such as schema, previousBlockID or block reward, without any consideration of the BFT rules.

  • Validating the transaction schema and minimum fee requirement.

  • Validating the block generator based on the given set of validators and the slots.

  • Providing database access to the blockchain data.

  • Saving and deleting block information.

State store

The state store is a data structure that holds temporary state while processing a block. The store is classified primarily based on 3 states - Accounts, Chain, and Consensus. The account store holds state per account, the chain store holds blockchain wide state information, and finally the consensus store holds the internal state related to the BFT.

  • The state store exposes an interface to create, restore, and finalize snapshots.

  • The account store is used mainly for registering delegates, keys and token transfers.

  • The chain state store handles the delegate vote weights, total burnt fees, block headers of the last three rounds, network identifier, and rewards for the last block.

  • The consensus store contains the finalized height, the BFT voting ledger, and a list of validator’s information.

Data access

The data access module provides simplified access to the persistent data storage (blockchain database).

Advantages of data access

  • The abstraction of an actual database engine allows the application to switch between different databases.

  • The decoupling of business logic allows more flexibility to modify the data model without impacting the application layer.

Features of data access

  • Encoding and decoding block headers, accounts, and transactions.

  • Caching of blocks.

  • Access to blocks, accounts, chain state, and transactions.

  • Saving and deleting blocks.

The last 500 blocks are cached in the memory in order to improve block access performance. The block related queries check in the cache memory before querying the storage.

How state changes are rolled back

The data access module implements a diff mechanism to roll back the blockchain to its previous state. For each new block that is added to the chain, the system looks for possible state changes (create, update, delete). This is followed by storing the state transition for each store (account, chain, consensus), by creating a collection of created, updated and deleted keys and their corresponding values. Whenever the chain needs to delete a block it can refer to the stored diff for a particular height and apply it to regain the state.