Zebra Utilities
Tools for maintaining and testing Zebra:
- zebra-checkpoints
- zebrad-hash-lookup
- zebrad-log-filter
- zcash-rpc-diff
- scanning-results-reader
- openapi-generator
Binaries are easier to use if they are located in your system execution path.
zebra-checkpoints
This command generates a list of zebra checkpoints, and writes them to standard output. Each checkpoint consists of a block height and hash.
Automatic Checkpoint Generation in CI
Zebra's GitHub workflows automatically generate checkpoints after every main branch update.
These checkpoints can be copied into the main-checkpoints.txt and test-checkpoints.txt files.
To find the latest checkpoints on the main branch:
- Find the latest completed
Run Testsworkflow run onmain. Due to GitHub UI issues, some runs will show as waiting, cancelled, or failed, but the checkpoints have still been generated. - From the list on the left, go to the
Integration testsand find theRun checkpoints-mainnet test, then click in theResult of checkpoints-mainnetstep. - Scroll down until you see the list of checkpoints.
- Add those checkpoints to the end of
zebra-consensus/src/checkpoint/main-checkpoints.txt - Repeat steps 2 to 4 for
Generate checkpoints testnet - Open a pull request at https://github.com/ZcashFoundation/zebra/pulls
Manual Checkpoint Generation
To create checkpoints, you need a synchronized instance of zebrad or zcashd.
zebrad can be queried directly or via an installed zcash-cli RPC client.
zcashd must be queried via zcash-cli, which performs the correct RPC authentication.
Checkpoint Generation Setup
Make sure your zebrad or zcashd is listening for RPC requests,
and synced to the network tip.
If you are on a Debian system, zcash-cli can be installed as a package.
zebra-checkpoints is a standalone rust binary, you can compile it using:
Checkpoint Generation Commands
You can update the checkpoints using these commands:
| &
| &
When updating the lists there is no need to start from the genesis block. The program option
--last-checkpoint will let you specify at what block height you want to start. Usually, the
maintainers will copy the last height from each list, and start from there.
Other useful options are:
--transport direct: connect directly to azebradinstance--addr: supply a custom RPC address and port for the node-- -testnet: connect thezcash-clibinary to a testnet node instance
You can see all the zebra-checkpoints options using:
For more details about checkpoint lists, see the zebra-checkpoints README.
Checkpoint Generation for Testnet
To update the testnet checkpoints, zebra-checkpoints needs to connect to a testnet node.
To launch a testnet node, you can either:
- start
zebradwith azebrad.tomlwithnetwork.networkset toTestnet, or - run
zcashd -testnet.
Then use the commands above to regenerate the checkpoints.
Submit new checkpoints as pull request
- If you started from the last checkpoint in the current list, add the checkpoint list to the end of the existing checkpoint file. If you started from genesis, replace the entire file.
- Open a pull request with the updated Mainnet and Testnet lists at: https://github.com/ZcashFoundation/zebra/pulls
zebrad-hash-lookup
Given a block hash the script will get additional information using zcash-cli.
|
This program is commonly used as part of zebrad-log-filter where hashes will be captured from zebrad output.
zebrad-log-filter
The program is designed to filter the output from the zebra terminal or log file. Each time a hash is seen the script will capture it and get the additional information using zebrad-hash-lookup.
Assuming zebrad, zcash-cli, zebrad-hash-lookup and zebrad-log-filter are in your path the program can used as:
|
))) max_checkpoint_height=Height()
zcash-rpc-diff
This program compares zebrad and zcashd RPC responses.
Make sure you have zcashd and zebrad installed and synced.
The script:
- gets the
zebradandzcashdtip height and network - sends the RPC request to both of them using
zcash-cli - compares the responses using
diff - leaves the full responses in files in a temporary directory, so you can check them in detail
- if possible, compares different RPC methods for consistency
Assuming zebrad's RPC port is 28232, you should be able to run:
)
{
}
Sometimes zcashd will have extra fields (+) or different data (- and +).
And sometimes it will have the same data, but in a different order.
The script will warn you if the heights or networks are different, then display the results of querying the mismatched node states.
The script accepts any RPC, with any number of arguments. If a node doesn't implement an RPC, the script will exit with an error.
Configuration
The script uses the configured zcash-cli RPC port,
and the zebrad port supplied on the command-line.
It doesn't actually check what kind of node it is talking to,
so you can compare two zcashd or zebrad nodes if you want.
(Just edit the zcash.conf file used by zcash-cli, or edit the script.)
You can override the binaries the script calls using these environmental variables:
$ZCASH_CLI$DIFF$JQ
OpenAPI generator
This utility generates an openapi.yaml specification by extracting information from RPC method documentation in the zebra-rpc crate code.
Usage
To use the generator tool, build and run it with the following command:
cargo run --bin openapi-generator --features="openapi-generator"
This command will create or update an openapi.yaml file at the root of the Zebra project repository.
The latest specification generated using this utility can be found here.
Documentation standard
In order for the script to work, each RPC method documentation needs to follow a specific well-defined format. For example, here is the in-code documentation for the getblock method, which takes arguments:
/// Returns the requested block by hash or height, as a [`GetBlock`] JSON string.
/// If the block is not in Zebra's state, returns
/// [error code `-8`.](https://github.com/zcash/zcash/issues/5758)
///
/// zcashd reference: [`getblock`](https://zcash.github.io/rpc/getblock.html)
/// method: post
/// tags: blockchain
///
/// # Parameters
///
/// - `hash_or_height`: (string, required, example="1") The hash or height for the block to be returned.
/// - `verbosity`: (number, optional, default=1, example=1) 0 for hex encoded data, 1 for a json object, and 2 for json object with transaction data.
///
/// # Notes
///
/// With verbosity=1, [`lightwalletd` only reads the `tx` field of the
/// result](https://github.com/zcash/lightwalletd/blob/dfac02093d85fb31fb9a8475b884dd6abca966c7/common/common.go#L152),
/// and other clients only read the `hash` and `confirmations` fields,
/// so we only return a few fields for now.
///
/// `lightwalletd` and mining clients also do not use verbosity=2, so we don't support it.
;
An example of a method with no arguments can be the getinfo call:
/// Returns software information from the RPC server, as a [`GetInfo`] JSON struct.
///
/// zcashd reference: [`getinfo`](https://zcash.github.io/rpc/getinfo.html)
/// method: post
/// tags: control
///
/// # Notes
///
/// [The zcashd reference](https://zcash.github.io/rpc/getinfo.html) might not show some fields
/// in Zebra's [`GetInfo`]. Zebra uses the field names and formats from the
/// [zcashd code](https://github.com/zcash/zcash/blob/v4.6.0-1/src/rpc/misc.cpp#L86-L87).
///
/// Some fields from the zcashd reference are missing from Zebra's [`GetInfo`]. It only contains the fields
/// [required for lightwalletd support.](https://github.com/zcash/lightwalletd/blob/v0.4.9/common/common.go#L91-L95)
;
Find more examples inside the zebra-rpc/src/methods.rs and the zebra-rpc/src/methods/get_block_template_rpcs.rs files.
The generator will detect new methods added if they are members of the Rpc trait for the zebra-rpc/src/methods.rs file and inside the GetBlockTemplateRpc in the file zebra-rpc/src/methods/get_block_template_rpcs.rs.