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

zcash_client_backend: Allow sharing instances of ScanningKeys between threads #1400

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion zcash_client_backend/src/data_api/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ where
ParamsT: consensus::Parameters + Send + 'static,
BlockSourceT: BlockSource,
DbT: WalletWrite,
<DbT as WalletRead>::AccountId: ConditionallySelectable + Default + Send + 'static,
<DbT as WalletRead>::AccountId: ConditionallySelectable + Default + Send + Sync + 'static,
{
assert_eq!(from_height, from_state.block_height + 1);

Expand Down
16 changes: 9 additions & 7 deletions zcash_client_backend/src/scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use std::marker::PhantomData;
/// [`CompactSaplingOutput`]: crate::proto::compact_formats::CompactSaplingOutput
/// [`CompactOrchardAction`]: crate::proto::compact_formats::CompactOrchardAction
/// [`scan_block`]: crate::scanning::scan_block
pub trait ScanningKeyOps<D: Domain, AccountId, Nf> {
pub trait ScanningKeyOps<D: Domain, AccountId, Nf>: Send + Sync {
/// Prepare the key for use in batch trial decryption.
fn prepare(&self) -> D::IncomingViewingKey;

Expand All @@ -72,8 +72,8 @@ pub trait ScanningKeyOps<D: Domain, AccountId, Nf> {
fn nf(&self, note: &D::Note, note_position: Position) -> Option<Nf>;
}

impl<D: Domain, AccountId, Nf, K: ScanningKeyOps<D, AccountId, Nf>> ScanningKeyOps<D, AccountId, Nf>
for &K
impl<D: Domain, AccountId, Nf, K: ScanningKeyOps<D, AccountId, Nf> + Send + Sync>
ScanningKeyOps<D, AccountId, Nf> for &K
{
fn prepare(&self) -> D::IncomingViewingKey {
(*self).prepare()
Expand Down Expand Up @@ -120,7 +120,7 @@ pub struct ScanningKey<Ivk, Nk, AccountId> {
key_scope: Option<Scope>,
}

impl<AccountId> ScanningKeyOps<SaplingDomain, AccountId, sapling::Nullifier>
impl<AccountId: Send + Sync> ScanningKeyOps<SaplingDomain, AccountId, sapling::Nullifier>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this bound (repeated everywhere) avoidable if we add the equivalent bound on AccountId in ScanningKeyOps?

for ScanningKey<sapling::SaplingIvk, sapling::NullifierDerivingKey, AccountId>
{
fn prepare(&self) -> sapling::note_encryption::PreparedIncomingViewingKey {
Expand All @@ -140,7 +140,7 @@ impl<AccountId> ScanningKeyOps<SaplingDomain, AccountId, sapling::Nullifier>
}
}

impl<AccountId> ScanningKeyOps<SaplingDomain, AccountId, sapling::Nullifier>
impl<AccountId: Send + Sync> ScanningKeyOps<SaplingDomain, AccountId, sapling::Nullifier>
for (AccountId, SaplingIvk)
{
fn prepare(&self) -> sapling::note_encryption::PreparedIncomingViewingKey {
Expand All @@ -161,7 +161,7 @@ impl<AccountId> ScanningKeyOps<SaplingDomain, AccountId, sapling::Nullifier>
}

#[cfg(feature = "orchard")]
impl<AccountId> ScanningKeyOps<OrchardDomain, AccountId, orchard::note::Nullifier>
impl<AccountId: Send + Sync> ScanningKeyOps<OrchardDomain, AccountId, orchard::note::Nullifier>
for ScanningKey<orchard::keys::IncomingViewingKey, orchard::keys::FullViewingKey, AccountId>
{
fn prepare(&self) -> orchard::keys::PreparedIncomingViewingKey {
Expand Down Expand Up @@ -241,7 +241,9 @@ impl<AccountId, IvkTag> ScanningKeys<AccountId, IvkTag> {
}
}

impl<AccountId: Copy + Eq + Hash + 'static> ScanningKeys<AccountId, (AccountId, Scope)> {
impl<AccountId: Copy + Eq + Hash + 'static + Send + Sync>
ScanningKeys<AccountId, (AccountId, Scope)>
{
/// Constructs a [`ScanningKeys`] from an iterator of [`UnifiedFullViewingKey`]s,
/// along with the account identifiers corresponding to those UFVKs.
pub fn from_account_ufvks(
Expand Down
6 changes: 3 additions & 3 deletions zcash_client_backend/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where
CaT: BlockCache,
CaT::Error: std::error::Error + Send + Sync + 'static,
DbT: WalletWrite + WalletCommitmentTrees,
DbT::AccountId: ConditionallySelectable + Default + Send + 'static,
DbT::AccountId: ConditionallySelectable + Default + Send + Sync + 'static,
<DbT as WalletRead>::Error: std::error::Error + Send + Sync + 'static,
<DbT as WalletCommitmentTrees>::Error: std::error::Error + Send + Sync + 'static,
{
Expand Down Expand Up @@ -87,7 +87,7 @@ where
CaT: BlockCache,
CaT::Error: std::error::Error + Send + Sync + 'static,
DbT: WalletWrite,
DbT::AccountId: ConditionallySelectable + Default + Send + 'static,
DbT::AccountId: ConditionallySelectable + Default + Send + Sync + 'static,
DbT::Error: std::error::Error + Send + Sync + 'static,
{
// 3) Download chain tip metadata from lightwalletd
Expand Down Expand Up @@ -363,7 +363,7 @@ where
CaT: BlockCache,
CaT::Error: std::error::Error + Send + Sync + 'static,
DbT: WalletWrite,
DbT::AccountId: ConditionallySelectable + Default + Send + 'static,
DbT::AccountId: ConditionallySelectable + Default + Send + Sync + 'static,
DbT::Error: std::error::Error + Send + Sync + 'static,
{
info!("Scanning {}", scan_range);
Expand Down
Loading