From 1d3892e1dcb3311047406d5f0580f8d393234afc Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 18 Sep 2020 11:20:55 -0700 Subject: [PATCH] network: rename alias to BoxError This is shorter and consistent with Tower (which is why we use it in the first place). --- zebra-network/src/isolated.rs | 4 ++-- zebra-network/src/lib.rs | 2 +- zebra-network/src/peer/connection.rs | 6 ++--- zebra-network/src/peer/connector.rs | 6 ++--- zebra-network/src/peer/handshake.rs | 10 ++++---- zebra-network/src/peer_set/candidate_set.rs | 6 ++--- zebra-network/src/peer_set/initialize.rs | 24 +++++++++---------- .../src/peer_set/inventory_registry.rs | 4 ++-- zebra-network/src/peer_set/set.rs | 22 ++++++++--------- zebrad/src/commands/seed.rs | 4 ++-- 10 files changed, 43 insertions(+), 45 deletions(-) diff --git a/zebra-network/src/isolated.rs b/zebra-network/src/isolated.rs index 223d9b9a9..65320b5f9 100644 --- a/zebra-network/src/isolated.rs +++ b/zebra-network/src/isolated.rs @@ -14,7 +14,7 @@ use tower::{ 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 /// isolated from all other node state. @@ -67,7 +67,7 @@ struct Wrapper(peer::Client); impl Service for Wrapper { type Response = Response; - type Error = BoxedStdError; + type Error = BoxError; type Future = Pin> + Send + 'static>>; diff --git a/zebra-network/src/lib.rs b/zebra-network/src/lib.rs index 3924e7ff7..b7e09a239 100644 --- a/zebra-network/src/lib.rs +++ b/zebra-network/src/lib.rs @@ -53,7 +53,7 @@ extern crate bitflags; /// 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 /// parameterized by 'a), *not* that the object itself has 'static lifetime. -pub type BoxedStdError = Box; +pub type BoxError = Box; mod address_book; mod config; diff --git a/zebra-network/src/peer/connection.rs b/zebra-network/src/peer/connection.rs index ff4545c9e..690311422 100644 --- a/zebra-network/src/peer/connection.rs +++ b/zebra-network/src/peer/connection.rs @@ -39,7 +39,7 @@ use crate::{ external::{types::Nonce, InventoryHash, Message}, internal::{Request, Response}, }, - BoxedStdError, + BoxError, }; use super::{ClientRequest, ErrorSlot, PeerError, SharedPeerError}; @@ -184,8 +184,8 @@ pub struct Connection { impl Connection where - S: Service, - S::Error: Into, + S: Service, + S::Error: Into, Tx: Sink + Unpin, { /// Consume this `Connection` to form a spawnable future containing its event loop. diff --git a/zebra-network/src/peer/connector.rs b/zebra-network/src/peer/connector.rs index 064145928..46023b6a7 100644 --- a/zebra-network/src/peer/connector.rs +++ b/zebra-network/src/peer/connector.rs @@ -9,7 +9,7 @@ use futures::prelude::*; use tokio::net::TcpStream; use tower::{discover::Change, Service, ServiceExt}; -use crate::{BoxedStdError, Request, Response}; +use crate::{BoxError, Request, Response}; use super::{Client, Handshake}; @@ -36,11 +36,11 @@ impl Connector { impl Service for Connector where - S: Service + Clone + Send + 'static, + S: Service + Clone + Send + 'static, S::Future: Send, { type Response = Change; - type Error = BoxedStdError; + type Error = BoxError; type Future = Pin> + Send + 'static>>; diff --git a/zebra-network/src/peer/handshake.rs b/zebra-network/src/peer/handshake.rs index a1e6fd925..3e232b061 100644 --- a/zebra-network/src/peer/handshake.rs +++ b/zebra-network/src/peer/handshake.rs @@ -27,7 +27,7 @@ use crate::{ internal::{Request, Response}, }, types::MetaAddr, - BoxedStdError, Config, + BoxError, Config, }; use super::{Client, Connection, ErrorSlot, HandshakeError}; @@ -58,7 +58,7 @@ pub struct Builder { impl Builder where - S: Service + Clone + Send + 'static, + S: Service + Clone + Send + 'static, S::Future: Send, { /// Provide a config. Mandatory. @@ -151,7 +151,7 @@ where impl Handshake where - S: Service + Clone + Send + 'static, + S: Service + Clone + Send + 'static, S::Future: Send, { /// Create a builder that configures a [`Handshake`] service. @@ -173,11 +173,11 @@ where impl Service<(TcpStream, SocketAddr)> for Handshake where - S: Service + Clone + Send + 'static, + S: Service + Clone + Send + 'static, S::Future: Send, { type Response = Client; - type Error = BoxedStdError; + type Error = BoxError; type Future = Pin> + Send + 'static>>; diff --git a/zebra-network/src/peer_set/candidate_set.rs b/zebra-network/src/peer_set/candidate_set.rs index 5619ac11c..d161f78a5 100644 --- a/zebra-network/src/peer_set/candidate_set.rs +++ b/zebra-network/src/peer_set/candidate_set.rs @@ -5,7 +5,7 @@ use futures::stream::{FuturesUnordered, StreamExt}; use tower::{Service, ServiceExt}; 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. /// @@ -84,7 +84,7 @@ pub(super) struct CandidateSet { impl CandidateSet where - S: Service, + S: Service, S::Future: Send + 'static, { pub fn new(peer_set: Arc>, peer_service: S) -> CandidateSet { @@ -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 // we're actively fetching peers. Continue independently of whether we // actually receive any peers, but always ask the network for more. diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index a87819a23..b52487b67 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -28,7 +28,7 @@ use tower::{ use tower_load::{peak_ewma::PeakEwmaDiscover, NoInstrument}; use crate::{ - constants, peer, timestamp_collector::TimestampCollector, AddressBook, BoxedStdError, Config, + constants, peer, timestamp_collector::TimestampCollector, AddressBook, BoxError, Config, Request, Response, }; @@ -37,18 +37,18 @@ use zebra_chain::parameters::Network; use super::CandidateSet; use super::PeerSet; -type PeerChange = Result, BoxedStdError>; +type PeerChange = Result, BoxError>; /// Initialize a peer set with the given `config`, forwarding peer requests to the `inbound_service`. pub async fn init( config: Config, inbound_service: S, ) -> ( - Buffer, Request>, + Buffer, Request>, Arc>, ) where - S: Service + Clone + Send + 'static, + S: Service + Clone + Send + 'static, S::Future: Send + 'static, { let (address_book, timestamp_collector) = TimestampCollector::spawn(); @@ -169,10 +169,9 @@ async fn add_initial_peers( initial_peers: std::collections::HashSet, connector: S, mut tx: mpsc::Sender, -) -> Result<(), BoxedStdError> +) -> Result<(), BoxError> where - S: Service, Error = BoxedStdError> - + Clone, + S: Service, Error = BoxError> + Clone, S::Future: Send + 'static, { info!(?initial_peers, "Connecting to initial peer set"); @@ -194,9 +193,9 @@ async fn listen( addr: SocketAddr, mut handshaker: S, tx: mpsc::Sender, -) -> Result<(), BoxedStdError> +) -> Result<(), BoxError> 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, { let mut listener = TcpListener::bind(addr).await?; @@ -236,12 +235,11 @@ async fn crawl_and_dial( mut candidates: CandidateSet, mut connector: C, mut success_tx: mpsc::Sender, -) -> Result<(), BoxedStdError> +) -> Result<(), BoxError> where - C: Service, Error = BoxedStdError> - + Clone, + C: Service, Error = BoxError> + Clone, C::Future: Send + 'static, - S: Service, + S: Service, S::Future: Send + 'static, { use futures::{ diff --git a/zebra-network/src/peer_set/inventory_registry.rs b/zebra-network/src/peer_set/inventory_registry.rs index e7af48c01..da119b9f2 100644 --- a/zebra-network/src/peer_set/inventory_registry.rs +++ b/zebra-network/src/peer_set/inventory_registry.rs @@ -1,7 +1,7 @@ //! Inventory Registry Implementation //! //! [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 std::{ collections::{HashMap, HashSet}, @@ -59,7 +59,7 @@ impl InventoryRegistry { /// /// - rotates HashMaps based on interval events /// - 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) { self.rotate(); } diff --git a/zebra-network/src/peer_set/set.rs b/zebra-network/src/peer_set/set.rs index eb44f0d78..a5be4689c 100644 --- a/zebra-network/src/peer_set/set.rs +++ b/zebra-network/src/peer_set/set.rs @@ -29,7 +29,7 @@ use crate::{ external::InventoryHash, internal::{Request, Response}, }, - BoxedStdError, + BoxError, }; use super::{ @@ -90,12 +90,12 @@ where /// 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 - handle_rx: tokio::sync::oneshot::Receiver>>>, + handle_rx: tokio::sync::oneshot::Receiver>>>, /// Unordered set of handles to background tasks associated with the `PeerSet` /// /// These guards are checked for errors as part of `poll_ready` which lets /// the `PeerSet` propagate errors from background tasks back to the user - guards: futures::stream::FuturesUnordered>>, + guards: futures::stream::FuturesUnordered>>, inventory_registry: InventoryRegistry, } @@ -103,8 +103,8 @@ impl PeerSet where D: Discover + Unpin, D::Service: Service + Load, - D::Error: Into, - >::Error: Into + 'static, + D::Error: Into, + >::Error: Into + 'static, >::Future: Send + 'static, ::Metric: Debug, { @@ -112,7 +112,7 @@ where pub fn new( discover: D, demand_signal: mpsc::Sender<()>, - handle_rx: tokio::sync::oneshot::Receiver>>>, + handle_rx: tokio::sync::oneshot::Receiver>>>, inv_stream: broadcast::Receiver<(InventoryHash, SocketAddr)>, ) -> Self { Self { @@ -128,7 +128,7 @@ where } } - fn poll_discover(&mut self, cx: &mut Context<'_>) -> Poll> { + fn poll_discover(&mut self, cx: &mut Context<'_>) -> Poll> { use futures::ready; loop { 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() { match self.handle_rx.try_recv() { Ok(handles) => { @@ -340,13 +340,13 @@ impl Service for PeerSet where D: Discover + Unpin, D::Service: Service + Load, - D::Error: Into, - >::Error: Into + 'static, + D::Error: Into, + >::Error: Into + 'static, >::Future: Send + 'static, ::Metric: Debug, { type Response = Response; - type Error = BoxedStdError; + type Error = BoxError; type Future = Pin> + Send + 'static>>; diff --git a/zebrad/src/commands/seed.rs b/zebrad/src/commands/seed.rs index 101546530..379e676a0 100644 --- a/zebrad/src/commands/seed.rs +++ b/zebrad/src/commands/seed.rs @@ -11,7 +11,7 @@ use abscissa_core::{Command, Options, Runnable}; use futures::{channel::oneshot, prelude::*}; 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::prelude::*; @@ -33,7 +33,7 @@ struct SeedService { impl Service for SeedService { type Response = Response; - type Error = BoxedStdError; + type Error = BoxError; type Future = Pin> + Send + 'static>>;