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 <teor@riseup.net>
This commit is contained in:
parent
1835ec2c8d
commit
f01e5bb817
|
@ -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<S>(
|
|||
config: Config,
|
||||
network: Network,
|
||||
mut state_service: S,
|
||||
debug_skip_parameter_preload: bool,
|
||||
) -> (
|
||||
Buffer<BoxService<Arc<Block>, block::Hash, VerifyChainError>, Arc<Block>>,
|
||||
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
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -83,11 +83,17 @@ fn default_test_config() -> Result<ZebradConfig> {
|
|||
..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<ZebradConfig> {
|
|||
fn create_cached_database_height<P>(
|
||||
network: Network,
|
||||
height: Height,
|
||||
debug_skip_parameter_preload: bool,
|
||||
test_child_predicate: impl Into<Option<P>>,
|
||||
) -> 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<PathBuf>| {
|
||||
// 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<PathBuf>| {
|
||||
// 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<PathBuf>| {
|
||||
// make sure cached database tests finish after the mandatory checkpoint,
|
||||
// using the non-finalized state (the checkpoint_sync config must be false)
|
||||
|
|
Loading…
Reference in New Issue