Skip to content

Commit

Permalink
use sync task
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 authored and oxarbitrage committed Jun 21, 2024
1 parent 75b4dd0 commit 3bb5a9e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6055,6 +6055,7 @@ dependencies = [
"zebra-chain",
"zebra-grpc",
"zebra-node-services",
"zebra-rpc",
"zebra-state",
"zebra-test",
]
Expand Down
1 change: 1 addition & 0 deletions zebra-scan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
43 changes: 25 additions & 18 deletions zebra-scan/src/bin/scanner/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -67,32 +68,33 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
};

// 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 =
{ zebra_scan::spawn_init(scanner_config, network, read_state, chain_tip_change) };

// 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(())
}
}
}

Expand Down Expand Up @@ -131,6 +133,11 @@ pub struct Args {
#[structopt(long)]
pub sapling_keys_to_scan: Vec<SaplingKey>,

/// 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<SocketAddr>,
Expand Down

0 comments on commit 3bb5a9e

Please sign in to comment.