Hi there... I believe you have read our previous blogs on Hyperledger. It will give you a basic understanding about Hyperledger. If not you read it from an overview of Hyperledger In this blog I am going to dig something deeper into Hyperledger as I promised earlier. Let’s familiarize the basic terminologies used in Hyperledger. The following basic terminologies of Hyperledger are explained here.
- Ordering Service API
- Endorsement Policy
- Writers policy
Any real-world assets can be modeled using assets in Hyperledger. They are defined as a collection of key-value pair. The term ‘state’ represents current key-value pair. And a change in the state is recorded as a transaction in the channel ledger. The state is maintained only by peer nodes and it is modeled as an element of mapping from the set of keys (K) to the set of V x N. It is described below.
K -> (V X N)
K => set of keys
V => set of values
N => an infinite ordered set of version numbers
A state is represented as
S( k )= (v, ver)
v is denoted by S( k ).value &
ver by S( k ).version
These entries are manipulated by the chaincodes (or the applications) running on the blockchain through ‘put’ and ‘get’ operations.
Put(k,v) takes the blockchain state S and changes it to a new state S’ such that
S’( k)=( v, next( S( k ).version ))
Get method returns S( k )
The state change of the assets are recorded as transactions on a channel ledger
|Let’s take an example to understand the concept|
- Consider an asset ‘price’ which represent the price of 1 kg of apple.
- Here, key is ‘price’ and different value can be set to this key ( i.e. prices of the apple)
For each changed value, we assign version number.
Suppose the current price of an apple is 50/kg. Then the current state is described as
S( ‘price’ )= (50,1)
Here, 50 is the value and 1 is the version number
If we change the price to 60/kg, then let us say an operation transaction is made. We can update the new value using put operation.
put( ‘price’, 60)
The operation changes the state of the asset as
S’( ‘price’ ) = ( 60,2)
If we call get operation at this stage, it will output the above state
As I explained earlier a transaction is a change in state of a digital asset. Basically, there are two types of transactions in hyperledger.
1. Deploy transaction
Deploy transaction create a new chaincode by taking a program as the parameter. And it will install the chaincode on the hyperledger.
2. Invoke transactions
Invoke transaction is applied in the case of a previously deployed chaincode. It can invoke the ‘functions’ of a chaincode that is deployed on Blockchain. A successful invoke transaction executes the functions of a chaincode to perform some operations in Blockchain.
So we know the State and Transaction, Ledger is closely associated with these two. Ledger records all transactions in the Blockchain channel. Or it is a sequential, immutable record of all transactions. The ledger contains both valid and invalid transactions. And as we explained earlier each transaction creates a new ‘Key’ value pair for an asset and it is stored in the ledger. An important thing in hyperledger is that there will be one ledger per channel. And all the nodes in the channel keeps a copy of that ledger.
In ledger transactions are ordered into blocks. Blocks are constructed by the ordering service as a totally ordered hash chain of blocks. In the context of an ordered, Ledger is referred as an Orderer Ledger. And in the context of a peer, the ledger is referred as Peer Ledger. PeerLedger differs from the OrdererLedger in a way that peers locally maintain a bitmask which distinguishes valid transactions from invalid ones while Orderer ledger does not.
Nodes are the communication entities of the blockchain
There are 3 types of nodes,
1. Client or submitting-client:
Let us say it is the end user of the hyperledger. A client must connect to a peer for communicating with the Blockchain. The node can communicate both with the Peers and Orderers.
Peer is basically a node that commits the transactions and maintains the state of the ledger. Peer keeps the copy of the ledger and they can take the role of an ‘Endorser’ also.
3. Ordering-service-node or order:
Orderer is a node that runs the communication service. The communication service provides a shared communication channel to clients and peers. The client can connect to a single or multiple communication channels and communicate with other clients or peers.
Ordering Service API
Peers are connected to the communication channel through ordering service API. The Ordering service API has following basic methods.
broadcast(blob) : A client calls this method to broadcast a message over the channel
deliver(seqno, prevhash, blob): The ordering service calls this on the peer to deliver the message (blob) with the sequence number (seqno) and the hash of the most recently delivered blob (prevhash)
As an effective communication strategy, most of the time, the ordering service will group the ‘blobs’ and output the blocks within a single deliver event instead of outputting individual transactions.
Ordering service provides a Safe (consistency guarantees), Live (delivery guarantee) communication mechanism.
Endorsement policy specifies the conditions to endorse a transaction. All the peers will have a pre-specified set of endorsement policies. The policy is specified by the deploy transaction at the time of installation of a specific chaincode. The policy can be parametrized and a transaction become valid only after it passed the endorsement conditions.
It is the channel specification rules for clients. The policy specifies which user is allowed to submit a transaction to a particular communication channel. It is defined at the time of channel creation.