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

Davor Kljajic
7 min readMar 14, 2019

--

Photo by Blockchain 101

Intro

If you are new with blockchain technology, and first time read our series, here is a simple explanation of what is blockchain:

A blockchain is an electronically distributed ledger or list of entries — much like an accounting ledger, for a company’s financial statements with debit and credit account records validated by a balance.”

Before we continue with the Hyperleger Fabric we must understand the basic principles of every blockchain solutions. I will explain in the basic terms, and after will connect technical with the examples for the better way of understanding the key concepts of Hyperledger Fabric.

Distributed Ledger

A heart of every blockchain network is a distributed ledger that records all the transactions that take place on the network, the most important properties are decentralized and immutability.

Consensus

The mechanism that keeps the ledger transactions sync across the network and ensures that ledgers update only when transactions are provided by the appropriate participants is called consensus.

Smart Contracts

The key mechanism to allow participants to execute certain aspects of the transaction is called a smart contract or in the Hyperldger Fabric (chaincode). Blockchain network use the s the smart contract as the business logic to provide controlled access to the ledger.

For example, a smart contract can be written to deal with the cost of transport an item where the transport charge changes depending on how fast the ian tem arrives.

b

For now, you have pictures in your head that blockchain is shared, replicated transaction system which is updated via smart contracts and kept consistently synchronized through a collaborative process called consensus. Before we dive into Hyperledger Fabric, I will provide a quick review of current business processes.

Current system

In the current system we must have provenance established each time when items are sold to ensure that the business selling an item possesses a chain of title verifying their ownership of it, also we don’t have a system to determine the identity for provenance, contracts must be signed and executed manually and we have databases for each place in the business chain, that represent the single point of failure.

What is Hyperledger Fabric?

Hyperledger Fabric is an enterprise-grade private and permissioned distributed ledger platform that offers modularity and versatility for a broad set of industry use cases.

Key concepts in the Hyperledger Fabric are:

Identity and membership

Ledger

Consensus

Smart contracts

Identity management

We see that problem in the current systems are to establish provenance when the item change the ownership. Hyperldger Fabric to enable permissioned networks, use a membership identity service(MSP) that manages user IDs and authenticates all participants on the network.

For example, you are in the supermarket and want to buy some items, you see that Visa and MasterCard card is accepted, but you have own card that is authentic and you have sufficient fund on your account but, it will be not accepted.

To have a valid card is not enough it must be accepted by the store.

simple_scenario

For identity to be verifiable, it must come from a trusted authority. Using the membership service provider (MSP) is how this is achieved in Fabric. The default MSP implementation in Fabric uses X.509 certificates as identities, adopting a traditional Public Key Infrastructure (PKI) hierarchical model.

PKI provides a list of identities, and an MSP says which of these are members of a given organization that participates in the network.

The main role of Membership Service is to identify which CAs and are trusted to define the members of a trust domain, either by listing the identities of their members or by identifying which CAs are authorized to issue valid identities for their members.

The ledger

In Hyperledger Fabric, a ledger consists of two parts world states and a blockchain. Each of these represents a set of facts about a set of business objects. Facts about the current state of a business object may change, the history of facts it is immutable, it can be added to, but it cannot be retrospectively changed.

ledger

Ledger states are, by default, expressed as key-value pairs. The world state can change frequently, as states can be created, updated and deleted.

Secondly, there’s a blockchain — a transaction log that records all the changes that have resulted in the current world state.

The blockchain is structured as a sequential log of interlinked blocks, where each block contains a sequence of transactions, each transaction representing a query or update to the world state.

What’s important is that block sequencing, as well as transaction sequencing within blocks, is established when blocks are first created by a Hyperledger Fabric component called the ordering service.

The best way of thinking is that there is one logical ledger in a Hyperledger Fabric network. In reality, the network maintains multiple copies of a ledger — which are kept consistent with every other copy through a process called consensus.

The term Distributed Ledger Technology (DLT) is often associated with this kind of ledger — one that is logically singular but has many consistent copies distributed throughout a network.

Consensus

In distributed ledger technology, a consensus has recently become synonymous with a specific algorithm, within a single function.

In a nutshell, a consensus is defined as the full-circle verification of the correctness of a set of transactions comprising a block.

consensus

Two things are important here. 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 you have to give $200 to someone called Jim, and there is a third person called Paul who is responsible for endorsing this transaction. Here, Paul makes sure that you had enough money to give to Jim, and you have actually given it to Jim.

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.

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.

Smart Contracts

The best explanation for a smart contract is the business logic in a blockchain.

Hyperledger Fabric smart contracts are written in chaincode and are invoked by an application external to the blockchain when that application needs to interact with the ledger.

For example, a smart contract might ensure that a new car delivery is made within a specified timeframe, or that funds are released according to prearranged terms, improving the flow of goods or capital respectively. Most importantly, however, the execution of a smart contract is much more efficient than a manual human business process.

smart_contract

Smart contract programmatically accesses two distinct pieces of the ledger — a blockchain, which immutably records the history of all transactions and a world state that holds a cache of the current value of these states, as it’s the current value of an object that is usually required.

Smart contracts primarily put, get and delete states in the world state, and can also query the immutable blockchain record of transactions.

Every smart contract has an endorsement policy associated with it. This endorsement policy identifies which organizations must approve transactions generated by the smart contract before those transactions can be identified as valid.

The most import thing is that all transactions, whether valid or invalid are added to a distributed ledger, but only valid transactions update the world state.

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

Conclusion

For the end, 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.

And you also recognized that Hyperledger Fabric has the answers on the current business system problems.

--

--