From 8db7a071a0b79687d79ffc6894fe573944b16008 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 26 Apr 2023 15:33:48 +0000 Subject: [PATCH] zcash_primitives: `impl DynamicUsage for sapling::Bundle` --- zcash_primitives/CHANGELOG.md | 4 +++ .../src/transaction/components/sapling.rs | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/zcash_primitives/CHANGELOG.md b/zcash_primitives/CHANGELOG.md index dbc7d8fe1..001a41fc5 100644 --- a/zcash_primitives/CHANGELOG.md +++ b/zcash_primitives/CHANGELOG.md @@ -10,6 +10,10 @@ and this library adheres to Rust's notion of - `zcash_primitives::transaction`: - `Transaction::temporary_zcashd_read_v5_sapling` - `Transaction::temporary_zcashd_write_v5_sapling` +- Implementations of `memuse::DynamicUsage` for the following types: + - `zcash_primitives::transaction::components::sapling`: + - `Bundle` + - `SpendDescription` ### Changed - Bumped dependencies to `secp256k1 0.26`, `hdwallet 0.4`. diff --git a/zcash_primitives/src/transaction/components/sapling.rs b/zcash_primitives/src/transaction/components/sapling.rs index dc1b66380..149bfdbd4 100644 --- a/zcash_primitives/src/transaction/components/sapling.rs +++ b/zcash_primitives/src/transaction/components/sapling.rs @@ -192,6 +192,24 @@ impl Bundle { } } +impl DynamicUsage for Bundle { + fn dynamic_usage(&self) -> usize { + self.shielded_spends.dynamic_usage() + self.shielded_outputs.dynamic_usage() + } + + fn dynamic_usage_bounds(&self) -> (usize, Option) { + let bounds = ( + self.shielded_spends.dynamic_usage_bounds(), + self.shielded_outputs.dynamic_usage_bounds(), + ); + + ( + bounds.0 .0 + bounds.1 .0, + bounds.0 .1.zip(bounds.1 .1).map(|(a, b)| a + b), + ) + } +} + #[derive(Clone)] pub struct SpendDescription { cv: ValueCommitment, @@ -263,6 +281,16 @@ impl SpendDescription { } } +impl DynamicUsage for SpendDescription { + fn dynamic_usage(&self) -> usize { + self.zkproof.dynamic_usage() + } + + fn dynamic_usage_bounds(&self) -> (usize, Option) { + self.zkproof.dynamic_usage_bounds() + } +} + /// Consensus rules (§4.4) & (§4.5): /// - Canonical encoding is enforced here. /// - "Not small order" is enforced here.