From a22c8d5f425996b7ad80e0ce6103583514878fd9 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 15 Nov 2023 22:32:22 -0300 Subject: [PATCH] feat(config): Allow to add keys to be scanned by the zebra-scan crate to config (#7949) * allow user to add sapling keys to config * apply code review suggestions Co-authored-by: teor --------- Co-authored-by: teor --- Cargo.lock | 3 +++ zebra-scan/Cargo.toml | 3 +++ zebra-scan/src/config.rs | 23 +++++++++++++++++++++++ zebra-scan/src/lib.rs | 1 + zebrad/Cargo.toml | 6 ++++++ zebrad/src/config.rs | 4 ++++ 6 files changed, 40 insertions(+) create mode 100644 zebra-scan/src/config.rs diff --git a/Cargo.lock b/Cargo.lock index 628af7eb..413174c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5780,8 +5780,10 @@ dependencies = [ "color-eyre", "ff", "group", + "indexmap 2.1.0", "jubjub", "rand 0.8.5", + "serde", "tokio", "zcash_client_backend", "zcash_note_encryption", @@ -5959,6 +5961,7 @@ dependencies = [ "zebra-network", "zebra-node-services", "zebra-rpc", + "zebra-scan", "zebra-state", "zebra-test", "zebra-utils", diff --git a/zebra-scan/Cargo.toml b/zebra-scan/Cargo.toml index cb1cbd77..2c3f2ba5 100644 --- a/zebra-scan/Cargo.toml +++ b/zebra-scan/Cargo.toml @@ -21,6 +21,9 @@ categories = ["cryptography::cryptocurrencies"] [dependencies] zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.31" } +indexmap = { version = "2.0.1", features = ["serde"] } +serde = { version = "1.0.192", features = ["serde_derive"] } + [dev-dependencies] zcash_client_backend = "0.10.0-rc.1" diff --git a/zebra-scan/src/config.rs b/zebra-scan/src/config.rs new file mode 100644 index 00000000..b460a253 --- /dev/null +++ b/zebra-scan/src/config.rs @@ -0,0 +1,23 @@ +//! Configuration for blockchain scanning tasks. + +use indexmap::IndexMap; +use serde::{Deserialize, Serialize}; + +use crate::storage::SaplingScanningKey; + +#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)] +#[serde(deny_unknown_fields, default)] +/// Configuration for scanning. +pub struct Config { + /// The sapling keys to scan for and the birthday height of each of them. + // TODO: any value below sapling activation as the birthday height should default to sapling activation. + pub sapling_keys_to_scan: IndexMap, +} + +impl Default for Config { + fn default() -> Self { + Self { + sapling_keys_to_scan: IndexMap::new(), + } + } +} diff --git a/zebra-scan/src/lib.rs b/zebra-scan/src/lib.rs index b469bb7d..a71810f9 100644 --- a/zebra-scan/src/lib.rs +++ b/zebra-scan/src/lib.rs @@ -4,6 +4,7 @@ #![doc(html_logo_url = "https://zfnd.org/wp-content/uploads/2022/03/zebra-icon.png")] #![doc(html_root_url = "https://docs.rs/zebra_scan")] +pub mod config; mod storage; #[cfg(test)] diff --git a/zebrad/Cargo.toml b/zebrad/Cargo.toml index 04ccc293..df89a0f8 100644 --- a/zebrad/Cargo.toml +++ b/zebrad/Cargo.toml @@ -68,6 +68,9 @@ getblocktemplate-rpcs = [ "zebra-chain/getblocktemplate-rpcs", ] +# Experimental shielded blockchain scanning +shielded-scan = ["zebra-scan"] + # Experimental elasticsearch indexing elasticsearch = [ "zebra-state/elasticsearch", @@ -152,6 +155,9 @@ zebra-node-services = { path = "../zebra-node-services", version = "1.0.0-beta.3 zebra-rpc = { path = "../zebra-rpc", version = "1.0.0-beta.31" } zebra-state = { path = "../zebra-state", version = "1.0.0-beta.31" } +# Experimental shielded-scan feature +zebra-scan = { path = "../zebra-scan", version = "0.1.0-alpha.0", optional = true } + # Required for crates.io publishing, but it's only used in tests zebra-utils = { path = "../zebra-utils", version = "1.0.0-beta.31", optional = true } diff --git a/zebrad/src/config.rs b/zebrad/src/config.rs index cb10e403..175ed8b8 100644 --- a/zebrad/src/config.rs +++ b/zebrad/src/config.rs @@ -43,4 +43,8 @@ pub struct ZebradConfig { #[serde(skip_serializing_if = "zebra_rpc::config::mining::Config::skip_getblocktemplate")] /// Mining configuration pub mining: zebra_rpc::config::mining::Config, + + #[cfg(feature = "zebra-scan")] + /// Scanner configuration + pub shielded_scan: zebra_scan::config::Config, }