From a1da018f1c055632d87032b32f3a692e8ba6d5a0 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 6 Dec 2022 06:13:09 +0000 Subject: [PATCH 1/5] zcash_primitives: Count Sapling padding in `Builder::build_zfuture` fees Closes zcash/librustzcash#709. --- zcash_primitives/CHANGELOG.md | 6 ++++++ zcash_primitives/src/transaction/builder.rs | 7 ++----- .../src/transaction/components/sapling/builder.rs | 13 +++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/zcash_primitives/CHANGELOG.md b/zcash_primitives/CHANGELOG.md index 1dab52deb..ad6d4817f 100644 --- a/zcash_primitives/CHANGELOG.md +++ b/zcash_primitives/CHANGELOG.md @@ -6,6 +6,12 @@ and this library adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- `zcash_primitives::transaction::builder`: + - `Builder::build` was calling `FeeRule::fee_required` with the number of + Sapling outputs that have been added to the builder. It now instead provides + the number of outputs that will be in the final Sapling bundle, including + any padding. ## [0.9.0] - 2022-11-12 ### Added diff --git a/zcash_primitives/src/transaction/builder.rs b/zcash_primitives/src/transaction/builder.rs index c24aa07fe..c4bd90a30 100644 --- a/zcash_primitives/src/transaction/builder.rs +++ b/zcash_primitives/src/transaction/builder.rs @@ -320,10 +320,7 @@ impl<'a, P: consensus::Parameters, R: RngCore> Builder<'a, P, R> { self.transparent_builder.inputs(), self.transparent_builder.outputs(), self.sapling_builder.inputs().len(), - match self.sapling_builder.inputs().len() { - 0 => self.sapling_builder.outputs().len(), - _ => (std::cmp::max(2, self.sapling_builder.outputs().len())), - }, + self.sapling_builder.bundle_output_count(), ) .map_err(Error::Fee)?; self.build_internal(prover, fee) @@ -346,7 +343,7 @@ impl<'a, P: consensus::Parameters, R: RngCore> Builder<'a, P, R> { self.transparent_builder.inputs(), self.transparent_builder.outputs(), self.sapling_builder.inputs().len(), - self.sapling_builder.outputs().len(), + self.sapling_builder.bundle_output_count(), self.tze_builder.inputs(), self.tze_builder.outputs(), ) diff --git a/zcash_primitives/src/transaction/components/sapling/builder.rs b/zcash_primitives/src/transaction/components/sapling/builder.rs index 60bf7a835..3a3c91608 100644 --- a/zcash_primitives/src/transaction/components/sapling/builder.rs +++ b/zcash_primitives/src/transaction/components/sapling/builder.rs @@ -256,6 +256,19 @@ impl

SaplingBuilder

{ &self.outputs } + /// Returns the number of outputs that will be present in the Sapling bundle built by + /// this builder. + /// + /// This may be larger than the number of outputs that have been added to the builder, + /// depending on whether padding is going to be applied. + pub(in crate::transaction) fn bundle_output_count(&self) -> usize { + // This matches the padding behaviour in `Self::build`. + match self.spends.len() { + 0 => self.outputs.len(), + _ => std::cmp::max(MIN_SHIELDED_OUTPUTS, self.outputs.len()), + } + } + /// Returns the net value represented by the spends and outputs added to this builder. pub fn value_balance(&self) -> Amount { self.value_balance From 4435c4789fa94b654deba758baa0282c83514fbf Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 6 Dec 2022 06:14:28 +0000 Subject: [PATCH 2/5] zcash_primitives 0.9.1 --- zcash_primitives/CHANGELOG.md | 2 ++ zcash_primitives/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/zcash_primitives/CHANGELOG.md b/zcash_primitives/CHANGELOG.md index ad6d4817f..c4e7280a2 100644 --- a/zcash_primitives/CHANGELOG.md +++ b/zcash_primitives/CHANGELOG.md @@ -6,6 +6,8 @@ and this library adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.9.1] - 2022-12-06 ### Fixed - `zcash_primitives::transaction::builder`: - `Builder::build` was calling `FeeRule::fee_required` with the number of diff --git a/zcash_primitives/Cargo.toml b/zcash_primitives/Cargo.toml index e551c0f96..e045a20ee 100644 --- a/zcash_primitives/Cargo.toml +++ b/zcash_primitives/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zcash_primitives" description = "Rust implementations of the Zcash primitives" -version = "0.9.0" +version = "0.9.1" authors = [ "Jack Grigg ", "Kris Nuttycombe " From 7e71cc5353542bc05424346ab8184ce417bfa834 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 6 Dec 2022 08:17:49 +0000 Subject: [PATCH 3/5] Add `tracing` spans to light client chain scanning This enables downstream users to profile how much time is spent in each of the main subcomponents of the current chain scanner. --- zcash_client_backend/CHANGELOG.md | 3 +++ zcash_client_backend/src/data_api/chain.rs | 1 + zcash_client_backend/src/welding_rig.rs | 2 ++ zcash_client_sqlite/CHANGELOG.md | 3 +++ zcash_client_sqlite/Cargo.toml | 3 +++ zcash_client_sqlite/src/lib.rs | 1 + 6 files changed, 13 insertions(+) diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index 469c8d55c..646056133 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -6,6 +6,9 @@ and this library adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `zcash_client_backend::data_api::chain::scan_cached_blocks` now generates + `tracing` spans, which can be used for profiling. ## [0.6.0] - 2022-11-12 ### Added diff --git a/zcash_client_backend/src/data_api/chain.rs b/zcash_client_backend/src/data_api/chain.rs index 401b2e9f9..70df26bf6 100644 --- a/zcash_client_backend/src/data_api/chain.rs +++ b/zcash_client_backend/src/data_api/chain.rs @@ -209,6 +209,7 @@ where /// /// Scanned blocks are required to be height-sequential. If a block is missing from the block /// source, an error will be returned with cause [`error::Cause::BlockHeightDiscontinuity`]. +#[tracing::instrument(skip(params, block_source, data_db))] #[allow(clippy::type_complexity)] pub fn scan_cached_blocks( params: &ParamsT, diff --git a/zcash_client_backend/src/welding_rig.rs b/zcash_client_backend/src/welding_rig.rs index f3cdf1083..932c35b2d 100644 --- a/zcash_client_backend/src/welding_rig.rs +++ b/zcash_client_backend/src/welding_rig.rs @@ -157,6 +157,7 @@ type TaggedBatch = Batch<(AccountId, S), SaplingDomain

