Zebra Documentation

repository·main·Indexed 20 days ago

https://github.com/zcashfoundation/zebra

Zebra is a Zcash full node written in Rust that provides core infrastructure for P2P connectivity and chain state management. This documentation covers setting up Zcash mining pools using S-NOMP and Redis, deploying observability tools including Grafana dashboards, Prometheus metrics, and Jaeger distributed tracing, and managing the node via Docker Compose.

Tokens
141.2K
Snippets
359
Records
604
Agent score
69%

What's inside Zebra

  1. Overview of Zebra Continuous Integration

    main

    Zebra utilizes extensive continuous integration (CI) testing to ensure the reliability of node syncing and lightwalletd integration.

    Key testing components include:

    • Integration Tests: Triggered on every Pull Request (PR), these run Docker-based tests on Google Cloud, covering Zebra updates, lightwalletd full/update syncs, and lightwalletd integration with Zebra JSON-RPC and Light Wallet gRPC calls.
    • Full Sync Tests: Triggered when a PR is merged into the main branch, running a Zebra full sync from genesis.
    • Unit Tests: A smaller set of tests running on tier 2 platforms via GitHub Actions runners.

    Tests utilize cached state images from Google Cloud to optimize speed. Tests prefer the latest image generated from the same commit, but will fall back to the latest image from any branch/commit if the state version matches.

  2. Summary of Zebra Utilities

    main

    The zebra-utils package provides several command-line tools for maintaining and testing the Zebra node:

    • zebra-checkpoints: Generates and updates block height/hash checkpoint lists.
    • zebrad-hash-lookup: Retrieves metadata for a specific block hash using zcash-cli.
    • zebrad-log-filter: A pipeable tool that intercepts logs, finds hashes, and expands them into detailed block info.
    • zcash-rpc-diff: Compares RPC responses between zebrad and zcashd to verify consistency.
  3. Zebra Platform Support Tiers

    main

    Zebra platform support is categorized into three tiers based on build and testing guarantees. Platforms are identified by their Rust "target triple" (<machine>-<vendor>-<operating system>).

    Tier 1: Guaranteed to work

    Official binary releases and Docker images are provided. Automated testing ensures these platforms build and pass tests after every change.

    • x86_64-unknown-linux-gnu (Debian 13, 64-bit): Provides Docker and binary artifacts.
    • aarch64-unknown-linux-gnu (Debian 13, 64-bit ARM64): Provides Docker and binary artifacts.

    Note: Official Docker images are multi-architecture and support both AMD64 and ARM64 using the same image tag.

    Tier 2: Guaranteed to build

    Automated CI builds ensure these platforms can compile, but not all tests are run. Official builds are not provided.

    • x86_64-unknown-linux-gnu (GitHub ubuntu-latest, 64-bit): Uses latest stable Rust.
    • x86_64-unknown-linux-gnu (GitHub ubuntu-latest, 64-bit beta): Uses latest beta Rust.

    Tier 3: Supported but untested

    The codebase supports these platforms, but they are not built or tested automatically. Official builds are not available.

    • x86_64-apple-darwin (macOS, 64-bit)
    • aarch64-apple-darwin (macOS, 64-bit Apple M1/M2)
    • x86_64-pc-windows-msvc (Windows, 64-bit)
  4. Understand the Zebra Startup and Sync Process

    main

    When Zebra starts, it launches multiple concurrent tasks to initialize the node. The process generally follows these stages:

    1. Load Configuration: Reads settings from the config file.
    2. Open Cached State: Loads existing blockchain data from disk or creates a new empty state.
    3. Peer Handling: Discovers initial peers via DNS seeders and establishes connections.
    4. Initialize JSON-RPC Server: Starts the optional RPC interface for external applications (e.g., lightwalletd).
    5. Initialize Verifiers: Loads Sprout and Sapling parameters to verify blocks and transactions.
    6. Initialize Transaction Mempool: Prepares tasks for syncing, verifying, and gossiping transaction hashes.
    7. Syncing the Block Chain: Downloads, verifies, and gossips blocks until the node reaches the network consensus chain tip.

    You can monitor the progress of these tasks using Grafana dashboards.

  5. Current Zebra Architecture for Wallet Functionality

    main

    Note: The zebra-client and zebra-cli crates have been removed from Zebra as of May 2023.

    Zebra no longer includes built-in wallet functionality. Instead, it serves as a pure full node backend for external wallet tools. To interact with the blockchain or manage funds, you should use one of the following methods:

    • Lightwalletd integration: Use this for blockchain scanning and wallet synchronization.
    • Standard RPC methods: Use methods like sendrawtransaction and getrawtransaction to interact with the node.
    • External Wallets: Use specialized tools such as Zecwallet.

    This architecture ensures a separation of concerns: Zebra remains a full node with no access to user private data, while specialized tools handle sensitive key management.

  6. Zebra Continuous Delivery Pipeline Overview

    main

    Zebra uses a continuous-delivery pipeline on Google Cloud Platform (GCP) to deploy different versions of the software based on git events:

    • stage environment: Automatically deployed for every commit merged to the main branch.
    • prod environment: Automatically deployed for every published release.
    • dev environment: Used for manual testing via workflow_dispatch (PR-triggered work does not deploy, it only runs Docker-configuration tests).

    The deployment targets Managed Instance Groups (MIGs) across multiple zones to ensure availability.

  7. What is Treestate and how is it used for validation

    main

    Treestate refers to the combined state of the note commitment tree and the nullifier set used to validate shielded transactions.

    To validate a block, Zebra must ensure the computed treestate (the root of the note commitment tree and the set of nullifiers revealed in the block) is consistent with:

    1. Metadata in the block header (for Sapling and Orchard).
    2. Previously finalized state (for Sprout).

    This consistency check ensures that the existence of value (via note commitments) and the prevention of double-spending (via nullifiers) are correctly maintained across the blockchain.

  8. What is Stolon transaction diffusion?

    main

    Stolon is a transaction diffusion algorithm designed to improve the privacy of shielded transactions by obscuring their provenance. It is inspired by the Dandelion algorithm but optimized for Zcash.

    Stolon operates in two distinct phases:

    1. Relay phase (stem phase): Transactions are relayed through a small-fanout network using ephemeral, isolated Tor connections. These connections are designed to be minimally distinguishable and are isolated from the node's other state to prevent information leakage.
    2. Broadcast phase (fluff phase): Transactions are broadcast widely across the standard clearnet P2P network to be propagated as quickly as possible.

    Transitioning from the relay phase to the broadcast phase occurs based on a random probability. Stolon is intended for use by full nodes (like Zebra or Zcashd) and wallet software to ensure that the initial creation of a transaction does not immediately reveal the sender's identity to the network.

  9. What is zcashd-compat mode?

    main

    The zcashd-compat mode is designed for operators (like exchanges or custodial services) who need to migrate to Zebra while maintaining their existing zcashd wallet and RPC integrations.

    In this topology, Zebra acts as the consensus node facing the public Zcash P2P network. zcashd runs as a P2P sidecar that makes a single outbound connection to the local Zebra node and does not listen for any inbound P2P connections.

    Key responsibilities shift as follows:

    FeatureProvided by zcashd (Unchanged)Moved to Zebra
    Wallet/RPCWallet RPC methods (transparent + Sapling)
    DataLocal block files, chainstate, indexes
    NotificationsZMQ notifications
    NetworkingPublic P2P networking and peer selection
    RelayNetwork-facing block and transaction relay
    MiningBlock templates for miners
    DiscoveryDNS seeding and peer discovery
  10. Understand the Zebra State Database Format

    main

    Zebra uses RocksDB to provide a persistent, thread-safe BTreeMap<&[u8], &[u8]>. The database is organized into several Column Families categorized by protocol features (Blocks, Transactions, Transparent, Sprout, Sapling, Orchard, and Chain).

    Key Storage Principles

    • Lexicographic Order: Keys are sorted using [u8].sorted(). To ensure integer values maintain numeric ordering in the database, they must be stored using big-endian encoding.
    • 1-to-Many Maps: Zebra uses prefix-based keys to implement 1-to-many relationships. For example, tx_loc_by_transparent_addr_loc maps an address to multiple transactions by prefixing each transaction key with the address, allowing for efficient prefix listing.
    • Encoding: Most Zcash protocol structures use ZcashSerialize/ZcashDeserialize. Some use custom IntoDisk/FromDisk implementations.

    Warning: Avoid using bincode for new column families, as it is sensitive to struct field order and type changes.

    /* Column Family Overview (Partial) */
    | Column Family                      | Keys                   | Values                        |
    | ---------------------------------- | ---------------------- | ----------------------------- |
    | _Blocks_                           |                        |                               |
    | `hash_by_height`                   | `block::Height`        | `block::Hash`                 |
    | `height_by_hash`                   | `block::Hash`          | `block::Height`               |
    | `block_header_by_height`           | `block::Height`        | `block::Header`               |
    | _Transactions_                     |                        |                               |
    | `tx_by_loc`                        | `TransactionLocation`  | `Transaction`                 |
  11. Core Treestate Definitions

    main

    The following terms are fundamental to understanding treestate management in Zebra:

    • notes: Values bound to a shielded payment address (public key).
    • nullifiers: Values revealed during a Spend to prevent double-spending.
    • nullifier set: The set of unique Nullifiers revealed by all transactions within a block.
    • note commitments: Pedersen commitments to the values of a Note.
    • note commitment tree: An incremental Merkle tree of fixed depth storing NoteCommitments. It expresses the existence of value.
    • note position: The index of a NoteCommitment at the leafmost layer, determined by the order of transactions in the block.
    • root: The layer 0 node of a Merkle tree.
    • anchor: A Merkle tree root of a NoteCommitment tree. It uniquely identifies a specific state of both the tree and the associated Nullifier set.
  12. How the Block Syncing Process Works

    main

    Zebra synchronizes the blockchain by following these steps:

    1. Genesis Download: Downloads the genesis block by its hash.
    2. Hash Discovery: Asks peers for the hashes of the next 500 blocks.
    3. Block Download: Downloads blocks based on the hashes obtained from peers.
    4. Verification & Storage: Verifies, saves, and gossips the downloaded blocks.
    5. Iteration: Repeats the process until the node reaches the network consensus chain tip.

    Zebra also handles small numbers of new blocks near the chain tip by downloading and verifying gossiped block hashes.