From 15feed173daced582340fdcdb4d4bb8cc9593a39 Mon Sep 17 00:00:00 2001 From: Arya Date: Wed, 19 Jun 2024 19:28:21 -0400 Subject: [PATCH] Fixes test on Windows, applies suggestions from code review --- zebra-rpc/src/methods.rs | 13 +++++++++++++ zebra-rpc/src/sync.rs | 6 ++++-- zebra-state/src/service/finalized_state/disk_db.rs | 8 ++++++-- zebrad/tests/acceptance.rs | 4 ++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/zebra-rpc/src/methods.rs b/zebra-rpc/src/methods.rs index b0f55867e..556b482a2 100644 --- a/zebra-rpc/src/methods.rs +++ b/zebra-rpc/src/methods.rs @@ -173,6 +173,10 @@ pub trait Rpc { fn get_best_block_hash(&self) -> Result; /// Returns the height and hash of the current best blockchain tip block, as a [`GetBlockHeightAndHash`] JSON struct. + /// + /// zcashd reference: none + /// method: post + /// tags: blockchain #[rpc(name = "getbestblockheightandhash")] fn get_best_block_height_and_hash(&self) -> Result; @@ -1560,6 +1564,15 @@ pub struct GetBlockHeightAndHash { pub hash: block::Hash, } +impl Default for GetBlockHeightAndHash { + fn default() -> Self { + Self { + height: block::Height::MIN, + hash: block::Hash([0; 32]), + } + } +} + impl Default for GetBlockHash { fn default() -> Self { GetBlockHash(block::Hash([0; 32])) diff --git a/zebra-rpc/src/sync.rs b/zebra-rpc/src/sync.rs index db7d7c30f..9f394bdea 100644 --- a/zebra-rpc/src/sync.rs +++ b/zebra-rpc/src/sync.rs @@ -166,6 +166,8 @@ impl TrustedChainSync { break false; } + // TODO: Check the finalized tip height and finalize blocks from the non-finalized state until + // all non-finalized state chain root previous block hashes match the finalized tip hash while self .non_finalized_state .best_chain_len() @@ -202,7 +204,6 @@ impl TrustedChainSync { } /// Tries to catch up to the primary db instance for an up-to-date view of finalized blocks. - // TODO: Use getblock RPC if it fails to catch up to primary? async fn try_catch_up_with_primary(&self) { let db = self.db.clone(); tokio::task::spawn_blocking(move || { @@ -232,7 +233,7 @@ impl TrustedChainSync { } } - /// Returns the current tip height and hash + /// Returns the current tip hash and the next height immediately after the current tip height async fn next_block_height_and_prev_hash(&self) -> (block::Height, block::Hash) { if let Some(tip) = self.non_finalized_state.best_tip() { Some(tip) @@ -251,6 +252,7 @@ impl TrustedChainSync { .unwrap_or((Height::MIN, GENESIS_PREVIOUS_BLOCK_HASH)) } + /// Reads the finalized tip block from the secondary db instance and converts it to a [`ChainTipBlock`]. async fn finalized_chain_tip_block(&self) -> Option { let db = self.db.clone(); tokio::task::spawn_blocking(move || { diff --git a/zebra-state/src/service/finalized_state/disk_db.rs b/zebra-state/src/service/finalized_state/disk_db.rs index 902c62488..0c25f6a27 100644 --- a/zebra-state/src/service/finalized_state/disk_db.rs +++ b/zebra-state/src/service/finalized_state/disk_db.rs @@ -839,9 +839,13 @@ impl DiskDb { .map(|cf_name| rocksdb::ColumnFamilyDescriptor::new(cf_name, db_options.clone())); let db_result = if read_only { - // TODO: Make this path configurable? + // Use a tempfile for the secondary instance cache directory + let secondary_config = Config { + ephemeral: true, + ..config.clone() + }; let secondary_path = - config.db_path("secondary_state", format_version_in_code.major, network); + secondary_config.db_path("secondary_state", format_version_in_code.major, network); let create_dir_result = std::fs::create_dir_all(&secondary_path); info!(?create_dir_result, "creating secondary db directory"); diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index ff7430319..f5119f32c 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -3419,11 +3419,15 @@ async fn trusted_chain_sync_handles_forks_correctly() -> Result<()> { tracing::info!("waiting for Zebra state cache to be opened"); + #[cfg(not(target_os = "windows"))] child.expect_stdout_line_matches(format!( "Opened Zebra state cache at {}", config.state.cache_dir.to_str().unwrap() ))?; + #[cfg(target_os = "windows")] + tokio::time::sleep(LAUNCH_DELAY).await; + tracing::info!("starting read state with syncer"); // Spawn a read state with the RPC syncer to check that it has the same best chain as Zebra let (_read_state, _latest_chain_tip, mut chain_tip_change, _sync_task) =