From 9aec53eec9cfb3cdbc488b8e1b6068f745439f45 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 27 Oct 2023 15:15:54 -0600 Subject: [PATCH] zcash_client_backend: Add Orchard components to `ScannedBlock` --- zcash_client_backend/CHANGELOG.md | 9 +++++-- zcash_client_backend/src/data_api.rs | 38 +++++++++++++++++++++++++--- zcash_client_backend/src/scanning.rs | 2 ++ zcash_client_sqlite/src/lib.rs | 3 ++- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index 1bd9f181a..1177a7f7c 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -12,8 +12,10 @@ and this library adheres to Rust's notion of - `BlockMetadata::orchard_tree_size`. - `TransparentInputSource` - `SaplingInputSource` - - `ScannedBlock::sapling_tree_size`. - - `ScannedBlock::orchard_tree_size`. + - `ScannedBlock::{ + sapling_tree_size, orchard_tree_size, orchard_nullifier_map, + orchard_commitments, into_commitments + }` - `wallet::propose_standard_transfer_to_address` - `wallet::input_selection::Proposal::from_parts` - `wallet::input_selection::SaplingInputs` @@ -164,6 +166,9 @@ and this library adheres to Rust's notion of removed without replacement as it was unused, and its functionality will be fully reproduced by `SaplingInputSource::select_spendable_sapling_notes` in a future change. +- `zcash_client_backend::data_api::ScannedBlock::into_sapling_commitments` has been + replaced by `into_commitments` which returns both Sapling and Orchard note commitments + and associated note commitment retention information for the block. ## [0.10.0] - 2023-09-25 diff --git a/zcash_client_backend/src/data_api.rs b/zcash_client_backend/src/data_api.rs index 06866b05e..740dd7350 100644 --- a/zcash_client_backend/src/data_api.rs +++ b/zcash_client_backend/src/data_api.rs @@ -516,6 +516,8 @@ pub struct ScannedBlock { transactions: Vec>, sapling_nullifier_map: Vec<(TxId, u16, Vec)>, sapling_commitments: Vec<(sapling::Node, Retention)>, + orchard_nullifier_map: Vec<(TxId, u16, Vec)>, + orchard_commitments: Vec<(orchard::note::NoteCommitment, Retention)>, } impl ScannedBlock { @@ -530,6 +532,8 @@ impl ScannedBlock { transactions: Vec>, sapling_nullifier_map: Vec<(TxId, u16, Vec)>, sapling_commitments: Vec<(sapling::Node, Retention)>, + orchard_nullifier_map: Vec<(TxId, u16, Vec)>, + orchard_commitments: Vec<(orchard::note::NoteCommitment, Retention)>, ) -> Self { Self { block_height, @@ -540,6 +544,8 @@ impl ScannedBlock { transactions, sapling_nullifier_map, sapling_commitments, + orchard_nullifier_map, + orchard_commitments, } } @@ -589,10 +595,34 @@ impl ScannedBlock { &self.sapling_commitments } - /// Consumes `self` and returns the list of Sapling note commitments associated with the - /// scanned block as an owned value. - pub fn into_sapling_commitments(self) -> Vec<(sapling::Node, Retention)> { - self.sapling_commitments + /// Returns the vector of Orchard nullifiers for each transaction in the block. + /// + /// The returned tuple is keyed by both transaction ID and the index of the transaction within + /// the block, so that either the txid or the combination of the block hash available from + /// [`Self::block_hash`] and returned transaction index may be used to uniquely identify the + /// transaction, depending upon the needs of the caller. + pub fn orchard_nullifier_map(&self) -> &[(TxId, u16, Vec)] { + &self.orchard_nullifier_map + } + + /// Returns the ordered list of Orchard note commitments to be added to the note commitment + /// tree. + pub fn orchard_commitments( + &self, + ) -> &[(orchard::note::NoteCommitment, Retention)] { + &self.orchard_commitments + } + + /// Consumes `self` and returns the lists of Sapling and Orchard note commitments associated + /// with the scanned block as an owned value. + #[allow(clippy::type_complexity)] + pub fn into_commitments( + self, + ) -> ( + Vec<(sapling::Node, Retention)>, + Vec<(orchard::note::NoteCommitment, Retention)>, + ) { + (self.sapling_commitments, self.orchard_commitments) } /// Returns the [`BlockMetadata`] corresponding to the scanned block. diff --git a/zcash_client_backend/src/scanning.rs b/zcash_client_backend/src/scanning.rs index 073056b76..5f778e487 100644 --- a/zcash_client_backend/src/scanning.rs +++ b/zcash_client_backend/src/scanning.rs @@ -644,6 +644,8 @@ pub(crate) fn scan_block_with_runner< wtxs, sapling_nullifier_map, sapling_note_commitments, + vec![], // FIXME: collect the Orchard nullifiers + vec![], // FIXME: collect the Orchard note commitments )) } diff --git a/zcash_client_sqlite/src/lib.rs b/zcash_client_sqlite/src/lib.rs index 596db68fc..39dae79fc 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -511,7 +511,8 @@ impl WalletWrite for WalletDb })); last_scanned_height = Some(block.height()); - sapling_commitments.extend(block.into_sapling_commitments().into_iter().map(Some)); + let (block_sapling_commitments, _) = block.into_commitments(); + sapling_commitments.extend(block_sapling_commitments.into_iter().map(Some)); } // Prune the nullifier map of entries we no longer need.