diff --git a/zebrad/src/components/inbound.rs b/zebrad/src/components/inbound.rs index 59bacabe..8646ce0b 100644 --- a/zebrad/src/components/inbound.rs +++ b/zebrad/src/components/inbound.rs @@ -10,7 +10,7 @@ use futures::{ stream::{Stream, TryStreamExt}, }; use tokio::sync::oneshot; -use tower::{buffer::Buffer, util::BoxService, Service, ServiceExt}; +use tower::{buffer::Buffer, timeout::Timeout, util::BoxService, Service, ServiceExt}; use zebra_network as zn; use zebra_state as zs; @@ -19,6 +19,9 @@ use zebra_chain::block::{self, Block}; use zebra_consensus::chain::VerifyChainError; use zebra_network::AddressBook; +// Re-use the syncer timeouts for consistency. +use super::sync::{BLOCK_DOWNLOAD_TIMEOUT, BLOCK_VERIFY_TIMEOUT}; + mod downloads; use downloads::Downloads; @@ -60,7 +63,7 @@ pub struct Inbound { address_book: Option>>, state: State, verifier: Verifier, - downloads: Option>>>, + downloads: Option, Timeout, State>>>>, } impl Inbound { @@ -96,12 +99,12 @@ impl Service for Inbound { use oneshot::error::TryRecvError; match rx.try_recv() { Ok((outbound, address_book)) => { - self.outbound = Some(outbound); + self.outbound = Some(outbound.clone()); self.address_book = Some(address_book); self.network_setup = None; self.downloads = Some(Box::pin(Downloads::new( - self.outbound.clone().unwrap(), - self.verifier.clone(), + Timeout::new(outbound, BLOCK_DOWNLOAD_TIMEOUT), + Timeout::new(self.verifier.clone(), BLOCK_VERIFY_TIMEOUT), self.state.clone(), ))); } diff --git a/zebrad/src/components/sync.rs b/zebrad/src/components/sync.rs index b82436c9..f44daf13 100644 --- a/zebrad/src/components/sync.rs +++ b/zebrad/src/components/sync.rs @@ -64,7 +64,7 @@ const TIPS_RESPONSE_TIMEOUT: Duration = Duration::from_secs(6); /// /// If this timeout is set too low, the syncer will sometimes get stuck in a /// failure loop. -const BLOCK_DOWNLOAD_TIMEOUT: Duration = Duration::from_secs(15); +pub(super) const BLOCK_DOWNLOAD_TIMEOUT: Duration = Duration::from_secs(15); /// Controls how long we wait for a block verify request to complete. /// @@ -92,7 +92,7 @@ const BLOCK_DOWNLOAD_TIMEOUT: Duration = Duration::from_secs(15); /// /// If this timeout is set too low, the syncer will sometimes get stuck in a /// failure loop. -const BLOCK_VERIFY_TIMEOUT: Duration = Duration::from_secs(180); +pub(super) const BLOCK_VERIFY_TIMEOUT: Duration = Duration::from_secs(180); /// Controls how long we wait to restart syncing after finishing a sync run. ///