Upgrade to Abscissa v0.5
This commit is contained in:
parent
d3e954cd4a
commit
45eb81a204
File diff suppressed because it is too large
Load Diff
|
|
@ -8,12 +8,11 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
abscissa_core = "0.3.0"
|
abscissa_core = "0.5"
|
||||||
failure = "0.1"
|
gumdrop = "0.7"
|
||||||
gumdrop = "0.6"
|
|
||||||
lazy_static = "1"
|
|
||||||
serde = { version = "1", features = ["serde_derive"] }
|
serde = { version = "1", features = ["serde_derive"] }
|
||||||
toml = "0.5"
|
toml = "0.5"
|
||||||
|
thiserror = "1"
|
||||||
|
|
||||||
tokio = { version = "0.2", features = ["time", "rt-threaded", "stream"] }
|
tokio = { version = "0.2", features = ["time", "rt-threaded", "stream"] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
|
@ -30,6 +29,6 @@ tower = "0.3"
|
||||||
zebra-chain = { path = "../zebra-chain" }
|
zebra-chain = { path = "../zebra-chain" }
|
||||||
zebra-network = { path = "../zebra-network" }
|
zebra-network = { path = "../zebra-network" }
|
||||||
|
|
||||||
[dev-dependencies.abscissa_core]
|
[dev-dependencies]
|
||||||
version = "0.3.0"
|
abscissa_core = { version = "0.5", features = ["testing"] }
|
||||||
features = ["testing"]
|
once_cell = "1.2"
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,12 @@
|
||||||
|
|
||||||
use crate::{commands::ZebradCmd, config::ZebradConfig};
|
use crate::{commands::ZebradCmd, config::ZebradConfig};
|
||||||
use abscissa_core::{
|
use abscissa_core::{
|
||||||
application, config, logging, Application, Component, EntryPoint, FrameworkError, StandardPaths,
|
application::{self, AppCell},
|
||||||
|
config, trace, Application, Component, EntryPoint, FrameworkError, StandardPaths,
|
||||||
};
|
};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
|
|
||||||
lazy_static! {
|
/// Application state
|
||||||
/// Application state
|
pub static APPLICATION: AppCell<ZebradApp> = AppCell::new();
|
||||||
pub static ref APPLICATION: application::Lock<ZebradApp> = application::Lock::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Obtain a read-only (multi-reader) lock on the application state.
|
/// Obtain a read-only (multi-reader) lock on the application state.
|
||||||
///
|
///
|
||||||
|
|
@ -120,11 +118,11 @@ impl Application for ZebradApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get logging configuration from command-line options
|
/// Get logging configuration from command-line options
|
||||||
fn logging_config(&self, command: &EntryPoint<ZebradCmd>) -> logging::Config {
|
fn tracing_config(&self, command: &EntryPoint<ZebradCmd>) -> trace::Config {
|
||||||
if command.verbose {
|
if command.verbose {
|
||||||
logging::Config::verbose()
|
trace::Config::verbose()
|
||||||
} else {
|
} else {
|
||||||
logging::Config::default()
|
trace::Config::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
//! `connect` subcommand - test stub for talking to zcashd
|
//! `connect` subcommand - test stub for talking to zcashd
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::{
|
||||||
|
error::{Error, ErrorKind},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
use abscissa_core::{Command, Options, Runnable};
|
use abscissa_core::{Command, Options, Runnable};
|
||||||
|
|
||||||
|
|
@ -34,7 +37,7 @@ impl Runnable for ConnectCmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConnectCmd {
|
impl ConnectCmd {
|
||||||
async fn connect(&self) -> Result<(), failure::Error> {
|
async fn connect(&self) -> Result<(), Error> {
|
||||||
use zebra_network::{AddressBook, Request, Response};
|
use zebra_network::{AddressBook, Request, Response};
|
||||||
|
|
||||||
info!("begin tower-based peer handling test stub");
|
info!("begin tower-based peer handling test stub");
|
||||||
|
|
@ -44,7 +47,7 @@ impl ConnectCmd {
|
||||||
service_fn(|req| {
|
service_fn(|req| {
|
||||||
async move {
|
async move {
|
||||||
info!(?req);
|
info!(?req);
|
||||||
Ok::<Response, failure::Error>(Response::Ok)
|
Ok::<Response, Error>(Response::Ok)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
1,
|
1,
|
||||||
|
|
@ -59,17 +62,22 @@ impl ConnectCmd {
|
||||||
let (mut peer_set, _address_book) = zebra_network::init(config, node).await;
|
let (mut peer_set, _address_book) = zebra_network::init(config, node).await;
|
||||||
|
|
||||||
info!("waiting for peer_set ready");
|
info!("waiting for peer_set ready");
|
||||||
peer_set.ready().await.map_err(Error::from_boxed_compat)?;
|
peer_set
|
||||||
|
.ready()
|
||||||
|
.await
|
||||||
|
.map_err(|e| Error::from(ErrorKind::Io.context(e)))?;
|
||||||
|
|
||||||
info!("peer_set became ready, constructing addr requests");
|
info!("peer_set became ready, constructing addr requests");
|
||||||
|
|
||||||
use failure::Error;
|
|
||||||
use futures::stream::{FuturesUnordered, StreamExt};
|
use futures::stream::{FuturesUnordered, StreamExt};
|
||||||
|
|
||||||
let mut addr_reqs = FuturesUnordered::new();
|
let mut addr_reqs = FuturesUnordered::new();
|
||||||
for i in 0..10usize {
|
for i in 0..10usize {
|
||||||
info!(i, "awaiting peer_set ready");
|
info!(i, "awaiting peer_set ready");
|
||||||
peer_set.ready().await.map_err(Error::from_boxed_compat)?;
|
peer_set
|
||||||
|
.ready()
|
||||||
|
.await
|
||||||
|
.map_err(|e| Error::from(ErrorKind::Io.context(e)))?;
|
||||||
info!(i, "calling peer_set");
|
info!(i, "calling peer_set");
|
||||||
addr_reqs.push(peer_set.call(Request::GetPeers));
|
addr_reqs.push(peer_set.call(Request::GetPeers));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,10 @@ use tower::{buffer::Buffer, Service, ServiceExt};
|
||||||
|
|
||||||
use zebra_network::{AddressBook, BoxedStdError, Request, Response};
|
use zebra_network::{AddressBook, BoxedStdError, Request, Response};
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::{
|
||||||
|
error::{Error, ErrorKind},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
/// Whether our `SeedService` is poll_ready or not.
|
/// Whether our `SeedService` is poll_ready or not.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -120,9 +123,7 @@ impl Runnable for SeedCmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SeedCmd {
|
impl SeedCmd {
|
||||||
async fn seed(&self) -> Result<(), failure::Error> {
|
async fn seed(&self) -> Result<(), Error> {
|
||||||
use failure::Error;
|
|
||||||
|
|
||||||
info!("begin tower-based peer handling test stub");
|
info!("begin tower-based peer handling test stub");
|
||||||
|
|
||||||
let (addressbook_tx, addressbook_rx) = oneshot::channel();
|
let (addressbook_tx, addressbook_rx) = oneshot::channel();
|
||||||
|
|
@ -138,7 +139,10 @@ impl SeedCmd {
|
||||||
let _ = addressbook_tx.send(address_book);
|
let _ = addressbook_tx.send(address_book);
|
||||||
|
|
||||||
info!("waiting for peer_set ready");
|
info!("waiting for peer_set ready");
|
||||||
peer_set.ready().await.map_err(Error::from_boxed_compat)?;
|
peer_set
|
||||||
|
.ready()
|
||||||
|
.await
|
||||||
|
.map_err(|e| Error::from(ErrorKind::Io.context(e)))?;
|
||||||
|
|
||||||
info!("peer_set became ready");
|
info!("peer_set became ready");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::components::tokio::TokioComponent;
|
use crate::components::tokio::TokioComponent;
|
||||||
|
|
||||||
use abscissa_core::{err, Component, FrameworkError, FrameworkErrorKind};
|
use abscissa_core::{format_err, Component, FrameworkError, FrameworkErrorKind};
|
||||||
|
|
||||||
use hyper::service::{make_service_fn, service_fn};
|
use hyper::service::{make_service_fn, service_fn};
|
||||||
use hyper::{Body, Request, Response, Server};
|
use hyper::{Body, Request, Response, Server};
|
||||||
|
|
@ -34,7 +34,7 @@ impl TracingEndpoint {
|
||||||
// XXX this is only required if we have a dependency that uses log;
|
// XXX this is only required if we have a dependency that uses log;
|
||||||
// currently this is maybe only abscissa itself?
|
// currently this is maybe only abscissa itself?
|
||||||
LogTracer::init().map_err(|e| {
|
LogTracer::init().map_err(|e| {
|
||||||
err!(
|
format_err!(
|
||||||
FrameworkErrorKind::ComponentError,
|
FrameworkErrorKind::ComponentError,
|
||||||
"could not set log subscriber: {}",
|
"could not set log subscriber: {}",
|
||||||
e
|
e
|
||||||
|
|
@ -52,7 +52,7 @@ impl TracingEndpoint {
|
||||||
|
|
||||||
// Set that subscriber to be the global tracing subscriber
|
// Set that subscriber to be the global tracing subscriber
|
||||||
tracing::subscriber::set_global_default(subscriber).map_err(|e| {
|
tracing::subscriber::set_global_default(subscriber).map_err(|e| {
|
||||||
err!(
|
format_err!(
|
||||||
FrameworkErrorKind::ComponentError,
|
FrameworkErrorKind::ComponentError,
|
||||||
"could not set tracing subscriber: {}",
|
"could not set tracing subscriber: {}",
|
||||||
e
|
e
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,12 @@
|
||||||
//! application's configuration file and/or command-line options
|
//! application's configuration file and/or command-line options
|
||||||
//! for specifying it.
|
//! for specifying it.
|
||||||
|
|
||||||
use abscissa_core::Config;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use zebra_network::Config as NetworkSection;
|
use zebra_network::Config as NetworkSection;
|
||||||
|
|
||||||
/// Zebrad Configuration
|
/// Zebrad Configuration
|
||||||
#[derive(Clone, Config, Default, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct ZebradConfig {
|
pub struct ZebradConfig {
|
||||||
/// Tracing configuration
|
/// Tracing configuration
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,64 @@
|
||||||
//! Error types
|
//! Error types
|
||||||
|
|
||||||
use abscissa_core::err;
|
use abscissa_core::error::{BoxError, Context};
|
||||||
use failure::Fail;
|
use std::{
|
||||||
use std::{fmt, io};
|
fmt::{self, Display},
|
||||||
|
io,
|
||||||
/// Error type
|
ops::Deref,
|
||||||
#[derive(Debug)]
|
};
|
||||||
pub struct Error(abscissa_core::Error<ErrorKind>);
|
use thiserror::Error;
|
||||||
|
|
||||||
/// Kinds of errors
|
/// Kinds of errors
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Fail)]
|
#[derive(Copy, Clone, Debug, Eq, Error, PartialEq)]
|
||||||
pub enum ErrorKind {
|
pub enum ErrorKind {
|
||||||
/// Error in configuration file
|
/// Error in configuration file
|
||||||
#[fail(display = "config error")]
|
#[error("config error")]
|
||||||
Config,
|
Config,
|
||||||
|
|
||||||
/// Input/output error
|
/// Input/output error
|
||||||
#[fail(display = "I/O error")]
|
#[error("I/O error")]
|
||||||
Io,
|
Io,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl ErrorKind {
|
||||||
|
/// Create an error context from this error
|
||||||
|
pub fn context(self, source: impl Into<BoxError>) -> Context<ErrorKind> {
|
||||||
|
Context::new(self, Some(source.into()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Error type
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Error(Box<Context<ErrorKind>>);
|
||||||
|
|
||||||
|
impl Deref for Error {
|
||||||
|
type Target = Context<ErrorKind>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Context<ErrorKind> {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
self.0.fmt(f)
|
self.0.fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<abscissa_core::Error<ErrorKind>> for Error {
|
impl From<Context<ErrorKind>> for Error {
|
||||||
fn from(other: abscissa_core::Error<ErrorKind>) -> Self {
|
fn from(context: Context<ErrorKind>) -> Self {
|
||||||
Error(other)
|
Error(Box::new(context))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<io::Error> for Error {
|
impl From<io::Error> for Error {
|
||||||
fn from(other: io::Error) -> Self {
|
fn from(other: io::Error) -> Self {
|
||||||
err!(ErrorKind::Io, other).into()
|
ErrorKind::Io.context(other).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for Error {
|
||||||
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
|
self.0.source()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
#[macro_use]
|
|
||||||
extern crate failure;
|
|
||||||
|
|
||||||
mod components;
|
mod components;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,9 @@ pub use crate::application::{app_config, app_reader, app_writer};
|
||||||
/// Commonly used Abscissa traits
|
/// Commonly used Abscissa traits
|
||||||
pub use abscissa_core::{Application, Command, Runnable};
|
pub use abscissa_core::{Application, Command, Runnable};
|
||||||
|
|
||||||
// These are disabled because we use tracing.
|
|
||||||
// Logging macros
|
|
||||||
//pub use abscissa_core::log::{debug, error, info, log, log_enabled, trace, warn};
|
|
||||||
|
|
||||||
/// Type alias to make working with tower traits easier.
|
/// Type alias to make working with tower traits easier.
|
||||||
///
|
///
|
||||||
/// Note: the 'static lifetime bound means that the *type* cannot have any
|
/// Note: the 'static lifetime bound means that the *type* cannot have any
|
||||||
/// non-'static lifetimes, (e.g., when a type contains a borrow and is
|
/// non-'static lifetimes, (e.g., when a type contains a borrow and is
|
||||||
/// parameterized by 'a), *not* that the object itself has 'static lifetime.
|
/// parameterized by 'a), *not* that the object itself has 'static lifetime.
|
||||||
pub(crate) type BoxedStdError = Box<dyn std::error::Error + Send + Sync + 'static>;
|
pub(crate) use abscissa_core::error::BoxError;
|
||||||
|
|
|
||||||
|
|
@ -11,17 +11,10 @@
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
|
|
||||||
use abscissa_core::testing::prelude::*;
|
use abscissa_core::testing::prelude::*;
|
||||||
use lazy_static::lazy_static;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
lazy_static! {
|
/// Executes your application binary via `cargo run`.
|
||||||
/// Executes your application binary via `cargo run`.
|
pub static RUNNER: Lazy<CmdRunner> = Lazy::new(|| CmdRunner::default());
|
||||||
///
|
|
||||||
/// Storing this value in a `lazy_static!` ensures that all instances of
|
|
||||||
/// the runner acquire a mutex when executing commands and inspecting
|
|
||||||
/// exit statuses, serializing what would otherwise be multithreaded
|
|
||||||
/// invocations as `cargo test` executes tests in parallel by default.
|
|
||||||
pub static ref RUNNER: CmdRunner = CmdRunner::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Example of a test which matches a regular expression
|
/// Example of a test which matches a regular expression
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue