From 3311f072d400a772a0354c8743470dc2260bd968 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 12 Jan 2023 17:26:30 +1000 Subject: [PATCH 1/2] Remove unused zebra-utils dependencies --- Cargo.lock | 4 +-- zebra-consensus/Cargo.toml | 19 ++++++++--- zebra-consensus/src/checkpoint.rs | 34 +++++++------------ zebra-consensus/src/checkpoint/tests.rs | 8 ++--- zebra-node-services/src/constants.rs | 20 +++++++++++ zebra-node-services/src/lib.rs | 1 + zebra-utils/Cargo.toml | 3 +- zebra-utils/src/bin/zebra-checkpoints/main.rs | 18 +++++----- 8 files changed, 62 insertions(+), 45 deletions(-) create mode 100644 zebra-node-services/src/constants.rs diff --git a/Cargo.lock b/Cargo.lock index 99ceea840a4..3a169795fb8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5460,6 +5460,7 @@ dependencies = [ "tracing-subscriber 0.3.16", "zcash_proofs", "zebra-chain", + "zebra-node-services", "zebra-script", "zebra-state", "zebra-test", @@ -5631,8 +5632,7 @@ dependencies = [ "tracing-error", "tracing-subscriber 0.3.16", "zebra-chain", - "zebra-consensus", - "zebra-state", + "zebra-node-services", ] [[package]] diff --git a/zebra-consensus/Cargo.toml b/zebra-consensus/Cargo.toml index 2a60bddef0d..1f050003e67 100644 --- a/zebra-consensus/Cargo.toml +++ b/zebra-consensus/Cargo.toml @@ -7,10 +7,17 @@ edition = "2021" [features] default = [] + +# Production features that activate extra dependencies, or extra features in dependencies + +# Experimental mining RPC support getblocktemplate-rpcs = [ - "zebra-state/getblocktemplate-rpcs", - "zebra-chain/getblocktemplate-rpcs", + "zebra-state/getblocktemplate-rpcs", + "zebra-node-services/getblocktemplate-rpcs", + "zebra-chain/getblocktemplate-rpcs", ] + +# Test-only features proptest-impl = ["proptest", "proptest-derive", "zebra-chain/proptest-impl", "zebra-state/proptest-impl"] [dependencies] @@ -45,10 +52,12 @@ zcash_proofs = { version = "0.9.0", features = ["local-prover", "multicore", "do tower-fallback = { path = "../tower-fallback/" } tower-batch = { path = "../tower-batch/" } -zebra-chain = { path = "../zebra-chain" } -zebra-state = { path = "../zebra-state" } zebra-script = { path = "../zebra-script" } +zebra-state = { path = "../zebra-state" } +zebra-node-services = { path = "../zebra-node-services" } +zebra-chain = { path = "../zebra-chain" } +# Test-only dependencies proptest = { version = "0.10.1", optional = true } proptest-derive = { version = "0.3.0", optional = true } @@ -67,6 +76,6 @@ tokio = { version = "1.24.1", features = ["full", "tracing", "test-util"] } tracing-error = "0.2.0" tracing-subscriber = "0.3.16" -zebra-chain = { path = "../zebra-chain", features = ["proptest-impl"] } zebra-state = { path = "../zebra-state", features = ["proptest-impl"] } +zebra-chain = { path = "../zebra-chain", features = ["proptest-impl"] } zebra-test = { path = "../zebra-test/" } diff --git a/zebra-consensus/src/checkpoint.rs b/zebra-consensus/src/checkpoint.rs index 155065e99e8..7681f3e16da 100644 --- a/zebra-consensus/src/checkpoint.rs +++ b/zebra-consensus/src/checkpoint.rs @@ -34,7 +34,16 @@ use zebra_chain::{ }; use zebra_state::{self as zs, FinalizedBlock}; -use crate::{block::VerifyBlockError, error::BlockError, BoxError}; +use crate::{ + block::VerifyBlockError, + checkpoint::types::{ + Progress, + Progress::*, + TargetHeight::{self, *}, + }, + error::BlockError, + BoxError, +}; pub(crate) mod list; mod types; @@ -42,9 +51,9 @@ mod types; #[cfg(test)] mod tests; +pub use zebra_node_services::constants::{MAX_CHECKPOINT_BYTE_COUNT, MAX_CHECKPOINT_HEIGHT_GAP}; + pub use list::CheckpointList; -use types::{Progress, Progress::*}; -use types::{TargetHeight, TargetHeight::*}; /// An unverified block, which is in the queue for checkpoint verification. #[derive(Debug)] @@ -84,25 +93,6 @@ type QueuedBlockList = Vec; /// usage by committing blocks to the disk state. (Or dropping invalid blocks.) pub const MAX_QUEUED_BLOCKS_PER_HEIGHT: usize = 4; -/// We limit the maximum number of blocks in each checkpoint. Each block uses a -/// constant amount of memory for the supporting data structures and futures. -/// -/// We choose a checkpoint gap that allows us to verify one checkpoint for -/// every `ObtainTips` or `ExtendTips` response. -/// -/// `zcashd`'s maximum `FindBlocks` response size is 500 hashes. `zebrad` uses -/// 1 hash to verify the tip, and discards 1-2 hashes to work around `zcashd` -/// bugs. So the most efficient gap is slightly less than 500 blocks. -pub const MAX_CHECKPOINT_HEIGHT_GAP: usize = 400; - -/// We limit the memory usage and download contention for each checkpoint, -/// based on the cumulative size of the serialized blocks in the chain. -/// -/// Deserialized blocks (in memory) are slightly larger than serialized blocks -/// (on the network or disk). But they should be within a constant factor of the -/// serialized size. -pub const MAX_CHECKPOINT_BYTE_COUNT: u64 = 32 * 1024 * 1024; - /// Convert a tip into its hash and matching progress. fn progress_from_tip( checkpoint_list: &CheckpointList, diff --git a/zebra-consensus/src/checkpoint/tests.rs b/zebra-consensus/src/checkpoint/tests.rs index 9a419af9f15..85fe894951e 100644 --- a/zebra-consensus/src/checkpoint/tests.rs +++ b/zebra-consensus/src/checkpoint/tests.rs @@ -11,13 +11,9 @@ use tokio::time::timeout; use tower::{Service, ServiceExt}; use tracing_futures::Instrument; -use zebra_chain::parameters::Network::*; -use zebra_chain::serialization::ZcashDeserialize; +use zebra_chain::{parameters::Network::*, serialization::ZcashDeserialize}; -use super::{ - types::{Progress::*, TargetHeight::*}, - *, -}; +use super::*; /// The timeout we apply to each verify future during testing. /// diff --git a/zebra-node-services/src/constants.rs b/zebra-node-services/src/constants.rs new file mode 100644 index 00000000000..da8fd89909d --- /dev/null +++ b/zebra-node-services/src/constants.rs @@ -0,0 +1,20 @@ +//! Constants shared by some Zebra node services. + +/// We limit the maximum number of blocks in each checkpoint. Each block uses a +/// constant amount of memory for the supporting data structures and futures. +/// +/// We choose a checkpoint gap that allows us to verify one checkpoint for +/// every `ObtainTips` or `ExtendTips` response. +/// +/// `zcashd`'s maximum `FindBlocks` response size is 500 hashes. `zebrad` uses +/// 1 hash to verify the tip, and discards 1-2 hashes to work around `zcashd` +/// bugs. So the most efficient gap is slightly less than 500 blocks. +pub const MAX_CHECKPOINT_HEIGHT_GAP: usize = 400; + +/// We limit the memory usage and download contention for each checkpoint, +/// based on the cumulative size of the serialized blocks in the chain. +/// +/// Deserialized blocks (in memory) are slightly larger than serialized blocks +/// (on the network or disk). But they should be within a constant factor of the +/// serialized size. +pub const MAX_CHECKPOINT_BYTE_COUNT: u64 = 32 * 1024 * 1024; diff --git a/zebra-node-services/src/lib.rs b/zebra-node-services/src/lib.rs index b113e1fca9e..a72b7e23c69 100644 --- a/zebra-node-services/src/lib.rs +++ b/zebra-node-services/src/lib.rs @@ -1,5 +1,6 @@ //! The interfaces of some Zebra node services. +pub mod constants; pub mod mempool; /// Error type alias to make working with tower traits easier. diff --git a/zebra-utils/Cargo.toml b/zebra-utils/Cargo.toml index ca25ac7ba1b..24379486deb 100644 --- a/zebra-utils/Cargo.toml +++ b/zebra-utils/Cargo.toml @@ -19,6 +19,5 @@ serde_json = "1.0.91" tracing-error = "0.2.0" tracing-subscriber = "0.3.16" +zebra-node-services = { path = "../zebra-node-services" } zebra-chain = { path = "../zebra-chain" } -zebra-consensus = { path = "../zebra-consensus" } -zebra-state = { path = "../zebra-state" } diff --git a/zebra-utils/src/bin/zebra-checkpoints/main.rs b/zebra-utils/src/bin/zebra-checkpoints/main.rs index ce9dd27d517..08d14c8ad9d 100644 --- a/zebra-utils/src/bin/zebra-checkpoints/main.rs +++ b/zebra-utils/src/bin/zebra-checkpoints/main.rs @@ -8,17 +8,19 @@ //! zebra-consensus accepts an ordered list of checkpoints, starting with the //! genesis block. Checkpoint heights can be chosen arbitrarily. +use std::process::Stdio; + +#[cfg(unix)] +use std::os::unix::process::ExitStatusExt; + use color_eyre::eyre::{ensure, Result}; use serde_json::Value; -use std::process::Stdio; use structopt::StructOpt; -use zebra_chain::block; +use zebra_chain::{block, transparent::MIN_TRANSPARENT_COINBASE_MATURITY}; +use zebra_node_services::constants::{MAX_CHECKPOINT_BYTE_COUNT, MAX_CHECKPOINT_HEIGHT_GAP}; use zebra_utils::init_tracing; -#[cfg(unix)] -use std::os::unix::process::ExitStatusExt; - mod args; /// Return a new `zcash-cli` command, including the `zebra-checkpoints` @@ -74,7 +76,7 @@ fn main() -> Result<()> { // Zcash reorg limit. let height_limit = height_limit .0 - .checked_sub(zebra_state::MAX_BLOCK_REORG_HEIGHT) + .checked_sub(MIN_TRANSPARENT_COINBASE_MATURITY) .map(block::Height) .expect("zcashd has some mature blocks: wait for zcashd to sync more blocks"); @@ -120,8 +122,8 @@ fn main() -> Result<()> { // check if checkpoint if height == block::Height(0) - || cumulative_bytes >= zebra_consensus::MAX_CHECKPOINT_BYTE_COUNT - || height_gap.0 >= zebra_consensus::MAX_CHECKPOINT_HEIGHT_GAP as u32 + || cumulative_bytes >= MAX_CHECKPOINT_BYTE_COUNT + || height_gap.0 >= MAX_CHECKPOINT_HEIGHT_GAP as u32 { // print to output println!("{} {hash}", height.0); From 3c6bf930a88f6aafa389ad5e08976769eb6c118d Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 13 Jan 2023 09:01:52 +1000 Subject: [PATCH 2/2] Cleanup zebra-checkpoints --- zebra-utils/src/bin/zebra-checkpoints/args.rs | 5 +---- zebra-utils/src/bin/zebra-checkpoints/main.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/zebra-utils/src/bin/zebra-checkpoints/args.rs b/zebra-utils/src/bin/zebra-checkpoints/args.rs index 283b5f557a5..7af67a8c754 100644 --- a/zebra-utils/src/bin/zebra-checkpoints/args.rs +++ b/zebra-utils/src/bin/zebra-checkpoints/args.rs @@ -2,13 +2,10 @@ //! //! For usage please refer to the program help: `zebra-checkpoints --help` -#![deny(missing_docs)] -#![allow(clippy::try_err)] - use structopt::StructOpt; /// zebra-checkpoints arguments -#[derive(Debug, StructOpt)] +#[derive(Clone, Debug, Eq, PartialEq, StructOpt)] pub struct Args { /// Path to zcash-cli command #[structopt(default_value = "zcash-cli", short, long)] diff --git a/zebra-utils/src/bin/zebra-checkpoints/main.rs b/zebra-utils/src/bin/zebra-checkpoints/main.rs index 08d14c8ad9d..f15043e449b 100644 --- a/zebra-utils/src/bin/zebra-checkpoints/main.rs +++ b/zebra-utils/src/bin/zebra-checkpoints/main.rs @@ -62,8 +62,8 @@ fn cmd_output(cmd: &mut std::process::Command) -> Result { #[allow(clippy::print_stdout)] fn main() -> Result<()> { + // initialise init_tracing(); - color_eyre::install()?; // get the current block count