Stop downloading unnecessary blocks in Zebra acceptance tests (#3072)
* Implement graceful shutdown for the peer set * Use the minimum lookahead limit in acceptance tests * Enable a doctest that compiles with newly public modules
This commit is contained in:
parent
9b17bbce3d
commit
375a997d2f
|
@ -6,10 +6,14 @@
|
|||
//! don't fit the async context well.
|
||||
|
||||
mod inbound;
|
||||
#[allow(missing_docs)]
|
||||
pub mod mempool;
|
||||
pub mod metrics;
|
||||
#[allow(missing_docs)]
|
||||
pub mod sync;
|
||||
#[allow(missing_docs)]
|
||||
pub mod tokio;
|
||||
#[allow(missing_docs)]
|
||||
pub mod tracing;
|
||||
|
||||
pub use inbound::Inbound;
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
//! The inbound service handles requests from Zebra's peers.
|
||||
//!
|
||||
//! It downloads and verifies gossiped blocks and mempool transactions,
|
||||
//! when Zebra is close to the chain tip.
|
||||
//!
|
||||
//! It also responds to peer requests for blocks, transactions, and peer addresses.
|
||||
|
||||
use std::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
|
@ -128,6 +135,10 @@ pub struct Inbound {
|
|||
}
|
||||
|
||||
impl Inbound {
|
||||
/// Create a new inbound service.
|
||||
///
|
||||
/// The address book and peer set use the newly created inbound service.
|
||||
/// So they are sent via the `network_setup` channel after initialization.
|
||||
pub fn new(
|
||||
network_setup: oneshot::Receiver<NetworkSetupData>,
|
||||
state: State,
|
||||
|
|
|
@ -42,7 +42,7 @@ use zebra_state::{ChainTipChange, TipAction};
|
|||
|
||||
use crate::components::sync::SyncStatus;
|
||||
|
||||
mod config;
|
||||
pub mod config;
|
||||
mod crawler;
|
||||
pub mod downloads;
|
||||
mod error;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
//!
|
||||
//! # Example
|
||||
//!
|
||||
//! ```compile_fail
|
||||
//! ```
|
||||
//! use zebrad::components::mempool;
|
||||
//! #
|
||||
//! # use zebra_chain::parameters::Network;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
//! The syncer downloads and verifies large numbers of blocks from peers to Zebra.
|
||||
//!
|
||||
//! It is used when Zebra is a long way behind the current chain tip.
|
||||
|
||||
use std::{collections::HashSet, pin::Pin, sync::Arc, time::Duration};
|
||||
|
||||
use color_eyre::eyre::{eyre, Report};
|
||||
|
@ -69,7 +73,12 @@ const BLOCK_DOWNLOAD_RETRY_LIMIT: usize = 2;
|
|||
/// Once these malicious blocks start failing validation, the syncer will cancel all
|
||||
/// the pending download and verify tasks, drop all the blocks, and start a new
|
||||
/// ObtainTips with a new set of peers.
|
||||
const MIN_LOOKAHEAD_LIMIT: usize = zebra_consensus::MAX_CHECKPOINT_HEIGHT_GAP * 2;
|
||||
pub const MIN_LOOKAHEAD_LIMIT: usize = zebra_consensus::MAX_CHECKPOINT_HEIGHT_GAP * 2;
|
||||
|
||||
/// The default for the user-specified lookahead limit.
|
||||
///
|
||||
/// See [`MIN_LOOKAHEAD_LIMIT`] for details.
|
||||
pub const DEFAULT_LOOKAHEAD_LIMIT: usize = zebra_consensus::MAX_CHECKPOINT_HEIGHT_GAP * 5;
|
||||
|
||||
/// Controls how long we wait for a tips response to return.
|
||||
///
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
//! Tracing and logging infrastructure for Zebra.
|
||||
|
||||
mod component;
|
||||
mod endpoint;
|
||||
mod flame;
|
||||
|
|
|
@ -8,11 +8,12 @@ use std::{net::SocketAddr, path::PathBuf};
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::components::mempool::Config as MempoolSection;
|
||||
use zebra_consensus::Config as ConsensusSection;
|
||||
use zebra_network::Config as NetworkSection;
|
||||
use zebra_state::Config as StateSection;
|
||||
|
||||
use crate::components::{mempool::Config as MempoolSection, sync};
|
||||
|
||||
/// Configuration for `zebrad`.
|
||||
///
|
||||
/// The `zebrad` config is a TOML-encoded version of this structure. The meaning
|
||||
|
@ -180,7 +181,7 @@ impl Default for SyncSection {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
max_concurrent_block_requests: 50,
|
||||
lookahead_limit: 2_000,
|
||||
lookahead_limit: sync::DEFAULT_LOOKAHEAD_LIMIT,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,11 +36,10 @@ extern crate tracing;
|
|||
/// parameterized by 'a), *not* that the object itself has 'static lifetime.
|
||||
pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
|
||||
|
||||
mod components;
|
||||
|
||||
pub mod application;
|
||||
pub mod async_ext;
|
||||
pub mod commands;
|
||||
pub mod components;
|
||||
pub mod config;
|
||||
pub mod prelude;
|
||||
pub mod sentry;
|
||||
|
|
|
@ -46,7 +46,10 @@ use zebra_test::{
|
|||
net::random_known_port,
|
||||
prelude::*,
|
||||
};
|
||||
use zebrad::config::ZebradConfig;
|
||||
use zebrad::{
|
||||
components::{mempool, sync},
|
||||
config::{SyncSection, ZebradConfig},
|
||||
};
|
||||
|
||||
/// The amount of time we wait after launching `zebrad`.
|
||||
///
|
||||
|
@ -54,18 +57,41 @@ use zebrad::config::ZebradConfig;
|
|||
/// metrics or tracing test failures in Windows CI.
|
||||
const LAUNCH_DELAY: Duration = Duration::from_secs(10);
|
||||
|
||||
/// Returns a config with:
|
||||
/// - a Zcash listener on an unused port on IPv4 localhost, and
|
||||
/// - an ephemeral state,
|
||||
/// - the minimum syncer lookahead limit, and
|
||||
/// - shorter task intervals, to improve test coverage.
|
||||
fn default_test_config() -> Result<ZebradConfig> {
|
||||
let auto_port_ipv4_local = zebra_network::Config {
|
||||
const TEST_DURATION: Duration = Duration::from_secs(30);
|
||||
|
||||
let network = zebra_network::Config {
|
||||
// The OS automatically chooses an unused port.
|
||||
listen_addr: "127.0.0.1:0".parse()?,
|
||||
crawl_new_peer_interval: Duration::from_secs(30),
|
||||
crawl_new_peer_interval: TEST_DURATION,
|
||||
..zebra_network::Config::default()
|
||||
};
|
||||
let local_ephemeral = ZebradConfig {
|
||||
|
||||
let sync = SyncSection {
|
||||
// Avoid downloading unnecessary blocks.
|
||||
lookahead_limit: sync::MIN_LOOKAHEAD_LIMIT,
|
||||
..SyncSection::default()
|
||||
};
|
||||
|
||||
let mempool = mempool::Config {
|
||||
eviction_memory_time: TEST_DURATION,
|
||||
..mempool::Config::default()
|
||||
};
|
||||
|
||||
let config = ZebradConfig {
|
||||
network,
|
||||
state: zebra_state::Config::ephemeral(),
|
||||
network: auto_port_ipv4_local,
|
||||
sync,
|
||||
mempool,
|
||||
..ZebradConfig::default()
|
||||
};
|
||||
Ok(local_ephemeral)
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
fn persistent_test_config() -> Result<ZebradConfig> {
|
||||
|
@ -949,6 +975,7 @@ fn sync_until(
|
|||
fn cached_mandatory_checkpoint_test_config() -> Result<ZebradConfig> {
|
||||
let mut config = persistent_test_config()?;
|
||||
config.state.cache_dir = "/zebrad-cache".into();
|
||||
config.sync.lookahead_limit = sync::DEFAULT_LOOKAHEAD_LIMIT;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue