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

services/horizon/internal/actions: populate default cursor value for history endpoints #5410

Merged
merged 7 commits into from
Aug 5, 2024

Conversation

tamirms
Copy link
Contributor

@tamirms tamirms commented Aug 5, 2024

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

The following endpoints use a TOID cursor value derived from the ledger sequence number:

/effects
/operations
/transactions
/ledgers
/trades
/payments

When a cursor is omitted the query to fetch the history data will look like:

select * from history_transactions order by id asc (if the order is asc which is by default))

or

select * from history_transactions order by id desc (if the order is desc)

However, the query performs better with a paging clause, eg:

select * from history_transactions where id >= 200076760811839488 order by id asc

This commit sets a default cursor value based on the paging order. If order is set to asc, we will use the oldest ledger -1 to create the default cursor value. Similarly, if the order is set to desc, we will use the latest ledger + 100 to create the default cursor value.

Known limitations

We obtain the oldest and latest ledger using ledgerState *ledger.State which is refreshed periodically. It is possible that ledgerState is out of date but that is why we add a buffer of 100 extra ledgers to ledgerState.CurrentStatus().HistoryLatest.

Copy link
Contributor

@urvisavla urvisavla left a comment

Choose a reason for hiding this comment

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

LGTM! Nice solution to addresses the issue of 503 timeouts for ASC. The same default cursor logic isn't required for DESC but I'm assuming there's no downside to using it for DESC as well.

@tamirms
Copy link
Contributor Author

tamirms commented Aug 5, 2024

@urvisavla good point regarding the order=desc behavior. I've decided to restore the original behavior for desc to limit the footprint of this PR

Copy link
Contributor

@sreuland sreuland 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, left one minor comment for consideration.

@tamirms tamirms merged commit 9b925b1 into stellar:master Aug 5, 2024
23 checks passed
@tamirms tamirms deleted the default-history-cursor branch August 5, 2024 20:18
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.

3 participants