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

pindexer: flesh out dex-explorer indexer #4917

Merged
merged 1 commit into from
Nov 14, 2024
Merged

Conversation

cronokirby
Copy link
Contributor

Describe your changes

Closes #4914.

The internal architecture of the app view tries to make use of batch processing to the extent possible, which simplifies a lot of the logic.

The price charts remain unchanged, but I collapsed the two tables into one for performance and simplicity.

I also did not implement insertion of empty candles ; if there are gaps in the events, there will be gaps in the resulting database as well.

The main addition and where I spent most of my time on this is the addition of summaries of information over arbitrary windows. The idea behind the architecture here is that any time a change to liquidity, trade count, or a candle for a directed pair happens in a block, that block then gets a "snapshot" inserted, with the current price, liquidity, volume in that block, etc. At the end of this batch, the current summary is then updated, for each window, using those timed snapshots. And then an aggregate summary, across all pairs, is created from these summaries, for each window.

In order to price values under a common denom, assets are filtered based on having a current USDC price, backed by enough liquidity (the denom and liquidity amount are parameters to the component).

For testing, I'd recommend trying to run the app view against mainnet and testnet, and checking some sanity items like the price not seeming crazy, and matching in the summary across all windows, etc.

I think for testing we'll notice potential issues relatively quickly when dogfooding the explorer.

Checklist before requesting a review

  • I have added guiding text to explain how a reviewer should test these changes.

  • If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason:

    indexing only

The main addition are all the metrics needed for the summary page, and
the supporting infrastructure therein.

Arbitrary windows are now supported for summaries too.

Performance was also greatly improved by making use of batch processing,
making the supply app view the bottleneck now.
@cronokirby
Copy link
Contributor Author

cronokirby commented Nov 9, 2024

image
image

with these changes seems like it takes 24 minutes or so to sync to block 1.86 million, or about 1300 blocks a second or so.

The dex explorer app view is still a bottleneck for the process though, which we can see more easily now that the app views run in parallel.

@erwanor erwanor self-requested a review November 13, 2024 17:26
@conorsch conorsch self-requested a review November 13, 2024 18:37
Copy link
Contributor

@conorsch conorsch left a comment

Choose a reason for hiding this comment

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

Overall looks good. The performance improvements are significant! I've got a small concern about chain-specific logic in the indexing code, in the form of hardcoded asset ids, but willing to follow up on that when we've updated the interfaces like dex-explorer to work with the new schema.

crates/bin/pindexer/src/indexer_ext.rs Show resolved Hide resolved
crates/bin/pindexer/src/dex_ex/schema.sql Show resolved Hide resolved
Copy link

@VanishMax VanishMax left a comment

Choose a reason for hiding this comment

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

Can't wait to apply this to penumbra-zone/dex-explorer#133!

@cronokirby I see that the header from the explore page can be simply taken from dex_ex_aggregate_summary table. What about the list of pairs and their stats?

image

@hdevalence
Copy link
Member

@VanishMax That should (initially, possibly permanently) be configuration data (JSON) loaded into the explorer. There can be one for testnet and one for mainnet. The trading interface needs to express opinions about the list, at minimum because it needs to choose which asset is treated as the numeraire (e.g., using USDC as asset 2), so it seems simplest to start with a list specified in config data (so that there can be one for a mainnet and one for a testnet deployment).

@cronokirby
Copy link
Contributor Author

From there, you can query the dex_ex_pair_summary table with a particular start asset, end asset, and window, which should give you all the stats you need.

@conorsch conorsch merged commit 31fca7e into main Nov 14, 2024
15 checks passed
@conorsch conorsch deleted the 4914-dex-ex-indexing branch November 14, 2024 17:22
@conorsch conorsch mentioned this pull request Nov 19, 2024
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.

Dex Public Trading Insights
4 participants