fix(events): order events consistently when querying #12623
Merged
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.
(This PR is against #12421 until it's merged)
In ChainIndexer and the existing master version of this same code, we do an
ORDER BY
when querying for events but then we do aslices.Sort
on the output, only sorting by epoch.ORDER BY
, in fact we do the reverse of what we ask for, so we should just do it thereORDER BY
relies on insertion order (_rowid_
) of the event entries, which should mostly be fine (aside from reverts perhaps), but we haveevent_index
that we use forlogIndex
on Eth output and we're not making use of that or properly ordering by it.Here's a list of eth events from epoch
4374648
, just listing their blockNumber, transactionIndex and logIndex:They should be nicely ordered. Here is the same but with this fix:
Note that in the process here we're going with
ASC
for all of the fields - epochs, messages, events and event entries.This is the query now for a from/to query of eth_getLogs:
And here's what the query plan looks like for that:
As long as we're hitting the height index first then we should be good.
Here's a larger range of epochs to see that it's doing ordering across epochs: