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(dex_ex): index batch swap execution traces #4990

Merged
merged 5 commits into from
Jan 17, 2025

Conversation

erwanor
Copy link
Member

@erwanor erwanor commented Jan 16, 2025

Describe your changes

This PR adds a dex_ex_batch_swap_traces table that tracks batch swap execution traces.

We do not (yet) track individual position ids for each subtrace hops, so this is left empty.

Notably, the schema contains a price float, but no input/output amount floats for now. This is good to have, but we can add it later and it's not immediately useful to the intended consumer of this data.

The schema:

-- This table tracks individual execution traces for a directed batch swap.
CREATE TABLE IF NOT EXISTS dex_ex_batch_swap_traces (
  -- Primary key
  rowid SERIAL PRIMARY KEY,

  -- The height of the block the batch swap was included in.
  height INTEGER NOT NULL,
  -- The time the batch swap was included in a block.
  time TIMESTAMPTZ NOT NULL,

  -- The amount of asset 1 consumed by the micro execution in raw denom.
  input NUMERIC(39) NOT NULL,
  -- The amount of asset 2 produced by the micro execution in raw denom.
  output NUMERIC(39) NOT NULL,

  -- The amount of asset 1 consumed by the macro execution.
  batch_input NUMERIC(39) NOT NULL,
  -- The amount of asset 2 produced by the macro execution.
  batch_output NUMERIC(39) NOT NULL,
  -- The price (output/input) as a float
  price_float DOUBLE PRECISION NOT NULL,


  -- The directed start asset of the batch swap.
  asset_start BYTEA NOT NULL,
  -- The directed end asset of the batch swap.
  asset_end BYTEA NOT NULL,

  -- Each hop in the list contains an asset id.
  asset_hops BYTEA[] NOT NULL,
  -- Each hop in the list contains an amount.
  amount_hops NUMERIC(39)[] NOT NULL,
  -- Each hop in the list contains a position ID.
  position_id_hops BYTEA[] NOT NULL
);

CREATE INDEX ON dex_ex_batch_swap_traces (time, height);
CREATE INDEX ON dex_ex_batch_swap_traces (asset_start, asset_end);

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:

    pindexer changes

@erwanor erwanor changed the title Erwan/pindexer swap execs pindexer(dex_ex): index batch swap execution traces Jan 16, 2025
@conorsch
Copy link
Contributor

To review, I've kicked off a reindex of a mainnet db using this binary. As long as that completes without error, I'll call it good enough, and get it in.

@conorsch
Copy link
Contributor

Encountered an error:

Error: error returned from database: syntax error at or near ")"

Caused by:
    syntax error at or near ")"

Investigating...

@erwanor
Copy link
Member Author

erwanor commented Jan 16, 2025

Thanks, downloading the mainnet db, it's taking a second

Comment on lines 1041 to 1043
asset_start,
asset_end,
price_float,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
asset_start,
asset_end,
price_float,
price_float,
asset_start,
asset_end,

to match the order stuff gets passed in later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@cronokirby cronokirby left a comment

Choose a reason for hiding this comment

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

I think there's currently a bug in the data insertion method.

asset_end,
asset_hops,
amount_hops,
position_id_hops,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
position_id_hops,
position_id_hops

I think this should fix the SQL error (no trailing commas allowed :()

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.

Tested again locally on e079188 (the most recent commit), and this time I was able to complete the reindex based on mainnet events. So LGTM, with the changes that have been added.

@conorsch
Copy link
Contributor

Intentionally not merging until @cronokirby has had a chance to look closely, and updates their requested-changes status.

Copy link
Contributor

@cronokirby cronokirby left a comment

Choose a reason for hiding this comment

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

All good for me!

@conorsch conorsch merged commit 1781508 into main Jan 17, 2025
15 checks passed
@conorsch conorsch deleted the erwan/pindexer_swap_execs branch January 17, 2025 17:14
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