Fablo

repository·main·Indexed 42 days ago

https://github.com/hyperledger-labs/fablo

A tool for generating and managing Hyperledger Fabric blockchain networks on Docker using a single configuration file. It supports RAFT and solo consensus protocols, multiple organizations and channels, and chaincode installation and upgrades. Version 2.6.0 supports Fabric 3.1.0 and provides features for local development, CI/CD, and chaincode hot reloading via Peer Dev Mode or CCaaS.

Tokens
27.3K
Snippets
101
Records
125
Agent score
48%

What's inside Fablo

  1. Overview of Fablo workflow

    main

    Fablo simplifies Hyperledger Fabric setup by replacing manual creation of crypto, configtx, and Docker Compose files with a single JSON or YAML configuration file.

    The core workflow is:

    1. Describe: Use fablo init <language> to create a starter config.
    2. Generate: Use fablo generate to produce the fablo-target directory containing Fabric configs and Docker files.
    3. Run: Use fablo up to start the network on Docker and deploy chaincode.

    Key Features:

    • Supported Chaincode: Node.js, Go, or Java. Supports Chaincode as a Service (CCaaS) with hot reload.
    • Database Options: CouchDB or LevelDB.
    • Ordering Services: RAFT or BFT (on Fabric v3); RAFT or solo (on Fabric v2).
    • Development Tools: Supports network snapshots for state restoration and can be integrated with Fablo REST or Blockchain Explorer.
  2. Overview of Fablo end-to-end test cases

    main

    Fablo includes several end-to-end test cases that demonstrate different Hyperledger Fabric network configurations. These test cases vary by Fabric version, deployment engine (Docker or Kubernetes), consensus mechanism (Solo, RAFT, or BFT), and specific features like Private Data or TLS. Use these configurations as templates for understanding how Fablo handles different network topologies and capabilities.

    | Test case | 01-v2-simple | 02-v2-raft-2orgs | 03-v2-private-data | 04-v2-snapshot | test-05-v3 | test-06-v3-bft | k8s-01-simple |
    | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
    | Fabric versions | 2.5.12 | 2.4.3 | 2.5.12 | 2.5.12 | 3.1.0 | 3.1.0 | 2.4.7 |
    | Engine | Docker | Docker | Docker | Docker | Docker | Docker | Kubernetes |
    | TLS | no | yes | no | yes | yes | yes | yes |
    | Channel capabilities | v2 | v2 | v2_5 | v2 | v3_0 | v3_0 | v2 |
    | Consensus | solo | RAFT | solo | RAFT | RAFT | BFT | RAFT |
    | Orderer nodes | 1 | 3 | 1 | 1 | 3 | 4 | 1 |
    | Organizations | 1 | 2 | 2 | 1 | 1 | 1 | 1 |
    | CA database | SQLite | SQLite | SQLite | Postgres | SQLite | SQLite | - |
    | Peer database | LevelDB | LevelDB | LevelDB | CouchDB | LevelDB | LevelDB | LevelDB |
    | Peer count | 2 | 2, 2 | 2, 1 | 2 | 2 | 2 | 2 |
    | Channels | 1 | 2 | 1 | 1 | 1 | 1 | 1 |
    | Node chaincode | yes | yes | yes | yes | yes | yes | yes, CCaaS |
    | Node chaincode upgrade | no | yes | no | no | no | no | no |
    | Node chaincode endorsement | OR | OR | OR, AND | default | OR | OR | default |
    | Private data | no | no | yes | yes | no | no | no |
    | Java chaincode | no | yes | no | no | no | no | no |
    | Go chaincode | no | no | yes | no | yes | no | no |
    | Tools | channel scripts | Fablo REST | - | Fablo REST, Explorer | - | - | fabricopsctl |
    | Other Fablo commands | init, reset | stop, start | - | snapshot, prune, restore | - | - | - |
  3. Fablo Configuration File Overview

    main

    A Fablo configuration file is a JSON or YAML document used to define your Hyperledger Fabric network.

    Required Top-Level Sections

    • global: Network-wide settings.
    • orgs: Organization definitions.
    • channels: Channel definitions and membership.
    • chaincodes: Chaincode definitions and endorsement policies.

    Optional Top-Level Fields

    • $schema: URL for JSON Schema validation.
    • hooks: Commands to run after generate or start.

    File Discovery

    Commands like fablo up and fablo validate automatically look for fablo-config.json in the current directory. If not found, they fall back to fablo-config.yaml.

  4. Achieve chaincode hot reload via CCaaS

    main

    The CCaaS (Chaincode as a Service) approach allows for hot reloading while maintaining container isolation. This is compatible with both TLS and non-TLS setups.

    How it works: You use the ccaas chaincode type and configure chaincodeMountPath and chaincodeStartCommand. This mounts your local source code into a CCaaS container, allowing the process inside the container to restart when the mounted code changes.

    Benefits:

    • Supports both TLS and non-TLS.
    • Granular control: only specific chaincodes need to be in hot-reload mode.
    • Fablo manages the lifecycle of the CCaaS processes.
    // Example CCaaS configuration in fablo-config.json
    {
      "name": "chaincode1",
      "version": "0.0.1",
      "channel": "my-channel1",
      "lang": "ccaas",
      "image": "hyperledger/fabric-nodeenv:${FABRIC_NODEENV_VERSION:-2.5}",
      "chaincodeMountPath": "$CHAINCODES_BASE_DIR/chaincodes/chaincode-kv-node",
      "chaincodeStartCommand": "npm run start:watch:ccaas",
      "privateData": []
    }
  5. Understand the Fablo configuration structure

    main

    The Fablo configuration is a single JSON or YAML file that defines the Hyperledger Fabric network topology, including network settings, CAs, orderers, organizations, peers, channels, and chaincodes.

    To ensure correctness, the config must be compatible with the project's schema. You can validate your configuration using the fablo validate command. You can also generate a basic starting configuration using the ./fablo init command.

    The top-level structure consists of four main sections:

    • global: Network-wide settings.
    • orgs: Definitions for organizations, peers, and orderers.
    • channels: Channel definitions and membership.
    • chaincodes: Chaincode definitions and deployment settings.
    {
      "$schema": "https://github.com/hyperledger-labs/fablo/releases/download/2.6.0/schema.json",
      "global": { ... },
      "orgs": [ ... ],
      "channels": [ ... ],
      "chaincodes": [ ... ]
    }
  6. Use `fabric-docker.sh` for manual network management

    main

    When you run fablo generate, a fabric-docker.sh script is created in the target directory. If you prefer to use Fablo only for initial configuration and want to manage the network without the fablo wrapper, you can use this script.

    It supports the following commands, which behave identically to the fablo equivalents:

    • up, down, start, stop, reset
    • chaincode and chaincodes
    • channel
    • snapshot
  7. Achieve chaincode hot reload via Peer Dev Mode

    main

    Peer dev mode allows you to run the chaincode process locally on your machine instead of inside a container, speeding up the development cycle.

    Requirements & Setup:

    1. In fablo-config.json, set global.peerDevMode to true and global.tls to false.
    2. Run fablo up. Fablo will approve and commit chaincode definitions but will not start the chaincode containers.
    3. Start the chaincode process manually on your local machine.

    Trade-offs:

    • Pros: Simpler setup; runs locally.
    • Cons: Non-TLS only; configuration is global per network; you must start a separate process for every peer you wish to use.

    Language Specifics:

    • Node.js: Install dependencies and use a watcher (like nodemon) to restart the process on code changes.
    • Java: Build using Gradle (shadowJar) and run a local script (like run-dev.sh) that maps to the peer's host port.
    # Node.js example: Install and start with watch mode
    (cd chaincodes/chaincode-kv-node && nvm use && npm i && npm run start:watch)
  8. Enable Blockchain Explorer for Fabric v2

    main

    Hyperledger Explorer can be enabled for Fabric v2 networks to inspect channels, blocks, and transactions.

    Important Notes:

    • Explorer is not supported for Fabric v3.
    • fablo validate will warn if the Fabric version is 2.5.13 or newer, or older than 1.4.0, due to potential compatibility issues.
    • You can enable it globally in the global.tools section or specifically for a single organization. If set globally, the organization-level setting is ignored.
    • Running fablo up will generate the necessary connection material and start the Explorer containers.
    {
      "global": {
        "fabricVersion": "2.5.12",
        "tls": true,
        "tools": { "explorer": true }
      }
    }
  9. Start a Hyperledger Fabric network

    main

    To launch your network, use the up command. Fablo will start the network components on Docker, create the specified channels, and deploy the defined chaincodes. This command is designed for local development and CI environments, allowing you to spin up a full network in a few minutes.

    fablo up
  10. Deploy to Kubernetes using FabricOps

    main

    Fablo can use FabricOps as a Kubernetes engine to generate a FabricNetwork manifest. This is intended for Kubernetes-backed networks rather than local Docker development.

    Requirements:

    • A Kubernetes cluster selected in your current kubectl context.
    • FabricOps installed in the target cluster.
    • fabricopsctl installed in your PATH (required for fablo chaincode invoke and fablo chaincode query).
    • global.engine set to kubernetes in your config.
    • CCaaS chaincodes must have prebuilt image values.
    • global.tls must be set to true when channels are declared.

    Setup fabricopsctl: If fabricopsctl is not in your path, install it via Go:

    go install github.com/LF-Decentralized-Trust-labs/FabricOps/cmd/fabricopsctl@latest
    export PATH="$(go env GOPATH)/bin:$PATH"

    Usage:

    fablo up samples/fablo-config-hlf2-1org-1chaincode-k8s.json
  11. Generate network files without starting the network

    main

    If you want to inspect the generated files or target a specific output directory without actually launching the Hyperledger Fabric network, use the fablo generate command.

    Usage: fablo generate [/path/to/fablo-config.json|yaml [/path/to/fablo/target]]

    The default output directory is fablo-target in your current directory.

    # Generate files into the default 'fablo-target' directory
    fablo generate
    
    # Generate files into a specific target directory
    fablo generate my-config.json ./custom-target-dir