Skip to content

Commit

Permalink
Bound ScanningKeyOps by Send + Sync
Browse files Browse the repository at this point in the history
This change allows sharing instances of `ScanningKeys` between threads
by auto-implementing `Send` and `Sync` instead of `!Send` and `!Sync`
for `ScanningKeys`.
  • Loading branch information
upbqdn committed May 29, 2024
1 parent 976a4d2 commit 9669142
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
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
14 changes: 8 additions & 6 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>
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 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

0 comments on commit 9669142

Please sign in to comment.