Skip to content

Commit

Permalink
Merge pull request #577 from EspressoSystems/jb/options
Browse files Browse the repository at this point in the history
Remove unused clap derivations, fix default for availability options
  • Loading branch information
jbearer authored May 8, 2024
2 parents a48483e + f748ed5 commit c4f0433
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 67 deletions.
9 changes: 1 addition & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

[package]
name = "hotshot-query-service"
version = "0.1.18"
version = "0.1.19"
authors = ["Espresso Systems <hello@espressosys.com>"]
edition = "2021"
license = "GPL-3.0-or-later"
Expand Down Expand Up @@ -68,8 +68,6 @@ async-trait = "0.1"
bincode = "1.3"
bit-vec = { version = "0.6.3", features = ["serde_std"] }
chrono = "0.4"
clap = { version = "4.5", features = ["derive", "env"] }
cld = "0.5"
committable = "0.2"
custom_debug = "0.6"
derivative = "2.2"
Expand Down Expand Up @@ -130,6 +128,7 @@ tempfile = { version = "3.10", optional = true }
backtrace-on-stack-overflow = { version = "0.3", optional = true }

[dev-dependencies]
clap = { version = "4.5", features = ["derive", "env"] }
espresso-macros = { git = "https://github.com/EspressoSystems/espresso-macros.git", tag = "0.1.0" }
generic-array = "0.14"
hotshot-example-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.50" }
Expand Down
35 changes: 11 additions & 24 deletions src/availability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@
//! the [node](crate::node) API.
use crate::{api::load_api, Payload};
use clap::Args;
use cld::ClDuration;
use derive_more::From;
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt};
use hotshot_types::traits::node_implementation::NodeType;
use serde::{Deserialize, Serialize};
use snafu::{OptionExt, Snafu};
use std::{fmt::Display, path::PathBuf, str::FromStr, time::Duration};
use std::{fmt::Display, path::PathBuf, time::Duration};
use tide_disco::{api::ApiError, method::ReadState, Api, RequestError, StatusCode};
use vbs::version::StaticVersionType;

Expand All @@ -45,49 +43,38 @@ pub use data_source::*;
pub use fetch::Fetch;
pub use query_data::*;

#[derive(Args, Default)]
pub struct Options {
#[arg(long = "availability-api-path", env = "HOTSHOT_AVAILABILITY_API_PATH")]
pub api_path: Option<PathBuf>,

/// Timeout for failing requests due to missing data.
///
/// If data needed to respond to a request is missing, it can (in some cases) be fetched from an
/// external provider. This parameter controls how long the request handler will wait for
/// missing data to be fetched before giving up and failing the request.
#[arg(
long = "availability-fetch-timeout",
env = "HOTSHOT_AVAILABILITY_FETCH_TIMEOUT",
default_value = "500ms",
value_parser = parse_duration,
)]
pub fetch_timeout: Duration,

/// Additional API specification files to merge with `availability-api-path`.
///
/// These optional files may contain route definitions for application-specific routes that have
/// been added as extensions to the basic availability API.
#[arg(
long = "availability-extension",
env = "HOTSHOT_AVAILABILITY_EXTENSIONS",
value_delimiter = ','
)]
pub extensions: Vec<toml::Value>,
}

impl Default for Options {
fn default() -> Self {
Self {
api_path: None,
fetch_timeout: Duration::from_millis(500),
extensions: vec![],
}
}
}

#[derive(Clone, Debug, Snafu)]
struct ParseDurationError {
reason: String,
}

fn parse_duration(s: &str) -> Result<Duration, ParseDurationError> {
ClDuration::from_str(s)
.map(Duration::from)
.map_err(|err| ParseDurationError {
reason: err.to_string(),
})
}

#[derive(Clone, Debug, From, Snafu, Deserialize, Serialize)]
#[snafu(visibility(pub))]
pub enum Error {
Expand Down
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,11 @@ impl QueryError {

pub type QueryResult<T> = Result<T, QueryError>;

#[derive(clap::Args, Default)]
#[derive(Default)]
pub struct Options {
#[clap(flatten)]
pub availability: availability::Options,
#[clap(flatten)]
pub node: node::Options,
#[clap(flatten)]
pub status: status::Options,
#[clap(short, long, default_value = "8080")]
pub port: u16,
}

Expand Down
12 changes: 1 addition & 11 deletions src/merklized_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//! If any parent state is missing then the partial snapshot can not be queried.
use std::{fmt::Display, path::PathBuf};

use clap::Args;
use derive_more::From;
use futures::FutureExt;
use hotshot_types::traits::node_implementation::NodeType;
Expand All @@ -33,23 +32,14 @@ use crate::{api::load_api, QueryError};
pub(crate) mod data_source;
pub use data_source::*;

#[derive(Args, Default)]
#[derive(Default)]
pub struct Options {
#[arg(
long = "merklized-state-api-path",
env = "HOTSHOT_MERKLIZED_STATE_API_PATH"
)]
pub api_path: Option<PathBuf>,

/// Additional API specification files to merge with `merklized-state-api-path`.
///
/// These optional files may contain route definitions for application-specific routes that have
/// been added as extensions to the basic status API.
#[arg(
long = "merklized-state-extension",
env = "HOTSHOT_MERKLIZED_STATE_EXTENSIONS",
value_delimiter = ','
)]
pub extensions: Vec<toml::Value>,
}

Expand Down
9 changes: 1 addition & 8 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
//! return the expected counts.
use crate::{api::load_api, QueryError};
use clap::Args;
use derive_more::From;
use futures::FutureExt;
use hotshot_types::traits::node_implementation::NodeType;
Expand All @@ -37,20 +36,14 @@ pub(crate) mod query_data;
pub use data_source::*;
pub use query_data::*;

#[derive(Args, Default)]
#[derive(Default)]
pub struct Options {
#[arg(long = "node-api-path", env = "HOTSHOT_NODE_API_PATH")]
pub api_path: Option<PathBuf>,

/// Additional API specification files to merge with `node-api-path`.
///
/// These optional files may contain route definitions for application-specific routes that have
/// been added as extensions to the basic node API.
#[arg(
long = "node-extension",
env = "HOTSHOT_NODE_EXTENSIONS",
value_delimiter = ','
)]
pub extensions: Vec<toml::Value>,
}

Expand Down
9 changes: 1 addition & 8 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
//! * summary statistics
use crate::api::load_api;
use clap::Args;
use derive_more::From;
use futures::FutureExt;
use serde::{Deserialize, Serialize};
Expand All @@ -39,20 +38,14 @@ pub(crate) mod data_source;

pub use data_source::*;

#[derive(Args, Default)]
#[derive(Default)]
pub struct Options {
#[arg(long = "status-api-path", env = "HOTSHOT_STATUS_API_PATH")]
pub api_path: Option<PathBuf>,

/// Additional API specification files to merge with `status-api-path`.
///
/// These optional files may contain route definitions for application-specific routes that have
/// been added as extensions to the basic status API.
#[arg(
long = "status-extension",
env = "HOTSHOT_STATUS_EXTENSIONS",
value_delimiter = ','
)]
pub extensions: Vec<toml::Value>,
}

Expand Down

0 comments on commit c4f0433

Please sign in to comment.