Add download and verify timeouts to the inbound service
This commit is contained in:
parent
973aec8ccc
commit
fb76eb2e6b
|
@ -10,7 +10,7 @@ use futures::{
|
||||||
stream::{Stream, TryStreamExt},
|
stream::{Stream, TryStreamExt},
|
||||||
};
|
};
|
||||||
use tokio::sync::oneshot;
|
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_network as zn;
|
||||||
use zebra_state as zs;
|
use zebra_state as zs;
|
||||||
|
@ -19,6 +19,9 @@ use zebra_chain::block::{self, Block};
|
||||||
use zebra_consensus::chain::VerifyChainError;
|
use zebra_consensus::chain::VerifyChainError;
|
||||||
use zebra_network::AddressBook;
|
use zebra_network::AddressBook;
|
||||||
|
|
||||||
|
// Re-use the syncer timeouts for consistency.
|
||||||
|
use super::sync::{BLOCK_DOWNLOAD_TIMEOUT, BLOCK_VERIFY_TIMEOUT};
|
||||||
|
|
||||||
mod downloads;
|
mod downloads;
|
||||||
use downloads::Downloads;
|
use downloads::Downloads;
|
||||||
|
|
||||||
|
@ -60,7 +63,7 @@ pub struct Inbound {
|
||||||
address_book: Option<Arc<Mutex<zn::AddressBook>>>,
|
address_book: Option<Arc<Mutex<zn::AddressBook>>>,
|
||||||
state: State,
|
state: State,
|
||||||
verifier: Verifier,
|
verifier: Verifier,
|
||||||
downloads: Option<Pin<Box<Downloads<Outbound, Verifier, State>>>>,
|
downloads: Option<Pin<Box<Downloads<Timeout<Outbound>, Timeout<Verifier>, State>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Inbound {
|
impl Inbound {
|
||||||
|
@ -96,12 +99,12 @@ impl Service<zn::Request> for Inbound {
|
||||||
use oneshot::error::TryRecvError;
|
use oneshot::error::TryRecvError;
|
||||||
match rx.try_recv() {
|
match rx.try_recv() {
|
||||||
Ok((outbound, address_book)) => {
|
Ok((outbound, address_book)) => {
|
||||||
self.outbound = Some(outbound);
|
self.outbound = Some(outbound.clone());
|
||||||
self.address_book = Some(address_book);
|
self.address_book = Some(address_book);
|
||||||
self.network_setup = None;
|
self.network_setup = None;
|
||||||
self.downloads = Some(Box::pin(Downloads::new(
|
self.downloads = Some(Box::pin(Downloads::new(
|
||||||
self.outbound.clone().unwrap(),
|
Timeout::new(outbound, BLOCK_DOWNLOAD_TIMEOUT),
|
||||||
self.verifier.clone(),
|
Timeout::new(self.verifier.clone(), BLOCK_VERIFY_TIMEOUT),
|
||||||
self.state.clone(),
|
self.state.clone(),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
/// If this timeout is set too low, the syncer will sometimes get stuck in a
|
||||||
/// failure loop.
|
/// 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.
|
/// 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
|
/// If this timeout is set too low, the syncer will sometimes get stuck in a
|
||||||
/// failure loop.
|
/// 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.
|
/// Controls how long we wait to restart syncing after finishing a sync run.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue