little more cleaning

This commit is contained in:
Jane Lusby 2020-06-15 17:07:55 -07:00 committed by Henry de Valence
parent 528fd2b5b1
commit d09c339dc5
3 changed files with 53 additions and 51 deletions

View File

@ -75,7 +75,7 @@ None: these are the core data structure definitions.
### Responsible for ### Responsible for
- definition of a sane, internal request/response protocol - definition of a well structured, internal request/response protocol
- provides an abstraction for "this node" and "the network" using the - provides an abstraction for "this node" and "the network" using the
internal protocol internal protocol
- dynamic, backpressure-driven peer set management - dynamic, backpressure-driven peer set management

View File

@ -8,7 +8,7 @@ mod start;
mod version; mod version;
use self::{ use self::{
config::ConfigCmd, connect::ConnectCmd, revhex::RevhexCmd, seed::SeedCmd, start::StartCmd, config::ConfigCmd, connect::ConnectCmd, revhex::RevhexCmd, seed::SeedCmd, start::StartArgs,
version::VersionCmd, version::VersionCmd,
}; };
use crate::config::ZebradConfig; use crate::config::ZebradConfig;
@ -45,7 +45,7 @@ pub enum ZebradCmd {
/// The `start` subcommand /// The `start` subcommand
#[options(help = "start the application")] #[options(help = "start the application")]
Start(StartCmd), Start(StartArgs),
/// The `version` subcommand /// The `version` subcommand
#[options(help = "display version information")] #[options(help = "display version information")]

View File

@ -7,8 +7,10 @@
//! * Network Service //! * Network Service
//! * primary interface to the node //! * primary interface to the node
//! * handles all external network requests for the zcash protocol //! * handles all external network requests for the zcash protocol
//! * via zebra_network::Message and zebra_network::Response
//! * provides an interface to the rest of the network for other services and //! * provides an interface to the rest of the network for other services and
//! tasks running within this node //! tasks running within this node
//! * via zebra_network::Request
//! * Consensus Service //! * Consensus Service
//! * handles all validation logic for the node //! * handles all validation logic for the node
//! * verifies blocks using zebra-chain and zebra-script, then stores verified //! * verifies blocks using zebra-chain and zebra-script, then stores verified
@ -37,7 +39,7 @@ static GENESIS: BlockHeaderHash = BlockHeaderHash([
/// `start` subcommand /// `start` subcommand
#[derive(Command, Debug, Options)] #[derive(Command, Debug, Options)]
pub struct StartCmd { pub struct StartArgs {
/// Filter strings /// Filter strings
#[options(free)] #[options(free)]
filters: Vec<String>, filters: Vec<String>,
@ -50,48 +52,8 @@ pub struct StartCmd {
addr: std::net::SocketAddr, addr: std::net::SocketAddr,
} }
impl Runnable for StartCmd { impl StartArgs {
/// Start the application. async fn start(&self) -> Result<(), Report> {
fn run(&self) {
info!(connect.addr = ?self.addr);
let rt = app_writer()
.state_mut()
.components
.get_downcast_mut::<TokioComponent>()
.expect("TokioComponent should be available")
.rt
.take();
let result = rt
.expect("runtime should not already be taken")
.block_on(self.connect());
match result {
Ok(()) => {}
Err(e) => {
eprintln!("Error: {:?}", e);
std::process::exit(1);
}
}
}
}
impl config::Override<ZebradConfig> for StartCmd {
// Process the given command line options, overriding settings from
// a configuration file using explicit flags taken from command-line
// arguments.
fn override_config(&self, mut config: ZebradConfig) -> Result<ZebradConfig, FrameworkError> {
if !self.filters.is_empty() {
config.tracing.filter = Some(self.filters.join(","));
}
Ok(config)
}
}
impl StartCmd {
async fn connect(&self) -> Result<(), Report> {
info!(?self, "begin tower-based peer handling test stub"); info!(?self, "begin tower-based peer handling test stub");
// The service that our node uses to respond to requests by peers // The service that our node uses to respond to requests by peers
@ -116,7 +78,7 @@ impl StartCmd {
let mut downloaded_block_heights = BTreeSet::<BlockHeight>::new(); let mut downloaded_block_heights = BTreeSet::<BlockHeight>::new();
downloaded_block_heights.insert(BlockHeight(0)); downloaded_block_heights.insert(BlockHeight(0));
let mut connect = Start { let mut connect = ZebraNode {
retry_peer_set, retry_peer_set,
peer_set, peer_set,
state, state,
@ -126,11 +88,51 @@ impl StartCmd {
downloaded_block_heights, downloaded_block_heights,
}; };
connect.connect().await connect.run().await
} }
} }
struct Start<ZN, ZS> impl Runnable for StartArgs {
/// Start the application.
fn run(&self) {
info!(connect.addr = ?self.addr);
let rt = app_writer()
.state_mut()
.components
.get_downcast_mut::<TokioComponent>()
.expect("TokioComponent should be available")
.rt
.take();
let result = rt
.expect("runtime should not already be taken")
.block_on(self.start());
match result {
Ok(()) => {}
Err(e) => {
eprintln!("Error: {:?}", e);
std::process::exit(1);
}
}
}
}
impl config::Override<ZebradConfig> for StartArgs {
// Process the given command line options, overriding settings from
// a configuration file using explicit flags taken from command-line
// arguments.
fn override_config(&self, mut config: ZebradConfig) -> Result<ZebradConfig, FrameworkError> {
if !self.filters.is_empty() {
config.tracing.filter = Some(self.filters.join(","));
}
Ok(config)
}
}
struct ZebraNode<ZN, ZS>
where where
ZN: Service<zebra_network::Request>, ZN: Service<zebra_network::Request>,
{ {
@ -143,7 +145,7 @@ where
downloaded_block_heights: BTreeSet<BlockHeight>, downloaded_block_heights: BTreeSet<BlockHeight>,
} }
impl<ZN, ZS> Start<ZN, ZS> impl<ZN, ZS> ZebraNode<ZN, ZS>
where where
ZN: Service<zebra_network::Request, Response = zebra_network::Response, Error = Error> ZN: Service<zebra_network::Request, Response = zebra_network::Response, Error = Error>
+ Send + Send
@ -156,7 +158,7 @@ where
+ 'static, + 'static,
ZS::Future: Send, ZS::Future: Send,
{ {
async fn connect(&mut self) -> Result<(), Report> { async fn run(&mut self) -> Result<(), Report> {
// TODO(jlusby): Replace with real state service // TODO(jlusby): Replace with real state service
while self.requested_block_heights < 700_000 { while self.requested_block_heights < 700_000 {