Fixes test on Windows, applies suggestions from code review
This commit is contained in:
parent
28902fa397
commit
15feed173d
|
@ -173,6 +173,10 @@ pub trait Rpc {
|
|||
fn get_best_block_hash(&self) -> Result<GetBlockHash>;
|
||||
|
||||
/// 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<GetBlockHeightAndHash>;
|
||||
|
||||
|
@ -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]))
|
||||
|
|
|
@ -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<ChainTipBlock> {
|
||||
let db = self.db.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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) =
|
||||
|
|
Loading…
Reference in New Issue