Skip to content

Commit

Permalink
Factor out minor internal code duplication in progress computation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Oct 9, 2024
1 parent 44bf309 commit d89c09e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
1 change: 0 additions & 1 deletion zcash_client_backend/src/data_api/testing/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,6 @@ pub fn spend_fails_on_unverified_notes<T: ShieldedPoolTester>(
// 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!(
Expand Down
33 changes: 17 additions & 16 deletions zcash_client_sqlite/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,17 +836,29 @@ 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<P: consensus::Parameters>(
conn: &rusqlite::Connection,
params: &P,
shielded_protocol: ShieldedProtocol,
pool_activation_height: BlockHeight,
chain_tip_height: BlockHeight,
) -> Result<Option<u64>, 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.
Expand Down Expand Up @@ -1002,18 +1014,7 @@ fn subtree_scan_progress<P: consensus::Parameters>(
fully_scanned_height: BlockHeight,
chain_tip_height: BlockHeight,
) -> Result<Progress, SqliteClientError> {
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})
Expand Down

0 comments on commit d89c09e

Please sign in to comment.