Skip to content

Commit

Permalink
Fixed build errors rebasing on changes from zcash#1192
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar-Pepper committed Mar 13, 2024
1 parent 853e64c commit 77d27a0
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 59 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions zcash_client_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ sapling.workspace = true
# - Sync engine
anyhow = { version = "1", optional = true }
futures-util = { version = "0.3", optional = true }
tokio = { version = "1.21.0", features = ["fs", "macros"] }

# - Note commitment trees
incrementalmerkletree.workspace = true
Expand Down
9 changes: 3 additions & 6 deletions zcash_client_backend/src/data_api/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@
use std::ops::Range;

use subtle::ConditionallySelectable;
use tokio::task::JoinHandle;
use zcash_primitives::consensus::{self, BlockHeight};

use crate::{
data_api::{NullifierQuery, WalletWrite},
data_api::{scanning::ScanRange, NullifierQuery, WalletWrite},
proto::compact_formats::CompactBlock,
scanning::{scan_block_with_runners, BatchRunners, Nullifiers, ScanningKeys},
};
Expand All @@ -157,9 +158,6 @@ use error::Error;

use super::WalletRead;

#[cfg(feature = "sync")]
use {crate::data_api::scanning::ScanRange, tokio::task::JoinHandle};

/// A struct containing metadata about a subtree root of the note commitment tree.
///
/// This stores the block height at which the leaf that completed the subtree was
Expand Down Expand Up @@ -360,7 +358,6 @@ pub trait BlockSource {
/// assert_eq!(block_cache.cached_blocks.lock().unwrap().len(), 0);
/// assert_eq!(block_cache.get_tip_height(None).unwrap(), None);
/// ```
#[cfg(feature = "sync")]
pub trait BlockCache: BlockSource + Send + Sync {
/// Retrieves contiguous compact blocks specified by the given `range` from the block cache.
///
Expand Down Expand Up @@ -616,7 +613,7 @@ pub mod testing {
Ok(Vec::new())
}

fn cache_tip(
fn get_tip_height(
&self,
_range: Option<&ScanRange>,
) -> Result<Option<BlockHeight>, Self::Error> {
Expand Down
8 changes: 4 additions & 4 deletions zcash_client_sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ subtle.workspace = true
orchard = { workspace = true, optional = true }
sapling.workspace = true

# - Sync engine
tokio = { version = "1.21.0", optional = true, features = ["fs", "macros"] }

# - Note commitment trees
incrementalmerkletree.workspace = true
shardtree = { workspace = true, features = ["legacy-api"] }
Expand All @@ -71,9 +74,6 @@ schemer-rusqlite = "0.2.2"
time = "0.3.22"
uuid = "1.1"

# - Sync engine
tokio.workspace = true

# Dependencies used internally:
# (Breaking upgrades to these are usually backwards-compatible, but check MSRVs.)
document-features.workspace = true
Expand Down Expand Up @@ -126,7 +126,7 @@ transparent-inputs = [
#! ### Experimental features

## Exposes unstable APIs. Their behaviour may change at any time.
unstable = ["zcash_client_backend/unstable"]
unstable = ["zcash_client_backend/unstable", "dep:tokio"]

[lib]
bench = false
11 changes: 7 additions & 4 deletions zcash_client_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,10 @@ impl BlockCache for FsBlockDb {
}

/// Returns the height of highest block known to the block cache.
fn cache_tip(&self, range: Option<&ScanRange>) -> Result<Option<BlockHeight>, Self::Error> {
fn get_tip_height(
&self,
range: Option<&ScanRange>,
) -> Result<Option<BlockHeight>, Self::Error> {
// TODO: Implement cache tip for a specified range.
if range.is_some() {
panic!("Cache tip for a specified range not currently implemented.")
Expand Down Expand Up @@ -1678,7 +1681,7 @@ mod tests {
.build();

// The BlockMeta DB starts off empty.
assert_eq!(st.cache().cache_tip(None).unwrap(), None);
assert_eq!(st.cache().get_tip_height(None).unwrap(), None);

// Generate some fake CompactBlocks.
let seed = [0u8; 32];
Expand All @@ -1697,7 +1700,7 @@ mod tests {
);

// The BlockMeta DB now sees blocks up to height 2.
assert_eq!(st.cache().cache_tip(None).unwrap(), Some(h2),);
assert_eq!(st.cache().get_tip_height(None).unwrap(), Some(h2),);
assert_eq!(
st.cache().find_block(h1).unwrap().map(|meta| meta.height),
Some(h1)
Expand All @@ -1710,7 +1713,7 @@ mod tests {

// Rewinding to height 1 should cause the metadata for height 2 to be deleted.
st.cache().truncate(h1).unwrap();
assert_eq!(st.cache().cache_tip(None).unwrap(), Some(h1),);
assert_eq!(st.cache().get_tip_height(None).unwrap(), Some(h1),);
assert_eq!(
st.cache().find_block(h1).unwrap().map(|meta| meta.height),
Some(h1)
Expand Down
16 changes: 10 additions & 6 deletions zcash_client_sqlite/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use zcash_primitives::{
use zcash_protocol::local_consensus::LocalNetwork;

use crate::{
chain::{self, init::init_cache_database},
chain::init::init_cache_database,
error::SqliteClientError,
wallet::{
commitment_tree, get_wallet_summary, init::init_wallet_db, sapling::tests::test_prover,
Expand Down Expand Up @@ -464,8 +464,7 @@ where
#[allow(dead_code)]
pub(crate) fn reset_latest_cached_block(&mut self) {
self.cache
.block_source()
.with_blocks::<_, Infallible>(None, None, |block: CompactBlock| {
.with_blocks(None, None, |block: CompactBlock| {
let chain_metadata = block.chain_metadata.unwrap();
self.latest_cached_block = Some(CachedBlock::at(
BlockHeight::from_u32(block.height.try_into().unwrap()),
Expand Down Expand Up @@ -1399,14 +1398,19 @@ impl BlockCache for TestBlockCache {
}

/// Returns the height of highest block known to the block cache.
fn cache_tip(&self, range: Option<&ScanRange>) -> Result<Option<BlockHeight>, Self::Error> {
fn get_tip_height(
&self,
range: Option<&ScanRange>,
) -> Result<Option<BlockHeight>, Self::Error> {
// TODO: Implement cache tip for a specified range.
if range.is_some() {
panic!("Cache tip for a specified range not currently implemented.")
}

chain::blockmetadb_get_max_cached_height(&self.db_cache.0.lock().unwrap())
.map_err(SqliteClientError::DbError)
// TODO: implement get_tip_height for TestBlockCache
// chain::blockmetadb_get_max_cached_height(&self.db_cache.0.lock().unwrap())
// .map_err(SqliteClientError::DbError)
todo!()
}

/// Inserts a compact block into the block cache.
Expand Down
Loading

0 comments on commit 77d27a0

Please sign in to comment.