From f01e5bb817a1c13aa864b7ed94274dd1834b97e9 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 14 Dec 2021 18:43:07 -0300 Subject: [PATCH] Add and use `debug_skip_parameter_preload` config option (#3197) * add and use a config option to skip groth16 parameters download * correct doc * enable parameters download in `sync_past_mandatory_checkpoint` test * change logging location * fix import * add argument to `create_cached_database_height()` Co-authored-by: teor --- zebra-consensus/src/chain.rs | 15 ++++++++++----- zebra-consensus/src/chain/tests.rs | 6 ++++-- zebra-consensus/src/config.rs | 3 +++ zebrad/src/commands/start.rs | 2 +- zebrad/src/components/inbound/tests.rs | 9 +++++++-- zebrad/tests/acceptance.rs | 24 +++++++++++++++++++----- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/zebra-consensus/src/chain.rs b/zebra-consensus/src/chain.rs index 58fe99b8c..e5bc38353 100644 --- a/zebra-consensus/src/chain.rs +++ b/zebra-consensus/src/chain.rs @@ -150,7 +150,8 @@ where } /// Initialize block and transaction verification services, -/// and pre-download Groth16 parameters if needed. +/// and pre-download Groth16 parameters if requested by the `debug_skip_parameter_preload` +/// config parameter and if the download is not already started. /// /// Returns a block verifier, transaction verifier, /// and the Groth16 parameter download task [`JoinHandle`]. @@ -185,6 +186,7 @@ pub async fn init( config: Config, network: Network, mut state_service: S, + debug_skip_parameter_preload: bool, ) -> ( Buffer, block::Hash, VerifyChainError>, Arc>, Buffer< @@ -204,10 +206,13 @@ where // The parameter download thread must be launched before initializing any verifiers. // Otherwise, the download might happen on the startup thread. - let groth16_download_handle = spawn_blocking(|| { - // The lazy static initializer does the download, if needed, - // and the file hash checks. - lazy_static::initialize(&crate::groth16::GROTH16_PARAMETERS); + let groth16_download_handle = spawn_blocking(move || { + if !debug_skip_parameter_preload { + // The lazy static initializer does the download, if needed, + // and the file hash checks. + lazy_static::initialize(&crate::groth16::GROTH16_PARAMETERS); + tracing::info!("Groth16 pre-download and check task finished"); + } }); // transaction verification diff --git a/zebra-consensus/src/chain/tests.rs b/zebra-consensus/src/chain/tests.rs index 5b2d0c617..ad3f7b41a 100644 --- a/zebra-consensus/src/chain/tests.rs +++ b/zebra-consensus/src/chain/tests.rs @@ -65,7 +65,7 @@ async fn verifiers_from_network( ) { let state_service = zs::init_test(network); let (chain_verifier, _transaction_verifier, _groth16_download_handle) = - crate::chain::init(Config::default(), network, state_service.clone()).await; + crate::chain::init(Config::default(), network, state_service.clone(), true).await; // We can drop the download task handle here, because: // - if the download task fails, the tests will panic, and @@ -136,10 +136,12 @@ static STATE_VERIFY_TRANSCRIPT_GENESIS: Lazy< async fn verify_checkpoint_test() -> Result<(), Report> { verify_checkpoint(Config { checkpoint_sync: true, + debug_skip_parameter_preload: true, }) .await?; verify_checkpoint(Config { checkpoint_sync: false, + debug_skip_parameter_preload: true, }) .await?; @@ -160,7 +162,7 @@ async fn verify_checkpoint(config: Config) -> Result<(), Report> { // // Download task panics and timeouts are propagated to the tests that use Groth16 verifiers. let (chain_verifier, _transaction_verifier, _groth16_download_handle) = - super::init(config.clone(), network, zs::init_test(network)).await; + super::init(config.clone(), network, zs::init_test(network), true).await; // Add a timeout layer let chain_verifier = diff --git a/zebra-consensus/src/config.rs b/zebra-consensus/src/config.rs index f766ee578..4cb51bf53 100644 --- a/zebra-consensus/src/config.rs +++ b/zebra-consensus/src/config.rs @@ -12,6 +12,8 @@ pub struct Config { /// Future versions of Zebra may change the mandatory checkpoint /// height. pub checkpoint_sync: bool, + /// Skip the pre-download of Groth16 parameters if this option is true. + pub debug_skip_parameter_preload: bool, } // we like our default configs to be explicit @@ -21,6 +23,7 @@ impl Default for Config { fn default() -> Self { Self { checkpoint_sync: false, + debug_skip_parameter_preload: false, } } } diff --git a/zebrad/src/commands/start.rs b/zebrad/src/commands/start.rs index eaa6f8300..1c4c30d37 100644 --- a/zebrad/src/commands/start.rs +++ b/zebrad/src/commands/start.rs @@ -106,6 +106,7 @@ impl StartCmd { config.consensus.clone(), config.network.network, state.clone(), + config.consensus.debug_skip_parameter_preload, ) .await; @@ -217,7 +218,6 @@ impl StartCmd { zebra_consensus::groth16::Groth16Parameters::failure_hint()) ); - info!("Groth16 pre-download and check task finished"); exit_when_task_finishes = false; Ok(()) } diff --git a/zebrad/src/components/inbound/tests.rs b/zebrad/src/components/inbound/tests.rs index ef5920d82..207170e09 100644 --- a/zebrad/src/components/inbound/tests.rs +++ b/zebrad/src/components/inbound/tests.rs @@ -591,8 +591,13 @@ async fn setup( // Download task panics and timeouts are propagated to the tests that use Groth16 verifiers. let (block_verifier, _transaction_verifier, _groth16_download_handle) = - zebra_consensus::chain::init(consensus_config.clone(), network, state_service.clone()) - .await; + zebra_consensus::chain::init( + consensus_config.clone(), + network, + state_service.clone(), + true, + ) + .await; let mut peer_set = MockService::build() .with_max_request_delay(MAX_PEER_SET_REQUEST_DELAY) diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index 6f90a809f..b1eff4803 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -83,11 +83,17 @@ fn default_test_config() -> Result { ..mempool::Config::default() }; + let consensus = zebra_consensus::Config { + debug_skip_parameter_preload: true, + ..zebra_consensus::Config::default() + }; + let config = ZebradConfig { network, state: zebra_state::Config::ephemeral(), sync, mempool, + consensus, ..ZebradConfig::default() }; @@ -990,6 +996,7 @@ fn cached_mandatory_checkpoint_test_config() -> Result { fn create_cached_database_height

( network: Network, height: Height, + debug_skip_parameter_preload: bool, test_child_predicate: impl Into>, ) -> Result<()> where @@ -1004,6 +1011,7 @@ where // TODO: add convenience methods? config.network.network = network; config.state.debug_stop_at_height = Some(height.0); + config.consensus.debug_skip_parameter_preload = debug_skip_parameter_preload; let dir = PathBuf::from("/zebrad-cache"); let mut child = dir @@ -1031,11 +1039,16 @@ where fn create_cached_database(network: Network) -> Result<()> { let height = network.mandatory_checkpoint_height(); - create_cached_database_height(network, height, |test_child: &mut TestChild| { - // make sure pre-cached databases finish before the mandatory checkpoint - test_child.expect_stdout_line_matches("CommitFinalized request")?; - Ok(()) - }) + create_cached_database_height( + network, + height, + true, + |test_child: &mut TestChild| { + // make sure pre-cached databases finish before the mandatory checkpoint + test_child.expect_stdout_line_matches("CommitFinalized request")?; + Ok(()) + }, + ) } fn sync_past_mandatory_checkpoint(network: Network) -> Result<()> { @@ -1043,6 +1056,7 @@ fn sync_past_mandatory_checkpoint(network: Network) -> Result<()> { create_cached_database_height( network, height.unwrap(), + false, |test_child: &mut TestChild| { // make sure cached database tests finish after the mandatory checkpoint, // using the non-finalized state (the checkpoint_sync config must be false)