Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scan): Start scanning task only if there are keys to scan #8059

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions zebrad/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ impl StartCmd {
let syncer_task_handle = tokio::spawn(syncer.sync().in_current_span());

#[cfg(feature = "shielded-scan")]
// Spawn never ending scan task.
let scan_task_handle = {
// Spawn never ending scan task only if we have keys to scan for.
let scan_task_handle = if !config.shielded_scan.sapling_keys_to_scan.is_empty() {
// TODO: log the number of keys and update the scan_task_starts() test
info!("spawning shielded scanner with configured viewing keys");
zebra_scan::spawn_init(
Expand All @@ -299,6 +299,8 @@ impl StartCmd {
state,
chain_tip_change,
)
} else {
tokio::spawn(std::future::pending().in_current_span())
};

#[cfg(not(feature = "shielded-scan"))]
Expand Down
23 changes: 17 additions & 6 deletions zebrad/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ pub const MAX_ASYNC_BLOCKING_TIME: Duration = zebra_test::mock_service::DEFAULT_
/// The test config file prefix for `--feature getblocktemplate-rpcs` configs.
pub const GET_BLOCK_TEMPLATE_CONFIG_PREFIX: &str = "getblocktemplate-";

/// The test config file prefix for `--feature shielded-scan` configs.
pub const SHIELDED_SCAN_CONFIG_PREFIX: &str = "shieldedscan-";

#[test]
fn generate_no_args() -> Result<()> {
let _init_guard = zebra_test::init();
Expand Down Expand Up @@ -806,18 +809,18 @@ fn last_config_is_stored() -> Result<()> {
zebrad generate | \n\
sed 's/cache_dir = \".*\"/cache_dir = \"cache_dir\"/' > \n\
zebrad/tests/common/configs/{}<next-release-tag>.toml",
if cfg!(feature = "getblocktemplate-rpcs") {
GET_BLOCK_TEMPLATE_CONFIG_PREFIX
if cfg!(feature = "shielded-scan") {
SHIELDED_SCAN_CONFIG_PREFIX
} else {
""
},
if cfg!(feature = "getblocktemplate-rpcs") {
"--features=getblocktemplate-rpcs "
if cfg!(feature = "shielded-scan") {
"--features=shielded-scan "
} else {
""
},
if cfg!(feature = "getblocktemplate-rpcs") {
GET_BLOCK_TEMPLATE_CONFIG_PREFIX
if cfg!(feature = "shielded-scan") {
SHIELDED_SCAN_CONFIG_PREFIX
} else {
""
},
Expand Down Expand Up @@ -946,6 +949,14 @@ fn stored_configs_work() -> Result<()> {
continue;
}

// ignore files starting with shieldedscan prefix
// if we were not built with the shielded-scan feature.
#[cfg(not(feature = "shielded-scan"))]
if config_file_name.starts_with(SHIELDED_SCAN_CONFIG_PREFIX) {
tracing::info!(?config_file_path, "skipping shielded-scan config file path");
continue;
}

let run_dir = testdir()?;
let stored_config_path = config_file_full_path(config_file.path());

Expand Down
20 changes: 20 additions & 0 deletions zebrad/tests/common/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ pub fn default_test_config(net: Network) -> Result<ZebradConfig> {
mining.miner_address = Some(miner_address.parse().expect("hard-coded address is valid"));
}

#[cfg(feature = "shielded_scan")]
{
let mut shielded_scan = zebra_scan::Config::default();
shielded_scan.ephemeral = true;

let config = ZebradConfig {
network,
state,
sync,
mempool,
consensus,
tracing,
mining,
shielded_scan,
..ZebradConfig::default()
};

return Ok(config);
}

let config = ZebradConfig {
network,
state,
Expand Down
80 changes: 80 additions & 0 deletions zebrad/tests/common/configs/shieldedscan-v1.5.0.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Default configuration for zebrad.
#
# This file can be used as a skeleton for custom configs.
#
# Unspecified fields use default values. Optional fields are Some(field) if the
# field is present and None if it is absent.
#
# This file is generated as an example using zebrad's current defaults.
# You should set only the config options you want to keep, and delete the rest.
# Only a subset of fields are present in the skeleton, since optional values
# whose default is None are omitted.
#
# The config format (including a complete list of sections and fields) is
# documented here:
# https://docs.rs/zebrad/latest/zebrad/config/struct.ZebradConfig.html
#
# zebrad attempts to load configs in the following order:
#
# 1. The -c flag on the command line, e.g., `zebrad -c myconfig.toml start`;
# 2. The file `zebrad.toml` in the users's preference directory (platform-dependent);
# 3. The default config.

[consensus]
checkpoint_sync = true

[mempool]
eviction_memory_time = "1h"
tx_cost_limit = 80000000

[metrics]

[mining]
debug_like_zcashd = true

[network]
cache_dir = true
crawl_new_peer_interval = "1m 1s"
initial_mainnet_peers = [
"dnsseed.z.cash:8233",
"dnsseed.str4d.xyz:8233",
"mainnet.seeder.zfnd.org:8233",
"mainnet.is.yolo.money:8233",
]
initial_testnet_peers = [
"dnsseed.testnet.z.cash:18233",
"testnet.seeder.zfnd.org:18233",
"testnet.is.yolo.money:18233",
]
listen_addr = "0.0.0.0:8233"
max_connections_per_ip = 1
network = "Mainnet"
peerset_initial_target_size = 25

[rpc]
debug_force_finished_sync = false
parallel_cpu_threads = 0

[shielded_scan]
cache_dir = "cache_dir"
delete_old_database = true
ephemeral = false

[shielded_scan.sapling_keys_to_scan]

[state]
cache_dir = "cache_dir"
delete_old_database = true
ephemeral = false

[sync]
checkpoint_verify_concurrency_limit = 1000
download_concurrency_limit = 50
full_verify_concurrency_limit = 20
parallel_cpu_threads = 0

[tracing]
buffer_limit = 128000
force_use_color = false
use_color = true
use_journald = false
Loading