From 3bb5a9eed55812336e0af98b0902297f371c8f7a Mon Sep 17 00:00:00 2001 From: Arya Date: Thu, 20 Jun 2024 12:49:35 -0400 Subject: [PATCH] use sync task --- Cargo.lock | 1 + zebra-scan/Cargo.toml | 1 + zebra-scan/src/bin/scanner/main.rs | 43 +++++++++++++++++------------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b5e6dc23964..909cd4d0d2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6055,6 +6055,7 @@ dependencies = [ "zebra-chain", "zebra-grpc", "zebra-node-services", + "zebra-rpc", "zebra-state", "zebra-test", ] diff --git a/zebra-scan/Cargo.toml b/zebra-scan/Cargo.toml index faf65603c95..3fe51a8a3a7 100644 --- a/zebra-scan/Cargo.toml +++ b/zebra-scan/Cargo.toml @@ -68,6 +68,7 @@ zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.37", features = [ zebra-state = { path = "../zebra-state", version = "1.0.0-beta.37", features = ["shielded-scan"] } zebra-node-services = { path = "../zebra-node-services", version = "1.0.0-beta.37", features = ["shielded-scan"] } zebra-grpc = { path = "../zebra-grpc", version = "0.1.0-alpha.4" } +zebra-rpc = { path = "../zebra-rpc", version = "1.0.0-beta.37" } chrono = { version = "0.4.38", default-features = false, features = ["clock", "std", "serde"] } diff --git a/zebra-scan/src/bin/scanner/main.rs b/zebra-scan/src/bin/scanner/main.rs index 42b0328a98b..38b2f2a76fc 100644 --- a/zebra-scan/src/bin/scanner/main.rs +++ b/zebra-scan/src/bin/scanner/main.rs @@ -1,12 +1,13 @@ //! The zebra-scanner binary. //! //! The zebra-scanner binary is a standalone binary that scans the Zcash blockchain for transactions using the given sapling keys. +use color_eyre::eyre::eyre; use lazy_static::lazy_static; use structopt::StructOpt; use tracing::*; use zebra_chain::{block::Height, parameters::Network}; -use zebra_state::{ChainTipSender, SaplingScanningKey}; +use zebra_state::SaplingScanningKey; use core::net::SocketAddr; use std::path::PathBuf; @@ -67,17 +68,14 @@ async fn main() -> Result<(), Box> { }; // Get a read-only state and the database. - let (read_state, db, _) = zebra_state::init_read_only(state_config, &network); - - // Get the initial tip block from the database. - let initial_tip = db - .tip_block() - .map(zebra_state::CheckpointVerifiedBlock::from) - .map(zebra_state::ChainTipBlock::from); - - // Create a chain tip sender and use it to get a chain tip change. - let (_chain_tip_sender, _latest_chain_tip, chain_tip_change) = - ChainTipSender::new(initial_tip, &network); + let (read_state, _latest_chain_tip, chain_tip_change, sync_task) = + zebra_rpc::sync::init_read_state_with_syncer( + state_config, + &network, + args.zebra_rpc_listen_addr, + ) + .await? + .map_err(|err| eyre!(err))?; // Spawn the scan task. let scan_task_handle = @@ -85,14 +83,18 @@ async fn main() -> Result<(), Box> { // Pin the scan task handle. tokio::pin!(scan_task_handle); + tokio::pin!(sync_task); // Wait for task to finish - loop { - let _result = tokio::select! { - scan_result = &mut scan_task_handle => scan_result - .expect("unexpected panic in the scan task") - .map(|_| info!("scan task exited")), - }; + tokio::select! { + scan_result = &mut scan_task_handle => scan_result + .expect("unexpected panic in the scan task") + .map(|_| info!("scan task exited")) + .map_err(Into::into), + sync_result = &mut sync_task => { + sync_result.expect("unexpected panic in the scan task"); + Ok(()) + } } } @@ -131,6 +133,11 @@ pub struct Args { #[structopt(long)] pub sapling_keys_to_scan: Vec, + /// The listen address of Zebra's RPC server used by the syncer to check for chain tip changes + /// and get blocks in Zebra's non-finalized state. + #[structopt(long)] + pub zebra_rpc_listen_addr: SocketAddr, + /// IP address and port for the gRPC server. #[structopt(long)] pub listen_addr: Option,