Skip to content

Maintain derived trades during sync#2588

Closed
findolor wants to merge 1 commit into
graphite-base/2588from
arda/derived-trades-maintenance
Closed

Maintain derived trades during sync#2588
findolor wants to merge 1 commit into
graphite-base/2588from
arda/derived-trades-maintenance

Conversation

@findolor
Copy link
Copy Markdown
Collaborator

@findolor findolor commented May 22, 2026

Chained PRs

Depends on #2587. Stack order: #2587 -> #2588 -> #2589 -> #2590

Motivation

derived_trades must be maintained by the same local DB sync pipeline that writes source events and state, otherwise producer bootstrap DBs and client incremental syncs can diverge from read-path expectations.

Solution

  • Add upsert_derived_trades SQL and builder utilities.
  • Delete and rebuild derived rows whose trade event block is inside the sync window.
  • Allow the rebuild query to read older order_events so trade rows can resolve the latest active AddOrderV3 even when the order add predates the window.
  • Wire derived-trade maintenance into the apply transaction before the target watermark update.

Checks

  • COMMIT_SHA=local nix develop -c cargo test -p raindex_common local_db::query --lib
  • COMMIT_SHA=local nix develop -c cargo test -p raindex_common local_db::pipeline::adapters::apply --lib
  • COMMIT_SHA=local nix develop -c cargo test -p raindex_common local_db::export --lib
  • COMMIT_SHA=local nix develop -c cargo test -p raindex_common raindex_client::trades --lib

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0a65eb33-6372-434c-8d24-dc5ac0d14efa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch arda/derived-trades-maintenance

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Collaborator Author

findolor commented May 22, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label Raindex-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@findolor findolor changed the base branch from arda/derived-trades-schema to graphite-base/2588 May 23, 2026 13:46
@findolor findolor force-pushed the graphite-base/2588 branch from 46756c6 to 381599c Compare May 23, 2026 13:46
@findolor findolor force-pushed the arda/derived-trades-maintenance branch from 3124557 to 055e02d Compare May 23, 2026 13:46
@findolor findolor changed the base branch from graphite-base/2588 to arda/derived-trades-schema May 23, 2026 13:46
@findolor findolor changed the base branch from arda/derived-trades-schema to graphite-base/2588 May 23, 2026 13:55
@findolor
Copy link
Copy Markdown
Collaborator Author

Folded into #2587 so the derived-trades local DB schema generation lands atomically.

@findolor findolor closed this May 23, 2026
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.

1 participant