fix(indexer): per-(tx,pair) swap ordinal so same-pair swaps aren't collapsed (#287) #752
No reviewers
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic!752
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "qa/287-swap-per-tx-ordinal"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up on #287, your approved per-tx swap-ordinal direction.
The bug:
insert_swapusedON CONFLICT (tx_hash, pair_id) DO NOTHING, so a tx emitting two swaps on the same pair (a route that revisits a pair, or batched swaps) kept only the first and silently dropped the rest.Fix:
ParsedSwapgets a deterministicswap_index(0-based, per(tx, pair), from parser walk order).ADD swap_index(backfilledrow_number()-1 OVER (PARTITION BY tx_hash, pair_id ORDER BY id)),DROPthe old(tx_hash, pair_id)unique index,CREATEthe(tx_hash, pair_id, swap_index)one.insert_swapbindsswap_index+ON CONFLICT (tx_hash, pair_id, swap_index);trade_existsscopes to it. Each swap now stores its own row/id (your "unique id per swap").Tests:
parse_swaps_assigns_per_pair_swap_index(two same-pair swaps -> 0,1; different pair restarts at 0); full indexer suite green (the one red is the pre-existingapi_hooks::hooks_list_returns_rowsshared-test-DB parallelism flake, passes single-threaded, untouched here).Honest scope note — the fill->swap linkage
swap_id_for_tx_pairstill resolvesMIN(id), so for the rare multi-swap-same-pair tx the fills point at the first swap. That's a net improvement over today (the swaps themselves are no longer lost), but making the linkage ordinal-correct needs the parser to carry the swap ordinal onto each fill (no LCD msg_index to lean on) — flagging it as the focused follow-up rather than bolting a half-association in here.Migration is additive + idempotent; it only takes effect when the new binary is deployed (the running indexer keeps its old conflict key until then). No closing keyword.
mentioned in issue #287
mentioned in commit
39a681f82fmentioned in merge request !780