UNIT-III: Hyperledger Fabric

 

Hyperledger Fabric (A): Decomposing the Consensus Process

1. Decomposing the Consensus Process in Hyperledger Fabric

Unlike traditional blockchains (like Bitcoin or Ethereum), Hyperledger Fabric separates the consensus process into three distinct phases:

Endorsement Phase (Transaction Proposal & Simulation)

  • A client application submits a transaction proposal.

  • Endorsing peers simulate the transaction without committing it to the ledger.

  • They return an endorsement signature if the transaction meets the required endorsement policy.

Ordering Phase (Transaction Ordering & Block Creation)

  • The Ordering Service (OSN) collects endorsed transactions.

  • It orders them into blocks using a consensus mechanism like Kafka, Raft, or Solo.

  • The ordered transactions are sent to all peers.

Validation & Commitment Phase

  • Peer nodes validate transactions by checking endorsement policies.

  • Transactions are committed to the blockchain only if they pass validation.

  • Invalid transactions are rejected but still recorded for auditability.

Hyperledger Fabric Components

🔹 Peers: Nodes that maintain the ledger and execute smart contracts (Chaincode).
🔹 Ordering Service: Orders transactions into blocks (Kafka, Raft, etc.).
🔹 Membership Service Provider (MSP): Manages identities and permissions.
🔹 Ledger: Stores transactions and world state.
🔹 Chaincode: Hyperledger Fabric’s version of smart contracts, executed by peers.

Chaincode Design and Implementation

Chaincode (similar to smart contracts) runs on peers and governs the logic of transactions. It is written in Go, Java, or Node.js.

Chaincode Lifecycle

Install → Chaincode is installed on peer nodes.
Instantiate → Defines parameters and initializes chaincode.
Execute → Client applications invoke functions.
Endorse → Peers simulate transactions based on the chaincode logic.
Commit → Valid transactions are added to the ledger.

Hyperledger Fabric (B): Beyond Chaincode

1. Fabric SDK and Frontend Integration

Hyperledger Fabric provides SDKs for application development in multiple languages:

  • Fabric SDK for Node.js (Most common for DApp development).

  • Fabric SDK for Java/Python/Go (Used in enterprise applications).

Role of Fabric SDK:

  • Connects client applications to the blockchain network.

  • Submits transaction proposals and queries.

  • Listens for events from peers and orderers.

Example: Node.js SDK Workflow

javascript

const { Gateway, Wallets } = require('fabric-network');
// Load credentials and connect to the network const gateway = new Gateway(); await gateway.connect(ccp, { wallet, identity: 'admin', discovery: { enabled: true, asLocalhost: true } }); // Get network and contract instance const network = await gateway.getNetwork('mychannel'); const contract = network.getContract('mychaincode'); // Submit transaction await contract.submitTransaction('createAsset', 'Asset1', 'Value1'); console.log('Transaction Submitted');

Hyperledger Composer Tool

Hyperledger Composer (now deprecated) was a toolset for building blockchain applications on Fabric quickly.

Key Features:

  • Model-driven approach: Used Business Network Definitions (BND) to define assets, participants, and transactions.

  • REST APIs: Auto-generated APIs for interacting with the blockchain.

  • Web-based IDE: Simplified development with an interactive UI.

Hyperledger Composer Alternative:

  • With Composer being phased out, developers now use Hyperledger Fabric SDKs for direct interaction with Fabric.

Comments