Unit-6 BCT
Unit-6 BCT
Hyperledger:
Hyperledger is not a blockchain, but a project that was initiated by the Linux Foundation in
December 2015 to advance blockchain technology. This project is a collaborative effort by its
members to build an open source distributed ledger framework that can be used to develop
and implement cross-industry blockchain applications and systems. The principal focus is to
create and run platforms that support global business transactions. The project also focuses on
improving the reliability and performance of blockchain systems.
Currently, there are six distributed ledger projects under the Hyperledger umbrella:Fabric,
Sawtooth, Iroha, Indy, Besu, and Burrow.
Under libraries, there are the Aries, Transact, Quilt, and Ursa projects.
The tools category of Hyperledger includes projects such as Avalon, Cello, Caliper, and
Explorer.
There are also domain-specific projects such as Hyperledger Grid and Hyperledger Labs.
Hyperledger reference architecture:
Hyperledger has published a white paper that presents a reference architecture model that can
serve as a guideline to build permissioned distributed ledgers. The reference architecture
consists of various components that form a business blockchain.
These high-level components are shown in the reference architecture diagram here, which has
been drawn fromthe aforementioned white paper:
Figure :Reference architecture
In the preceding diagram, starting from the left, we see that we have five top-level
components that provide various services. The first is identity, which provides authorization,
identification, and authentication services under membership services. Then, we have the
policy component, which provides policy services.
Hyperledger project:
The Hyperledger project is an open-source collaborative effort created to advance cross-
industry blockchain technologies. It's hosted by The Linux Foundation and counts numerous
organizations, including major players in finance, banking, Internet of Things (IoT), supply
chain, manufacturing, and technology, among its members.
Hyperledger Fabric:
Hyperledger Fabric, or Fabric for short, is the contribution made initially by IBM and
Digital Assets to the Hyperledger project. This contribution aims to enable a modular, open,
and flexible approach toward building blockchain networks.
Hyperledger Fabric is an open-source platform for building distributed ledger solutions, with
a modular architecture that delivers high degrees of confidentiality, flexibility, resiliency, and
scalability. This enables solutions developed with fabric to be adapted for any industry. This
is a private and confidential blockchain framework managed by the Linux Foundation. The
article focuses on discussing Hyperledger Fabric in Blockchain.
Workflow:
For each and every transaction in the fabric, the following steps are followed-
1. Creation of the proposal: Imagine a deal between a smartphone manufacturer
company and a smartphone dealership. The transaction begins when a member
organization proposes or invokes a transaction request with the help of the client
application or portal. Then the client application sends the proposal to peers in each
organization for endorsement.
2. Endorsement of the transaction: After the proposal reaches the endorser peers (peers
in each organization for endorsement of a proposal) the peer checks the fabric
certificate authority of the requesting member and other details that are needed to
authenticate the transaction. Then it executes the chain code (a piece of code that is
written in one of the supported languages such as Go or Java) and returns a response.
This response indicates the approval or rejection of the following transaction. The
response is carried out to the client.
3. Submission to ordering service: After receiving the endorsement output, the approved
transactions are sent to the ordering service by the client-side application. The peer
responsible for the ordering service includes the transaction into a specific block and
sends it to the peer nodes of different members of the network.
4. Updating the ledger: After receiving this block the peer nodes of such organizations
update their local ledger with this block. Hence the new transactions are now
committed.
Hyperledger Fabric Architecture:
Role: Manages digital identities of participants in the network (peers, clients, orderers).
Responsibilities:
Issuance of Certificates: Issues X.509 certificates to participants during registration.
Renewal and Expiry: Handles the renewal and expiration of certificates.
Revocation: Manages the process of revoking certificates if needed.
Verification and Authentication: Verifies the authenticity of participants based on
their certificates.
Organizational Affiliation: Associates participants with specific organizations within
the network.
Identity Lifecycle:
Registration: Participants request enrollment with the Certificate Authority (CA) to
obtain certificates.
Enrollment: The CA issues enrollment certificates, which include a public-private
key pair.
Certificate Renewal: MSP manages the renewal process to ensure participants have
up-to-date certificates.
Certificate Revocation: In case of compromised keys or other security issues,
certificates can be revoked.
Access Control:
Access control policies in Hyperledger Fabric are used to define who has permission to
perform specific actions in the network. These policies include:
Endorsement Policies: Specify which peers must endorse a transaction for it to be
valid.
Channel Policies: Determine who has access to a specific channel and what actions
they can perform.
Access Control Lists (ACLs): Define permissions for specific resources, such as
chaincode invocation or ledger query.
Channels:
Definition: Channels are private sub-networks within a Hyperledger Fabric network.
Purpose:
Allow a subset of network participants to conduct transactions privately.
Transactions within a channel are only visible to participants in that channel.
Key Points:
Each channel has its own ledger and set of endorsing peers.
Participants can be part of multiple channels.
Channels are a way to implement privacy in a Hyperledger Fabric network.
Transaction Validation:
1. Endorsement Phase:
Role: Determines whether a transaction is valid based on the chaincode's logic.
Process:
The client sends a transaction proposal to the endorsing peers.
Endorsing peers simulate the transaction using the chaincode and return the results.
The endorsement results include read and write sets.
2. Ordering Phase:
Role: Orders transactions into blocks and distributes them to all peers in the network.
Process:
Endorsed transactions are sent to the ordering service.
The ordering service creates a block of transactions in a specified order.
The block is broadcasted to all peers.
3. Validation Phase:
Role: Ensures that transactions meet the endorsement policy before committing them to the
ledger.
Process:
Peers validate the endorsements against the endorsement policy.
If the endorsements are valid, the transactions are committed to the ledger.
4. Commit Phase:
Role: Updates the ledger and state database with the committed transactions.
Process:
The validated transactions are appended to the ledger.
The world state database is updated to reflect the new state.
5. Consensus Mechanism:
Practical Byzantine Fault Tolerance (PBFT): Ensures that a transaction is considered valid
if it receives endorsements from a specified number of endorsing peers.
Other Consensus Mechanisms (if used): Depending on the network configuration, different
consensus mechanisms may be employed.
These processes ensure that transactions in Hyperledger Fabric are executed, validated, and
recorded in a secure and reliable manner. The modular architecture and use of channels allow
for a high degree of customization and privacy in transaction processing.
Below, I'll provide an example of a simple smart contract written in Go for Hyperledger
Fabric. This contract will keep track of a key-value pair in the ledger.
// SPDX-License-Identifier: Apache-2.0
package main
import (
"fmt"
"github.com/hyperledger/fabric-contract-api-go/contractapi"
)
// SimpleStorageContract defines the Smart Contract structure
type SimpleStorageContract struct {
contractapi.Contract
}
// KeyValue represents a key-value pair
type KeyValue struct {
Key string `json:"key"`
Value string `json:"value"`
}
// Set stores the key-value pair in the ledger
func (s *SimpleStorageContract) Set(ctx contractapi.TransactionContextInterface, key string,
value string) error {
keyValue := KeyValue{
Key: key,
Value: value,
}
return nil
}
// Get retrieves the value for a given key from the ledger
func (s *SimpleStorageContract) Get(ctx contractapi.TransactionContextInterface, key string)
(*KeyValue, error) {
// Retrieve the value from the ledger
keyValueBytes, err := ctx.GetStub().GetState(key)
if err != nil {
return nil, fmt.Errorf("failed to read from world state: %v", err)
}
// If the key does not exist, return nil
if keyValueBytes == nil {
return nil, nil
}
// Unmarshal the value into a KeyValue struct
var keyValue KeyValue
err = json.Unmarshal(keyValueBytes, &keyValue)
if err != nil {
return nil, err
}
return &keyValue, nil
}
In this example, we define a smart contract named SimpleStorageContract with two
functions: Set and Get.
Set takes a key and value, converts them to a KeyValue struct, and stores it in the ledger.
Get retrieves the value for a given key from the ledger.
Remember to import the necessary packages (fmt, github.com/hyperledger/fabric-contract-
api-go/contractapi, and encoding/json) and set up your development environment with the
Hyperledger Fabric SDK and tools.
Additionally, you'll need to package this code into a chaincode and deploy it to a Hyperledger
Fabric network. The deployment process involves writing a client application that interacts
with the blockchain network and deploys the chaincode.