From d89c09ecfc2946d1af2107078157f91cb845c973 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Tue, 8 Oct 2024 18:33:50 -0600 Subject: [PATCH] Factor out minor internal code duplication in progress computation. --- .../src/data_api/testing/pool.rs | 1 - zcash_client_sqlite/src/wallet.rs | 33 ++++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/zcash_client_backend/src/data_api/testing/pool.rs b/zcash_client_backend/src/data_api/testing/pool.rs index bcda45dcca..3bf8715640 100644 --- a/zcash_client_backend/src/data_api/testing/pool.rs +++ b/zcash_client_backend/src/data_api/testing/pool.rs @@ -886,7 +886,6 @@ pub fn spend_fails_on_unverified_notes( // resulting ratio (the number of notes in the recovery range) is zero. let no_recovery = Some(Ratio::new(0, 0)); - // Wallet is fully scanned let summary = st.get_wallet_summary(1); assert_eq!( diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index 9e0db4e8fc..81879ce7c0 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -836,6 +836,21 @@ pub(crate) trait ScanProgress { #[derive(Debug)] pub(crate) struct SubtreeScanProgress; +fn table_constants(shielded_protocol: ShieldedProtocol) -> (&'static str, &'static str, u8) { + match shielded_protocol { + ShieldedProtocol::Sapling => ( + SAPLING_TABLES_PREFIX, + "sapling_output_count", + SAPLING_SHARD_HEIGHT, + ), + ShieldedProtocol::Orchard => ( + ORCHARD_TABLES_PREFIX, + "orchard_action_count", + ORCHARD_SHARD_HEIGHT, + ), + } +} + fn estimate_tree_size( conn: &rusqlite::Connection, params: &P, @@ -843,10 +858,7 @@ fn estimate_tree_size( pool_activation_height: BlockHeight, chain_tip_height: BlockHeight, ) -> Result, SqliteClientError> { - let (table_prefix, shard_height) = match shielded_protocol { - ShieldedProtocol::Sapling => (SAPLING_TABLES_PREFIX, SAPLING_SHARD_HEIGHT), - ShieldedProtocol::Orchard => (ORCHARD_TABLES_PREFIX, ORCHARD_SHARD_HEIGHT), - }; + let (table_prefix, _, shard_height) = table_constants(shielded_protocol); // Estimate the size of the tree by linear extrapolation from available // data closest to the chain tip. @@ -1002,18 +1014,7 @@ fn subtree_scan_progress( fully_scanned_height: BlockHeight, chain_tip_height: BlockHeight, ) -> Result { - let (table_prefix, output_count_col, shard_height) = match shielded_protocol { - ShieldedProtocol::Sapling => ( - SAPLING_TABLES_PREFIX, - "sapling_output_count", - SAPLING_SHARD_HEIGHT, - ), - ShieldedProtocol::Orchard => ( - ORCHARD_TABLES_PREFIX, - "orchard_action_count", - ORCHARD_SHARD_HEIGHT, - ), - }; + let (table_prefix, output_count_col, shard_height) = table_constants(shielded_protocol); let mut stmt_scanned_count_until = conn.prepare_cached(&format!( "SELECT SUM({output_count_col})