network: rename alias to BoxError

This is shorter and consistent with Tower (which is why we use it in the
first place).
This commit is contained in:
Henry de Valence 2020-09-18 11:20:55 -07:00
parent 5fbb07460c
commit 1d3892e1dc
10 changed files with 43 additions and 45 deletions

View File

@ -14,7 +14,7 @@ use tower::{
Service, Service,
}; };
use crate::{peer, BoxedStdError, Config, Request, Response}; use crate::{peer, BoxError, Config, Request, Response};
/// Use the provided TCP connection to create a Zcash connection completely /// Use the provided TCP connection to create a Zcash connection completely
/// isolated from all other node state. /// isolated from all other node state.
@ -67,7 +67,7 @@ struct Wrapper(peer::Client);
impl Service<Request> for Wrapper { impl Service<Request> for Wrapper {
type Response = Response; type Response = Response;
type Error = BoxedStdError; type Error = BoxError;
type Future = type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>; Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

View File

@ -53,7 +53,7 @@ extern crate bitflags;
/// 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 type BoxedStdError = Box<dyn std::error::Error + Send + Sync + 'static>; pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
mod address_book; mod address_book;
mod config; mod config;

View File

@ -39,7 +39,7 @@ use crate::{
external::{types::Nonce, InventoryHash, Message}, external::{types::Nonce, InventoryHash, Message},
internal::{Request, Response}, internal::{Request, Response},
}, },
BoxedStdError, BoxError,
}; };
use super::{ClientRequest, ErrorSlot, PeerError, SharedPeerError}; use super::{ClientRequest, ErrorSlot, PeerError, SharedPeerError};
@ -184,8 +184,8 @@ pub struct Connection<S, Tx> {
impl<S, Tx> Connection<S, Tx> impl<S, Tx> Connection<S, Tx>
where where
S: Service<Request, Response = Response, Error = BoxedStdError>, S: Service<Request, Response = Response, Error = BoxError>,
S::Error: Into<BoxedStdError>, S::Error: Into<BoxError>,
Tx: Sink<Message, Error = SerializationError> + Unpin, Tx: Sink<Message, Error = SerializationError> + Unpin,
{ {
/// Consume this `Connection` to form a spawnable future containing its event loop. /// Consume this `Connection` to form a spawnable future containing its event loop.

View File

@ -9,7 +9,7 @@ use futures::prelude::*;
use tokio::net::TcpStream; use tokio::net::TcpStream;
use tower::{discover::Change, Service, ServiceExt}; use tower::{discover::Change, Service, ServiceExt};
use crate::{BoxedStdError, Request, Response}; use crate::{BoxError, Request, Response};
use super::{Client, Handshake}; use super::{Client, Handshake};
@ -36,11 +36,11 @@ impl<S> Connector<S> {
impl<S> Service<SocketAddr> for Connector<S> impl<S> Service<SocketAddr> for Connector<S>
where where
S: Service<Request, Response = Response, Error = BoxedStdError> + Clone + Send + 'static, S: Service<Request, Response = Response, Error = BoxError> + Clone + Send + 'static,
S::Future: Send, S::Future: Send,
{ {
type Response = Change<SocketAddr, Client>; type Response = Change<SocketAddr, Client>;
type Error = BoxedStdError; type Error = BoxError;
type Future = type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>; Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

View File

@ -27,7 +27,7 @@ use crate::{
internal::{Request, Response}, internal::{Request, Response},
}, },
types::MetaAddr, types::MetaAddr,
BoxedStdError, Config, BoxError, Config,
}; };
use super::{Client, Connection, ErrorSlot, HandshakeError}; use super::{Client, Connection, ErrorSlot, HandshakeError};
@ -58,7 +58,7 @@ pub struct Builder<S> {
impl<S> Builder<S> impl<S> Builder<S>
where where
S: Service<Request, Response = Response, Error = BoxedStdError> + Clone + Send + 'static, S: Service<Request, Response = Response, Error = BoxError> + Clone + Send + 'static,
S::Future: Send, S::Future: Send,
{ {
/// Provide a config. Mandatory. /// Provide a config. Mandatory.
@ -151,7 +151,7 @@ where
impl<S> Handshake<S> impl<S> Handshake<S>
where where
S: Service<Request, Response = Response, Error = BoxedStdError> + Clone + Send + 'static, S: Service<Request, Response = Response, Error = BoxError> + Clone + Send + 'static,
S::Future: Send, S::Future: Send,
{ {
/// Create a builder that configures a [`Handshake`] service. /// Create a builder that configures a [`Handshake`] service.
@ -173,11 +173,11 @@ where
impl<S> Service<(TcpStream, SocketAddr)> for Handshake<S> impl<S> Service<(TcpStream, SocketAddr)> for Handshake<S>
where where
S: Service<Request, Response = Response, Error = BoxedStdError> + Clone + Send + 'static, S: Service<Request, Response = Response, Error = BoxError> + Clone + Send + 'static,
S::Future: Send, S::Future: Send,
{ {
type Response = Client; type Response = Client;
type Error = BoxedStdError; type Error = BoxError;
type Future = type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>; Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

View File

@ -5,7 +5,7 @@ use futures::stream::{FuturesUnordered, StreamExt};
use tower::{Service, ServiceExt}; use tower::{Service, ServiceExt};
use tracing::Level; use tracing::Level;
use crate::{types::MetaAddr, AddressBook, BoxedStdError, Request, Response}; use crate::{types::MetaAddr, AddressBook, BoxError, Request, Response};
/// The `CandidateSet` maintains a pool of candidate peers. /// The `CandidateSet` maintains a pool of candidate peers.
/// ///
@ -84,7 +84,7 @@ pub(super) struct CandidateSet<S> {
impl<S> CandidateSet<S> impl<S> CandidateSet<S>
where where
S: Service<Request, Response = Response, Error = BoxedStdError>, S: Service<Request, Response = Response, Error = BoxError>,
S::Future: Send + 'static, S::Future: Send + 'static,
{ {
pub fn new(peer_set: Arc<Mutex<AddressBook>>, peer_service: S) -> CandidateSet<S> { pub fn new(peer_set: Arc<Mutex<AddressBook>>, peer_service: S) -> CandidateSet<S> {
@ -97,7 +97,7 @@ where
} }
} }
pub async fn update(&mut self) -> Result<(), BoxedStdError> { pub async fn update(&mut self) -> Result<(), BoxError> {
// Opportunistically crawl the network on every update call to ensure // Opportunistically crawl the network on every update call to ensure
// we're actively fetching peers. Continue independently of whether we // we're actively fetching peers. Continue independently of whether we
// actually receive any peers, but always ask the network for more. // actually receive any peers, but always ask the network for more.

View File

@ -28,7 +28,7 @@ use tower::{
use tower_load::{peak_ewma::PeakEwmaDiscover, NoInstrument}; use tower_load::{peak_ewma::PeakEwmaDiscover, NoInstrument};
use crate::{ use crate::{
constants, peer, timestamp_collector::TimestampCollector, AddressBook, BoxedStdError, Config, constants, peer, timestamp_collector::TimestampCollector, AddressBook, BoxError, Config,
Request, Response, Request, Response,
}; };
@ -37,18 +37,18 @@ use zebra_chain::parameters::Network;
use super::CandidateSet; use super::CandidateSet;
use super::PeerSet; use super::PeerSet;
type PeerChange = Result<Change<SocketAddr, peer::Client>, BoxedStdError>; type PeerChange = Result<Change<SocketAddr, peer::Client>, BoxError>;
/// Initialize a peer set with the given `config`, forwarding peer requests to the `inbound_service`. /// Initialize a peer set with the given `config`, forwarding peer requests to the `inbound_service`.
pub async fn init<S>( pub async fn init<S>(
config: Config, config: Config,
inbound_service: S, inbound_service: S,
) -> ( ) -> (
Buffer<BoxService<Request, Response, BoxedStdError>, Request>, Buffer<BoxService<Request, Response, BoxError>, Request>,
Arc<Mutex<AddressBook>>, Arc<Mutex<AddressBook>>,
) )
where where
S: Service<Request, Response = Response, Error = BoxedStdError> + Clone + Send + 'static, S: Service<Request, Response = Response, Error = BoxError> + Clone + Send + 'static,
S::Future: Send + 'static, S::Future: Send + 'static,
{ {
let (address_book, timestamp_collector) = TimestampCollector::spawn(); let (address_book, timestamp_collector) = TimestampCollector::spawn();
@ -169,10 +169,9 @@ async fn add_initial_peers<S>(
initial_peers: std::collections::HashSet<SocketAddr>, initial_peers: std::collections::HashSet<SocketAddr>,
connector: S, connector: S,
mut tx: mpsc::Sender<PeerChange>, mut tx: mpsc::Sender<PeerChange>,
) -> Result<(), BoxedStdError> ) -> Result<(), BoxError>
where where
S: Service<SocketAddr, Response = Change<SocketAddr, peer::Client>, Error = BoxedStdError> S: Service<SocketAddr, Response = Change<SocketAddr, peer::Client>, Error = BoxError> + Clone,
+ Clone,
S::Future: Send + 'static, S::Future: Send + 'static,
{ {
info!(?initial_peers, "Connecting to initial peer set"); info!(?initial_peers, "Connecting to initial peer set");
@ -194,9 +193,9 @@ async fn listen<S>(
addr: SocketAddr, addr: SocketAddr,
mut handshaker: S, mut handshaker: S,
tx: mpsc::Sender<PeerChange>, tx: mpsc::Sender<PeerChange>,
) -> Result<(), BoxedStdError> ) -> Result<(), BoxError>
where where
S: Service<(TcpStream, SocketAddr), Response = peer::Client, Error = BoxedStdError> + Clone, S: Service<(TcpStream, SocketAddr), Response = peer::Client, Error = BoxError> + Clone,
S::Future: Send + 'static, S::Future: Send + 'static,
{ {
let mut listener = TcpListener::bind(addr).await?; let mut listener = TcpListener::bind(addr).await?;
@ -236,12 +235,11 @@ async fn crawl_and_dial<C, S>(
mut candidates: CandidateSet<S>, mut candidates: CandidateSet<S>,
mut connector: C, mut connector: C,
mut success_tx: mpsc::Sender<PeerChange>, mut success_tx: mpsc::Sender<PeerChange>,
) -> Result<(), BoxedStdError> ) -> Result<(), BoxError>
where where
C: Service<SocketAddr, Response = Change<SocketAddr, peer::Client>, Error = BoxedStdError> C: Service<SocketAddr, Response = Change<SocketAddr, peer::Client>, Error = BoxError> + Clone,
+ Clone,
C::Future: Send + 'static, C::Future: Send + 'static,
S: Service<Request, Response = Response, Error = BoxedStdError>, S: Service<Request, Response = Response, Error = BoxError>,
S::Future: Send + 'static, S::Future: Send + 'static,
{ {
use futures::{ use futures::{

View File

@ -1,7 +1,7 @@
//! Inventory Registry Implementation //! Inventory Registry Implementation
//! //!
//! [RFC]: https://zebra.zfnd.org/dev/rfcs/0003-inventory-tracking.html //! [RFC]: https://zebra.zfnd.org/dev/rfcs/0003-inventory-tracking.html
use crate::{protocol::external::InventoryHash, BoxedStdError}; use crate::{protocol::external::InventoryHash, BoxError};
use futures::Stream; use futures::Stream;
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
@ -59,7 +59,7 @@ impl InventoryRegistry {
/// ///
/// - rotates HashMaps based on interval events /// - rotates HashMaps based on interval events
/// - drains the inv_stream channel and registers all advertised inventory /// - drains the inv_stream channel and registers all advertised inventory
pub fn poll_inventory(&mut self, cx: &mut Context<'_>) -> Result<(), BoxedStdError> { pub fn poll_inventory(&mut self, cx: &mut Context<'_>) -> Result<(), BoxError> {
while let Poll::Ready(_) = self.interval.poll_tick(cx) { while let Poll::Ready(_) = self.interval.poll_tick(cx) {
self.rotate(); self.rotate();
} }

View File

@ -29,7 +29,7 @@ use crate::{
external::InventoryHash, external::InventoryHash,
internal::{Request, Response}, internal::{Request, Response},
}, },
BoxedStdError, BoxError,
}; };
use super::{ use super::{
@ -90,12 +90,12 @@ where
/// Channel for passing ownership of tokio JoinHandles from PeerSet's background tasks /// Channel for passing ownership of tokio JoinHandles from PeerSet's background tasks
/// ///
/// The join handles passed into the PeerSet are used populate the `guards` member /// The join handles passed into the PeerSet are used populate the `guards` member
handle_rx: tokio::sync::oneshot::Receiver<Vec<JoinHandle<Result<(), BoxedStdError>>>>, handle_rx: tokio::sync::oneshot::Receiver<Vec<JoinHandle<Result<(), BoxError>>>>,
/// Unordered set of handles to background tasks associated with the `PeerSet` /// Unordered set of handles to background tasks associated with the `PeerSet`
/// ///
/// These guards are checked for errors as part of `poll_ready` which lets /// These guards are checked for errors as part of `poll_ready` which lets
/// the `PeerSet` propagate errors from background tasks back to the user /// the `PeerSet` propagate errors from background tasks back to the user
guards: futures::stream::FuturesUnordered<JoinHandle<Result<(), BoxedStdError>>>, guards: futures::stream::FuturesUnordered<JoinHandle<Result<(), BoxError>>>,
inventory_registry: InventoryRegistry, inventory_registry: InventoryRegistry,
} }
@ -103,8 +103,8 @@ impl<D> PeerSet<D>
where where
D: Discover<Key = SocketAddr> + Unpin, D: Discover<Key = SocketAddr> + Unpin,
D::Service: Service<Request, Response = Response> + Load, D::Service: Service<Request, Response = Response> + Load,
D::Error: Into<BoxedStdError>, D::Error: Into<BoxError>,
<D::Service as Service<Request>>::Error: Into<BoxedStdError> + 'static, <D::Service as Service<Request>>::Error: Into<BoxError> + 'static,
<D::Service as Service<Request>>::Future: Send + 'static, <D::Service as Service<Request>>::Future: Send + 'static,
<D::Service as Load>::Metric: Debug, <D::Service as Load>::Metric: Debug,
{ {
@ -112,7 +112,7 @@ where
pub fn new( pub fn new(
discover: D, discover: D,
demand_signal: mpsc::Sender<()>, demand_signal: mpsc::Sender<()>,
handle_rx: tokio::sync::oneshot::Receiver<Vec<JoinHandle<Result<(), BoxedStdError>>>>, handle_rx: tokio::sync::oneshot::Receiver<Vec<JoinHandle<Result<(), BoxError>>>>,
inv_stream: broadcast::Receiver<(InventoryHash, SocketAddr)>, inv_stream: broadcast::Receiver<(InventoryHash, SocketAddr)>,
) -> Self { ) -> Self {
Self { Self {
@ -128,7 +128,7 @@ where
} }
} }
fn poll_discover(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), BoxedStdError>> { fn poll_discover(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), BoxError>> {
use futures::ready; use futures::ready;
loop { loop {
match ready!(Pin::new(&mut self.discover).poll_discover(cx)).map_err(Into::into)? { match ready!(Pin::new(&mut self.discover).poll_discover(cx)).map_err(Into::into)? {
@ -179,7 +179,7 @@ where
}); });
} }
fn check_for_background_errors(&mut self, cx: &mut Context) -> Result<(), BoxedStdError> { fn check_for_background_errors(&mut self, cx: &mut Context) -> Result<(), BoxError> {
if self.guards.is_empty() { if self.guards.is_empty() {
match self.handle_rx.try_recv() { match self.handle_rx.try_recv() {
Ok(handles) => { Ok(handles) => {
@ -340,13 +340,13 @@ impl<D> Service<Request> for PeerSet<D>
where where
D: Discover<Key = SocketAddr> + Unpin, D: Discover<Key = SocketAddr> + Unpin,
D::Service: Service<Request, Response = Response> + Load, D::Service: Service<Request, Response = Response> + Load,
D::Error: Into<BoxedStdError>, D::Error: Into<BoxError>,
<D::Service as Service<Request>>::Error: Into<BoxedStdError> + 'static, <D::Service as Service<Request>>::Error: Into<BoxError> + 'static,
<D::Service as Service<Request>>::Future: Send + 'static, <D::Service as Service<Request>>::Future: Send + 'static,
<D::Service as Load>::Metric: Debug, <D::Service as Load>::Metric: Debug,
{ {
type Response = Response; type Response = Response;
type Error = BoxedStdError; type Error = BoxError;
type Future = type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>; Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

View File

@ -11,7 +11,7 @@ use abscissa_core::{Command, Options, Runnable};
use futures::{channel::oneshot, prelude::*}; use futures::{channel::oneshot, prelude::*};
use tower::{buffer::Buffer, Service, ServiceExt}; use tower::{buffer::Buffer, Service, ServiceExt};
use zebra_network::{AddressBook, BoxedStdError, Request, Response}; use zebra_network::{AddressBook, BoxError, Request, Response};
use crate::components::tokio::RuntimeRun; use crate::components::tokio::RuntimeRun;
use crate::prelude::*; use crate::prelude::*;
@ -33,7 +33,7 @@ struct SeedService {
impl Service<Request> for SeedService { impl Service<Request> for SeedService {
type Response = Response; type Response = Response;
type Error = BoxedStdError; type Error = BoxError;
type Future = type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>; Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;