Go to file
Janito Vaqueiro Ferreira Filho 0ad89f2f41
Disconnect from outdated peers on network upgrade (#3108)
* Replace usage of `discover::Change` with a tuple

Remove the assumption that a `Remove` variant would never be created
with type changes that allow the compiler to guarantee that assumption.

* Add a `version` field to the `Client` type

Keep track of the peer's reported protocol version.

* Create `LoadTrackedClient` type

A `peer::Client` type wrapper that implements `Load`. This helps with
the creation of a client service that has extra peer information to be
accessed without having to send requests.

* Use `LoadTrackedClient` in `initialize`

Ensure that `PeerSet` receives `LoadTrackedClient`s so that it will be
able to query the peer's protocol version later on.

* Require `LoadTrackedClient` in `PeerSet`

Replace the generic type with a concrete `LoadTrackedClient` so that we
can query its version.

* Create `MinimumPeerVersion` helper type

A type to track the current minimum protocol version for connected
peers based on the current block height.

* Use `MinimumPeerVersion` in handshakes

Keep the code to obtain the current minimum peer protocol version in a
central place.

* Add a `MinimumPeerVersion` instance to `PeerSet`

Prepare it to be able to disconnect from outdated peers based on the
current minimum supported peer protocol version.

* Disconnect from ready services for outdated peers

When the minimum peer protocol version is detected to have changed
(because of a network upgrade), remove all ready services of peers that
became outdated.

* Cancel added unready services of outdated peers

Only add an unready service if it's for a peer that has a supported
protocol version. Otherwise, add it but drop the cancel handle so that
the `UnreadyService` can execute and detect that it was cancelled.

* Avoid adding ready services for outdated peers

If a service becomes ready but it's for a connection to an outdated
peer, drop it.

* Improve comment inside `crawl_and_dial`

Describe an edge case that is also handled but was not explicit.

Co-authored-by: teor <teor@riseup.net>

* Test if calculated minimum peer version is correct

Given an arbitrary best chain tip height, check that the calculated
minimum peer protocol version is the expected value.

* Test if minimum version changes with chain tip

Apply an arbitrary list of chain tip height updates and check that for
each update the minimum peer version is calculated correctly.

* Test minimum peer version changed reports

Simulate a series of best chain tip height updates, and check for
minimum peer version updates at least once between them. Changes should
only be reported once.

* Create a `MockedClientHandle` helper type

Used to create and then track a mock `Client` instance.

* Add `MinimumPeerVersion::with_mock_chain_tip`

An extension method useful for tests, that contains some shared
boilerplate code.

* Bias arbitrary `Version`s to be in valid range

Give a 50% chance for an arbitrary `Version` to be in the range of
previously used values the Zcash network.

* Create a `PeerVersions` helper type

Helps with the creation of mocked client services with arbitrary
protocol versions.

* Create a `PeerSetGuard` helper type

An auxiliary type to a `PeerSet` instance created for testing. It keeps
track of any dummy endpoints of channels created and passed to the
`PeerSet` instance.

* Create a `PeerSetBuilder` helper type

Helps to reduce the code when preparing a `PeerSet` test instance.

* Test if outdated peers are rejected by `PeerSet`

Simulate a set of discovered peers being sent to the `PeerSet`. Ensure
that only up-to-date peers are kept by the `PeerSet` and that outdated
peers are dropped.

* Create `BlockHeightPairAcrossNetworkUpgrades` type

A helper type that allows the creation of arbitrary block height pairs,
where one value is before and the other is at or after the activation
height of an arbitrary network upgrade.

* Test if peers are dropped as they become outdated

Simulate a network upgrade, and check that peers that become outdated
are dropped by the `PeerSet`.

* Remove dbg! macros

Co-authored-by: teor <teor@riseup.net>
2021-12-09 02:54:29 +00:00
.github Bump EmbarkStudios/cargo-deny-action from 1.2.6 to 1.2.9 (#3163) 2021-12-07 11:08:51 +10:00
book Updates for zebra v1.0.0-beta.1 release (#3073) 2021-11-19 13:05:11 +01:00
docker Download Zcash Sapling parameters and load them from cached files (#3057) 2021-11-19 23:02:56 +00:00
grafana Add transaction-verification.json Grafana dashboard (#3122) 2021-12-01 06:44:33 +00:00
tower-batch Release Zebra v1.0.0-beta.2 (#3132) 2021-12-03 06:54:14 +10:00
tower-fallback Updates for zebra v1.0.0-beta.1 release (#3073) 2021-11-19 13:05:11 +01:00
zebra-chain Bump itertools from 0.10.1 to 0.10.3 (#3171) 2021-12-08 22:57:14 +00:00
zebra-client V1.0.0-beta.0 (#2973) 2021-10-29 20:21:26 +00:00
zebra-consensus Release Zebra v1.0.0-beta.2 (#3132) 2021-12-03 06:54:14 +10:00
zebra-network Disconnect from outdated peers on network upgrade (#3108) 2021-12-09 02:54:29 +00:00
zebra-rpc V1.0.0-beta.0 (#2973) 2021-10-29 20:21:26 +00:00
zebra-script Release Zebra v1.0.0-beta.2 (#3132) 2021-12-03 06:54:14 +10:00
zebra-state Bump itertools from 0.10.1 to 0.10.3 (#3171) 2021-12-08 22:57:14 +00:00
zebra-test Add `zebra_test::init_async` helper function (#3169) 2021-12-09 00:18:17 +00:00
zebra-utils Release Zebra v1.0.0-beta.2 (#3132) 2021-12-03 06:54:14 +10:00
zebrad Add `zebra_test::init_async` helper function (#3169) 2021-12-09 00:18:17 +00:00
.gitignore switch to source based coverage (#1293) 2020-12-03 13:36:40 -08:00
CHANGELOG.md Release Zebra v1.0.0-beta.2 (#3132) 2021-12-03 06:54:14 +10:00
CODE_OF_CONDUCT.md CODE_OF_CONDUCT.md (#1097) 2021-03-25 10:54:08 +01:00
CONTRIBUTING.md Make the RFC TOC into a separate step (#2126) 2021-05-10 10:17:42 -03:00
Cargo.lock Bump itertools from 0.10.1 to 0.10.3 (#3171) 2021-12-08 22:57:14 +00:00
Cargo.toml Automatically download and load sprout parameters (#3085) 2021-11-25 13:26:32 -03:00
LICENSE-APACHE Add copyright marks on each license 2019-11-14 11:50:49 -08:00
LICENSE-MIT Add copyright marks on each license 2019-11-14 11:50:49 -08:00
README.md Release Zebra v1.0.0-beta.2 (#3132) 2021-12-03 06:54:14 +10:00
SECURITY.md Explicitly allow unencrypted disclosures for alpha releases (#2127) 2021-05-11 14:41:33 +02:00
clippy.toml Apply clippy fixes 2020-02-05 12:42:32 -08:00
cloudbuild.yaml Pipe SHORT_SHA into container builds (#1451) 2020-12-03 22:51:42 -05:00
codecov.yml Disable CodeCov annotations via GitHub Checks 2020-09-10 14:52:01 -04:00
deny.toml Stop doing thousands of time checks each time we connect to a peer (#3106) 2021-12-03 15:09:43 -03:00
firebase.json Configure redirect for firebase hosting 2020-01-16 18:38:16 -05:00
katex-header.html Add KaTeX to rendered docs. (#832) 2020-08-05 17:34:30 -07:00
prometheus.yaml Tell Prometheus to scrape more aggressively 2020-02-14 20:14:05 -05:00

README.md

Zebra logotype


codecov License

Contents

About

Zebra is the Zcash Foundation's independent, consensus-compatible implementation of a Zcash node, currently under development. It can be used to join the Zcash peer-to-peer network, which helps keeping Zcash working by validating and broadcasting transactions, and maintaining the Zcash blockchain state in a distributed manner. Please join us on Discord if you'd like to find out more or get involved!

Zcash is a cryptocurrency designed to preserve the user's privacy. Like most cryptocurrencies, it works by a collection of software nodes run by members of the Zcash community or any other interested parties. The nodes talk to each other in peer-to-peer fashion in order to maintain the state of the Zcash blockchain. They also communicate with miners who create new blocks. When a Zcash user sends Zcash, their wallet broadcasts transactions to these nodes which will eventually reach miners, and the mined transaction will then go through Zcash nodes until they reach the recipient's wallet which will report the received Zcash to the recipient.

The original Zcash node is named zcashd and is developed by the Electric Coin Company as a fork of the original Bitcoin node. Zebra, on the other hand, is an independent Zcash node implementation developed from scratch. Since they implement the same protocol, zcashd and Zebra nodes can communicate with each other and maintain the Zcash network interoperably.

If you just want to send and receive Zcash then you don't need to use Zebra directly. You can download a Zcash wallet application which will handle that for you. (Eventually, Zebra can be used by wallets to implement their functionality.) You would want to run Zebra if you want to contribute to the Zcash network: the more nodes are run, the more reliable the network will be in terms of speed and resistance to denial of service attacks, for example.

These are some of the advantages or benefits of Zebra:

  • Better performance: since it was implemented from scratch in an async, parallelized way, Zebra is currently faster than zcashd.
  • Better security: since it is developed in a memory-safe language (Rust), Zebra is less likely to be affected by memory-safety and correctness security bugs that could compromise the environment where it is run.
  • Better governance: with a new node deployment, there will be more developers who can implement different features for the Zcash network.
  • Dev accessibility: supports more developers, which gives new developers options for contributing to Zcash protocol development.
  • Runtime safety: with an independent implementation, the detection of consensus bugs can happen quicker, reducing the risk of consensus splits.
  • Spec safety: with several node implementations, it is much easier to notice bugs and ambiguity in protocol specification.
  • User options: different nodes present different features and tradeoffs for users to decide on their preferred options.
  • Additional contexts: wider target deployments for people to use a consensus node in more contexts e.g. mobile, wasm, etc.

Beta Releases

Every few weeks, we release a new Zebra beta release.

Zebra's network stack is interoperable with zcashd, and Zebra implements all the features required to reach Zcash network consensus.

The goals of the beta release series are for Zebra to act as a fully validating Zcash node, for all active consensus rules as of NU5 activation.

Currently, Zebra does not validate the following Zcash consensus rules:

NU1 - Sapling

  • Validation of Sprout JoinSplit-on-Groth16 proofs

Sprout

  • Validation of Sprout anchors (root of the Sprout note commitment tree)

Other

  • Undocumented rules derived from Bitcoin
  • Undocumented network protocol requirements

Getting Started

Building zebrad requires Rust, libclang, and a C++ compiler.

Build and Run Instructions

zebrad is still under development, so there is no supported packaging or install mechanism. To run zebrad, follow the instructions to compile zebrad for your platform:

  1. Install cargo and rustc.
  2. Install Zebra's build dependencies:
    • libclang: the libclang, libclang-dev, llvm, or llvm-dev packages, depending on your package manager
    • clang or another C++ compiler: g++, Xcode, or MSVC
  3. Run cargo install --locked --git https://github.com/ZcashFoundation/zebra --tag v1.0.0-beta.2 zebrad
  4. Run zebrad start (see Running Zebra for more information)

If you're interested in testing out zebrad please feel free, but keep in mind that there is a lot of key functionality still missing.

For more detailed instructions, refer to the documentation.

System Requirements

The recommended requirements for compiling and running zebrad are:

  • 4+ CPU cores
  • 16+ GB RAM
  • 50GB+ available disk space for finalized state
  • 100+ Mbps network connections

We continuously test that our builds and tests pass on:

The latest GitHub Runners for:

  • Windows Server
  • macOS
  • Ubuntu

Docker:

  • Debian Buster

Zebra's tests can take over an hour, depending on your machine. We're working on making them faster.

zebrad might build and run fine on smaller and slower systems - we haven't tested its exact limits yet.

For more detailed requirements, refer to the documentation.

Memory Troubleshooting

If Zebra's build runs out of RAM, try setting: export CARGO_BUILD_JOBS=2

If Zebra's tests timeout or run out of RAM, try running: cargo test -- --test-threads=2

(cargo uses all the processor cores on your machine by default.)

macOS Test Troubleshooting

Some of Zebra's tests deliberately cause errors that make Zebra panic. macOS records these panics as crash reports.

If you are seeing "Crash Reporter" dialogs during Zebra tests, you can disable them using this Terminal.app command:

defaults write com.apple.CrashReporter DialogType none

Network Ports and Data Usage

By default, Zebra uses the following inbound TCP listener ports:

  • 8233 on Mainnet
  • 18233 on Testnet

zebrad's typical network usage is:

  • Initial sync: 30 GB download
  • Ongoing updates: 10-50 MB upload and download per day, depending on peer requests

For more detailed information, refer to the documentation.

Network Troubleshooting

Some of Zebra's tests download Zcash blocks, so they might be unreliable depending on your network connection. You can set ZEBRA_SKIP_NETWORK_TESTS=1 to skip the network tests.

Zebra may be unreliable on Testnet, and under less-than-perfect network conditions. See our roadmap for details.

Known Issues

There are a few bugs in Zebra that we're still working on fixing:

Zebra's state commits changes using database transactions. If you forcibly terminate it, or it panics, any incomplete changes will be rolled back the next time it starts.

Future Work

In 2021, we intend to finish NU5 validation, start adding RPC support and start adding wallet integrations. This phased approach allows us to test Zebra's independent implementation of the consensus rules, before asking users to entrust it with their funds.

Features:

  • Full consensus rule validation
  • Wallet functionality
  • RPC functionality

Performance and Reliability:

  • Reliable syncing on Testnet
  • Reliable syncing under poor network conditions
  • Batch verification
  • Performance tuning

Currently, the following features are out of scope:

  • Mining support
  • Optional Zcash network protocol messages
  • Consensus rules removed before Canopy activation (Zebra checkpoints on Canopy activation)

Documentation

The Zebra website contains user documentation, such as how to run or configure Zebra, set up metrics integrations, etc., as well as developer documentation, such as design documents. We also render API documentation for the external API of our crates, as well as internal documentation for private APIs.

Security

Zebra has a responsible disclosure policy, which we encourage security researchers to follow.

License

Zebra is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT.