Add download and verify timeouts to the inbound service

This commit is contained in:
teor 2021-01-13 19:39:33 +10:00 committed by Deirdre Connolly
parent 973aec8ccc
commit fb76eb2e6b
2 changed files with 10 additions and 7 deletions

View File

@ -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<Arc<Mutex<zn::AddressBook>>>,
state: State,
verifier: Verifier,
downloads: Option<Pin<Box<Downloads<Outbound, Verifier, State>>>>,
downloads: Option<Pin<Box<Downloads<Timeout<Outbound>, Timeout<Verifier>, State>>>>,
}
impl Inbound {
@ -96,12 +99,12 @@ impl Service<zn::Request> 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(),
)));
}

View File

@ -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.
///