Skip to main content

zebrad/
lib.rs

1//! ![Zebra logotype](https://zfnd.org/wp-content/uploads/2022/03/zebra-logotype.png)
2//!
3//! Zebra is a Zcash full node written in Rust. Follow the [introductory
4//! page](https://zebra.zfnd.org/index.html#documentation) in the Zebra Book to learn more.
5//!
6//! ## About Zcash
7//!
8//! Zcash is a cryptocurrency designed to preserve the user's privacy. Like most
9//! cryptocurrencies, it works by a collection of software nodes run by members of
10//! the Zcash community or any other interested parties. The nodes talk to each
11//! other in peer-to-peer fashion in order to maintain the state of the Zcash
12//! blockchain. They also communicate with miners who create new blocks. When a
13//! Zcash user sends Zcash, their wallet broadcasts transactions to these nodes
14//! which will eventually reach miners, and the mined transaction will then go
15//! through Zcash nodes until they reach the recipient's wallet which will report
16//! the received Zcash to the recipient.
17//!
18//! ## Alternative Implementations
19//!
20//! The first Zcash node, `zcashd`, was originally created as a fork of Bitcoin
21//! Core and is no longer maintained. Zebra is an independent Zcash node
22//! implementation, written from scratch, and is the actively maintained node
23//! for the network. Other implementations built on or alongside Zebra also
24//! exist. Because they implement the same protocol, conforming nodes
25//! interoperate and maintain the Zcash network together.
26//!
27//! ## Zebra Advantages
28//!
29//! These are some of the advantages or benefits of Zebra:
30//!
31//! - **Performance**: Zebra is built from scratch in an async, parallelized
32//!   design, giving it high throughput for block validation and syncing.
33//! - **Security**: Zebra is written in Rust, a memory-safe language, which
34//!   reduces the risk of memory-safety and correctness bugs that could
35//!   compromise the node or the environment it runs in.
36//! - **Modularity**: Zebra is organized as a set of reusable crates
37//!   (`zebra-chain`, `zebra-consensus`, `zebra-network`, `zebra-state`,
38//!   `zebra-rpc`, and more). Wallets, indexers, and other tools can build on
39//!   these directly instead of reimplementing core Zcash logic.
40//! - **Broader deployment targets**: Its modular design makes it possible to run
41//!   Zcash consensus code in a wider range of environments, including mobile and
42//!   WebAssembly.
43//! - **Open contribution**: A modern, well-documented Rust codebase lowers the
44//!   barrier for new contributors, widening the pool of developers who can
45//!   review, maintain, and extend the Zcash protocol.
46//! - **Ecosystem foundation**: Because Zebra is independent and openly developed,
47//!   other teams can build implementations, forks, and services on top of it,
48//!   supporting a healthy and decentralized network.
49//!
50//! ## Configuration
51//!
52//! The command below places the generated `zebrad.toml` config file in the default preferences directory of Linux:
53//!
54//! ```console
55//! zebrad generate -o ~/.config/zebrad.toml
56//! ```
57//!
58//! See [`config::ZebradConfig`] for other OSes default locations or more information about how to configure Zebra.
59//!
60//! ## Zebra Feature Flags
61//!
62//! The following [Cargo
63//! features](https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options)
64//! are available at compile time:
65//!
66//! ### Metrics
67//!
68//! * configuring a `tracing.progress_bar`: shows key metrics in the terminal using progress bars,
69//!   and automatically configures Zebra to send logs to a file.
70//!   (The `progress-bar` feature is activated by default.)
71//! * `prometheus`: export metrics to prometheus.
72//!
73//! Read the [metrics](https://zebra.zfnd.org/user/metrics.html) section of the book
74//! for more details.
75//!
76//! ### Tracing
77//!
78//! Sending traces to different subscribers:
79//! * configuring a `tracing.log_file`: appends traces to a file on disk.
80//! * `journald`: send tracing spans and events to `systemd-journald`.
81//! * `sentry`: send crash and panic events to sentry.io.
82//! * `flamegraph`: generate a flamegraph of tracing spans.
83//!
84//! Changing the traces that are collected:
85//! * `filter-reload`: dynamically reload tracing filters at runtime.
86//! * `error-debug`: enable extra debugging in release builds.
87//! * `tokio-console`: enable tokio's `console-subscriber` (needs [specific compiler flags])
88//! * A set of features that [skip verbose tracing].
89//!   The default features ignore `debug` and `trace` logs in release builds.
90//!
91//! Read the [tracing](https://zebra.zfnd.org/user/tracing.html) section of the book
92//! for more details.
93//!
94//! [skip verbose tracing]: https://docs.rs/tracing/0.1.35/tracing/level_filters/index.html#compile-time-filters
95//! [specific compiler flags]: https://zebra.zfnd.org/dev/tokio-console.html#setup
96//!
97//! ### Testing
98//!
99//! * `proptest-impl`: enable randomised test data generation.
100//! * `lightwalletd-grpc-tests`: enable Zebra JSON-RPC tests that query `lightwalletd` using gRPC.
101//!
102//! ### Experimental
103//!
104//! * `elasticsearch`: save block data into elasticsearch database. Read the [elasticsearch](https://zebra.zfnd.org/user/elasticsearch.html)
105//!   section of the book for more details.
106//! * `internal-miner`: enable experimental support for mining inside Zebra, without an external
107//!   mining pool. This feature is only supported on testnet. Use a GPU or ASIC on mainnet for
108//!   efficient mining.
109//!
110//! ## Zebra crates
111//!
112//! [The Zebra monorepo](https://github.com/ZcashFoundation/zebra) is a collection of the following
113//! crates:
114//!
115//! - [tower-batch-control](https://docs.rs/tower-batch-control/latest/tower_batch_control/)
116//! - [tower-fallback](https://docs.rs/tower-fallback/latest/tower_fallback/)
117//! - [zebra-chain](https://docs.rs/zebra-chain/latest/zebra_chain/)
118//! - [zebra-consensus](https://docs.rs/zebra-consensus/latest/zebra_consensus/)
119//! - [zebra-network](https://docs.rs/zebra-network/latest/zebra_network/)
120//! - [zebra-node-services](https://docs.rs/zebra-node-services/latest/zebra_node_services/)
121//! - [zebra-rpc](https://docs.rs/zebra-rpc/latest/zebra_rpc/)
122//! - [zebra-script](https://docs.rs/zebra-script/latest/zebra_script/)
123//! - [zebra-state](https://docs.rs/zebra-state/latest/zebra_state/)
124//! - [zebra-test](https://docs.rs/zebra-test/latest/zebra_test/)
125//! - [zebra-utils](https://docs.rs/zebra-utils/latest/zebra_utils/)
126//! - [zebrad](https://docs.rs/zebrad/latest/zebrad/)
127//!
128//! The links in the list above point to the documentation of the public APIs of the crates. For
129//! the documentation of the internal APIs, follow <https://zebra.zfnd.org/internal> that lists
130//! all Zebra crates as well in the left sidebar.
131
132#![doc(html_favicon_url = "https://zfnd.org/wp-content/uploads/2022/03/zebra-favicon-128.png")]
133#![doc(html_logo_url = "https://zfnd.org/wp-content/uploads/2022/03/zebra-icon.png")]
134#![doc(html_root_url = "https://docs.rs/zebrad")]
135// Tracing causes false positives on this lint:
136// https://github.com/tokio-rs/tracing/issues/553
137#![allow(clippy::cognitive_complexity)]
138
139#[macro_use]
140extern crate tracing;
141
142/// Error type alias to make working with tower traits easier.
143///
144/// Note: the 'static lifetime bound means that the *type* cannot have any
145/// non-'static lifetimes, (e.g., when a type contains a borrow and is
146/// parameterized by 'a), *not* that the object itself has 'static lifetime.
147pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
148
149pub mod application;
150pub mod commands;
151pub mod components;
152pub mod config;
153pub mod prelude;
154
155#[cfg(feature = "sentry")]
156pub(crate) mod sentry;