Skip to content

feat: add pagination to CheckNullifiersByPrefix#1191

Merged
SantiagoPittella merged 12 commits intonextfrom
santiagopittella-check-nullifiers-pagination
Sep 3, 2025
Merged

feat: add pagination to CheckNullifiersByPrefix#1191
SantiagoPittella merged 12 commits intonextfrom
santiagopittella-check-nullifiers-pagination

Conversation

@SantiagoPittella
Copy link
Collaborator

closes #1186

@SantiagoPittella SantiagoPittella force-pushed the santiagopittella-check-nullifiers-pagination branch from 84ed02b to 20c090b Compare September 1, 2025 21:00
@SantiagoPittella SantiagoPittella requested review from Mirko-von-Leipzig, bobbinth, drahnr and igamigo and removed request for bobbinth September 2, 2025 13:22
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left a few small comments inline.

@@ -30,9 +30,15 @@ Request proofs for a set of nullifiers.

## CheckNullifiersByPrefix
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking we should rename this to SyncNullifiers endpoint. This would be consistent with having all endpoints which may return "chunked" data to have a Sync prefix.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to have a Paged-prefix or similar, Sync implies what you do with the data, but imho it's more useful to describe the behavior of the function at hand.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should I opened an issue to discuss whether to use Sync, Paged or another prefix?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd still probably prefer with SyncNullifiers. One reason is that I'd prefer our endpoints to start with an action verb (though, we could of course do GetPagedNullifiers). The other reason I think it better describes what this endpoint is for - i.e., it is for synchronizing the state of the client with the state of the network (and it should be used together with other Sync* endpoints).

I would do the renaming in this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just pushed a commit renaming to SyncNullifiers.

Comment on lines +429 to +430
block_from: BlockNumber,
block_to: BlockNumber,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we use ranges here to make the inclusive/exclusive explicit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can either do this in this PR or as part of #1204 , wdyt?


Returns a list of nullifiers that match the specified prefixes and are recorded in the node.
Returns nullifier synchronization data for a set of prefixes within a given block range. This method allows
clients to efficiently track nullifier creation by retrieving only the nullifiers produced between two blocks.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
clients to efficiently track nullifier creation by retrieving only the nullifiers produced between two blocks.
clients to efficiently track nullifier creation by retrieving only the nullifiers produced within a specific range of blocks.

}

let nullifiers = self
let chain_tip = self.state.latest_block_num().await.as_u32();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I think probably makes more sense to add .as_u32() in the response segment.

Suggested change
let chain_tip = self.state.latest_block_num().await.as_u32();
let chain_tip = self.state.latest_block_num().await;

pub const MAX_PAYLOAD_BYTES: usize = 2 * 1024 * 1024; // 2 MB
pub const NULLIFIER_BYTES: usize = 32; // digest size
pub const ROW_OVERHEAD_BYTES: usize = NULLIFIER_BYTES + size_of::<i64>(); // 40 bytes
pub const ROW_LIMIT: usize = (MAX_PAYLOAD_BYTES / ROW_OVERHEAD_BYTES) + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know we've done this previously, but I would prefer calling this MAX_ROWS and then

// Request an additional row so we can determine whether this is the last page.
.limit(i64::try_from(MAX_ROWS + 1).expect("limit fits in i64"))

) -> Result<(Vec<NullifierInfo>, BlockNumber), DatabaseError> {
self.db
.select_nullifiers_by_prefix(prefix_len, nullifier_prefixes, block_num)
.select_nullifiers_by_prefix(prefix_len, nullifier_prefixes, block_from, block_to)
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of scope: I propose introducing a Range like type to simplify our API and reduce the need to document inclusive/exclusive boundaries.

Copy link
Contributor

@drahnr drahnr left a comment

Choose a reason for hiding this comment

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

Bar the open comments, looks good!

@SantiagoPittella @Mirko-von-Leipzig I'd defer the BlockRange proto / Range rust type refactor to a separate follow up PR / #1193 if this lands before that.

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you!

@SantiagoPittella SantiagoPittella merged commit 054fed7 into next Sep 3, 2025
6 checks passed
@SantiagoPittella SantiagoPittella deleted the santiagopittella-check-nullifiers-pagination branch September 3, 2025 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pagination to the CheckNullifiersByPrefix endpoint

4 participants