Skip to content

Commit

Permalink
Updates callers of FinalizedState::{new, new_with_debug} to pass a …
Browse files Browse the repository at this point in the history
…bool to try enabling elasticsearch
  • Loading branch information
arya2 committed Jun 7, 2024
1 parent 281668b commit 33a3ccf
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 19 deletions.
16 changes: 14 additions & 2 deletions zebra-state/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -1928,7 +1933,14 @@ pub fn init_read_only(
ZebraDb,
tokio::sync::watch::Sender<NonFinalizedState>,
) {
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));

Expand Down
20 changes: 17 additions & 3 deletions zebra-state/src/service/finalized_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -177,6 +189,8 @@ impl FinalizedState {
.expect("elasticsearch transport builder should not fail");

Some(Elasticsearch::new(transport))
} else {
None
};

let db = ZebraDb::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions zebra-state/src/service/finalized_state/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion zebra-state/src/service/non_finalized_state/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<NonNegative>::fake_populated_pool();
finalized_state.set_finalized_value_pool(fake_value_pool);
Expand Down
16 changes: 8 additions & 8 deletions zebra-state/src/service/non_finalized_state/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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::<NonNegative>::fake_populated_pool();
Expand Down Expand Up @@ -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::<NonNegative>::fake_populated_pool();
Expand Down Expand Up @@ -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::<NonNegative>::fake_populated_pool();
Expand Down Expand Up @@ -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::<NonNegative>::fake_populated_pool();
Expand Down Expand Up @@ -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::<NonNegative>::fake_populated_pool();
Expand Down Expand Up @@ -426,7 +426,7 @@ fn history_tree_is_updated_for_network_upgrade(
&Config::ephemeral(),
&network,
#[cfg(feature = "elasticsearch")]
None,
false,
);

state
Expand Down Expand Up @@ -525,7 +525,7 @@ fn commitment_is_validated_for_network_upgrade(network: Network, network_upgrade
&Config::ephemeral(),
&network,
#[cfg(feature = "elasticsearch")]
None,
false,
);

state
Expand Down
2 changes: 1 addition & 1 deletion zebra-state/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 33a3ccf

Please sign in to comment.