concept world state in category hyperledger

appears as: world state, world state
Programming Hyperledger Fabric: Creating Permissioned Blockchains

This is an excerpt from Manning's book Programming Hyperledger Fabric: Creating Permissioned Blockchains.

In above, Bob is trying to transfer $100 from his account #77050379840613 in Bank A to account #756505487689 in Bank B. Included with the request is an X.509 certificate and a signature (we will cover these later) which proves the request is coming from Bob and acts as his digital identity. Bob submits his request to all the banks in the consortium where it is evaluated independently and in parallel. The request triggers execution of a smart contract on each peer node. This smart contract will perform business logic specific to the application being built. In this case, the smart contract might check if Bob is authorized to perform the transaction and if he has enough balance in his account to complete the transfer. We will see how to write a smart contract using the fabric-contract-api 16 provided by Fabric later on in the book. The smart contract exposes the data stored in the blockchain as a key-value store known as the world state with just two fundamental operations: getState(key) and putState(key, value). For the developer writing smart contract Fabric will appear just like a key-value database. All data in Fabric is stored as key-value pairs in a NoSQL db and Fabric provides two databases to choose from for this NoSQL db: LevelDB and CouchDB with LevelDB being the default. So we could imagine a key-value store that stores all the users' account balances. An example is shown in Table 1. 3. Every bank will have their own copy of this database.

These logs are quite instructive. Since this is the first transaction we are performing, it results in the creation of the world state db tracktrace_mycc. The next line is telling it took 20.8 sec to run the smart contract. The long time is because I paused the code in the debugger. Next there is a message informing when the peer receives a new block containing the transaction. The peer then validates the block and commits it to its copy of the ledger.

Let’s see how well you understand Fabric. We have seen the chaincode makes get/put calls to update the world state key-value store. Pop Quiz: Do you think the chaincode connects directly to the world state db? The answer is no. The getState, putState calls we make in the chaincode cause requests to be sent to the chaincode’s peer to get or update the world state db. The chaincode does not talk directly to the world state db. The getState, putState and pretty much all other calls to interact with the world state are defined on the ChaincodeStub class and get forwarded to ChaincodeSupportClient which then forwards them onto the peer. You can find the relevant source code in the fabric-chaincode-node repository.[9]