From 33a3ccffe499ba1b894d04075b17efc8a23a9008 Mon Sep 17 00:00:00 2001 From: Arya Date: Thu, 6 Jun 2024 21:46:41 -0400 Subject: [PATCH] Updates callers of `FinalizedState::{new, new_with_debug}` to pass a bool to try enabling elasticsearch --- zebra-state/src/service.rs | 16 +++++++++++++-- zebra-state/src/service/finalized_state.rs | 20 ++++++++++++++++--- .../disk_format/tests/snapshot.rs | 2 +- .../src/service/finalized_state/tests/prop.rs | 4 ++-- .../zebra_db/block/tests/snapshot.rs | 2 +- .../service/non_finalized_state/tests/prop.rs | 2 +- .../non_finalized_state/tests/vectors.rs | 16 +++++++-------- zebra-state/src/tests/setup.rs | 2 +- 8 files changed, 45 insertions(+), 19 deletions(-) diff --git a/zebra-state/src/service.rs b/zebra-state/src/service.rs index d6b3a416021..0fbe8d8eaad 100644 --- a/zebra-state/src/service.rs +++ b/zebra-state/src/service.rs @@ -310,7 +310,12 @@ impl StateService { checkpoint_verify_concurrency_limit: usize, ) -> (Self, ReadStateService, LatestChainTip, ChainTipChange) { let timer = CodeTimer::start(); - let finalized_state = { FinalizedState::new(&config, network) }; + let finalized_state = FinalizedState::new( + &config, + network, + #[cfg(feature = "elasticsearch")] + true, + ); timer.finish(module_path!(), line!(), "opening finalized state database"); let timer = CodeTimer::start(); @@ -1928,7 +1933,14 @@ pub fn init_read_only( ZebraDb, tokio::sync::watch::Sender, ) { - let finalized_state = { FinalizedState::new_with_debug(&config, network, true, true) }; + let finalized_state = FinalizedState::new_with_debug( + &config, + network, + true, + #[cfg(feature = "elasticsearch")] + false, + true, + ); let (non_finalized_state_sender, non_finalized_state_receiver) = tokio::sync::watch::channel(NonFinalizedState::new(network)); diff --git a/zebra-state/src/service/finalized_state.rs b/zebra-state/src/service/finalized_state.rs index 26e7b62a1f7..f8c9bade5c1 100644 --- a/zebra-state/src/service/finalized_state.rs +++ b/zebra-state/src/service/finalized_state.rs @@ -139,8 +139,19 @@ pub struct FinalizedState { impl FinalizedState { /// Returns an on-disk database instance for `config`, `network`, and `elastic_db`. /// If there is no existing database, creates a new database on disk. - pub fn new(config: &Config, network: &Network) -> Self { - Self::new_with_debug(config, network, false, false) + pub fn new( + config: &Config, + network: &Network, + #[cfg(feature = "elasticsearch")] enable_elastic_db: bool, + ) -> Self { + Self::new_with_debug( + config, + network, + false, + #[cfg(feature = "elasticsearch")] + enable_elastic_db, + false, + ) } /// Returns an on-disk database instance with the supplied production and debug settings. @@ -151,10 +162,11 @@ impl FinalizedState { config: &Config, network: &Network, debug_skip_format_upgrades: bool, + #[cfg(feature = "elasticsearch")] enable_elastic_db: bool, read_only: bool, ) -> Self { #[cfg(feature = "elasticsearch")] - let elastic_db = { + let elastic_db = if enable_elastic_db { use elasticsearch::{ auth::Credentials::Basic, cert::CertificateValidation, @@ -177,6 +189,8 @@ impl FinalizedState { .expect("elasticsearch transport builder should not fail"); Some(Elasticsearch::new(transport)) + } else { + None }; let db = ZebraDb::new( diff --git a/zebra-state/src/service/finalized_state/disk_format/tests/snapshot.rs b/zebra-state/src/service/finalized_state/disk_format/tests/snapshot.rs index 14a8dd6c2a7..eb12cf41f1b 100644 --- a/zebra-state/src/service/finalized_state/disk_format/tests/snapshot.rs +++ b/zebra-state/src/service/finalized_state/disk_format/tests/snapshot.rs @@ -62,7 +62,7 @@ fn test_raw_rocksdb_column_families_with_network(network: Network) { &Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] - None, + false, ); // Snapshot the column family names diff --git a/zebra-state/src/service/finalized_state/tests/prop.rs b/zebra-state/src/service/finalized_state/tests/prop.rs index d48761795f5..7ff2c3ac91b 100644 --- a/zebra-state/src/service/finalized_state/tests/prop.rs +++ b/zebra-state/src/service/finalized_state/tests/prop.rs @@ -24,7 +24,7 @@ fn blocks_with_v5_transactions() -> Result<()> { .and_then(|v| v.parse().ok()) .unwrap_or(DEFAULT_PARTIAL_CHAIN_PROPTEST_CASES)), |((chain, count, network, _history_tree) in PreparedChain::default())| { - let mut state = FinalizedState::new(&Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] None); + let mut state = FinalizedState::new(&Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] false); let mut height = Height(0); // use `count` to minimize test failures, so they are easier to diagnose for block in chain.iter().take(count) { @@ -65,7 +65,7 @@ fn all_upgrades_and_wrong_commitments_with_fake_activation_heights() -> Result<( .unwrap_or(DEFAULT_PARTIAL_CHAIN_PROPTEST_CASES)), |((chain, _count, network, _history_tree) in PreparedChain::default().with_valid_commitments().no_shrink())| { - let mut state = FinalizedState::new(&Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] None); + let mut state = FinalizedState::new(&Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] false); let mut height = Height(0); let heartwood_height = NetworkUpgrade::Heartwood.activation_height(&network).unwrap(); let heartwood_height_plus1 = (heartwood_height + 1).unwrap(); diff --git a/zebra-state/src/service/finalized_state/zebra_db/block/tests/snapshot.rs b/zebra-state/src/service/finalized_state/zebra_db/block/tests/snapshot.rs index dbd0e7c1dae..c5f1ba371d5 100644 --- a/zebra-state/src/service/finalized_state/zebra_db/block/tests/snapshot.rs +++ b/zebra-state/src/service/finalized_state/zebra_db/block/tests/snapshot.rs @@ -169,7 +169,7 @@ fn test_block_and_transaction_data_with_network(network: Network) { &Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] - None, + false, ); // Assert that empty databases are the same, regardless of the network. diff --git a/zebra-state/src/service/non_finalized_state/tests/prop.rs b/zebra-state/src/service/non_finalized_state/tests/prop.rs index d4ef55344c0..68f7d77588b 100644 --- a/zebra-state/src/service/non_finalized_state/tests/prop.rs +++ b/zebra-state/src/service/non_finalized_state/tests/prop.rs @@ -479,7 +479,7 @@ fn rejection_restores_internal_state_genesis() -> Result<()> { } ))| { let mut state = NonFinalizedState::new(&network); - let finalized_state = FinalizedState::new(&Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] None); + let finalized_state = FinalizedState::new(&Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] false); let fake_value_pool = ValueBalance::::fake_populated_pool(); finalized_state.set_finalized_value_pool(fake_value_pool); diff --git a/zebra-state/src/service/non_finalized_state/tests/vectors.rs b/zebra-state/src/service/non_finalized_state/tests/vectors.rs index 6f908f080c0..b489d6f94f0 100644 --- a/zebra-state/src/service/non_finalized_state/tests/vectors.rs +++ b/zebra-state/src/service/non_finalized_state/tests/vectors.rs @@ -157,7 +157,7 @@ fn best_chain_wins_for_network(network: Network) -> Result<()> { &Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] - None, + false, ); state.commit_new_chain(block2.prepare(), &finalized_state)?; @@ -194,7 +194,7 @@ fn finalize_pops_from_best_chain_for_network(network: Network) -> Result<()> { &Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] - None, + false, ); let fake_value_pool = ValueBalance::::fake_populated_pool(); @@ -245,7 +245,7 @@ fn commit_block_extending_best_chain_doesnt_drop_worst_chains_for_network( &Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] - None, + false, ); let fake_value_pool = ValueBalance::::fake_populated_pool(); @@ -289,7 +289,7 @@ fn shorter_chain_can_be_best_chain_for_network(network: Network) -> Result<()> { &Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] - None, + false, ); let fake_value_pool = ValueBalance::::fake_populated_pool(); @@ -334,7 +334,7 @@ fn longer_chain_with_more_work_wins_for_network(network: Network) -> Result<()> &Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] - None, + false, ); let fake_value_pool = ValueBalance::::fake_populated_pool(); @@ -378,7 +378,7 @@ fn equal_length_goes_to_more_work_for_network(network: Network) -> Result<()> { &Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] - None, + false, ); let fake_value_pool = ValueBalance::::fake_populated_pool(); @@ -426,7 +426,7 @@ fn history_tree_is_updated_for_network_upgrade( &Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] - None, + false, ); state @@ -525,7 +525,7 @@ fn commitment_is_validated_for_network_upgrade(network: Network, network_upgrade &Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] - None, + false, ); state diff --git a/zebra-state/src/tests/setup.rs b/zebra-state/src/tests/setup.rs index d407726330e..cc53a0d7ee5 100644 --- a/zebra-state/src/tests/setup.rs +++ b/zebra-state/src/tests/setup.rs @@ -101,7 +101,7 @@ pub(crate) fn new_state_with_mainnet_genesis( // The tests that use this setup function also commit invalid blocks to the state. true, #[cfg(feature = "elasticsearch")] - None, + false, false, ); let non_finalized_state = NonFinalizedState::new(&network);