diff --git a/zebra-chain/src/parameters/network.rs b/zebra-chain/src/parameters/network.rs index c90ce860798..753e8230dbf 100644 --- a/zebra-chain/src/parameters/network.rs +++ b/zebra-chain/src/parameters/network.rs @@ -129,6 +129,19 @@ impl Network { pub fn is_a_test_network(&self) -> bool { *self != Network::Mainnet } + + /// Returns the minimum Sapling birthday height. + pub fn sapling_activation_height(self) -> Height { + // Assume that the genesis block never contains shielded inputs or outputs. + // + // # Consensus + // + // For Zcash mainnet and the public testnet, Sapling activates above genesis, + // so this is always true. + super::NetworkUpgrade::Sapling + .activation_height(self) + .expect("Sapling activation height needs to be set") + } } impl FromStr for Network { diff --git a/zebra-scan/src/service.rs b/zebra-scan/src/service.rs index 3dee20f787d..4f86c108929 100644 --- a/zebra-scan/src/service.rs +++ b/zebra-scan/src/service.rs @@ -86,7 +86,7 @@ impl Service for ScanService { return async move { Ok(Response::Info { - min_sapling_birthday_height: db.min_sapling_birthday_height(), + min_sapling_birthday_height: db.network().sapling_activation_height(), }) } .boxed(); diff --git a/zebra-scan/src/service/scan_task/commands.rs b/zebra-scan/src/service/scan_task/commands.rs index 58d9bd88d7e..6ce10015a5e 100644 --- a/zebra-scan/src/service/scan_task/commands.rs +++ b/zebra-scan/src/service/scan_task/commands.rs @@ -12,7 +12,7 @@ use color_eyre::{eyre::eyre, Report}; use tokio::sync::oneshot; use zcash_primitives::{sapling::SaplingIvk, zip32::DiversifiableFullViewingKey}; -use zebra_chain::{block::Height, transaction::Transaction}; +use zebra_chain::{block::Height, parameters::Network, transaction::Transaction}; use zebra_state::SaplingScanningKey; use super::ScanTask; @@ -61,11 +61,13 @@ impl ScanTask { SaplingScanningKey, (Vec, Vec), >, + network: Network, ) -> Result< HashMap, Vec, Height)>, Report, > { let mut new_keys = HashMap::new(); + let sapling_activation_height = network.sapling_activation_height(); loop { let cmd = match cmd_receiver.try_recv() { diff --git a/zebra-scan/src/service/scan_task/scan.rs b/zebra-scan/src/service/scan_task/scan.rs index 9af1e3ef97d..9654735960e 100644 --- a/zebra-scan/src/service/scan_task/scan.rs +++ b/zebra-scan/src/service/scan_task/scan.rs @@ -76,7 +76,7 @@ pub async fn start( cmd_receiver: Receiver, ) -> Result<(), Report> { let network = storage.network(); - let sapling_activation_height = storage.min_sapling_birthday_height(); + let sapling_activation_height = network.sapling_activation_height(); // Do not scan and notify if we are below sapling activation height. wait_for_height( @@ -126,7 +126,7 @@ pub async fn start( } } - let new_keys = ScanTask::process_messages(&cmd_receiver, &mut parsed_keys)?; + let new_keys = ScanTask::process_messages(&cmd_receiver, &mut parsed_keys, network)?; // TODO: Check if the `start_height` is at or above the current height if !new_keys.is_empty() { diff --git a/zebra-scan/src/service/scan_task/scan/scan_range.rs b/zebra-scan/src/service/scan_task/scan/scan_range.rs index 4e16d4ccdf1..8d5f6c025e9 100644 --- a/zebra-scan/src/service/scan_task/scan/scan_range.rs +++ b/zebra-scan/src/service/scan_task/scan/scan_range.rs @@ -71,7 +71,7 @@ pub async fn scan_range( state: State, storage: Storage, ) -> Result<(), BoxError> { - let sapling_activation_height = storage.min_sapling_birthday_height(); + let sapling_activation_height = storage.network().sapling_activation_height(); // Do not scan and notify if we are below sapling activation height. wait_for_height( sapling_activation_height, diff --git a/zebra-scan/src/storage.rs b/zebra-scan/src/storage.rs index 61a51a29d3e..2372957014e 100644 --- a/zebra-scan/src/storage.rs +++ b/zebra-scan/src/storage.rs @@ -2,10 +2,7 @@ use std::collections::{BTreeMap, HashMap}; -use zebra_chain::{ - block::Height, - parameters::{Network, NetworkUpgrade}, -}; +use zebra_chain::{block::Height, parameters::Network}; use zebra_state::TransactionIndex; use crate::config::Config; @@ -126,19 +123,4 @@ impl Storage { ) -> BTreeMap> { self.sapling_results_for_key(sapling_key) } - - // Parameters - - /// Returns the minimum sapling birthday height for the configured network. - pub fn min_sapling_birthday_height(&self) -> Height { - // Assume that the genesis block never contains shielded inputs or outputs. - // - // # Consensus - // - // For Zcash mainnet and the public testnet, Sapling activates above genesis, - // so this is always true. - NetworkUpgrade::Sapling - .activation_height(self.network()) - .unwrap_or(Height(0)) - } } diff --git a/zebra-scan/src/storage/db/sapling.rs b/zebra-scan/src/storage/db/sapling.rs index 8ad0fcce72b..6892fc30af9 100644 --- a/zebra-scan/src/storage/db/sapling.rs +++ b/zebra-scan/src/storage/db/sapling.rs @@ -213,7 +213,7 @@ impl Storage { sapling_key: &SaplingScanningKey, birthday_height: Option, ) { - let min_birthday_height = self.min_sapling_birthday_height(); + let min_birthday_height = self.network().sapling_activation_height(); // The birthday height must be at least the minimum height for that pool. let birthday_height = birthday_height