Skip to content

Commit

Permalink
Expose raw database methods with shielded-scan
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Nov 30, 2023
1 parent 43af6c9 commit 61d4924
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion zebra-scan/src/storage/db/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ impl Storage {

/// Returns a handle to the `sapling_tx_ids` column family.
pub(crate) fn sapling_tx_ids_cf(&self) -> impl AsColumnFamilyRef + '_ {
self.db.cf_handle(SAPLING_TX_IDS).unwrap()
self.db
.cf_handle(SAPLING_TX_IDS)
.expect("column family was created when database was created")
}

// Writing batches
Expand Down
3 changes: 2 additions & 1 deletion zebra-state/src/service/finalized_state/zebra_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ pub mod metrics;
pub mod shielded;
pub mod transparent;

#[cfg(any(test, feature = "proptest-impl"))]
#[cfg(any(test, feature = "proptest-impl", feature = "shielded-scan"))]
// TODO: when the database is split out of zebra-state, always expose these methods.
pub mod arbitrary;

/// Wrapper struct to ensure high-level `zebra-state` database access goes through the correct API.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Arbitrary value generation and test harnesses for high-level typed database access.
#![allow(unused_imports)]

use std::ops::Deref;

use zebra_chain::{amount::NonNegative, block::Block, sprout, value_balance::ValueBalance};
Expand All @@ -21,13 +23,14 @@ impl Deref for ZebraDb {
impl ZebraDb {
/// Returns the inner database.
///
/// This is a test-only method, because it allows write access
/// This is a test-only and shielded-scan-only method, because it allows write access
/// and raw read access to the RocksDB instance.
pub fn db(&self) -> &DiskDb {
&self.db
}

/// Allow to set up a fake value pool in the database for testing purposes.
#[cfg(any(test, feature = "proptest-impl"))]
pub fn set_finalized_value_pool(&self, fake_value_pool: ValueBalance<NonNegative>) {
let mut batch = DiskWriteBatch::new();
let value_pool_cf = self.db().cf_handle("tip_chain_value_pool").unwrap();
Expand All @@ -38,6 +41,7 @@ impl ZebraDb {

/// Artificially prime the note commitment tree anchor sets with anchors
/// referenced in a block, for testing purposes _only_.
#[cfg(any(test, feature = "proptest-impl"))]
pub fn populate_with_anchors(&self, block: &Block) {
let mut batch = DiskWriteBatch::new();

Expand Down

0 comments on commit 61d4924

Please sign in to comment.