Skip to content

Conversation

@ASuciuX
Copy link
Collaborator

@ASuciuX ASuciuX commented Sep 12, 2025

[wip] to add prev_cursor

Fixes #2349 by adding cursor-based pagination for events. This provides stable iteration through results, unlike offset-based pagination where responses can shift as new events are added.

@github-actions
Copy link

Vercel deployment URL: https://stacks-blockchain-1xeisooxq-hirosystems.vercel.app 🚀

@codecov
Copy link

codecov bot commented Sep 12, 2025

Codecov Report

❌ Patch coverage is 97.72727% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/datastore/pg-store.ts 96.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@pradel
Copy link
Contributor

pradel commented Sep 23, 2025

@ASuciuX thanks for giving a shot at this pr. With this cursor based approach, will it be possible to got from event 1 (the first one that happened) to the last one? My use case would be to index all the events from the start to a specific block.

@ASuciuX
Copy link
Collaborator Author

ASuciuX commented Sep 23, 2025

Yes, with the cursor you can iterate forward from the very first event to the latest, page by page. It’s designed so you can start at genesis and stop at any specific block height.

@pradel
Copy link
Contributor

pradel commented Sep 23, 2025

Amazing, looking forward to be able to use this approach 🙏

@ASuciuX ASuciuX requested a review from rafaelcr September 24, 2025 09:45
@ASuciuX ASuciuX marked this pull request as ready for review September 30, 2025 12:19
// Validate cursor format if provided
if (cursor && !cursor.match(/^\d+-\d+-\d+$/)) {
throw new InvalidRequestError(
'Invalid cursor format. Expected format: blockHeight-txIndex-eventIndex',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of a block height, the cursor should use the index block hash so it is resistent to re-orgs. If you look at Matt's approach to cursors in the other endpoints, he uses this approach and also tests with different re-org scenarios.

This will change your queries a bit but you'll just need to transform from the index block hash into the block height before using your current filters.

@pradel
Copy link
Contributor

pradel commented Nov 3, 2025

@ASuciuX lmk if I can help to get the pr merged faster

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 block-based filtering to prevent pagination issues in endpoints

4 participants