services/horizon/internal/actions: populate default cursor value for history endpoints #5410
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Structure
otherwise).
services/friendbot
, orall
ordoc
if the changes are broad or impact manypackages.
Thoroughness
.md
files, etc... affected by this change). Take a look in the
docs
folder for a given service,like this one.
Release planning
needed with deprecations, added features, breaking changes, and DB schema changes.
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 thatledgerState
is out of date but that is why we add a buffer of 100 extra ledgers toledgerState.CurrentStatus().HistoryLatest
.