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,
|
/// 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,
|
/// Returns a block verifier, transaction verifier,
|
||||||
/// and the Groth16 parameter download task [`JoinHandle`].
|
/// and the Groth16 parameter download task [`JoinHandle`].
|
||||||
|
@ -185,6 +186,7 @@ pub async fn init<S>(
|
||||||
config: Config,
|
config: Config,
|
||||||
network: Network,
|
network: Network,
|
||||||
mut state_service: S,
|
mut state_service: S,
|
||||||
|
debug_skip_parameter_preload: bool,
|
||||||
) -> (
|
) -> (
|
||||||
Buffer<BoxService<Arc<Block>, block::Hash, VerifyChainError>, Arc<Block>>,
|
Buffer<BoxService<Arc<Block>, block::Hash, VerifyChainError>, Arc<Block>>,
|
||||||
Buffer<
|
Buffer<
|
||||||
|
@ -204,10 +206,13 @@ where
|
||||||
|
|
||||||
// The parameter download thread must be launched before initializing any verifiers.
|
// The parameter download thread must be launched before initializing any verifiers.
|
||||||
// Otherwise, the download might happen on the startup thread.
|
// Otherwise, the download might happen on the startup thread.
|
||||||
let groth16_download_handle = spawn_blocking(|| {
|
let groth16_download_handle = spawn_blocking(move || {
|
||||||
// The lazy static initializer does the download, if needed,
|
if !debug_skip_parameter_preload {
|
||||||
// and the file hash checks.
|
// The lazy static initializer does the download, if needed,
|
||||||
lazy_static::initialize(&crate::groth16::GROTH16_PARAMETERS);
|
// and the file hash checks.
|
||||||
|
lazy_static::initialize(&crate::groth16::GROTH16_PARAMETERS);
|
||||||
|
tracing::info!("Groth16 pre-download and check task finished");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// transaction verification
|
// transaction verification
|
||||||
|
|
|
@ -65,7 +65,7 @@ async fn verifiers_from_network(
|
||||||
) {
|
) {
|
||||||
let state_service = zs::init_test(network);
|
let state_service = zs::init_test(network);
|
||||||
let (chain_verifier, _transaction_verifier, _groth16_download_handle) =
|
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:
|
// We can drop the download task handle here, because:
|
||||||
// - if the download task fails, the tests will panic, and
|
// - 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> {
|
async fn verify_checkpoint_test() -> Result<(), Report> {
|
||||||
verify_checkpoint(Config {
|
verify_checkpoint(Config {
|
||||||
checkpoint_sync: true,
|
checkpoint_sync: true,
|
||||||
|
debug_skip_parameter_preload: true,
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
verify_checkpoint(Config {
|
verify_checkpoint(Config {
|
||||||
checkpoint_sync: false,
|
checkpoint_sync: false,
|
||||||
|
debug_skip_parameter_preload: true,
|
||||||
})
|
})
|
||||||
.await?;
|
.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.
|
// Download task panics and timeouts are propagated to the tests that use Groth16 verifiers.
|
||||||
let (chain_verifier, _transaction_verifier, _groth16_download_handle) =
|
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
|
// Add a timeout layer
|
||||||
let chain_verifier =
|
let chain_verifier =
|
||||||
|
|
|
@ -12,6 +12,8 @@ pub struct Config {
|
||||||
/// Future versions of Zebra may change the mandatory checkpoint
|
/// Future versions of Zebra may change the mandatory checkpoint
|
||||||
/// height.
|
/// height.
|
||||||
pub checkpoint_sync: bool,
|
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
|
// we like our default configs to be explicit
|
||||||
|
@ -21,6 +23,7 @@ impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
checkpoint_sync: false,
|
checkpoint_sync: false,
|
||||||
|
debug_skip_parameter_preload: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,7 @@ impl StartCmd {
|
||||||
config.consensus.clone(),
|
config.consensus.clone(),
|
||||||
config.network.network,
|
config.network.network,
|
||||||
state.clone(),
|
state.clone(),
|
||||||
|
config.consensus.debug_skip_parameter_preload,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -217,7 +218,6 @@ impl StartCmd {
|
||||||
zebra_consensus::groth16::Groth16Parameters::failure_hint())
|
zebra_consensus::groth16::Groth16Parameters::failure_hint())
|
||||||
);
|
);
|
||||||
|
|
||||||
info!("Groth16 pre-download and check task finished");
|
|
||||||
exit_when_task_finishes = false;
|
exit_when_task_finishes = false;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -591,8 +591,13 @@ async fn setup(
|
||||||
|
|
||||||
// Download task panics and timeouts are propagated to the tests that use Groth16 verifiers.
|
// Download task panics and timeouts are propagated to the tests that use Groth16 verifiers.
|
||||||
let (block_verifier, _transaction_verifier, _groth16_download_handle) =
|
let (block_verifier, _transaction_verifier, _groth16_download_handle) =
|
||||||
zebra_consensus::chain::init(consensus_config.clone(), network, state_service.clone())
|
zebra_consensus::chain::init(
|
||||||
.await;
|
consensus_config.clone(),
|
||||||
|
network,
|
||||||
|
state_service.clone(),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
let mut peer_set = MockService::build()
|
let mut peer_set = MockService::build()
|
||||||
.with_max_request_delay(MAX_PEER_SET_REQUEST_DELAY)
|
.with_max_request_delay(MAX_PEER_SET_REQUEST_DELAY)
|
||||||
|
|
|
@ -83,11 +83,17 @@ fn default_test_config() -> Result<ZebradConfig> {
|
||||||
..mempool::Config::default()
|
..mempool::Config::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let consensus = zebra_consensus::Config {
|
||||||
|
debug_skip_parameter_preload: true,
|
||||||
|
..zebra_consensus::Config::default()
|
||||||
|
};
|
||||||
|
|
||||||
let config = ZebradConfig {
|
let config = ZebradConfig {
|
||||||
network,
|
network,
|
||||||
state: zebra_state::Config::ephemeral(),
|
state: zebra_state::Config::ephemeral(),
|
||||||
sync,
|
sync,
|
||||||
mempool,
|
mempool,
|
||||||
|
consensus,
|
||||||
..ZebradConfig::default()
|
..ZebradConfig::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -990,6 +996,7 @@ fn cached_mandatory_checkpoint_test_config() -> Result<ZebradConfig> {
|
||||||
fn create_cached_database_height<P>(
|
fn create_cached_database_height<P>(
|
||||||
network: Network,
|
network: Network,
|
||||||
height: Height,
|
height: Height,
|
||||||
|
debug_skip_parameter_preload: bool,
|
||||||
test_child_predicate: impl Into<Option<P>>,
|
test_child_predicate: impl Into<Option<P>>,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
|
@ -1004,6 +1011,7 @@ where
|
||||||
// TODO: add convenience methods?
|
// TODO: add convenience methods?
|
||||||
config.network.network = network;
|
config.network.network = network;
|
||||||
config.state.debug_stop_at_height = Some(height.0);
|
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 dir = PathBuf::from("/zebrad-cache");
|
||||||
let mut child = dir
|
let mut child = dir
|
||||||
|
@ -1031,11 +1039,16 @@ where
|
||||||
|
|
||||||
fn create_cached_database(network: Network) -> Result<()> {
|
fn create_cached_database(network: Network) -> Result<()> {
|
||||||
let height = network.mandatory_checkpoint_height();
|
let height = network.mandatory_checkpoint_height();
|
||||||
create_cached_database_height(network, height, |test_child: &mut TestChild<PathBuf>| {
|
create_cached_database_height(
|
||||||
// make sure pre-cached databases finish before the mandatory checkpoint
|
network,
|
||||||
test_child.expect_stdout_line_matches("CommitFinalized request")?;
|
height,
|
||||||
Ok(())
|
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<()> {
|
fn sync_past_mandatory_checkpoint(network: Network) -> Result<()> {
|
||||||
|
@ -1043,6 +1056,7 @@ fn sync_past_mandatory_checkpoint(network: Network) -> Result<()> {
|
||||||
create_cached_database_height(
|
create_cached_database_height(
|
||||||
network,
|
network,
|
||||||
height.unwrap(),
|
height.unwrap(),
|
||||||
|
false,
|
||||||
|test_child: &mut TestChild<PathBuf>| {
|
|test_child: &mut TestChild<PathBuf>| {
|
||||||
// make sure cached database tests finish after the mandatory checkpoint,
|
// make sure cached database tests finish after the mandatory checkpoint,
|
||||||
// using the non-finalized state (the checkpoint_sync config must be false)
|
// using the non-finalized state (the checkpoint_sync config must be false)
|
||||||
|
|
Loading…
Reference in New Issue