IoT + Hyperledger Development from scratch within 21 days — Day 2

Davor Kljajic
7 min readMar 21, 2019

--

Welcome

Hello everybody! In the previous article, we introduce IOT+Hyperledger development from scratch with 21 days, what we will cover in this serial and what new industrial revolution will bring.

As we write about what is Hyperldger, now we will start with the key concepts in the Hyperldger Fabric.

Here are the sections what we will cover in this article:

  • Organization, channels and ordered
  • Identity management
  • Consensus
  • Ledger and world state
  • Cain codeTransaction flow

Organization, channels and ordered

Hyperleger Fabric is a platform for distributed ledger solution, but basically, that is a network that has different actors. The main actors in the network are organizations that consist of peers. Peers from other organizations communicate with each other with orderer through the channel.

Example:

Image the peers like division in the real company, for example, you have an organization called “Buyer” that have two peers “peerStock” and “peerBuyer”. Another organization in “Seller” that have also two peers “peerStock” and “per seller”. The last one in “Logistic” with peers “peered” and peerDeliver”.

In this scenario organization Buyer what to buy some goods from the Seller that will be delivered by the company Logistic.

The “peerBuyer“ communicate the order to the “per seller” with orderer through the channel1, peer notifies in his organization another peer in this case “ peerStock”.This peer communicates with the “peerDeliver” through the channel2, that peer notifies in his organization, PeerSend” to communicate with the peerStock in Buyer organization with the channel3.

Where is the magic?

The whole processes are automated, each channel has own data set, called channel state, for example, business deals between “Logistic” organization to deliver goods for Buyer and Seller can be in realized in different terms, and not visible to each other.

Identity management

In the real world we have different mechanisms of authorization, but how is that achieved in Hyperledger Fabric?

As we say that the main actors in the network are organizations, but the real question is how we know is who is a single organization?

To determine who have permissions over resources and access to information in the network, Hyperledger Fabric uses concept identities.

What is identity?

Each member in the organization have digital identity encapsulated in an X.509 digital certificate, this is like ID in the real word.

Second question who is responsible to determine the credibility of that identity?

Here it comes from the trusted authority, knows as a Membership service provider that define rules that govern valid identities for this organization.

How is that achieved?

Fabric uses Public Key Infrastructure(PKI), that is a collection of internet technologies that provide secure communications in the network.

There are four key elements to PKI:

  • Digital Certificates
  • Public and Private Keys
  • Certificate Authorities
  • Certificate Revocation Lists

For digital certificate image for yourself a simple document that has a set of attributes relating to the holder of that certificates.

The relationship between a private key and the respective public key is the cryptographic magic that makes secure communications possible.

The job to dispense and issued certificates in the single organization is in the charge of Certificate Authority. To be valid certificates must be are digitally signed by the organization CA and bind together the actor with the actor’s public key.

The last and the simplest to understand, the list of certificates that Central Authority must know that are not valid is called Certificate Revocation List (CRL).

Consensus

The simplest way to understand consensus is that is a mechanism to check which order is transaction occurs in the network.

Two things are important

Orderer service and endorsement policy. Since it is a Blockchain network, we do not have a central authority for validation, but a policy called “Endorsement Policy”.

To understand what endorsement means, consider an analogy. Let’s say to organization Buyer pay $200 to organization Seller, and there is a third organization Logistic who is responsible for endorsing this transaction. Here, Logistic makes sure that Buyer has enough money to give to Seller.

Endorsers in the Hyperledger Fabric does a similar task. Once a transaction is endorsed by the relevant participants.

The client broadcast endorsed (signed) transaction to Orderer(s) in the channel. The Orderer does two things. Firstly, it verifies that the client has an appropriate role, which is required to modify the ledger. Once that is confirmed, Orderer collects the transaction into a block and broadcasts the block to the channel if it reaches a defined size or a defined amount of time has been elapsed.

consensus

Hyperleder has two consensus mechanisms available, namely, SOLO and Kafka.

SOLO is the simplest mechanism, which only broadcasts the transaction without establishing any real consensus. It’s not recommended for production. On the other hand, Kafka uses a fault-tolerant distributed streaming platform called Apache Kafka with multiple Orderer nodes to avoid a single point of failure.

Ledger and world state

The best real-life example of the ledger is your bank account. If you want to know which is your state, then you go through the transactions and determined it.

That is the same as in the Hyperledger Fabric. Before we continue let call the this with the right names.

The current values of a ledger state are called world states, and to capture the history of transaction that determined these states are blockchain.

Each channel has a completely separate ledger. Also, in reality, each chain code also has its own world state that is separate from all other chain code. World states are in a namespace so that only smart contracts within the same chain code can access a given namespace.

This is a little confusing?

The right reason is that applications and smart contracts to communicate between channels must have ledger information that can be accessed between them.

Also, Blockchain is not namespaced, it contains just transactions from chain codes.

Chaincode

Smart contract or “chain code” is business rules between organizations. Application invokes a smart contract to generate a transaction that is recorded on the ledger.

As we say blockchain is immutable and world state is changeable, so Smart contracts primarily put, get and delete states in the world state, and can also query the immutable blockchain record of transactions.

smart_contract

For example, a smart contract might ensure that a new order in our example is delivered within a specified timeframe, or that funds are released according to prearranged terms, improving the flow of goods or capital respectively.

Hyperedge Fabric provides writing the smart contract in Go, Java, and NodeJS.

Transaction flow

We will explain the flow of transaction on example. To simplify here is two organization “Buyer” and “Seller”. They have peers “peerBuyer” and “per seller” which send their transaction.

The users in the organizations are is registered, enrolled with own CA’s and have necessary crypto material to interact with the network.

transaction_flow
  1. “PeerBuyer” initiates a transaction

The “Buyer” sending the request to a new order. And request targets a “peerBuyer” and “per seller”. The endorsement policy says that both peers must endorse transaction.

The proposal is created and requests the chain code function that data can be read/write on a ledger. It’s created a signature from user cryptographic credentials.

2. “PeerBuyer” and “per seller” verify signature & execute the transaction

The peer’s checks that proposal is well formed, does not happen in the past and that signature is valid.

3. Proposal response is inspected

Verifying that the “PeerBuyer” and “per seller” signatures and compares the proposal responses to determine if the proposal responses are the same.

4. Assembles endorsements into a transaction

The transaction proposal and response are broadcasted to the Ordering Service via an application.

5. A transaction is valid and committed

The blocks of transactions are valid and delivered to all peers on the channel.

6. Ledger updated

“PeerBuyer” and “per seller” appends the block to the channel’s chain, and for each valid transaction, the write sets are committed to a current state database.

Conclusion

The two important things to remember is Hyperledger Fabric supports networks where privacy (using channels) is a key operational requirement. By using the Fabric we creating the permissioned networks where all parties know identities.

We hope that you learn something new about Hyperldger Fabric and blockchain, and be prepared for the new article in which we define the architecture for Hyperldger Fabric, the real world solution in the logistics industry. Be prepare.

See ya!

Read IoT + Hyperledger Development introduction article — Day 1

Work with Beyond

Beyond offers high-quality services: Web Development and Design, Mobile Development and Design, Embedded Solutions, Blockchain Solutions, and Team Augmentation? You can find more about our services on our website.

--

--