zcash_client_backend: Add Orchard components to `ScannedBlock`

This commit is contained in:
Kris Nuttycombe 2023-10-27 15:15:54 -06:00
parent c0babd54cd
commit 9aec53eec9
4 changed files with 45 additions and 7 deletions

View File

@ -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

View File

@ -516,6 +516,8 @@ pub struct ScannedBlock<Nf> {
transactions: Vec<WalletTx<Nf>>,
sapling_nullifier_map: Vec<(TxId, u16, Vec<sapling::Nullifier>)>,
sapling_commitments: Vec<(sapling::Node, Retention<BlockHeight>)>,
orchard_nullifier_map: Vec<(TxId, u16, Vec<orchard::note::Nullifier>)>,
orchard_commitments: Vec<(orchard::note::NoteCommitment, Retention<BlockHeight>)>,
}
impl<Nf> ScannedBlock<Nf> {
@ -530,6 +532,8 @@ impl<Nf> ScannedBlock<Nf> {
transactions: Vec<WalletTx<Nf>>,
sapling_nullifier_map: Vec<(TxId, u16, Vec<sapling::Nullifier>)>,
sapling_commitments: Vec<(sapling::Node, Retention<BlockHeight>)>,
orchard_nullifier_map: Vec<(TxId, u16, Vec<orchard::note::Nullifier>)>,
orchard_commitments: Vec<(orchard::note::NoteCommitment, Retention<BlockHeight>)>,
) -> Self {
Self {
block_height,
@ -540,6 +544,8 @@ impl<Nf> ScannedBlock<Nf> {
transactions,
sapling_nullifier_map,
sapling_commitments,
orchard_nullifier_map,
orchard_commitments,
}
}
@ -589,10 +595,34 @@ impl<Nf> ScannedBlock<Nf> {
&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<BlockHeight>)> {
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<orchard::note::Nullifier>)] {
&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<BlockHeight>)] {
&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<BlockHeight>)>,
Vec<(orchard::note::NoteCommitment, Retention<BlockHeight>)>,
) {
(self.sapling_commitments, self.orchard_commitments)
}
/// Returns the [`BlockMetadata`] corresponding to the scanned block.

View File

@ -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
))
}

View File

@ -511,7 +511,8 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
}));
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.