Keep searchAfter cursors on their positions when sorting locally - #1646
Open
stefangutica wants to merge 4 commits into
Open
stefangutica wants to merge 4 commits into
stefangutica wants to merge 4 commits into
Conversation
|
k6 load testing comparison.
Legend: Avg - Average Response Time, Max - Maximum Response Time, 90 - 90th Percentile, 95 - 95th Percentile |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
claudiulataretu
approved these changes
Sep 25, 2026
radumojic
approved these changes
Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reasoning
sortElasticTransfersandsortElasticTransfersByTxsOrderfor transfers, andreorderAccountSentTransactionsByNoncefor account transactions and transfers.searchAfterholds the elastic sort values of that item. After a local sort, the last item is not always the last elastic hit, so continuing with itssearchAfterstarts the next page from an earlier position, and items already returned come back again.searchAfterwas set, andwithTxsOrder+miniBlockHashwithsearchAfterwas rejected with a 400. As a result, the first page and the next ones were ordered differently.order=ascthe first page came back descending while elastic returned the next ones ascending.Proposed Changes
SearchAfterUtils.sortKeepingSearchAfterPositions: it sorts the items and then puts eachsearchAfterback on its original position. When two items swap places, they also swap theirsearchAfter, so the last item always carries the cursor of the last elastic hit.searchAfter, andwithTxsOrder+miniBlockHash+searchAfteris accepted instead of returning 400.filter.order: ascending fororder=asc, descending otherwise (same default as before). ThewithTxsOrderexecution order is left as it is.searchAfter(the normal flow) is exact; continuing from an item in the middle of a page resumes from that position in elastic order.docs/swagger.md: on endpoints that reorder the results, only thesearchAfterof the last item is guaranteed to be consistent.How to test
npx jest --config ./src/test/jest-unit-config.json src/test/unit/utils/search.after.utils.spec.ts src/test/unit/services/transfers.spec.ts src/test/unit/services/transactions.spec.tsGET /accounts/:address/transfers?size=50, then request the next pages with thesearchAfterof the last item. There should be no duplicatedtxHashacross pages, and each page should be ordered the same way as the first one.GET /accounts/:address/transactions: sent transactions should be ordered by nonce on every page.order=asc: every page should be ascending, including the first one.GET /transfers?miniBlockHash=<hash>&withTxsOrder=true&searchAfter=<cursor>should return 200 instead of 400./docsand check the new disclaimer in the Pagination section.