feat: add pagination to CheckNullifiersByPrefix#1191
Conversation
84ed02b to
20c090b
Compare
bobbinth
left a comment
There was a problem hiding this comment.
Looks good! Thank you! I left a few small comments inline.
docs/src/user/rpc.md
Outdated
| @@ -30,9 +30,15 @@ Request proofs for a set of nullifiers. | |||
|
|
|||
| ## CheckNullifiersByPrefix | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Should I opened an issue to discuss whether to use Sync, Paged or another prefix?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Just pushed a commit renaming to SyncNullifiers.
| block_from: BlockNumber, | ||
| block_to: BlockNumber, |
There was a problem hiding this comment.
Could we use ranges here to make the inclusive/exclusive explicit?
There was a problem hiding this comment.
I can either do this in this PR or as part of #1204 , wdyt?
crates/store/README.md
Outdated
|
|
||
| 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. |
There was a problem hiding this comment.
| 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. |
crates/store/src/server/rpc_api.rs
Outdated
| } | ||
|
|
||
| let nullifiers = self | ||
| let chain_tip = self.state.latest_block_num().await.as_u32(); |
There was a problem hiding this comment.
Nit: I think probably makes more sense to add .as_u32() in the response segment.
| 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; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Out of scope: I propose introducing a Range like type to simplify our API and reduce the need to document inclusive/exclusive boundaries.
There was a problem hiding this comment.
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.
closes #1186