zcash_client_backend: Precompute IVKs in `scan_cached_blocks`
This commit is contained in:
parent
b33330f9ca
commit
2d3d5e8fe6
|
@ -26,6 +26,7 @@ and this library adheres to Rust's notion of
|
|||
- `zcash_client_backend::scanning`:
|
||||
- `ScanError`
|
||||
- `impl<K: ScanningKey> ScanningKey for &K`
|
||||
- `impl ScanningKey for (zip32::Scope, sapling::SaplingIvk, sapling::NullifierDerivingKey)`
|
||||
|
||||
### Changed
|
||||
- MSRV is now 1.65.0.
|
||||
|
|
|
@ -155,7 +155,7 @@ use crate::{
|
|||
data_api::{BlockMetadata, NullifierQuery, WalletWrite},
|
||||
proto::compact_formats::CompactBlock,
|
||||
scan::BatchRunner,
|
||||
scanning::{add_block_to_runner, check_continuity, scan_block_with_runner},
|
||||
scanning::{add_block_to_runner, check_continuity, scan_block_with_runner, ScanningKey},
|
||||
};
|
||||
|
||||
pub mod error;
|
||||
|
@ -254,6 +254,15 @@ where
|
|||
.iter()
|
||||
.filter_map(|(account, ufvk)| ufvk.sapling().map(move |k| (account, k)))
|
||||
.collect();
|
||||
// Precompute the IVKs instead of doing so per block.
|
||||
let ivks = dfvks
|
||||
.iter()
|
||||
.flat_map(|(account, dfvk)| {
|
||||
dfvk.to_sapling_keys()
|
||||
.into_iter()
|
||||
.map(|key| (*account, key))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Get the nullifiers for the unspent notes we are tracking
|
||||
let mut sapling_nullifiers = data_db
|
||||
|
@ -337,7 +346,7 @@ where
|
|||
let scanned_block = scan_block_with_runner(
|
||||
params,
|
||||
block,
|
||||
&dfvks,
|
||||
&ivks,
|
||||
&sapling_nullifiers,
|
||||
prior_block_metadata.as_ref(),
|
||||
Some(&mut batch_runner),
|
||||
|
|
|
@ -107,6 +107,21 @@ impl ScanningKey for DiversifiableFullViewingKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl ScanningKey for (Scope, SaplingIvk, sapling::NullifierDerivingKey) {
|
||||
type Scope = Scope;
|
||||
type SaplingNk = sapling::NullifierDerivingKey;
|
||||
type SaplingKeys = [(Self::Scope, SaplingIvk, Self::SaplingNk); 1];
|
||||
type Nf = sapling::Nullifier;
|
||||
|
||||
fn to_sapling_keys(&self) -> Self::SaplingKeys {
|
||||
[self.clone()]
|
||||
}
|
||||
|
||||
fn sapling_nf(key: &Self::SaplingNk, note: &sapling::Note, position: Position) -> Self::Nf {
|
||||
note.nf(key, position.into())
|
||||
}
|
||||
}
|
||||
|
||||
/// The [`ScanningKey`] implementation for [`SaplingIvk`]s.
|
||||
/// Nullifiers cannot be derived when scanning with these keys.
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue