Hyperledger fabric -- Ledger

(Due to time issues, the content of this article has not yet been perfected, and will continue to be updated later~)

In the process of reading and learning the official documentation of Hyperledger fabric v1.4, write this article to record what you have gained.

This article is based on official documents, mainly for translation and expression of relevant content with my own understanding.

The Ledger

In Hyperledger Fabric, Ledger (ledger) consists of two parts, world state (world state) and blockchain (block chain).

The world state, a database that caches the current value of a set of ledger states. The world state allows a program to access it directly without traversing the entire transaction log to calculate the current value. By default, ledger state will be represented by key-value pairs. Hyperledger fabric provides considerable flexibility for the management of the world state, which will also change frequently due to the creation, update and deletion of states.

Blockchain, a transaction log that records all changes that lead to changes in the current state of the world. Transactions are collected in blocks, which are appended to the blockchain.

The blockchain data structure is very different from the world state in that once written it cannot be modified - i.e. immutable.

The ledger consists of the blockchain and the state of the world, which is determined by the blockchain. In other words, the state of the world is derived from the blockchain.

It is helpful to think of the Hyperledger fabric network as a logical ledger. In effect, the network maintains multiple copies of a ledger that are kept consistent through a consensus process. Therefore, the above-mentioned ledger is usually associated with distributed ledger technology (DLT), and the former is logically single, although it has many copies of the same content distributed in the network.

World State

The world state holds the current values ​​of business object properties as the only ledger state. In doing so, we can obtain the current value directly from the world state without having to traverse the entire blockchain to calculate the current value.

 As shown in the figure, the world state of a ledger contains two states. The key of the first state=CAR1, value=Audi. The second state has a more complicated value, key=CAR2, value={model:BMW, color=red, owner=Jane}. Both states are version 0.

Ledger state records a set of facts about a particular object. In the above example, the ledger status of CAR1 and CAR2 is shown, each of which contains a pair of key-value pairs. An application can call a smart contract to get, write and delete state by using simple ledger APIs. Note that the status value can be a simple Audi or a composite BMW type. Typically, objects with specific properties can be retrieved by querying the world state, for example: finding all BMWs with red color.

The world state is implemented as a database to provide a rich set of operators for efficient storage and retrieval of the state.

Applications submit transactions capturing changes to the world state, which will eventually be committed to the ledger blockchain. Applications will be isolated from the consensus mechanism through the Hyperledger Fabric SDK. The application only needs to call the smart contract to be notified that the transaction is included in the blockchain (whether the transaction is valid or not). The most critical design point is that only transactions signed by a set of approved organizations that meet the requirements will result in an update of the world state.

As shown in the figure, states CAR1 and CAR2 are at their start version version0. This version number will be incremented with each state change. Whenever the state is updated, a version check is performed to ensure that the current state matches the version at the time of signature endorsement. This ensures that the world state changes as expected without concurrent updates.

When a ledger is first created, the world state is empty because any transaction representing a valid change to the world state is recorded on the blockchain, which means that the world state can be regenerated from the blockchain at any time. The generation of the world state is very convenient. For example, when creating a peer, the world state is automatically generated. In addition, if the peer is abnormal, the world state can be regenerated before the transaction is accepted when the peer restarts.

Blockchain

The blockchain records how transactional objects arrived at their current state, recording the previous version of each ledger state and how it changed.

A blockchain is a sequential log of interconnected blocks, where each block contains a set of transactions, each transaction representing a query or update to the state of the world.

The transaction ordering mechanism is important for block ordering and intra-block transaction ordering, which was established when Hyperledger Fabric, known as the ordering service, was first created. 

Guess you like

Origin blog.csdn.net/jianyuzhi/article/details/122305094