World state operations and ledger operations of Hyperledger Fabric

In Hyperledger Fabric, the ledger is composed of two different but related parts - the world state and the blockchain.

World State: A database that stores a cache of current values ​​of the ledger state. The world state allows programs to easily access the current value of the state directly without having to calculate the state value by traversing the entire transaction log. The state of the world can change frequently, as states can be created, updated, and deleted.

Blockchain: A transaction log that records all changes that have led to the current state of the world. Transactions are collected inside blocks attached to the blockchain, allowing you to understand the history of changes that led to the current state of the world. Blockchain data structures are very different from world state in that once written, they cannot be modified; it is immutable. This is the bank's flow.


The account book data status operation API includes the following contents.
getstate(Key string)([]byte, error): Query the corresponding data status according to the specified Key.
put state (key string, value [] byte): Save the corresponding value in the ledger based on the specified key.
DelState(key string): Delete the corresponding data state according to the specified key

******************************************************

The following is from the webpage
https://dandelioncloud.cn/article/details/1575115195137880066
3.3.2.3 Chaincode query< a i=3> Just like calling a transaction, the verification peer sends a QUERY message to the shim of the chaincode container, which calls the Query function of the chaincode and passes the parameters obtained from ChaincodeInput. The Query function may return a status value or error, which it passes to the verification peer via a RESPONSE or ERROR message.

3.3.2.4 Chaincode status
Each chaincode may define its own persistent state variables. For example, a chaincode might create an asset such as a TV, a car, or a stock to preserve the asset's properties. When the Invoke function is processed, the chaincode may update state variables, such as changing the asset owner. The chaincode operates on state variables based on the following message type classes:

PUT_STATE
The chain code sends a PU_STATE message whose payload contains a PutStateInfo object to save the key-value pair.

message PutStateInfo {     string key = 1;     bytes value = 2; } GET_STATE The chaincode sends a GET_STATE message with the key whose value is specified by the payload.




DEL_STATE
The chaincode sends a DEL_STATE message with the payload specifying the key of the value to be deleted.

RANGE_QUERY_STATE
The chain code sends a payload containing a RANGE_QUERY_STATE object of RANGE_QUERY_STATE to obtain a value in a range.
The ReadOnlyLedger interface is for querying the local backup of the general ledger without modifying it.
The UtilLedger interface defines some useful functionality provided by the local ledger.
HashBlock(block *pb.Block) ([]byte, error)
VerifyBlockchain(start, finish uint64) (uint64, error)< a i=6> This method is used to verify large areas in the blockchain. WritableLedger interface Definition:


type WritableLedger interface {     PutBlock(blockNumber uint64, block *pb.Block) error     ApplyStateDelta(id interface{}, delta *statemgmt.StateDelta) error     CommitStateDelta(id interface{}) error     RollbackStateDelta(id interface{}) error     EmptyState() error }The WritableLedger interface allows callers to update the blockchain. Note that this NOT is a common usage of the consensus plugin. The current state needs to be modified by executing a transaction through the Executor interface, and a new block is generated when the transaction is submitted. Instead, this interface is primarily used for state changes and corruption recovery. In particular, functions under this interface can never be directly exposed to consensus messages, which would break the concept of immutability promised by the blockchain. This structure contains the following functions. PutBlock(blockNumber uint64, block *pb.Block) error This function inserts the underlying block into the blockchain based on the given block number. ApplyStateDelta(id interface{}, delta *statemgmt.StateDelta) error This function receives the state change and applies it to the current state. CommitStateDelta(id interface{}) error RollbackStateDelta(id interface{}) error EmptyState() error delete the entire current Status











******************************************************

It seems that the world state can only be manipulated at present. Read the information online for 3-4 days and make a record.

Thanksto the friendly penguin for his generous advice.

Guess you like

Origin blog.csdn.net/sjh2100/article/details/127897366