From 90b0a55deef18552869151bdf2dccf8731c6aad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=BAc=C3=A1s=20Meier?= Date: Fri, 13 Sep 2024 10:03:16 -0700 Subject: [PATCH] pindexer: Allow for multiple BatchSwaps in a single block (#4853) This fixes a bug where we assumed there was only one swap per block, ignoring the fact that each trading pair will have a different batch swap. ## Checklist before requesting a review - [x] 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 --- crates/bin/pindexer/src/dex/dex.sql | 3 ++- crates/bin/pindexer/src/dex/mod.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/bin/pindexer/src/dex/dex.sql b/crates/bin/pindexer/src/dex/dex.sql index 720dbce968..a5d1c3c13d 100644 --- a/crates/bin/pindexer/src/dex/dex.sql +++ b/crates/bin/pindexer/src/dex/dex.sql @@ -116,7 +116,8 @@ CREATE TABLE IF NOT EXISTS dex_lp_execution ( --- Represents instances where swap executions happened. CREATE TABLE IF NOT EXISTS dex_batch_swap ( - height BIGINT PRIMARY KEY, + id SERIAL PRIMARY KEY, + height BIGINT NOT NULL, trace12_start INTEGER REFERENCES dex_trace (id), trace12_end INTEGER REFERENCES dex_trace (id), trace21_start INTEGER REFERENCES dex_trace (id), diff --git a/crates/bin/pindexer/src/dex/mod.rs b/crates/bin/pindexer/src/dex/mod.rs index f084a25d08..ec668d7bb8 100644 --- a/crates/bin/pindexer/src/dex/mod.rs +++ b/crates/bin/pindexer/src/dex/mod.rs @@ -368,7 +368,7 @@ impl Event { insert_swap_execution(dbtx, execution12.as_ref()).await?; let (trace21_start, trace21_end) = insert_swap_execution(dbtx, execution21.as_ref()).await?; - sqlx::query(r#"INSERT INTO dex_batch_swap VALUES ($1, $2, $3, $4, $5, $6, $7, CAST($8 AS Amount), CAST($9 AS Amount), CAST($10 AS Amount), CAST($11 AS Amount), CAST($12 AS Amount), CAST($13 AS Amount));"#) + sqlx::query(r#"INSERT INTO dex_batch_swap VALUES (DEFAULT, $1, $2, $3, $4, $5, $6, $7, CAST($8 AS Amount), CAST($9 AS Amount), CAST($10 AS Amount), CAST($11 AS Amount), CAST($12 AS Amount), CAST($13 AS Amount));"#) .bind(i64::try_from(*height)?) .bind(trace12_start) .bind(trace12_end)