Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cursor in GetEventResponse #287

Merged
merged 7 commits into from
Sep 20, 2024
Merged

Add cursor in GetEventResponse #287

merged 7 commits into from
Sep 20, 2024

Conversation

psheth9
Copy link
Contributor

@psheth9 psheth9 commented Sep 9, 2024

What

Add endLedger in GetEventResponse

Why

  • This tells the client until what ledger events are being queried. e.g.: startLedger (inclusive) - endLedger (exclusive)
  • currently getEvents are capped by 10K LedgerScanLimit which means you can query events for 10K ledger at maximum for a given request.

Fixes: #289 and #118

@psheth9 psheth9 requested a review from a team September 9, 2024 20:03
Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

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

Shouldn't we add a cursor, instead? It will be more precise relative to the end ledger.

@psheth9
Copy link
Contributor Author

psheth9 commented Sep 9, 2024

I am more inclined towards endLedger for simplicity, cursor makes sense and is already there in eventInfo when we wan to paginate.

but this is for the case when no events are found for given filter and we need to tell clients that we looked thru startLedger to endLedger range so that client could just copy paste the endLedger to startLedger in follow up request.

We had a discussion in past around this here We got this suggestion to add endLedger from Product team/Jane.

@tamirms
Copy link
Contributor

tamirms commented Sep 10, 2024

I think I agree with @Shaptic in that it would be more useful to have a field in the response which indicates what cursor value should be used so we can continue the search. Assume the search window is [request.StartLedger, request.EndLedger], consider the following possibilities:

  1. there are more than 10k events in the search window and the response is full
  2. there are less than 10k events in the search window and the search window is below the latest ledger in the soroban-rpc db
  3. there are less than 10k events in the search window, however the search window exceeds the latest ledger in the soroban-rpc db

For case (1) you cannot use EndLedger in the response to continue the search. Instead, you must use the cursor value from the last event in the response.

For case (2) you can use EndLedger in the response to continue the search.

For case (3) you cannot use EndLedger in the response to continue the search and instead you should use the LatestLedger field from the response

@psheth9 psheth9 self-assigned this Sep 10, 2024
@psheth9 psheth9 added the api-change Any changes to existing API or addition of new API label Sep 10, 2024
@sreuland
Copy link
Contributor

driving by, agree with the suggestions for encapsulating the notion of 'next' into a cursor on the response, as @tamirms highlights the complexity for a client to use endLedger correctly. GetEventResponse could provide the pre-computed 'next' cursor based on internal endLedger/scanLimit chunking, and the caller can just paste into its next GetEventRequest:

type GetEventsResponse struct {
	Events       []EventInfo `json:"events"`
	LatestLedger uint32      `json:"latestLedger"`
        Pagination  *PaginationOptions `json:"next,omitempty"`
}

if 'next' is absent, implies there are no more events in rpc db to scan at that time.

@psheth9
Copy link
Contributor Author

psheth9 commented Sep 10, 2024

Thank you for all the inputs @tamirms @sreuland

okay so we talked about this in planning and agreed on using cursor instead of endLedger. Also now with this task #118 (move pagination-token/cursor to root level) it actually kinda makes more sense to not introduce more fields for less confusion.

Building up on aforementioned cases:

  1. there are more than 10k events in the search window and the response is full --> client can use cursor to paginate thru in next folllow up request. This is simple and same as existing flow. note: here cursor id is last populated event_id

  2. No events found for given search window --> we will set the cursor_id to startLedger + LedgerScanLimit so that client can make a follow up request to fetch events in next search window. note: here cursor id is represents the start of the next search window

so all in all we are using cursor_id as normal pagination token and also as end of the search window based on the use cases.

@janewang Do you have any feedback/suggestions on this?
I will make sure to update the getEvents doc to reflect all this.

@janewang
Copy link
Collaborator

janewang commented Sep 10, 2024

@mollykarcher
Copy link
Contributor

@janewang it will but it is not yet "breaking". See context here - #118 - but pagingToken will still work for now, and we'll remove it in p23. So lab should migrate to cursor when it can.

@janewang
Copy link
Collaborator

Got it, thank you @mollykarcher 👍

@psheth9 psheth9 changed the title Add endLedger in GetEventResponse Add cursor in GetEventResponse Sep 11, 2024
@psheth9 psheth9 requested review from tamirms and Shaptic September 18, 2024 19:48
CHANGELOG.md Outdated Show resolved Hide resolved
@psheth9 psheth9 requested a review from Shaptic September 20, 2024 01:48
@psheth9 psheth9 merged commit cae1740 into main Sep 20, 2024
19 checks passed
@psheth9 psheth9 deleted the add-endLedger-in-getEvents branch September 20, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-change Any changes to existing API or addition of new API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support of EndLedger in getEvents
6 participants