Skip to content

Commit

Permalink
rpc: getter for nullifier queries by epoch index
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei committed Feb 5, 2025
1 parent cc6be74 commit 3e4d86d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use penumbra_sdk_sct::{component::clock::EpochRead, Nullifier};

#[async_trait]
pub trait NullifierRead: StateRead {
/// Returns the `TransactionId` if the nullifier has been spent; otherwise, returns None.
/// Returns the `TransactionId` if the nullifier has been spent in the current epoch;
/// Otherwise, returns None.
async fn get_lqt_spent_nullifier(&self, nullifier: Nullifier) -> Option<TransactionId> {
// Grab the ambient epoch index.
let epoch_index = self
Expand All @@ -29,6 +30,26 @@ pub trait NullifierRead: StateRead {

tx_id
}

/// Returns the `TransactionId` if the nullifier has been spent in a specific epoch;
/// Otherwise, returns None.
async fn get_lqt_spent_nullifier_by_epoch(
&self,
nullifier: Nullifier,
epoch_index: u64,
) -> Option<TransactionId> {
let nullifier_key = &state_key::lqt::v1::nullifier::key(epoch_index, &nullifier);

let tx_id: Option<TransactionId> = self
.nonverifiable_get(&nullifier_key.as_bytes())
.await
.expect(&format!(
"failed to retrieve key {} from non-verifiable storage",
nullifier_key,
));

tx_id
}
}

impl<T: StateRead + ?Sized> NullifierRead for T {}
Expand Down
4 changes: 3 additions & 1 deletion crates/core/component/funding/src/component/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ impl FundingService for Server {
};

// Perform a state nullifier lookup.
let maybe_tx_id = state.get_lqt_spent_nullifier(nullifier).await;
let maybe_tx_id = state
.get_lqt_spent_nullifier_by_epoch(nullifier, epoch_index)
.await;

if let Some(tx_id) = maybe_tx_id {
// Nullifier was spent and user has already voted.
Expand Down

0 comments on commit 3e4d86d

Please sign in to comment.