-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add(scan): Start scanner gRPC server with
zebrad
(#8241)
* adds clear_results RPC method for zebra-scan * adds delete_keys rpc method * adds docs * Update zebra-grpc/proto/scanner.proto Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com> * Apply suggestions from code review * start zebra-scan gRPC server from zebrad start command * adds a test that the scanner starts with zebrad * adds a `listen_addr` field to the shielded scan config * updates test to use a random port and set the listen_addr config field * fixes test * Update zebra-scan/src/config.rs Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com> * fixes panic when trying to open multiple mutable storage instances. * open db in blocking task * fixes test --------- Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
- Loading branch information
1 parent
1cfed24
commit 2c0bc3a
Showing
15 changed files
with
161 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,66 @@ | ||
//! Initializing the scanner and gRPC server. | ||
use std::net::SocketAddr; | ||
|
||
use color_eyre::Report; | ||
use tokio::task::JoinHandle; | ||
use tower::ServiceBuilder; | ||
|
||
use zebra_chain::parameters::Network; | ||
use tracing::Instrument; | ||
use zebra_chain::{diagnostic::task::WaitForPanics, parameters::Network}; | ||
use zebra_state::ChainTipChange; | ||
|
||
use crate::{scan, service::ScanService, Config}; | ||
use crate::{scan, service::ScanService, storage::Storage, Config}; | ||
|
||
/// Initialize [`ScanService`] based on its config. | ||
/// | ||
/// TODO: add a test for this function. | ||
pub async fn init( | ||
pub async fn init_with_server( | ||
listen_addr: SocketAddr, | ||
config: Config, | ||
network: Network, | ||
state: scan::State, | ||
chain_tip_change: ChainTipChange, | ||
) -> Result<(), Report> { | ||
let scan_service = ServiceBuilder::new().buffer(10).service(ScanService::new( | ||
&config, | ||
network, | ||
state, | ||
chain_tip_change, | ||
)); | ||
info!(?config, "starting scan service"); | ||
let scan_service = ServiceBuilder::new() | ||
.buffer(10) | ||
.service(ScanService::new(&config, network, state, chain_tip_change).await); | ||
|
||
// TODO: move this to zebra-grpc init() function and include addr | ||
info!("starting scan gRPC server"); | ||
|
||
// Start the gRPC server. | ||
zebra_grpc::server::init(scan_service).await?; | ||
zebra_grpc::server::init(listen_addr, scan_service).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Initialize the scanner and its gRPC server based on its config, and spawn a task for it. | ||
pub fn spawn_init( | ||
config: Config, | ||
network: Network, | ||
state: scan::State, | ||
chain_tip_change: ChainTipChange, | ||
) -> JoinHandle<Result<(), Report>> { | ||
if let Some(listen_addr) = config.listen_addr { | ||
// TODO: spawn an entirely new executor here, to avoid timing attacks. | ||
tokio::spawn( | ||
init_with_server(listen_addr, config, network, state, chain_tip_change) | ||
.in_current_span(), | ||
) | ||
} else { | ||
// TODO: spawn an entirely new executor here, to avoid timing attacks. | ||
tokio::spawn( | ||
async move { | ||
let storage = | ||
tokio::task::spawn_blocking(move || Storage::new(&config, network, false)) | ||
.wait_for_panics() | ||
.await; | ||
let (_cmd_sender, cmd_receiver) = std::sync::mpsc::channel(); | ||
scan::start(state, chain_tip_change, storage, cmd_receiver).await | ||
} | ||
.in_current_span(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.