Module 2: Core Components of Hyperledger Fabric
2.2 Core Components
Hyperledger Fabric is comprised of several modular components that work together to form a complete blockchain platform. Understanding these components is essential for designing, deploying, and maintaining Fabric networks.
Peers and Their Roles
Peers are a fundamental element of the Fabric network. They host ledgers and smart contracts (chaincode) and serve as the entry point for applications to interact with the blockchain.
Types of Peers
- Endorsing Peers
- Execute proposed transactions
- Verify transaction validity
- Produce endorsement signatures
-
Must have the relevant chaincode installed
-
Committing Peers
- Validate transaction results
- Maintain a copy of the ledger
- Commit valid transactions to the ledger
-
All peers in the network are committing peers
-
Anchor Peers
- Enable cross-organization communication
- Advertised to other organizations
- Allow peers from different organizations to discover each other
- At least one anchor peer per organization is recommended
Peer Functions
Peers perform several critical functions:
- Ledger Hosting: Maintain a copy of the blockchain ledger
- Chaincode Execution: Run smart contracts to execute transactions
- Endorsement: Simulate and endorse transaction proposals
- Validation: Verify transactions before committing to the ledger
- Event Emission: Generate events for client applications
- Discovery Service: Provide information about network resources
Peer Architecture
Each peer consists of several components:
- Endorser: Simulates transaction execution
- Committer: Validates and commits transactions
- Ledger Provider: Manages access to the ledger
- Gossip Component: Disseminates data across the network
- Chaincode Support: Manages chaincode lifecycle and execution
Ordering Service
The ordering service is a key component that provides a shared communication channel to clients and peers, offering a broadcast service for messages containing transactions.
Functions of the Ordering Service
- Consensus on Transaction Order: Establishes agreement on the order of transactions
- Block Creation: Batches transactions into blocks
- Block Distribution: Delivers blocks to peers
- Channel Management: Maintains configuration for different channels
Ordering Service Implementations
- Solo
- Single ordering node
- Used for development and testing
- No fault tolerance
-
Not suitable for production
-
Raft
- Crash Fault Tolerant (CFT) implementation
- Leader-based consensus
- Multiple ordering nodes
- Production-ready with fault tolerance
-
Default since Fabric v2.0
-
Kafka
- Uses Apache Kafka and ZooKeeper
- Crash Fault Tolerant (CFT)
- Being phased out in favor of Raft
Ordering Service Nodes (OSNs)
Ordering Service Nodes are the individual nodes that collectively form the ordering service. They:
- Receive endorsed transactions from clients
- Agree on the order of transactions
- Create blocks of transactions
- Broadcast blocks to peers
- Maintain channel configurations
Certificate Authority (CA)
The Certificate Authority is responsible for issuing and managing the certificates used to identify components and users in the Hyperledger Fabric network.
Hyperledger Fabric CA
Fabric provides a built-in CA server that can be used to generate certificates and keys for components and users. Key features include:
- Identity Registration: Register identities with the CA
- Certificate Issuance: Issue X.509 certificates
- Certificate Renewal and Revocation: Manage the certificate lifecycle
- User Attribute Management: Include attributes in certificates
- Affiliation Management: Group users by affiliation
CA Hierarchy
A typical CA hierarchy in Fabric includes:
- Root CA: The top-level CA that issues certificates to intermediate CAs
- Intermediate CAs: Issue certificates to components and users
- Organization CAs: Managed by individual organizations
- TLS CAs: Issue certificates specifically for TLS communication
Certificate Types
Fabric uses different types of certificates:
- Enrollment Certificates: Identify components and users
- Transaction Certificates: Used for transaction authentication
- TLS Certificates: Secure communication between components
Membership Service Provider (MSP)
The Membership Service Provider (MSP) is a component that defines the rules that govern valid identities for an organization. It translates cryptographic identities into roles and permissions within the Fabric network.
MSP Functions
- Identity Validation: Verify that identities are valid
- Role Assignment: Assign roles to identities (admin, member, client, peer)
- Signature Verification: Validate signatures on transactions and blocks
- Certificate Path Validation: Ensure certificates are issued by trusted CAs
MSP Types
- Local MSP
- Defined for a specific node (peer, orderer)
- Defines the permissions for that node
-
Stored in the filesystem of the node
-
Channel MSP
- Defined at the channel level
- Shared by all members of the channel
- Stored in the channel configuration
MSP Structure
An MSP configuration typically includes:
- Root CAs: Certificates of trusted root CAs
- Intermediate CAs: Certificates of trusted intermediate CAs
- Organizational Units (OUs): Subdivisions within an organization
- Administrators: Identities that can administer the MSP
- Revocation List: Certificates that have been revoked
- Node Identity: The identity of the node (for local MSP)
- TLS Root CAs: CAs trusted for TLS communication
Channels
Channels are private "subnets" of communication between specific network members. Each channel has its own independent ledger, accessible only to channel members.
Channel Features
- Data Isolation: Transactions on one channel are invisible to other channels
- Governance: Each channel can have its own governance and policies
- Membership: Organizations can participate in multiple channels
- Configuration: Channel configuration is stored on the ledger itself
Channel Creation and Management
- Channel Creation
- Generate channel configuration transaction
- Submit to ordering service
-
First members join the channel
-
Channel Joining
- Peers receive the genesis block
- Peers initialize the channel ledger
-
Peers join the channel gossip network
-
Channel Configuration Updates
- Propose configuration changes
- Collect required signatures
- Submit update to ordering service
Channel Policies
Channels use policies to control various aspects of operation:
- Admins Policy: Who can modify the channel configuration
- Writers Policy: Who can write to the ledger
- Readers Policy: Who can read from the ledger
- Endorsement Policies: Requirements for transaction endorsement
- Lifecycle Endorsement Policy: Requirements for chaincode lifecycle operations
Ledger
The ledger is the record of all transactions for a channel. Each peer maintains a copy of the ledger for each channel it belongs to.
Ledger Components
- World State
- Current state of the ledger
- Key-value store
- Implemented as a database (LevelDB or CouchDB)
-
Provides efficient read access to current values
-
Transaction Log
- Complete history of all transactions
- Immutable record of all state changes
- Implemented as a file-based append-only log
- Allows for historical queries and audit
Ledger Features
- Immutability: Once recorded, transactions cannot be altered
- Tamper-Evident: Any attempt to modify the ledger is detectable
- Queryable: Both current state and historical data can be queried
- Shared: All channel members have the same view of the ledger
State Database Options
- LevelDB
- Default state database
- Embedded in the peer process
- Key-value storage
- Simple queries based on keys
-
Efficient and lightweight
-
CouchDB
- Optional alternative state database
- Document-oriented database
- JSON document storage
- Rich queries using CouchDB query language
- Indexes for improved query performance
Smart Contracts and Chaincode
Smart contracts in Hyperledger Fabric are implemented as chaincode, which is software that defines assets and the transaction instructions for modifying those assets.
Chaincode Characteristics
- Deterministic Execution: Same input always produces same output
- Isolated Execution: Runs in a secure container environment
- Multiple Language Support: Go, Node.js, Java
- Access Control: Governed by endorsement policies
- State Management: Interacts with the ledger state
Chaincode Lifecycle
- Package: Create a chaincode package
- Install: Install on peers
- Approve: Organizations approve the chaincode definition
- Commit: Commit the chaincode definition to the channel
- Invoke: Execute transactions using the chaincode
System Chaincode
Fabric includes several system chaincodes that provide core functionality:
- Lifecycle System Chaincode (LSCC): Manages chaincode lifecycle
- Configuration System Chaincode (CSCC): Manages channel configuration
- Query System Chaincode (QSCC): Provides ledger query functions
- Endorsement System Chaincode (ESCC): Handles transaction endorsement
- Validation System Chaincode (VSCC): Validates transaction endorsements
Understanding these core components and their interactions is essential for designing, implementing, and maintaining Hyperledger Fabric networks. Each component plays a specific role in the overall architecture, contributing to the platform's flexibility, security, and performance.