Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poc(scanner): add a populated state test for ZECpages viewing key #7916

Merged
merged 42 commits into from
Nov 8, 2023
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
743fcce
get started with the blockchain scanner poc
oxarbitrage Oct 17, 2023
65f5369
Merge remote-tracking branch 'origin/main' into issue7727
oxarbitrage Oct 17, 2023
d6600a9
rustfmt
oxarbitrage Oct 17, 2023
cb1a76a
fix the tests
oxarbitrage Oct 17, 2023
c0f7dbd
Reads blocks from db
arya2 Oct 17, 2023
c5c6c80
Adds conversion functions
arya2 Oct 18, 2023
de32a43
scans blocks and counts transactions
arya2 Oct 18, 2023
0d0117d
fix bug
arya2 Oct 18, 2023
cee1db6
split into 2 tests
oxarbitrage Oct 19, 2023
83e0542
add duplicated dependencies to deny.toml
oxarbitrage Oct 19, 2023
6913525
upgrade zebra-scanner version
oxarbitrage Oct 20, 2023
b384bf0
Merge remote-tracking branch 'origin/main' into issue7727
oxarbitrage Oct 20, 2023
8f1e6e1
try removing ecc duplicated dependencies
oxarbitrage Oct 20, 2023
b88e932
try fix deny.toml
oxarbitrage Oct 20, 2023
598cda6
remove unintended paste from deny.toml
oxarbitrage Oct 20, 2023
19dfaa7
remove duplicated code from the other test
oxarbitrage Oct 24, 2023
96bd5dd
Merge remote-tracking branch 'origin/main' into issue7727
oxarbitrage Oct 24, 2023
2ca1c93
remove strict version of `zcash_primitives` crate
oxarbitrage Oct 25, 2023
273fd95
change description
oxarbitrage Oct 25, 2023
b296769
remove feture
oxarbitrage Oct 25, 2023
51affba
remove tokio features
oxarbitrage Oct 25, 2023
5621836
change lib doc
oxarbitrage Oct 25, 2023
b455a37
add more documentation
oxarbitrage Oct 25, 2023
475a771
change expect
oxarbitrage Oct 25, 2023
3909795
do not use default in compact block creation
oxarbitrage Oct 25, 2023
25e205b
more docs
oxarbitrage Oct 25, 2023
550681e
add more checks to test
oxarbitrage Oct 25, 2023
6c83618
remove zebra-consensus dependency
oxarbitrage Oct 26, 2023
ad19e00
move all deps to dev-deps
oxarbitrage Oct 26, 2023
d10940e
change crate version
oxarbitrage Oct 26, 2023
6f8fe4c
Merge remote-tracking branch 'origin/main' into issue7727
oxarbitrage Oct 26, 2023
d8bd9ae
rename crate to zebra-scan
oxarbitrage Nov 1, 2023
b9d05c8
Merge remote-tracking branch 'origin/main' into issue7727
oxarbitrage Nov 1, 2023
9b08dea
lock file
oxarbitrage Nov 1, 2023
073495e
add test for zecpages populated state
oxarbitrage Nov 6, 2023
52958eb
scans all cached blocks for zecpages viewing key expecting Ok results.
arya2 Nov 7, 2023
133e461
use test blocks
arya2 Nov 7, 2023
46a5e36
fixes test
arya2 Nov 7, 2023
48a1d3a
fix expect messages
oxarbitrage Nov 8, 2023
d8af410
Merge branch 'main' into issue7903
teor2345 Nov 8, 2023
7d6ae23
Discard changes to Cargo.lock
teor2345 Nov 8, 2023
0fc1c1f
Discard changes to deny.toml
teor2345 Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions zebra-scan/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use std::sync::Arc;

use zcash_client_backend::{
data_api::BlockMetadata,
encoding::decode_extended_full_viewing_key,
proto::compact_formats::{
self as compact, ChainMetadata, CompactBlock, CompactSaplingOutput, CompactSaplingSpend,
Expand Down Expand Up @@ -183,36 +184,37 @@ async fn scanning_zecpages_from_populated_zebra_state() -> Result<()> {
.unwrap();

let account = AccountId::from(1);
let nf = Nullifier([7; 32]);

// Build a vector of viewing keys `vks` to scan for.
let fvk = efvk.fvk;
let ivk = fvk.vk.ivk();
let vks: Vec<(&AccountId, &SaplingIvk)> = vec![(&account, &ivk)];

let network = zebra_chain::parameters::Network::default();
arya2 marked this conversation as resolved.
Show resolved Hide resolved
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
let state_config = Default::default();

// Create a continuous chain of mainnet blocks from genesis
let blocks: Vec<Arc<Block>> = zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS
.iter()
.map(|(_height, block_bytes)| block_bytes.zcash_deserialize_into().unwrap())
.collect();

// Create a populated state service.
let (_state_service, read_only_state_service, latest_chain_tip, _chain_tip_change) =
zebra_state::populated_state(blocks.clone(), network).await;

zebra_state::spawn_init(state_config, network, zebra_chain::block::Height::MAX, 3000)
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved
.await?;
let db = read_only_state_service.db();

// use the tip as starting height
let mut height = latest_chain_tip.best_tip_height().unwrap();

let mut transactions_found = 0;
let mut transactions_scanned = 0;
let mut blocks_scanned = 0;
while let Some(block) = db.block(height.into()) {
// We fake the sapling tree size to 1 because we are not in Sapling heights.
let sapling_tree_size = 1;
let sapling_tree_size = db
.sapling_tree_by_hash_or_height(height.into())
.expect("should exist")
.count();

let previous_sapling_tree_size = if height.is_min() {
0
} else {
db.sapling_tree_by_hash_or_height(block.header.previous_block_hash.into())
.expect("should exist")
.count()
};

let orchard_tree_size = db
.orchard_tree_by_hash_or_height(height.into())
.expect("should exist")
Expand All @@ -227,20 +229,24 @@ async fn scanning_zecpages_from_populated_zebra_state() -> Result<()> {
.expect("position should fit in u32"),
};

arya2 marked this conversation as resolved.
Show resolved Hide resolved
let block_metadata = BlockMetadata::from_parts(
height.previous()?.0.into(),
BlockHash(block.header.previous_block_hash.0),
previous_sapling_tree_size
.try_into()
.expect("should fit in u32"),
);

let compact_block = block_to_compact(block, chain_metadata);

let res = scan_block(
scan_block(
&zcash_primitives::consensus::MainNetwork,
compact_block.clone(),
&vks[..],
&[(account, nf)],
None,
&[],
Some(&block_metadata),
)
.unwrap();

transactions_found += res.transactions().len();
transactions_scanned += compact_block.vtx.len();
blocks_scanned += 1;
.expect("should scan block successfully");

// scan backwards
if height.is_min() {
Expand All @@ -249,13 +255,6 @@ async fn scanning_zecpages_from_populated_zebra_state() -> Result<()> {
height = height.previous()?;
}

// make sure all blocks and transactions were scanned
assert_eq!(blocks_scanned, 11);
assert_eq!(transactions_scanned, 11);

// no relevant transactions should be found
assert_eq!(transactions_found, 0);

Ok(())
}

Expand Down
Loading