, CompactOutputDe type TaggedBatchRunner = BatchRunner<(AccountId, S), SaplingDomain

, CompactOutputDescription, T>; +#[tracing::instrument(skip_all, fields(height = block.height))] pub(crate) fn add_block_to_runner( params: &P, block: CompactBlock, @@ -189,6 +190,7 @@ pub(crate) fn add_block_to_runner( } } +#[tracing::instrument(skip_all, fields(height = block.height))] pub(crate) fn scan_block_with_runner< P: consensus::Parameters + Send + 'static, K: ScanningKey, diff --git a/zcash_client_sqlite/CHANGELOG.md b/zcash_client_sqlite/CHANGELOG.md index 4821a4504..6bcaca573 100644 --- a/zcash_client_sqlite/CHANGELOG.md +++ b/zcash_client_sqlite/CHANGELOG.md @@ -6,6 +6,9 @@ and this library adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `zcash_client_sqlite::DataConnStmtCache::advance_by_block` now generates a + `tracing` span, which can be used for profiling. ## [0.4.0] - 2022-11-12 ### Added diff --git a/zcash_client_sqlite/Cargo.toml b/zcash_client_sqlite/Cargo.toml index 96077a005..9c744939a 100644 --- a/zcash_client_sqlite/Cargo.toml +++ b/zcash_client_sqlite/Cargo.toml @@ -23,6 +23,9 @@ zcash_primitives = { version = "0.9", path = "../zcash_primitives" } bs58 = { version = "0.4", features = ["check"] } hdwallet = { version = "0.3.1", optional = true } +# - Logging and metrics +tracing = "0.1" + # - Protobuf interfaces prost = "0.11" diff --git a/zcash_client_sqlite/src/lib.rs b/zcash_client_sqlite/src/lib.rs index e7a0ebebd..fec6daa71 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -517,6 +517,7 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> { } } + #[tracing::instrument(skip_all, fields(height = u32::from(block.block_height)))] #[allow(clippy::type_complexity)] fn advance_by_block( &mut self, From 1ea585fee9966f48308e106ee73dfae011c0b2bf Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 6 Dec 2022 08:18:34 +0000 Subject: [PATCH 4/5] zcash_client_backend 0.6.1 --- zcash_client_backend/CHANGELOG.md | 6 ++++++ zcash_client_backend/Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index 646056133..e6909948b 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -6,10 +6,16 @@ and this library adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.6.1] - 2022-12-06 ### Added - `zcash_client_backend::data_api::chain::scan_cached_blocks` now generates `tracing` spans, which can be used for profiling. +### Fixed +- `zcash_client_backend:zip321` no longer returns an error when trying to parse + a URI without query parameters. + ## [0.6.0] - 2022-11-12 ### Added - Functionality that enables the receiving and spending of transparent funds, diff --git a/zcash_client_backend/Cargo.toml b/zcash_client_backend/Cargo.toml index 52dfb42db..a965a3917 100644 --- a/zcash_client_backend/Cargo.toml +++ b/zcash_client_backend/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zcash_client_backend" description = "APIs for creating shielded Zcash light clients" -version = "0.6.0" +version = "0.6.1" authors = [ "Jack Grigg ", "Kris Nuttycombe " From 9d50c0726e859fc9490050cb179723dcde0f6c19 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 6 Dec 2022 08:19:14 +0000 Subject: [PATCH 5/5] zcash_client_sqlite 0.4.1 --- zcash_client_sqlite/CHANGELOG.md | 2 ++ zcash_client_sqlite/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/zcash_client_sqlite/CHANGELOG.md b/zcash_client_sqlite/CHANGELOG.md index 6bcaca573..5dae923f1 100644 --- a/zcash_client_sqlite/CHANGELOG.md +++ b/zcash_client_sqlite/CHANGELOG.md @@ -6,6 +6,8 @@ and this library adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.4.1] - 2022-12-06 ### Added - `zcash_client_sqlite::DataConnStmtCache::advance_by_block` now generates a `tracing` span, which can be used for profiling. diff --git a/zcash_client_sqlite/Cargo.toml b/zcash_client_sqlite/Cargo.toml index 9c744939a..b0a987ac8 100644 --- a/zcash_client_sqlite/Cargo.toml +++ b/zcash_client_sqlite/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zcash_client_sqlite" description = "An SQLite-based Zcash light client" -version = "0.4.0" +version = "0.4.1" authors = [ "Jack Grigg ", "Kris Nuttycombe "