Skip to content

Commit

Permalink
Merge pull request #1319 from Oscar-Pepper/zingo_sync_calculate_nulli…
Browse files Browse the repository at this point in the history
…fiers_and_positions

Zingo sync calculate nullifiers and positions
  • Loading branch information
fluidvanadium authored Aug 9, 2024
2 parents 31e38f0 + 04534d4 commit 8146f16
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 150 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions zingo-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ zcash_note_encryption.workspace = true
sapling-crypto.workspace = true
orchard.workspace = true

# Commitment tree
incrementalmerkletree.workspace = true

# Async
futures.workspace = true
tokio.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions zingo-sync/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use zcash_primitives::consensus::BlockHeight;

use tokio::sync::{mpsc::UnboundedSender, oneshot};

pub mod fetcher;
pub mod fetch;

/// Fetch requests are created and sent to the [`crate::client::fetcher::fetcher`] task when a connection to the server is required.
/// Fetch requests are created and sent to the [`crate::client::fetch::fetch`] task when a connection to the server is required.
///
/// Each variant includes a [`tokio::sync::oneshot::Sender`] for returning the fetched data to the requester.
#[derive(Debug)]
Expand All @@ -30,7 +30,7 @@ pub enum FetchRequest {

/// Gets the height of the blockchain from the server.
///
/// Requires [`crate::client::fetcher::fetcher`] to be running concurrently, connected via the `fetch_request` channel.
/// Requires [`crate::client::fetch::fetch`] to be running concurrently, connected via the `fetch_request` channel.
pub async fn get_chain_height(
fetch_request_sender: UnboundedSender<FetchRequest>,
) -> Result<BlockHeight, ()> {
Expand All @@ -44,7 +44,7 @@ pub async fn get_chain_height(
}
/// Gets the specified range of compact blocks from the server (end exclusive).
///
/// Requires [`crate::client::fetcher::fetcher`] to be running concurrently, connected via the `fetch_request` channel.
/// Requires [`crate::client::fetch::fetch`] to be running concurrently, connected via the `fetch_request` channel.
pub async fn get_compact_block_range(
fetch_request_sender: UnboundedSender<FetchRequest>,
block_range: Range<BlockHeight>,
Expand All @@ -59,7 +59,7 @@ pub async fn get_compact_block_range(
}
/// Gets the frontiers for a specified block height..
///
/// Requires [`crate::client::fetcher::fetcher`] to be running concurrently, connected via the `fetch_request` channel.
/// Requires [`crate::client::fetch::fetch`] to be running concurrently, connected via the `fetch_request` channel.
pub async fn get_frontiers(
fetch_request_sender: UnboundedSender<FetchRequest>,
block_height: BlockHeight,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::client::FetchRequest;
///
/// Allows all requests to the server to be handled from a single task for efficiency and also enables
/// request prioritisation for further performance enhancement
pub async fn fetcher(
pub async fn fetch(
mut fetch_request_receiver: UnboundedReceiver<FetchRequest>,
mut client: CompactTxStreamerClient<zingo_netutils::UnderlyingService>,
) -> Result<(), ()> {
Expand Down
2 changes: 1 addition & 1 deletion zingo-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pub mod client;
pub mod interface;
#[allow(missing_docs)]
pub mod primitives;
pub(crate) mod scanner;
pub(crate) mod scan;
pub mod sync;
39 changes: 21 additions & 18 deletions zingo-sync/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
use std::sync::{Arc, RwLock};

use getset::{Getters, MutGetters};
use getset::{CopyGetters, Getters, MutGetters};

use zcash_client_backend::{data_api::scanning::ScanRange, PoolType};
use zcash_primitives::transaction::TxId;
use zcash_client_backend::data_api::scanning::ScanRange;
use zcash_primitives::{block::BlockHash, consensus::BlockHeight, transaction::TxId};

/// Encapsulates the current state of sync
#[derive(Getters, MutGetters)]
Expand All @@ -29,37 +29,40 @@ impl Default for SyncState {
}
}

/// Unified general ID for any output
#[derive(Getters)]
#[getset(get = "pub")]
/// Output ID for a given pool type
#[derive(PartialEq, Eq, Hash, Clone, Copy, CopyGetters)]
#[getset(get_copy = "pub")]
pub struct OutputId {
/// ID of associated transaction
txid: TxId,
/// Index of output within the transactions bundle of the given pool type.
output_index: usize,
/// Pool type the output belongs to
pool: PoolType,
}

impl OutputId {
/// Creates new OutputId from parts
pub fn from_parts(txid: TxId, output_index: usize, pool: PoolType) -> Self {
OutputId {
txid,
output_index,
pool,
}
pub fn from_parts(txid: TxId, output_index: usize) -> Self {
OutputId { txid, output_index }
}
}

/// Wallet compact block data
#[allow(dead_code)]
#[derive(CopyGetters)]
#[getset(get_copy = "pub")]
pub struct WalletCompactBlock {
block_height: u64,
block_hash: Vec<u8>,
prev_hash: Vec<u8>,
time: Vec<u8>,
block_height: BlockHeight,
block_hash: BlockHash,
prev_hash: BlockHash,
time: u32,
#[getset(skip)]
txids: Vec<TxId>,
sapling_commitment_tree_size: u32,
orchard_commitment_tree_size: u32,
}

impl WalletCompactBlock {
pub fn txids(&self) -> &[TxId] {
&self.txids
}
}
Loading

0 comments on commit 8146f16

Please sign in to comment.