Hyperledger Fabric

repository·main·Indexed 12 days ago

https://github.com/hyperledger/fabric

A modular, enterprise-grade distributed ledger platform designed for high confidentiality, scalability, and flexibility. It features a pluggable architecture for complex blockchain ecosystems, including components like the Fabric peer for ledger management and an ordering service for atomic broadcast. Current LTS release is v2.5.x.

Tokens
254K
Snippets
582
Records
1.1K
Agent score
96%

What's inside Hyperledger Fabric

  1. What is Hyperledger Fabric?

    main

    Hyperledger Fabric is an open-source, enterprise-grade permissioned distributed ledger technology (DLT) platform. Unlike public permissionless blockchains (like Bitcoin or Ethereum) where participants are anonymous and untrusted, Fabric is designed for enterprise contexts where participants are known, identified, and vetted.

    Key characteristics include:

    • Permissioned: Participants are known to each other, allowing for governance models based on legal agreements or frameworks.
    • Modular Architecture: Components like consensus, identity management, and cryptographic libraries are pluggable and configurable.
    • General-Purpose Smart Contracts: Supports smart contracts (called chaincode) written in standard languages like Java, Go, and Node.js, rather than domain-specific languages (DSL).
    • Pluggable Consensus: Allows choosing between different consensus protocols (e.g., Crash Fault Tolerant (CFT) or Byzantine Fault Tolerant (BFT)) based on the specific trust model and performance needs.
    • No Native Cryptocurrency: Does not require mining or a native token to incentivize participation, reducing operational costs and attack vectors.
  2. Overview of Hyperledger Fabric

    main
    Hyperledger Fabric is a graduated project under the Hyperledger umbrella designed for distributed ledger solutions. It features a modular, elastic, and extensible architecture that allows for pluggable implementations of various components. This design provides high levels of confidentiality, resiliency, flexibility, and scalability, making it suitable for complex enterprise blockchain ecosystems.
  3. Use osnadmin channel to manage Ordering Service Node (OSN) channels

    main

    The osnadmin channel command allows administrators to perform channel-related operations on an orderer. This includes joining an OSN to a channel, listing existing channels, removing channels, updating channel configurations, and fetching specific blocks.

    Prerequisites:

    • The channel participation API must be enabled.
    • The Admin endpoint must be configured in the orderer.yaml for each orderer.
  4. Troubleshoot ledger divergence with ledgerutil

    main

    The ledgerutil suite is a set of tools designed for troubleshooting Hyperledger Fabric network instances where peer ledgers on a channel have diverged. Divergence typically means the state databases of different peers are inconsistent.

    To locate the cause of divergence, you can use these three subcommands:

    1. compare: Compares channel snapshots from two different peers to find state differences.
    2. identifytxs: Takes a list of keys (often from a compare output) and identifies the specific transactions in the local block store that wrote to those keys.
    3. verify: (Details in subsequent segments) used for verifying ledger integrity.
  5. Choose an ordering service implementation

    main

    Hyperledger Fabric supports several ordering service implementations to achieve consensus on transaction ordering. Choose based on your requirements for fault tolerance and decentralization:

    • Raft: The recommended choice for production networks. It is a Crash Fault Tolerant (CFT) service using a leader/follower model. It can sustain the loss of a minority of nodes (e.g., 1 node in a 3-node cluster, or 2 nodes in a 5-node cluster).
    • BFT (Byzantine Fault Tolerant): Available as of v3.0 using the SmartBFT library. Use this if you require true decentralization where up to one-third of the nodes may be malicious or compromised.
    • Solo: Deprecated. Intended for testing only. Users should migrate to a single-node Raft network for equivalent functionality.
    • Kafka: Deprecated in v2.x and no longer supported in v3.x.
  6. Ways to contribute to Hyperledger Fabric

    main

    Hyperledger Fabric accepts contributions from users, writers, and developers.

    As a User

    • Feature/Enhancement Proposals: Propose new capabilities.
    • Bug Reporting: Report issues found during use.

    As a Writer or Information Developer

    • Documentation Updates: Improve existing topics or create new ones to help users understand Fabric.
    • Language Translation: Join existing teams (English, Chinese, Malayalam, and Brazilian Portuguese) or start a new language translation team to make documentation more accessible.

    As a Developer

    • Small Tasks: Look for tasks labeled good first issue on GitHub.
    • Full-time Development: Propose new features or join an existing Epic. You can find the Epic backlog using the Epic label on GitHub and should contact the Epic assignee via a GitHub issue.
  7. Understand Hyperledger Fabric release artifacts

    main

    When a new release is published, Hyperledger Fabric provides two main types of artifacts:

    GitHub Release

    Contains release notes and binary tars for the following architectures:

    • darwin-amd64
    • darwin-arm64 (available since v2.5.0)
    • linux-amd64
    • linux-arm64 (available since v2.5.0)
    • windows-amd64

    DockerHub Images

    Provides Docker images for peer, orderer, ccenv, baseos, and tools (CLI) for these architectures:

    • linux-amd64
    • linux-arm64 (available since v2.5.0)
  8. Use configtxgen to create channel configuration artifacts

    main

    The configtxgen command is used to create and inspect channel configuration artifacts, such as genesis blocks and organization definitions. The behavior and content of these artifacts are determined by the configtx.yaml file.

    To operate, configtxgen requires a configtx.yaml file, which it searches for at the path specified by the FABRIC_CFG_PATH environment variable.

    configtxgen -outputBlock genesis_block.pb -profile SampleSingleMSPRaftV1_1 -channelID application-channel-1
  9. Understand the Hyperledger Fabric Model

    main

    Hyperledger Fabric is a customizable enterprise blockchain solution designed around several core pillars:

    • Assets: Represented as key-value pairs (in binary or JSON) that can be modified via chaincode.
    • Chaincode: The business logic that defines assets and enforces rules for reading or altering the state database.
    • Ledger: A sequenced, tamper-resistant record of all state transitions, consisting of a blockchain (for history) and a state database (for current state).
    • Privacy: Achieved through Channels (isolating transactions from the broader network) and Private Data Collections (segregating data between subsets of organizations on a single channel).
    • Security & Membership Services: A permissioned network using Public Key Infrastructure (PKI) to tie cryptographic certificates to organizations and users.
    • Consensus: A multi-stage process involving proposal, endorsement, ordering, validation, and commitment to ensure transaction correctness.
  10. Manage the chaincode lifecycle with peer lifecycle chaincode

    main

    The peer lifecycle chaincode subcommand is used by administrators to manage the complete Fabric chaincode lifecycle. This includes packaging chaincode, installing it on peers, approving definitions for an organization, and committing definitions to a channel. A chaincode is only ready for use once its definition has been successfully committed to the channel.

    Available subcommands:

    • package: Package a chaincode and write it to a file.
    • install: Install a chaincode package on a peer.
    • queryinstalled: Query the installed chaincodes on a peer.
    • getinstalledpackage: Get an installed chaincode package from a peer.
    • calculatepackageid: Calculate the package ID for a chaincode.
    • approveformyorg: Approve the chaincode definition for your organization.
    • queryapproved: Query an organization's approved chaincode definitions.
    • checkcommitreadiness: Check if a chaincode definition is ready to be committed.
    • commit: Commit the chaincode definition to a channel.
    • querycommitted: Query the committed chaincode definitions on a channel.
  11. Use the peer CLI to manage Fabric components

    main

    The peer command is the primary CLI entrypoint for administrators to manage Hyperledger Fabric components. It uses a hierarchical subcommand structure to organize tasks.

    Available subcommands include:

    • peer chaincode: Deploy and manage smart contract chaincode.
    • peer channel: Manage channel membership (e.g., joining a peer to a channel).
    • peer node: Manage peer node operations.
    • peer version: Check the version of the peer binary.

    If you run a subcommand without a specific option, the CLI returns high-level help text.

    peer chaincode [option] [flags]
    peer channel   [option] [flags]
    peer node      [option] [flags]
    peer version   [option] [flags]
  12. Use the Fabric test network for learning and testing

    main

    The Fabric test network is a tool provided in the fabric-samples repository for educational purposes and testing smart contracts/applications on a local machine. It is not a production model.

    Key Characteristics:

    • Includes two peer organizations (Org1, Org2) and one ordering organization.
    • Uses a single-node Raft ordering service.
    • Uses root CAs for certificate issuance (no TLS CA deployed).
    • Deployed via Docker Compose and isolated within a Docker network.

    Important Note: These instructions are verified against the latest stable Fabric Docker images and pre-compiled setup utilities. Using images from the main branch may cause errors.